Skip to content

Commit 9b9bb07

Browse files
committed
add a test
1 parent 0e8fcf3 commit 9b9bb07

File tree

2 files changed

+25
-10
lines changed

2 files changed

+25
-10
lines changed

src/System.CommandLine.Tests/Binding/ModelBindingCommandHandlerTests.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff 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)]

src/System.CommandLine.Tests/OptionTests.cs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,15 @@
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;
54
using System.CommandLine.Parsing;
65
using System.Linq;
76
using FluentAssertions;
87
using Xunit;
9-
using Xunit.Abstractions;
108

119
namespace 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
}

0 commit comments

Comments
 (0)