Skip to content

Commit 40018fb

Browse files
committed
add a binding test
1 parent 3289d65 commit 40018fb

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,28 @@ public async Task When_argument_type_is_not_known_until_binding_then_int_paramet
252252
received.Should().Be(123);
253253
}
254254

255+
[Fact]
256+
public void When_argument_type_is_more_specific_than_parameter_type_then_parameter_is_bound_correctly()
257+
{
258+
FileSystemInfo received = null;
259+
260+
var root = new RootCommand
261+
{
262+
new Option<DirectoryInfo>("-f")
263+
};
264+
root.Handler = CommandHandler.Create<FileSystemInfo>(f => received = f);
265+
var path = $"{Directory.GetCurrentDirectory()}{Path.DirectorySeparatorChar}";
266+
267+
root.Invoke($"-f {path}");
268+
269+
received.Should()
270+
.BeOfType<DirectoryInfo>()
271+
.Which
272+
.FullName
273+
.Should()
274+
.Be(path);
275+
}
276+
255277
[Theory]
256278
[InlineData(typeof(ClassWithCtorParameter<int>), false)]
257279
[InlineData(typeof(ClassWithCtorParameter<int>), true)]

0 commit comments

Comments
 (0)