Пример #1
0
        void Failure_Throws()
        {
            Failure<string> fail = new Failure<string>(new TestException());
            Assert.Throws<TestException>(() => fail.GetOrThrow());
            Assert.IsType<TestException>(fail.Exception);
            Assert.Equal("TestException :)", fail.Convert((s) => "success? " + s, (e) => "TestException :)"));

            Try<string> thend = fail.Then((succ) => succ);
            Assert.Throws<TestException>(() => thend.GetOrThrow());
            Assert.Equal("Fail", thend.Convert((s) => "succeeded", (e) => "Fail"));

            Try<string> successThen = fail.Then((succ) => "S", (e) => "F");
            Assert.Equal("F", successThen.GetOrThrow());
            Assert.IsType<Success<string>>(successThen);

            Try<string> kindaFail = fail.Then((succ) => "S", (e) => { throw new TestException2(); });
            Assert.Throws<TestException2>(() => kindaFail.GetOrThrow());
        }
Пример #2
0
        void Failure_Throws()
        {
            Failure <string> fail = new Failure <string>(new TestException());

            Assert.Throws <TestException>(() => fail.GetOrThrow());
            Assert.IsType <TestException>(fail.Exception);
            Assert.Equal("TestException :)", fail.Convert((s) => "success? " + s, (e) => "TestException :)"));

            Try <string> thend = fail.Then((succ) => succ);

            Assert.Throws <TestException>(() => thend.GetOrThrow());
            Assert.Equal("Fail", thend.Convert((s) => "succeeded", (e) => "Fail"));

            Try <string> successThen = fail.Then((succ) => "S", (e) => "F");

            Assert.Equal("F", successThen.GetOrThrow());
            Assert.IsType <Success <string> >(successThen);

            Try <string> kindaFail = fail.Then((succ) => "S", (e) => { throw new TestException2(); });

            Assert.Throws <TestException2>(() => kindaFail.GetOrThrow());
        }