@@ -107,7 +107,7 @@ public void Ensure_Description_Can_Be_Set()
107
107
108
108
const string expected = "my description" ;
109
109
110
- var cmdOption = parser . Setup < string > ( 's' ) . WithDescription ( expected ) ;
110
+ var cmdOption = parser . Setup < string > ( 's' ) . WithDescription ( expected ) ;
111
111
112
112
var actual = ( ( ICommandLineOption ) cmdOption ) . Description ;
113
113
@@ -356,39 +356,39 @@ public void Ensure_Parser_Calls_The_Callback_With_Expected_DateTime_When_Using_L
356
356
357
357
#endregion DateTime Option
358
358
359
- #region Long Option Only
359
+ #region Long Option Only
360
360
361
- [ Test ]
362
- public void Can_have_long_option_only ( )
363
- {
364
- var parser = CreateFluentParser ( ) ;
365
- var s = "" ;
361
+ [ Test ]
362
+ public void Can_have_long_option_only ( )
363
+ {
364
+ var parser = CreateFluentParser ( ) ;
365
+ var s = "" ;
366
366
367
- parser . Setup < string > ( "my-feature" )
368
- . Callback ( val => s = val ) ;
367
+ parser . Setup < string > ( "my-feature" )
368
+ . Callback ( val => s = val ) ;
369
369
370
- var result = parser . Parse ( new [ ] { "--my-feature" , "somevalue" } ) ;
370
+ var result = parser . Parse ( new [ ] { "--my-feature" , "somevalue" } ) ;
371
371
372
- Assert . IsFalse ( result . HasErrors ) ;
373
- Assert . IsFalse ( result . EmptyArgs ) ;
374
- Assert . IsFalse ( result . HelpCalled ) ;
372
+ Assert . IsFalse ( result . HasErrors ) ;
373
+ Assert . IsFalse ( result . EmptyArgs ) ;
374
+ Assert . IsFalse ( result . HelpCalled ) ;
375
375
376
- Assert . AreEqual ( "somevalue" , s ) ;
377
- }
376
+ Assert . AreEqual ( "somevalue" , s ) ;
377
+ }
378
378
379
- [ Test ]
380
- [ ExpectedException ( typeof ( ArgumentOutOfRangeException ) ) ]
381
- public void Cannot_have_single_character_long_option ( )
382
- {
383
- var parser = CreateFluentParser ( ) ;
384
- parser . Setup < string > ( "s" ) ;
385
- }
379
+ [ Test ]
380
+ [ ExpectedException ( typeof ( ArgumentOutOfRangeException ) ) ]
381
+ public void Cannot_have_single_character_long_option ( )
382
+ {
383
+ var parser = CreateFluentParser ( ) ;
384
+ parser . Setup < string > ( "s" ) ;
385
+ }
386
386
387
- #endregion
387
+ #endregion
388
388
389
- #region Required
389
+ #region Required
390
390
391
- [ Test ]
391
+ [ Test ]
392
392
public void Ensure_Expected_Error_Is_Returned_If_A_Option_Is_Required_And_Null_Args_Are_Specified ( )
393
393
{
394
394
var parser = CreateFluentParser ( ) ;
@@ -588,66 +588,66 @@ public void Ensure_Defaults_Are_Called_When_Empty_Args_Specified()
588
588
589
589
#region Example
590
590
591
- [ Test ]
592
- public void Ensure_Example_Works_As_Expected ( )
593
- {
594
- const int expectedRecordId = 10 ;
595
- const string expectedValue = "Mr. Smith" ;
596
- const bool expectedSilentMode = true ;
597
- const bool expectedSwitchA = true ;
598
- const bool expectedSwitchB = true ;
599
- const bool expectedSwitchC = false ;
600
-
601
- var args = new [ ] { "-r" , expectedRecordId . ToString ( CultureInfo . InvariantCulture ) , "-v" , "\" Mr. Smith\" " , "--silent" , "-ab" , "-c-" } ;
602
-
603
- var recordId = 0 ;
604
- string newValue = null ;
605
- var inSilentMode = false ;
606
- var switchA = false ;
607
- var switchB = false ;
608
- var switchC = true ;
609
-
610
- var parser = CreateFluentParser ( ) ;
611
-
612
- parser . Setup < bool > ( 'a' )
613
- . Callback ( value => switchA = value ) ;
614
-
615
- parser . Setup < bool > ( 'b' )
616
- . Callback ( value => switchB = value ) ;
617
-
618
- parser . Setup < bool > ( 'c' )
619
- . Callback ( value => switchC = value ) ;
620
-
621
- // create a new Option using a short and long name
622
- parser . Setup < int > ( 'r' , "record" )
623
- . WithDescription ( "The record id to update (required)" )
624
- . Callback ( record => recordId = record ) // use callback to assign the record value to the local RecordID property
625
- . Required ( ) ; // fail if this Option is not provided in the arguments
626
-
627
- parser . Setup < bool > ( "silent" )
628
- . WithDescription ( "Execute the update in silent mode without feedback (default is false)" )
629
- . Callback ( silent => inSilentMode = silent )
630
- . SetDefault ( false ) ; // explicitly set the default value to use if this Option is not specified in the arguments
631
-
632
-
633
- parser . Setup < string > ( 'v' , "value" )
634
- . WithDescription ( "The new value for the record (required)" ) // used when help is requested e.g -? or --help
635
- . Callback ( value => newValue = value )
636
- . Required ( ) ;
637
-
638
- // do the work
639
- ICommandLineParserResult result = parser . Parse ( args ) ;
640
-
641
- Assert . IsFalse ( result . HasErrors ) ;
642
- Assert . IsFalse ( result . Errors . Any ( ) ) ;
643
-
644
- Assert . AreEqual ( expectedRecordId , recordId ) ;
645
- Assert . AreEqual ( expectedValue , newValue ) ;
646
- Assert . AreEqual ( expectedSilentMode , inSilentMode ) ;
647
- Assert . AreEqual ( expectedSwitchA , switchA ) ;
648
- Assert . AreEqual ( expectedSwitchB , switchB ) ;
649
- Assert . AreEqual ( expectedSwitchC , switchC ) ;
650
- }
591
+ [ Test ]
592
+ public void Ensure_Example_Works_As_Expected ( )
593
+ {
594
+ const int expectedRecordId = 10 ;
595
+ const string expectedValue = "Mr. Smith" ;
596
+ const bool expectedSilentMode = true ;
597
+ const bool expectedSwitchA = true ;
598
+ const bool expectedSwitchB = true ;
599
+ const bool expectedSwitchC = false ;
600
+
601
+ var args = new [ ] { "-r" , expectedRecordId . ToString ( CultureInfo . InvariantCulture ) , "-v" , "\" Mr. Smith\" " , "--silent" , "-ab" , "-c-" } ;
602
+
603
+ var recordId = 0 ;
604
+ string newValue = null ;
605
+ var inSilentMode = false ;
606
+ var switchA = false ;
607
+ var switchB = false ;
608
+ var switchC = true ;
609
+
610
+ var parser = CreateFluentParser ( ) ;
611
+
612
+ parser . Setup < bool > ( 'a' )
613
+ . Callback ( value => switchA = value ) ;
614
+
615
+ parser . Setup < bool > ( 'b' )
616
+ . Callback ( value => switchB = value ) ;
617
+
618
+ parser . Setup < bool > ( 'c' )
619
+ . Callback ( value => switchC = value ) ;
620
+
621
+ // create a new Option using a short and long name
622
+ parser . Setup < int > ( 'r' , "record" )
623
+ . WithDescription ( "The record id to update (required)" )
624
+ . Callback ( record => recordId = record ) // use callback to assign the record value to the local RecordID property
625
+ . Required ( ) ; // fail if this Option is not provided in the arguments
626
+
627
+ parser . Setup < bool > ( "silent" )
628
+ . WithDescription ( "Execute the update in silent mode without feedback (default is false)" )
629
+ . Callback ( silent => inSilentMode = silent )
630
+ . SetDefault ( false ) ; // explicitly set the default value to use if this Option is not specified in the arguments
631
+
632
+
633
+ parser . Setup < string > ( 'v' , "value" )
634
+ . WithDescription ( "The new value for the record (required)" ) // used when help is requested e.g -? or --help
635
+ . Callback ( value => newValue = value )
636
+ . Required ( ) ;
637
+
638
+ // do the work
639
+ ICommandLineParserResult result = parser . Parse ( args ) ;
640
+
641
+ Assert . IsFalse ( result . HasErrors ) ;
642
+ Assert . IsFalse ( result . Errors . Any ( ) ) ;
643
+
644
+ Assert . AreEqual ( expectedRecordId , recordId ) ;
645
+ Assert . AreEqual ( expectedValue , newValue ) ;
646
+ Assert . AreEqual ( expectedSilentMode , inSilentMode ) ;
647
+ Assert . AreEqual ( expectedSwitchA , switchA ) ;
648
+ Assert . AreEqual ( expectedSwitchB , switchB ) ;
649
+ Assert . AreEqual ( expectedSwitchC , switchC ) ;
650
+ }
651
651
652
652
#endregion
653
653
0 commit comments