public void ResolvedWithDefaultErr_UnwrapValueThrowsException() { Resolved <int> resolved = Resolved.ErrAsIEnumerable(new Exception()); Assert.Throws(typeof(InvalidOperationException), () => resolved.Unwrap()); }
public void ResolvedWithDefaultErr_ForwardErrThroughTheChain() { string errorMessage = "Forwarded Err"; Resolved resolved = Resolved.ErrAsIEnumerable(new Exception(errorMessage)); var result = resolved .Match( Ok: () => Resolved.Ok(), Err: Behavior.Forward ) .Match( Ok: () => Resolved.Ok(), Err: Behavior.Forward ) .Match <int>( Ok: () => Resolved.Ok(1), Err: Behavior.Forward ); Assert.AreEqual(typeof(Err), result.Value.GetType()); var err = (Err)result.Value; Assert.AreEqual(err.Value.First().Message, errorMessage); }
public void ErrAsIEnumerable_ReturnsResolvedWithDefaultErr() { Resolved resolved = Resolved.ErrAsIEnumerable(new Exception()); Assert.IsTrue(resolved.IsErr); resolved.Match( Ok: () => Assert.Fail("Unexpected error"), Err: (err) => Assert.IsTrue(err.GetType().GetInterfaces().Contains(typeof(IEnumerable <Exception>))) ); }