예제 #1
0
 public void Create_Exceptional_Recover_Continue_Empty_Custom_Type()
 {
     UnitTest(
         _ => new InformationSource(new FirstSource("Third")),
         s =>
     {
         return(Exc.Create <IImmutableList <string>, ArgumentException>(_ => s.UnsafeGetFirst().GetInformation())
                .OnFailure(e =>
         {
             var information = new InformationSource(new SecondSource("First"));
             return information.UnsafeGetSecond().GetInformation();
         })
                .OnFailure(e => default(IImmutableList <string>))
                .OnEmpty(_ =>
         {
             var information = new InformationSource(new FirstSource("First"));
             return information.UnsafeGetFirst().GetInformation();
         }));
     },
         s =>
     {
         Assert.Equal(new List <string> {
             "1", "2", "3"
         }.Map(), s.UnsafeGetSuccess());
     }
         );
 }
예제 #2
0
 public void Associativity(Exc <int, Exception> exc)
 {
     UnitTest(
         _ => rec(func((int o) => Exc.Create <int, Exception>(__ => o / 3)), func((int o) => success <int, Exception>(o * 4))),
         r => exc.FlatMap(r.Item1).FlatMap(r.Item2).SafeEquals(exc.FlatMap(v => r.Item1(v).FlatMap(r.Item2))),
         Assert.True
         );
 }
예제 #3
0
 public void Create_Exceptional_Throws()
 {
     UnitTest(
         _ => "Funk12",
         s => act(() => Exc.Create <string, EmptyValueException>(_ => GetNameById(s))),
         a => Assert.Throws <ArgumentException>(a)
         );
 }
예제 #4
0
 public void Create_Exceptional_Throws_Recover_Chain_Throws()
 {
     UnitTest(
         _ => "Funk12",
         s =>
     {
         return(act(() => Exc.Create <string, ArgumentException>(_ => GetNameById(s))
                    .OnFailure(e => GetNameById(null))));
     },
         a => Assert.Throws <InvalidOperationException>(a)
         );
 }
예제 #5
0
 public void Create_Exceptional_Continue()
 {
     UnitTest(
         _ => "Funk123",
         s =>
     {
         return(Exc.Create <string, ArgumentException>(_ => GetNameById(s))
                .Map(ss => ss.Concat(GetNameById(s))));
     },
         s => Assert.Equal("HarunHarun", s.UnsafeGetSuccess())
         );
 }
예제 #6
0
 public void Deconstruct_Exc()
 {
     UnitTest(
         _ => "Funk123",
         s =>
     {
         var(success, failure) = Exc.Create <string, ArgumentException>(_ => GetNameById(s))
                                 .Map(ss => ss.Concat(GetNameById(s)));
         return(success, failure);
     },
         s => Assert.Equal("HarunHarun", s.success.UnsafeGet())
         );
 }
예제 #7
0
 public void Create_Exceptional()
 {
     UnitTest(
         _ => Exc.Create <string, ArgumentException>(__ => GetNameById("Funk12")),
         e => e.Failure,
         f =>
     {
         Assert.True(f.NotEmpty);
         Assert.NotEmpty(f.UnsafeGet());
         var action = act(() => throw f.UnsafeGet());
         Assert.Throws <EnumerableException <ArgumentException> >(action);
     }
         );
 }
예제 #8
0
 public void Create_Exceptional_Throws_Recover()
 {
     UnitTest(
         _ => "Funk12",
         s =>
     {
         return(Exc.Create <string, ArgumentException>(_ => GetNameById(s))
                .OnFailure(e => GetNameById("Funk123")));
     },
         e =>
     {
         Assert.True(e.IsSuccess);
         Assert.Equal("Harun", e.Success.UnsafeGet());
     }
         );
 }
예제 #9
0
파일: Static.cs 프로젝트: hcerim/Funk
 public static Exc <T, JsonException> SafeDeserialize <T>(this string content) => Exc.Create <T, JsonException>(_ => JsonConvert.DeserializeObject <T>(content));