示例#1
0
        public void ResolvedWithDefaultErr_UnwrapValueThrowsException()
        {
            Resolved <int> resolved = Resolved.ErrAsIEnumerable(new Exception());

            Assert.Throws(typeof(InvalidOperationException),
                          () => resolved.Unwrap());
        }
示例#2
0
        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);
        }
示例#3
0
        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>)))
                );
        }