From 719b4e85f55aaa8eeefbb48fb45a2acf80bc7f99 Mon Sep 17 00:00:00 2001 From: JustFixMe Date: Mon, 18 Dec 2023 20:55:48 +0400 Subject: [PATCH] extended recover tests --- Railway/Error.cs | 7 +++++-- Raliway.Tests/Results/GeneralUsage.cs | 16 ++++++++++++++-- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/Railway/Error.cs b/Railway/Error.cs index d22cad3..523da7d 100644 --- a/Railway/Error.cs +++ b/Railway/Error.cs @@ -178,14 +178,17 @@ public sealed class ExceptionalError : Error { internal readonly Exception? Exception; + [Pure, MethodImpl(MethodImplOptions.AggressiveInlining)] + internal static string ToErrorType(Type exceptionType) => exceptionType.FullName ?? exceptionType.Name; + internal ExceptionalError(Exception exception) - : this(exception.GetType().FullName ?? exception.GetType().Name, exception.Message) + : this(ToErrorType(exception.GetType()), exception.Message) { Exception = exception; ExtensionData = ExtractExtensionData(exception); } internal ExceptionalError(string message, Exception exception) - : this(exception.GetType().FullName ?? exception.GetType().Name, message) + : this(ToErrorType(exception.GetType()), message) { Exception = exception; ExtensionData = ExtractExtensionData(exception); diff --git a/Raliway.Tests/Results/GeneralUsage.cs b/Raliway.Tests/Results/GeneralUsage.cs index 6784ce0..3f2d35e 100644 --- a/Raliway.Tests/Results/GeneralUsage.cs +++ b/Raliway.Tests/Results/GeneralUsage.cs @@ -138,7 +138,12 @@ public class GeneralUsage var result = failed.TryRecover(err => { Assert.IsType(err.ToException()); - return "recovered"; + + if (err.Type == "System.NotImplementedException") + return "recovered"; + + Assert.Fail(); + return ""; }); // Then Assert.True(result.IsSuccess); @@ -152,7 +157,14 @@ public class GeneralUsage var error = Error.New("test"); Result failed = new NotImplementedException(); // When - var result = failed.TryRecover(err => error); + var result = failed.TryRecover(err => + { + if (err.Type == "System.NotImplementedException") + return error; + + Assert.Fail(); + return ""; + }); // Then Assert.True(result.IsFailure); Assert.Equal(error, result.Error);