mirror of
https://github.com/nsnail/spectre.console.git
synced 2025-06-19 13:28:16 +08:00
Implemented AddAsyncDelegate
(#766)
This commit is contained in:
@ -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();
|
||||
|
Reference in New Issue
Block a user