public void MatchFailure_Calls_Action_For_Failure() { var ex = new ExceptionWithContext(); var sut = Result.Failure <int>(ex); object actual = null; sut.DoOnFailure(o => actual = o); actual.ShouldBeSameAs(ex); }
public void Match_Executes_On_Failure_Value_If_Instance_Is_a_Failure() { var ex = new ExceptionWithContext(); var sut = Result.Failure <string>(ex); sut.Match( _ => Assert.True(false, "Function called on either"), o => o.ShouldBeSameAs(ex)); }
public void Two_Results_Are_Equal_If_Their_Failure_Values_Are_Equal() { var ex = new ExceptionWithContext(); var value = Result.Failure <int>(ex); var otherValue = Result.Failure <int>(ex); value.ShouldSatisfyAllConditions( () => value.ShouldBeStructuralEqual(otherValue), () => (value == otherValue).ShouldBe(true, "value == otherValue"), () => (value != otherValue).ShouldBe(false, "value != otherValue")); }
public void Test_Linq_comprehension_for_generic_ExceptionWithContext_case() { var exceptionToThrow = new ExceptionWithContext("Error", null); var actual = from r1 in Result.Success(42) from r2 in ThrowsExceptionWithContext <string>(exceptionToThrow) select r2; actual.Match( _ => Assert.True(false, "Success Should not happen"), e => e.ShouldBe(exceptionToThrow)); }
private static Result <T> ThrowsExceptionWithContext <T>(ExceptionWithContext e) => throw e;
public static Result <TSuccess> ToResult <TSuccess>(this ExceptionWithContext input) => Result.Failure <TSuccess>(input);