Ejemplo n.º 1
0
        public void ExnToResultFunc()
        {
            var f0 = new Func<int>(() =>  + 0);
            var g0 = f0.ExnToResultFunc();
            Assert.That(g0(), Is.EqualTo(Result.NewSuccess<int, Exception>( + 0)));
            f0 = new Func<int>(() => { throw new MyException(); });
            g0 = f0.ExnToResultFunc();
            Assert.That(g0(), Is.EqualTo(Result.NewFailure<int, Exception>(new MyException())));

            var f1 = new Func<int, int>((a1) => a1 + 0);
            var g1 = f1.ExnToResultFunc();
            Assert.That(g1(1), Is.EqualTo(Result.NewSuccess<int, Exception>(1 + 0)));
            f1 = new Func<int, int>((a1) => { throw new MyException(); });
            g1 = f1.ExnToResultFunc();
            Assert.That(g1(1), Is.EqualTo(Result.NewFailure<int, Exception>(new MyException())));

            var f2 = new Func<int, int, int>((a1, a2) => a1 + a2 + 0);
            var g2 = f2.ExnToResultFunc();
            Assert.That(g2(1, 2), Is.EqualTo(Result.NewSuccess<int, Exception>(1 + 2 + 0)));
            f2 = new Func<int, int, int>((a1, a2) => { throw new MyException(); });
            g2 = f2.ExnToResultFunc();
            Assert.That(g2(1, 2), Is.EqualTo(Result.NewFailure<int, Exception>(new MyException())));

            var f3 = new Func<int, int, int, int>((a1, a2, a3) => a1 + a2 + a3 + 0);
            var g3 = f3.ExnToResultFunc();
            Assert.That(g3(1, 2, 3), Is.EqualTo(Result.NewSuccess<int, Exception>(1 + 2 + 3 + 0)));
            f3 = new Func<int, int, int, int>((a1, a2, a3) => { throw new MyException(); });
            g3 = f3.ExnToResultFunc();
            Assert.That(g3(1, 2, 3), Is.EqualTo(Result.NewFailure<int, Exception>(new MyException())));

            var f4 = new Func<int, int, int, int, int>((a1, a2, a3, a4) => a1 + a2 + a3 + a4 + 0);
            var g4 = f4.ExnToResultFunc();
            Assert.That(g4(1, 2, 3, 4), Is.EqualTo(Result.NewSuccess<int, Exception>(1 + 2 + 3 + 4 + 0)));
            f4 = new Func<int, int, int, int, int>((a1, a2, a3, a4) => { throw new MyException(); });
            g4 = f4.ExnToResultFunc();
            Assert.That(g4(1, 2, 3, 4), Is.EqualTo(Result.NewFailure<int, Exception>(new MyException())));

            var f5 = new Func<int, int, int, int, int, int>((a1, a2, a3, a4, a5) => a1 + a2 + a3 + a4 + a5 + 0);
            var g5 = f5.ExnToResultFunc();
            Assert.That(g5(1, 2, 3, 4, 5), Is.EqualTo(Result.NewSuccess<int, Exception>(1 + 2 + 3 + 4 + 5 + 0)));
            f5 = new Func<int, int, int, int, int, int>((a1, a2, a3, a4, a5) => { throw new MyException(); });
            g5 = f5.ExnToResultFunc();
            Assert.That(g5(1, 2, 3, 4, 5), Is.EqualTo(Result.NewFailure<int, Exception>(new MyException())));

            var f6 = new Func<int, int, int, int, int, int, int>((a1, a2, a3, a4, a5, a6) => a1 + a2 + a3 + a4 + a5 + a6 + 0);
            var g6 = f6.ExnToResultFunc();
            Assert.That(g6(1, 2, 3, 4, 5, 6), Is.EqualTo(Result.NewSuccess<int, Exception>(1 + 2 + 3 + 4 + 5 + 6 + 0)));
            f6 = new Func<int, int, int, int, int, int, int>((a1, a2, a3, a4, a5, a6) => { throw new MyException(); });
            g6 = f6.ExnToResultFunc();
            Assert.That(g6(1, 2, 3, 4, 5, 6), Is.EqualTo(Result.NewFailure<int, Exception>(new MyException())));

            var f7 = new Func<int, int, int, int, int, int, int, int>((a1, a2, a3, a4, a5, a6, a7) => a1 + a2 + a3 + a4 + a5 + a6 + a7 + 0);
            var g7 = f7.ExnToResultFunc();
            Assert.That(g7(1, 2, 3, 4, 5, 6, 7), Is.EqualTo(Result.NewSuccess<int, Exception>(1 + 2 + 3 + 4 + 5 + 6 + 7 + 0)));
            f7 = new Func<int, int, int, int, int, int, int, int>((a1, a2, a3, a4, a5, a6, a7) => { throw new MyException(); });
            g7 = f7.ExnToResultFunc();
            Assert.That(g7(1, 2, 3, 4, 5, 6, 7), Is.EqualTo(Result.NewFailure<int, Exception>(new MyException())));

            var f8 = new Func<int, int, int, int, int, int, int, int, int>((a1, a2, a3, a4, a5, a6, a7, a8) => a1 + a2 + a3 + a4 + a5 + a6 + a7 + a8 + 0);
            var g8 = f8.ExnToResultFunc();
            Assert.That(g8(1, 2, 3, 4, 5, 6, 7, 8), Is.EqualTo(Result.NewSuccess<int, Exception>(1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 0)));
            f8 = new Func<int, int, int, int, int, int, int, int, int>((a1, a2, a3, a4, a5, a6, a7, a8) => { throw new MyException(); });
            g8 = f8.ExnToResultFunc();
            Assert.That(g8(1, 2, 3, 4, 5, 6, 7, 8), Is.EqualTo(Result.NewFailure<int, Exception>(new MyException())));

            var f9 = new Func<int, int, int, int, int, int, int, int, int, int>((a1, a2, a3, a4, a5, a6, a7, a8, a9) => a1 + a2 + a3 + a4 + a5 + a6 + a7 + a8 + a9 + 0);
            var g9 = f9.ExnToResultFunc();
            Assert.That(g9(1, 2, 3, 4, 5, 6, 7, 8, 9), Is.EqualTo(Result.NewSuccess<int, Exception>(1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 0)));
            f9 = new Func<int, int, int, int, int, int, int, int, int, int>((a1, a2, a3, a4, a5, a6, a7, a8, a9) => { throw new MyException(); });
            g9 = f9.ExnToResultFunc();
            Assert.That(g9(1, 2, 3, 4, 5, 6, 7, 8, 9), Is.EqualTo(Result.NewFailure<int, Exception>(new MyException())));

            var f10 = new Func<int, int, int, int, int, int, int, int, int, int, int>((a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) => a1 + a2 + a3 + a4 + a5 + a6 + a7 + a8 + a9 + a10 + 0);
            var g10 = f10.ExnToResultFunc();
            Assert.That(g10(1, 2, 3, 4, 5, 6, 7, 8, 9, 10), Is.EqualTo(Result.NewSuccess<int, Exception>(1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 0)));
            f10 = new Func<int, int, int, int, int, int, int, int, int, int, int>((a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) => { throw new MyException(); });
            g10 = f10.ExnToResultFunc();
            Assert.That(g10(1, 2, 3, 4, 5, 6, 7, 8, 9, 10), Is.EqualTo(Result.NewFailure<int, Exception>(new MyException())));

            var f11 = new Func<int, int, int, int, int, int, int, int, int, int, int, int>((a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11) => a1 + a2 + a3 + a4 + a5 + a6 + a7 + a8 + a9 + a10 + a11 + 0);
            var g11 = f11.ExnToResultFunc();
            Assert.That(g11(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11), Is.EqualTo(Result.NewSuccess<int, Exception>(1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 0)));
            f11 = new Func<int, int, int, int, int, int, int, int, int, int, int, int>((a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11) => { throw new MyException(); });
            g11 = f11.ExnToResultFunc();
            Assert.That(g11(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11), Is.EqualTo(Result.NewFailure<int, Exception>(new MyException())));

            var f12 = new Func<int, int, int, int, int, int, int, int, int, int, int, int, int>((a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12) => a1 + a2 + a3 + a4 + a5 + a6 + a7 + a8 + a9 + a10 + a11 + a12 + 0);
            var g12 = f12.ExnToResultFunc();
            Assert.That(g12(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12), Is.EqualTo(Result.NewSuccess<int, Exception>(1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 0)));
            f12 = new Func<int, int, int, int, int, int, int, int, int, int, int, int, int>((a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12) => { throw new MyException(); });
            g12 = f12.ExnToResultFunc();
            Assert.That(g12(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12), Is.EqualTo(Result.NewFailure<int, Exception>(new MyException())));

            var f13 = new Func<int, int, int, int, int, int, int, int, int, int, int, int, int, int>((a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13) => a1 + a2 + a3 + a4 + a5 + a6 + a7 + a8 + a9 + a10 + a11 + a12 + a13 + 0);
            var g13 = f13.ExnToResultFunc();
            Assert.That(g13(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13), Is.EqualTo(Result.NewSuccess<int, Exception>(1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 0)));
            f13 = new Func<int, int, int, int, int, int, int, int, int, int, int, int, int, int>((a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13) => { throw new MyException(); });
            g13 = f13.ExnToResultFunc();
            Assert.That(g13(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13), Is.EqualTo(Result.NewFailure<int, Exception>(new MyException())));

            var f14 = new Func<int, int, int, int, int, int, int, int, int, int, int, int, int, int, int>((a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14) => a1 + a2 + a3 + a4 + a5 + a6 + a7 + a8 + a9 + a10 + a11 + a12 + a13 + a14 + 0);
            var g14 = f14.ExnToResultFunc();
            Assert.That(g14(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14), Is.EqualTo(Result.NewSuccess<int, Exception>(1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + 0)));
            f14 = new Func<int, int, int, int, int, int, int, int, int, int, int, int, int, int, int>((a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14) => { throw new MyException(); });
            g14 = f14.ExnToResultFunc();
            Assert.That(g14(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14), Is.EqualTo(Result.NewFailure<int, Exception>(new MyException())));

            var f15 = new Func<int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int>((a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15) => a1 + a2 + a3 + a4 + a5 + a6 + a7 + a8 + a9 + a10 + a11 + a12 + a13 + a14 + a15 + 0);
            var g15 = f15.ExnToResultFunc();
            Assert.That(g15(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15), Is.EqualTo(Result.NewSuccess<int, Exception>(1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + 15 + 0)));
            f15 = new Func<int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int>((a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15) => { throw new MyException(); });
            g15 = f15.ExnToResultFunc();
            Assert.That(g15(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15), Is.EqualTo(Result.NewFailure<int, Exception>(new MyException())));

            var f16 = new Func<int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int>((a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16) => a1 + a2 + a3 + a4 + a5 + a6 + a7 + a8 + a9 + a10 + a11 + a12 + a13 + a14 + a15 + a16 + 0);
            var g16 = f16.ExnToResultFunc();
            Assert.That(g16(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16), Is.EqualTo(Result.NewSuccess<int, Exception>(1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + 15 + 16 + 0)));
            f16 = new Func<int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int>((a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16) => { throw new MyException(); });
            g16 = f16.ExnToResultFunc();
            Assert.That(g16(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16), Is.EqualTo(Result.NewFailure<int, Exception>(new MyException())));

        }