Esempio n. 1
0
        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);
        }
Esempio n. 2
0
        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));
        }
Esempio n. 3
0
        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"));
        }
Esempio n. 4
0
        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));
        }
Esempio n. 5
0
 private static Result <T> ThrowsExceptionWithContext <T>(ExceptionWithContext e) => throw e;
Esempio n. 6
0
 public static Result <TSuccess> ToResult <TSuccess>(this ExceptionWithContext input) =>
 Result.Failure <TSuccess>(input);