File tree Expand file tree Collapse file tree 2 files changed +25
-10
lines changed
src/System.CommandLine.Tests Expand file tree Collapse file tree 2 files changed +25
-10
lines changed Original file line number Diff line number Diff line change @@ -132,6 +132,30 @@ await handler.InvokeAsync(
132132 console . Out . ToString ( ) . Should ( ) . Be ( $ "ClassWithCtorParameter<{ type . Name } >: { expectedValue } ") ;
133133 }
134134
135+ [ Fact ]
136+ public void When_name_is_not_among_aliases_then_binder_will_bind_option_by_name ( )
137+ {
138+ var rootCommand = new RootCommand
139+ {
140+ new Option ( "-n" )
141+ {
142+ Argument = new Argument < string [ ] > ( "header" ) ,
143+ Name = "name"
144+ }
145+ } ;
146+
147+ string [ ] receivedHeaders = null ;
148+
149+ rootCommand . Handler = CommandHandler . Create ( ( string [ ] name ) =>
150+ {
151+ receivedHeaders = name ;
152+ } ) ;
153+
154+ rootCommand . Invoke ( "-n one -n two" ) ;
155+
156+ receivedHeaders . Should ( ) . BeEquivalentTo ( "one" , "two" ) ;
157+ }
158+
135159 [ Theory ]
136160 [ InlineData ( typeof ( string ) , "hello" , "hello" ) ]
137161 [ InlineData ( typeof ( int ) , "123" , 123 ) ]
Original file line number Diff line number Diff line change 11// Copyright (c) .NET Foundation and contributors. All rights reserved.
22// Licensed under the MIT license. See LICENSE file in the project root for full license information.
33
4- using System . CommandLine . Invocation ;
54using System . CommandLine . Parsing ;
65using System . Linq ;
76using FluentAssertions ;
87using Xunit ;
9- using Xunit . Abstractions ;
108
119namespace System . CommandLine . Tests
1210{
1311 public class OptionTests : SymbolTests
1412 {
15- private ITestOutputHelper _output ;
16-
17- public OptionTests ( ITestOutputHelper output )
18- {
19- _output = output ;
20- }
21-
2213 [ Fact ]
2314 public void When_an_option_has_only_one_alias_then_that_alias_is_its_name ( )
2415 {
@@ -343,7 +334,7 @@ public void Option_T_default_value_is_validated()
343334 . BeEquivalentTo ( new [ ] { "ERR" } ) ;
344335
345336 }
346-
337+
347338 protected override Symbol CreateSymbol ( string name ) => new Option ( name ) ;
348339 }
349340}
You can’t perform that action at this time.
0 commit comments