Implemented AddAsyncDelegate (#766)

This commit is contained in:
Ignacio Calvo
2023-05-25 12:31:01 +02:00
committed by GitHub
parent 0ec70a44db
commit 35ce60b596
13 changed files with 859 additions and 675 deletions

View File

@ -1127,6 +1127,37 @@ public sealed partial class CommandAppTests
// When
var result = app.Run(new[] { "foo", "4", "12" });
// Then
result.ShouldBe(1);
dog.ShouldNotBeNull();
dog.Age.ShouldBe(12);
dog.Legs.ShouldBe(4);
data.ShouldBe(2);
}
[Fact]
public async void Should_Execute_Async_Delegate_Command_At_Root_Level()
{
// Given
var dog = default(DogSettings);
var data = 0;
var app = new CommandApp();
app.Configure(config =>
{
config.PropagateExceptions();
config.AddAsyncDelegate<DogSettings>(
"foo", (context, settings) =>
{
dog = settings;
data = (int)context.Data;
return Task.FromResult(1);
}).WithData(2);
});
// When
var result = await app.RunAsync(new[] { "foo", "4", "12" });
// Then
result.ShouldBe(1);
dog.ShouldNotBeNull();
@ -1161,6 +1192,40 @@ public sealed partial class CommandAppTests
// When
var result = app.Run(new[] { "foo", "4", "bar", "12" });
// Then
result.ShouldBe(1);
dog.ShouldNotBeNull();
dog.Age.ShouldBe(12);
dog.Legs.ShouldBe(4);
data.ShouldBe(2);
}
[Fact]
public async void Should_Execute_Nested_Async_Delegate_Command()
{
// Given
var dog = default(DogSettings);
var data = 0;
var app = new CommandApp();
app.Configure(config =>
{
config.PropagateExceptions();
config.AddBranch<AnimalSettings>("foo", foo =>
{
foo.AddAsyncDelegate<DogSettings>(
"bar", (context, settings) =>
{
dog = settings;
data = (int)context.Data;
return Task.FromResult(1);
}).WithData(2);
});
});
// When
var result = await app.RunAsync(new[] { "foo", "4", "bar", "12" });
// Then
result.ShouldBe(1);
dog.ShouldNotBeNull();