mirror of
https://github.com/nsnail/spectre.console.git
synced 2025-06-19 13:28:16 +08:00
Added the ITypeResolver to the ExceptionHandler (#1411)
This commit is contained in:
@ -51,7 +51,7 @@ public sealed partial class CommandAppTests
|
||||
app.Configure(config =>
|
||||
{
|
||||
config.AddCommand<ThrowingCommand>("throw");
|
||||
config.SetExceptionHandler(_ =>
|
||||
config.SetExceptionHandler((_, _) =>
|
||||
{
|
||||
exceptionHandled = true;
|
||||
});
|
||||
@ -74,7 +74,7 @@ public sealed partial class CommandAppTests
|
||||
app.Configure(config =>
|
||||
{
|
||||
config.AddCommand<ThrowingCommand>("throw");
|
||||
config.SetExceptionHandler(_ =>
|
||||
config.SetExceptionHandler((_, _) =>
|
||||
{
|
||||
exceptionHandled = true;
|
||||
return -99;
|
||||
@ -88,5 +88,49 @@ public sealed partial class CommandAppTests
|
||||
result.ExitCode.ShouldBe(-99);
|
||||
exceptionHandled.ShouldBeTrue();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Should_Have_Resolver_Set_When_Exception_Occurs_In_Command_Execution()
|
||||
{
|
||||
// Given
|
||||
ITypeResolver resolver = null;
|
||||
var app = new CommandAppTester();
|
||||
app.Configure(config =>
|
||||
{
|
||||
config.AddCommand<ThrowingCommand>("throw");
|
||||
config.SetExceptionHandler((_, r) =>
|
||||
{
|
||||
resolver = r;
|
||||
});
|
||||
});
|
||||
|
||||
// When
|
||||
app.Run(new[] { "throw" });
|
||||
|
||||
// Then
|
||||
resolver.ShouldNotBeNull();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Should_Not_Have_Resolver_Set_When_Exception_Occurs_Before_Command_Execution()
|
||||
{
|
||||
// Given
|
||||
ITypeResolver resolver = null;
|
||||
var app = new CommandAppTester();
|
||||
app.Configure(config =>
|
||||
{
|
||||
config.AddCommand<DogCommand>("Лайка");
|
||||
config.SetExceptionHandler((_, r) =>
|
||||
{
|
||||
resolver = r;
|
||||
});
|
||||
});
|
||||
|
||||
// When
|
||||
app.Run(new[] { "throw", "on", "arg", "parsing" });
|
||||
|
||||
// Then
|
||||
resolver.ShouldBeNull();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user