11using System ;
22using System . ComponentModel . DataAnnotations ;
33using FluentAssertions ;
4- using Microsoft . Extensions . Hosting ;
54using Xunit ;
5+
66// ReSharper disable UnusedMember.Global
77// ReSharper disable UnusedParameter.Global
88
@@ -22,20 +22,44 @@ public void Validate_String_Length_Test()
2222 const string optionValue = "too-large-string-value" ;
2323
2424 var args = new [ ] { nameof ( AppWithValidationAttributes . StrLength ) , $ "--{ optionName } ", optionValue } ;
25- Host . CreateDefaultBuilder ( ) . RunConsoleAppFrameworkAsync < AppWithValidationAttributes > ( args ) ;
25+ ConsoleApp . Run < AppWithValidationAttributes > ( args ) ;
2626
27- // Validation fails , so StrLength command is not executed.
28- console . Output . Should ( ) . NotContain ( AppWithValidationAttributes . StrLengthOutput ) ;
27+ // Validation should fail , so StrLength command should not be executed.
28+ console . Output . Should ( ) . NotContain ( AppWithValidationAttributes . Output ) ;
2929
3030 console . Output . Should ( ) . Contain ( optionName ) ;
3131 console . Output . Should ( ) . Contain ( optionValue ) ;
3232 }
3333
34+ [ Fact ]
35+ public void Command_With_Multiple_Params ( )
36+ {
37+ using var console = new CaptureConsoleOutput ( ) ;
38+
39+ var args = new [ ]
40+ {
41+ nameof ( AppWithValidationAttributes . MultipleParams ) ,
42+ "--second-arg" , "10" ,
43+ "--first-arg" , "invalid-email-address"
44+ } ;
45+
46+ ConsoleApp . Run < AppWithValidationAttributes > ( args ) ;
47+
48+ // Validation should fail, so StrLength command should not be executed.
49+ console . Output . Should ( ) . NotContain ( AppWithValidationAttributes . Output ) ;
50+ }
51+
3452 /// <inheritdoc />
3553 internal class AppWithValidationAttributes : ConsoleAppBase
3654 {
37- public const string StrLengthOutput = $ "hello from { nameof ( StrLength ) } ";
55+ public const string Output = $ "hello from { nameof ( AppWithValidationAttributes ) } ";
56+
57+ [ Command ( nameof ( StrLength ) ) ]
58+ public void StrLength ( [ StringLength ( maximumLength : 8 ) ] string arg ) => Console . WriteLine ( Output ) ;
3859
39- public void StrLength ( [ StringLength ( maximumLength : 8 ) ] string arg ) => Console . WriteLine ( StrLengthOutput ) ;
60+ [ Command ( nameof ( MultipleParams ) ) ]
61+ public void MultipleParams (
62+ [ EmailAddress ] string firstArg ,
63+ [ Range ( 0 , 2 ) ] int secondArg ) => Console . WriteLine ( Output ) ;
4064 }
4165}
0 commit comments