@@ -167,24 +167,6 @@ public void Parse()
167167 Assert . NotEmpty ( test ) ;
168168 }
169169
170- /// <summary>
171- /// Tests the <see cref="Utility.CommandLine.Arguments.Parse(string)"/> method with an explicit operand delimiter.
172- /// </summary>
173- [ Fact ]
174- public void ParseStrictOperands ( )
175- {
176- CommandLine . Arguments test = CommandLine . Arguments . Parse ( "--test one two -- three -four --five /six \" seven eight\" 'nine ten'" ) ;
177-
178- Assert . Equal ( 7 , test . OperandList . Count ) ;
179- Assert . Equal ( "two" , test . OperandList [ 0 ] ) ;
180- Assert . Equal ( "three" , test . OperandList [ 1 ] ) ;
181- Assert . Equal ( "-four" , test . OperandList [ 2 ] ) ;
182- Assert . Equal ( "--five" , test . OperandList [ 3 ] ) ;
183- Assert . Equal ( "/six" , test . OperandList [ 4 ] ) ;
184- Assert . Equal ( "\" seven eight\" " , test . OperandList [ 5 ] ) ;
185- Assert . Equal ( "'nine ten'" , test . OperandList [ 6 ] ) ;
186- }
187-
188170 /// <summary>
189171 /// Tests the <see cref="Utility.CommandLine.Arguments.Parse(string)"/> method with an explicit command line string
190172 /// containing a mixture of upper and lower case arguments.
@@ -207,6 +189,17 @@ public void ParseCaseSensitive()
207189 Assert . False ( test . ContainsKey ( "C" ) ) ;
208190 }
209191
192+ /// <summary>
193+ /// Tests the <see cref="Utility.CommandLine.Arguments.Parse(string)"/> method with an empty string.
194+ /// </summary>
195+ [ Fact ]
196+ public void ParseEmpty ( )
197+ {
198+ Exception ex = Record . Exception ( ( ) => CommandLine . Arguments . Parse ( string . Empty ) ) ;
199+
200+ Assert . Null ( ex ) ;
201+ }
202+
210203 /// <summary>
211204 /// Tests the <see cref="Utility.CommandLine.Arguments.Parse(string)"/> method with an explicit command line string
212205 /// containing values with inner quoted strings.
@@ -265,6 +258,17 @@ public void ParseMultipleQuotes()
265258 Assert . Equal ( "4" , test [ "test4" ] ) ;
266259 }
267260
261+ /// <summary>
262+ /// Tests the <see cref="Utility.CommandLine.Arguments.Parse(string)"/> method with a null argument.
263+ /// </summary>
264+ [ Fact ]
265+ public void ParseNull ( )
266+ {
267+ Exception ex = Record . Exception ( ( ) => CommandLine . Arguments . Parse ( null ) ) ;
268+
269+ Assert . Null ( ex ) ;
270+ }
271+
268272 /// <summary>
269273 /// Tests the <see cref="Utility.CommandLine.Arguments.Parse(string)"/> method with a string containing only a series
270274 /// of operands.
@@ -324,6 +328,37 @@ public void ParseShorts()
324328 Assert . Equal ( "hello world" , test [ "c" ] ) ;
325329 }
326330
331+ /// <summary>
332+ /// Tests the <see cref="Utility.CommandLine.Arguments.Parse(string)"/> method with an explicit operand delimiter.
333+ /// </summary>
334+ [ Fact ]
335+ public void ParseStrictOperands ( )
336+ {
337+ CommandLine . Arguments test = CommandLine . Arguments . Parse ( "--test one two -- three -four --five /six \" seven eight\" 'nine ten'" ) ;
338+
339+ Assert . Equal ( 7 , test . OperandList . Count ) ;
340+ Assert . Equal ( "two" , test . OperandList [ 0 ] ) ;
341+ Assert . Equal ( "three" , test . OperandList [ 1 ] ) ;
342+ Assert . Equal ( "-four" , test . OperandList [ 2 ] ) ;
343+ Assert . Equal ( "--five" , test . OperandList [ 3 ] ) ;
344+ Assert . Equal ( "/six" , test . OperandList [ 4 ] ) ;
345+ Assert . Equal ( "\" seven eight\" " , test . OperandList [ 5 ] ) ;
346+ Assert . Equal ( "'nine ten'" , test . OperandList [ 6 ] ) ;
347+ }
348+
349+ /// <summary>
350+ /// Tests the <see cref="Utility.CommandLine.Arguments.Parse(string)"/> method with an explicit operand delimiter, and
351+ /// nothing after the delimiter.
352+ /// </summary>
353+ [ Fact ]
354+ public void ParseStrictOperandsEmpty ( )
355+ {
356+ CommandLine . Arguments test = CommandLine . Arguments . Parse ( "--test one two -- " ) ;
357+
358+ Assert . Equal ( 1 , test . OperandList . Count ) ;
359+ Assert . Equal ( "two" , test . OperandList [ 0 ] ) ;
360+ }
361+
327362 /// <summary>
328363 /// Tests the <see cref="Utility.CommandLine.Arguments.Parse(string)"/> method with an explicit command line string
329364 /// containing only long parameters.
@@ -459,6 +494,20 @@ public void PopulateTypeMismatch()
459494 Assert . IsType < ArgumentException > ( ex ) ;
460495 }
461496
497+ /// <summary>
498+ /// Tests the <see cref="Utility.CommandLine.Arguments.Populate(Type, string)"/> method with a Type external to the
499+ /// calling class and with an explicit string.
500+ /// </summary>
501+ [ Fact ]
502+ public void PopulateExternalClass ( )
503+ {
504+ CommandLine . Arguments . Populate ( typeof ( TestClassPublicProperties ) , "--test test! operand1 operand2" ) ;
505+
506+ Assert . Equal ( "test!" , TestClassPublicProperties . Test ) ;
507+ Assert . Equal ( "operand1" , TestClassPublicProperties . Operands [ 0 ] ) ;
508+ Assert . Equal ( "operand2" , TestClassPublicProperties . Operands [ 1 ] ) ;
509+ }
510+
462511 #endregion Public Methods
463512 }
464513
@@ -497,7 +546,7 @@ public class TestClassWithArrayOperands
497546 /// Gets or sets a test property.
498547 /// </summary>
499548 [ CommandLine . Operands ]
500- private static string [ ] Operands { get ; set ; }
549+ public static string [ ] Operands { get ; set ; }
501550
502551 #endregion Private Properties
503552
@@ -581,4 +630,23 @@ public void Populate()
581630
582631 #endregion Public Methods
583632 }
633+
634+ /// <summary>
635+ /// Unit tests for the <see cref="CommandLine.Arguments"/> class.
636+ /// </summary>
637+ /// <remarks>Used to facilitate testing of a class with public properties.</remarks>
638+ public class TestClassPublicProperties
639+ {
640+ /// <summary>
641+ /// Gets or sets a test property.
642+ /// </summary>
643+ [ CommandLine . Argument ( 't' , "test" ) ]
644+ public static string Test { get ; set ; }
645+
646+ /// <summary>
647+ /// Gets or sets a test property.
648+ /// </summary>
649+ [ CommandLine . Operands ]
650+ public static string [ ] Operands { get ; set ; }
651+ }
584652}
0 commit comments