extended recover tests
This commit is contained in:
@@ -178,14 +178,17 @@ public sealed class ExceptionalError : Error
|
|||||||
{
|
{
|
||||||
internal readonly Exception? Exception;
|
internal readonly Exception? Exception;
|
||||||
|
|
||||||
|
[Pure, MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
internal static string ToErrorType(Type exceptionType) => exceptionType.FullName ?? exceptionType.Name;
|
||||||
|
|
||||||
internal ExceptionalError(Exception exception)
|
internal ExceptionalError(Exception exception)
|
||||||
: this(exception.GetType().FullName ?? exception.GetType().Name, exception.Message)
|
: this(ToErrorType(exception.GetType()), exception.Message)
|
||||||
{
|
{
|
||||||
Exception = exception;
|
Exception = exception;
|
||||||
ExtensionData = ExtractExtensionData(exception);
|
ExtensionData = ExtractExtensionData(exception);
|
||||||
}
|
}
|
||||||
internal ExceptionalError(string message, Exception exception)
|
internal ExceptionalError(string message, Exception exception)
|
||||||
: this(exception.GetType().FullName ?? exception.GetType().Name, message)
|
: this(ToErrorType(exception.GetType()), message)
|
||||||
{
|
{
|
||||||
Exception = exception;
|
Exception = exception;
|
||||||
ExtensionData = ExtractExtensionData(exception);
|
ExtensionData = ExtractExtensionData(exception);
|
||||||
|
|||||||
@@ -138,7 +138,12 @@ public class GeneralUsage
|
|||||||
var result = failed.TryRecover(err =>
|
var result = failed.TryRecover(err =>
|
||||||
{
|
{
|
||||||
Assert.IsType<NotImplementedException>(err.ToException());
|
Assert.IsType<NotImplementedException>(err.ToException());
|
||||||
return "recovered";
|
|
||||||
|
if (err.Type == "System.NotImplementedException")
|
||||||
|
return "recovered";
|
||||||
|
|
||||||
|
Assert.Fail();
|
||||||
|
return "";
|
||||||
});
|
});
|
||||||
// Then
|
// Then
|
||||||
Assert.True(result.IsSuccess);
|
Assert.True(result.IsSuccess);
|
||||||
@@ -152,7 +157,14 @@ public class GeneralUsage
|
|||||||
var error = Error.New("test");
|
var error = Error.New("test");
|
||||||
Result<string> failed = new NotImplementedException();
|
Result<string> failed = new NotImplementedException();
|
||||||
// When
|
// When
|
||||||
var result = failed.TryRecover(err => error);
|
var result = failed.TryRecover(err =>
|
||||||
|
{
|
||||||
|
if (err.Type == "System.NotImplementedException")
|
||||||
|
return error;
|
||||||
|
|
||||||
|
Assert.Fail();
|
||||||
|
return "";
|
||||||
|
});
|
||||||
// Then
|
// Then
|
||||||
Assert.True(result.IsFailure);
|
Assert.True(result.IsFailure);
|
||||||
Assert.Equal(error, result.Error);
|
Assert.Equal(error, result.Error);
|
||||||
|
|||||||
Reference in New Issue
Block a user