예제 #1
0
        public async Task Create_Exceptional_Merge_With_More()
        {
            await UnitTestAsync(
                _ => result("Funk12"),
                async s =>
            {
                var first = await Exc.CreateAsync <string, ArgumentException>(_ => GetNameByIdAsync(s))
                            .OnFailureAsync(e => GetNullStringAsync())
                            .OnEmptyAsync(_ => GetNameByIdAsync("Funk123"))
                            .MapAsync(async ss => ss.Concat(await GetNameByIdAsync("Funk123")).ToString());

                var second = failure <string, ArgumentException>(new ArgumentException("Error occured")).ToImmutableList()
                             .Concat(failure <string, ArgumentException>(new ArgumentException("Another occured")).ToImmutableList())
                             .Concat(Exc.Empty <string, ArgumentException>().ToImmutableList());
                return(first.MergeRange(second));
            },
                r =>
            {
                Assert.True(r.IsFailure);
                Assert.IsType <EnumerableException <ArgumentException> >(r.Failure.UnsafeGet());
                Assert.Equal(2, r.Failure.UnsafeGet().Count);
                Assert.Equal("Error occured", r.RootFailure.UnsafeGet().Message);
            }
                );
        }
예제 #2
0
 public async Task Create_Exceptional_Recover_Continue_Empty()
 {
     await UnitTestAsync(
         _ => result("Funk12"),
         s =>
     {
         return(Exc.CreateAsync <string, ArgumentException>(_ => GetNameByIdAsync(s))
                .OnFailureAsync(e => GetNullStringAsync())
                .OnEmptyAsync(_ => GetNameByIdAsync("Funk123"))
                .MapAsync(async ss => ss.Concat(await GetNameByIdAsync("Funk123"))));
     },
         s => Assert.Equal("HarunHarun", s.UnsafeGetSuccess())
         );
 }
예제 #3
0
 public async Task Create_Exceptional_Throws_Recover_On_Empty_Nothing()
 {
     await UnitTestAsync(
         _ => result("Funk12"),
         s =>
     {
         return(run(func(async() =>
         {
             var result = await Exc.CreateAsync <string, ArgumentException>(_ => GetNameByIdAsync(s));
             return result.OnFailure(e => GetNameById("Funk12")).OnEmpty(_ => GetNameById("Funk123"));
         })));
     },
         e => Assert.IsType <EnumerableException <ArgumentException> >(e.Failure.UnsafeGet())
         );
 }
예제 #4
0
 public async Task Create_Exceptional_Throws_Recover_On_Empty()
 {
     await UnitTestAsync(
         _ => result("Funk12"),
         s =>
     {
         return(run(func(async() =>
         {
             var result = await Exc.CreateAsync <string, ArgumentException>(_ => GetNameByIdAsync(s));
             return result.OnFailure(e => GetNullString()).OnEmpty(_ => GetNameById("Funk123"));
         })));
     },
         e => Assert.Equal("Harun", e.UnsafeGetSuccess())
         );
 }
예제 #5
0
 public async Task Create_Exceptional_Throws_Recover_Chain_Throws_Async()
 {
     await UnitTestAsync(
         _ => result("Funk12"),
         s =>
     {
         return(result(act(async() =>
         {
             await Exc.CreateAsync <string, ArgumentException>(_ => GetNameByIdAsync(s))
             .OnFailureAsync(e => GetNameByIdAsync(null));
         })));
     },
         async a => Assert.Throws <InvalidOperationException>(await a)
         );
 }
예제 #6
0
        public async Task Create_Exceptional_Merge_With_Another()
        {
            await UnitTestAsync(
                _ => result("Funk12"),
                async s =>
            {
                var first = await Exc.CreateAsync <string, ArgumentException>(_ => GetNameByIdAsync(s))
                            .OnFailureAsync(e => GetNullStringAsync())
                            .OnEmptyAsync(_ => GetNameByIdAsync("Funk123"))
                            .MapAsync(async ss => ss.Concat(await GetNameByIdAsync("Funk123")).ToString());

                var second = Exc.Empty <string, ArgumentException>();
                return(first.Merge(second));
            },
                r => Assert.True(r.IsEmpty)
                );
        }
예제 #7
0
 public async Task Create_Exceptional_Continue_When_Failure()
 {
     await UnitTestAsync(
         _ => result("Funk12"),
         s =>
     {
         return(Exc.CreateAsync <string, ArgumentException>(_ => GetNameByIdAsync(s))
                .MapAsync(async ss => ss.Concat(await GetNameByIdAsync(s)))
                .MapAsync(async ss => ss.Concat(await GetNameByIdAsync(s))));
     },
         e =>
     {
         var root = e.RootFailure.UnsafeGet();
         Assert.Equal("Invalid id", root.Message);
         Assert.IsType <EnumerableException <ArgumentException> >(e.UnsafeGetFailure());
     }
         );
 }
예제 #8
0
 public async Task Create_Exceptional_MapFailureAsync()
 {
     await UnitTestAsync(
         _ => result("Funk12"),
         async s =>
     {
         return(await Exc.CreateAsync <string, ArgumentException>(_ => GetNameByIdAsync(s))
                .OnFailureAsync(e => GetNullStringAsync())
                .OnEmptyAsync(_ => GetNameByIdAsync(s))
                .MapAsync(async ss => ss.Concat(await GetNameByIdAsync("Funk123")).ToString())
                .MapFailureAsync(e => new InvalidOperationException(e.Root.UnsafeGet().Message)));
     },
         r =>
     {
         Assert.True(r.IsFailure);
         Assert.IsType <EnumerableException <InvalidOperationException> >(r.Failure.UnsafeGet());
         Assert.Equal("Invalid id", r.RootFailure.UnsafeGet().Message);
     }
         );
 }
예제 #9
0
        public async Task Create_Exceptional_Merge_With_Another_Map_Failure()
        {
            await UnitTestAsync(
                _ => result("Funk12"),
                async s =>
            {
                var first = await Exc.CreateAsync <string, ArgumentException>(_ => GetNameByIdAsync(s))
                            .OnFailureAsync(e => GetNullStringAsync())
                            .OnEmptyAsync(_ => GetNameByIdAsync("Funk123"))
                            .MapAsync(async ss => ss.Concat(await GetNameByIdAsync("Funk123")).ToString());

                return(first.Merge(failure <string, ArgumentException>(new ArgumentException("Error occured")))
                       .MapFailure(e => new InvalidOperationException("New Exception type.")));
            },
                r =>
            {
                Assert.True(r.IsFailure);
                Assert.IsType <EnumerableException <InvalidOperationException> >(r.Failure.UnsafeGet());
                Assert.Equal("New Exception type.", r.RootFailure.UnsafeGet().Message);
            }
                );
        }