@@ -189,6 +189,18 @@ public void ParseCaseSensitive()
189189 Assert . False ( test . ContainsKey ( "C" ) ) ;
190190 }
191191
192+ /// <summary>
193+ /// Tests the <see cref="Utility.CommandLine.Arguments.Parse(string)"/> method with a string coning a single operand
194+ /// which contains a dash.
195+ /// </summary>
196+ [ Fact ]
197+ public void ParseDashedOperand ( )
198+ {
199+ CommandLine . Arguments test = CommandLine . Arguments . Parse ( "hello-world" ) ;
200+
201+ Assert . Equal ( "hello-world" , test . OperandList [ 0 ] ) ;
202+ }
203+
192204 /// <summary>
193205 /// Tests the <see cref="Utility.CommandLine.Arguments.Parse(string)"/> method with an empty string.
194206 /// </summary>
@@ -309,18 +321,6 @@ public void ParseOperands()
309321 Assert . Equal ( "four" , test . OperandList [ 2 ] ) ;
310322 }
311323
312- /// <summary>
313- /// Tests the <see cref="Utility.CommandLine.Arguments.Parse(string)"/> method with a string coning a single operand
314- /// which contains a dash.
315- /// </summary>
316- [ Fact ]
317- public void ParseDashedOperand ( )
318- {
319- CommandLine . Arguments test = CommandLine . Arguments . Parse ( "hello-world" ) ;
320-
321- Assert . Equal ( "hello-world" , test . OperandList [ 0 ] ) ;
322- }
323-
324324 /// <summary>
325325 /// Tests the <see cref="Utility.CommandLine.Arguments.Parse(string)"/> method with an explicit command line string
326326 /// containing only short parameters.
@@ -443,6 +443,35 @@ public void PopulateDictionary()
443443 Assert . Equal ( 1 , Integer ) ;
444444 }
445445
446+ /// <summary>
447+ /// Tests the <see cref="Utility.CommandLine.Arguments.Populate(Type, string)"/> method with an explicit command line
448+ /// string and with a class containing duplicate properties.
449+ /// </summary>
450+ [ Fact ]
451+ public void PopulateDuplicateProperties ( )
452+ {
453+ Exception ex = Record . Exception ( ( ) => CommandLine . Arguments . Populate ( typeof ( TestClassDuplicateProperties ) , "--hello world" ) ) ;
454+
455+ Assert . Null ( ex ) ;
456+
457+ Assert . Equal ( "world" , TestClassDuplicateProperties . Test1 ) ;
458+ Assert . Equal ( default ( string ) , TestClassDuplicateProperties . Test2 ) ;
459+ }
460+
461+ /// <summary>
462+ /// Tests the <see cref="Utility.CommandLine.Arguments.Populate(Type, string)"/> method with a Type external to the
463+ /// calling class and with an explicit string.
464+ /// </summary>
465+ [ Fact ]
466+ public void PopulateExternalClass ( )
467+ {
468+ CommandLine . Arguments . Populate ( typeof ( TestClassPublicProperties ) , "--test test! operand1 operand2" ) ;
469+
470+ Assert . Equal ( "test!" , TestClassPublicProperties . Test ) ;
471+ Assert . Equal ( "operand1" , TestClassPublicProperties . Operands [ 0 ] ) ;
472+ Assert . Equal ( "operand2" , TestClassPublicProperties . Operands [ 1 ] ) ;
473+ }
474+
446475 /// <summary>
447476 /// Tests the <see cref="Utility.CommandLine.Arguments.Populate(Type, string)"/> method with an explicit command line
448477 /// string containing two operands.
@@ -506,20 +535,6 @@ public void PopulateTypeMismatch()
506535 Assert . IsType < ArgumentException > ( ex ) ;
507536 }
508537
509- /// <summary>
510- /// Tests the <see cref="Utility.CommandLine.Arguments.Populate(Type, string)"/> method with a Type external to the
511- /// calling class and with an explicit string.
512- /// </summary>
513- [ Fact ]
514- public void PopulateExternalClass ( )
515- {
516- CommandLine . Arguments . Populate ( typeof ( TestClassPublicProperties ) , "--test test! operand1 operand2" ) ;
517-
518- Assert . Equal ( "test!" , TestClassPublicProperties . Test ) ;
519- Assert . Equal ( "operand1" , TestClassPublicProperties . Operands [ 0 ] ) ;
520- Assert . Equal ( "operand2" , TestClassPublicProperties . Operands [ 1 ] ) ;
521- }
522-
523538 #endregion Public Methods
524539 }
525540
@@ -543,6 +558,52 @@ public void Constructor()
543558 #endregion Public Methods
544559 }
545560
561+ /// <summary>
562+ /// Unit tests for the <see cref="CommandLine.Arguments"/> class.
563+ /// </summary>
564+ /// <remarks>Used to facilitate testing of a class with duplicate properties.</remarks>
565+ public class TestClassDuplicateProperties
566+ {
567+ #region Public Properties
568+
569+ /// <summary>
570+ /// Gets or sets a test property.
571+ /// </summary>
572+ [ CommandLine . Argument ( 'h' , "hello" ) ]
573+ public static string Test1 { get ; set ; }
574+
575+ /// <summary>
576+ /// Gets or sets a test property.
577+ /// </summary>
578+ [ CommandLine . Argument ( 'h' , "hello" ) ]
579+ public static string Test2 { get ; set ; }
580+
581+ #endregion Public Properties
582+ }
583+
584+ /// <summary>
585+ /// Unit tests for the <see cref="CommandLine.Arguments"/> class.
586+ /// </summary>
587+ /// <remarks>Used to facilitate testing of a class with public properties.</remarks>
588+ public class TestClassPublicProperties
589+ {
590+ #region Public Properties
591+
592+ /// <summary>
593+ /// Gets or sets a test property.
594+ /// </summary>
595+ [ CommandLine . Operands ]
596+ public static string [ ] Operands { get ; set ; }
597+
598+ /// <summary>
599+ /// Gets or sets a test property.
600+ /// </summary>
601+ [ CommandLine . Argument ( 't' , "test" ) ]
602+ public static string Test { get ; set ; }
603+
604+ #endregion Public Properties
605+ }
606+
546607 /// <summary>
547608 /// Unit tests for the <see cref="CommandLine.Arguments"/> class.
548609 /// </summary>
@@ -552,15 +613,15 @@ public void Constructor()
552613 [ Collection ( "Arguments" ) ]
553614 public class TestClassWithArrayOperands
554615 {
555- #region Private Properties
616+ #region Public Properties
556617
557618 /// <summary>
558619 /// Gets or sets a test property.
559620 /// </summary>
560621 [ CommandLine . Operands ]
561622 public static string [ ] Operands { get ; set ; }
562623
563- #endregion Private Properties
624+ #endregion Public Properties
564625
565626 #region Public Methods
566627
@@ -642,23 +703,4 @@ public void Populate()
642703
643704 #endregion Public Methods
644705 }
645-
646- /// <summary>
647- /// Unit tests for the <see cref="CommandLine.Arguments"/> class.
648- /// </summary>
649- /// <remarks>Used to facilitate testing of a class with public properties.</remarks>
650- public class TestClassPublicProperties
651- {
652- /// <summary>
653- /// Gets or sets a test property.
654- /// </summary>
655- [ CommandLine . Argument ( 't' , "test" ) ]
656- public static string Test { get ; set ; }
657-
658- /// <summary>
659- /// Gets or sets a test property.
660- /// </summary>
661- [ CommandLine . Operands ]
662- public static string [ ] Operands { get ; set ; }
663- }
664706}
0 commit comments