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(
132
132
console . Out . ToString ( ) . Should ( ) . Be ( $ "ClassWithCtorParameter<{ type . Name } >: { expectedValue } ") ;
133
133
}
134
134
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
+
135
159
[ Theory ]
136
160
[ InlineData ( typeof ( string ) , "hello" , "hello" ) ]
137
161
[ InlineData ( typeof ( int ) , "123" , 123 ) ]
Original file line number Diff line number Diff line change 1
1
// Copyright (c) .NET Foundation and contributors. All rights reserved.
2
2
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3
3
4
- using System . CommandLine . Invocation ;
5
4
using System . CommandLine . Parsing ;
6
5
using System . Linq ;
7
6
using FluentAssertions ;
8
7
using Xunit ;
9
- using Xunit . Abstractions ;
10
8
11
9
namespace System . CommandLine . Tests
12
10
{
13
11
public class OptionTests : SymbolTests
14
12
{
15
- private ITestOutputHelper _output ;
16
-
17
- public OptionTests ( ITestOutputHelper output )
18
- {
19
- _output = output ;
20
- }
21
-
22
13
[ Fact ]
23
14
public void When_an_option_has_only_one_alias_then_that_alias_is_its_name ( )
24
15
{
@@ -343,7 +334,7 @@ public void Option_T_default_value_is_validated()
343
334
. BeEquivalentTo ( new [ ] { "ERR" } ) ;
344
335
345
336
}
346
-
337
+
347
338
protected override Symbol CreateSymbol ( string name ) => new Option ( name ) ;
348
339
}
349
340
}
You can’t perform that action at this time.
0 commit comments