public async void Can_Compose_Operations() { var firstResult = await GetFirstResult(2); var composedResult = await firstResult.Apply(Add5).Finally(); Assertions.ResultEquals(15, composedResult); }
public async void Can_Compose_With_Result() { Task <Result <int> > ConvertToResult(int i) => Begin(i).Finally(); var value = await Begin(2) .Then(Add3) .Then(ConvertToResult) .Finally(); Assertions.ResultEquals(5, value); }
public async void Can_Compose_With_Func_Returning_Task() { async Task FuncReturningTask(int i) { await Task.FromResult(i); } var value = await Begin(1) .Then(FuncReturningTask) .Finally(Add3); Assertions.ResultEquals(4, value); }
public async void Can_Compose_With_Enumerable_And_Map_Each_Element_On_Finally() { var value = await Begin(2) .Then(Add3) .Then(Add5) .Then(Times10) .Then(Times10) .Then(WaitAndReturn) .Then(FetchNames) .FinallyForEach(Capitalize); Assertions.ResultEquals(GetExpectedListValue(10 * 10 * 10, "VALUE"), value); }
public async void Can_Compose_With_Complex_Branching() { var Add5If15 = Begin(1).Then(Add5).Then(Sub5).Then(Add5); var Sub5IfNot15 = Begin(1).Then(Sub5); Predicate <int> IsNot15 = x => x != 15; var composedResult = await GetFirstResult(2) .Apply(Add5) .IfThenElse(IsNot15, Add5If15, Sub5IfNot15) .Finally(); Assertions.ResultEquals(10, composedResult); }
public async void Can_Compose_With_Complex_Branching_With_Funcs_Different_Return_Type_Async_Result() { Task <Result <string> > Add5If15(int val) => Begin(val).Finally(v => $"{v + 5}"); Task <Result <string> > Sub5IfNot15(int val) => Begin(val).Finally(v => $"{v - 5}"); Predicate <int> IsNot15 = x => x != 15; var composedResult = await GetFirstResult(2) .Apply(Add5) .IfThenElse(IsNot15, Add5If15, Sub5IfNot15) .Finally(); Assertions.ResultEquals("10", composedResult); }
public async void Can_Compose_With_Complex_Branching_With_Funcs_Different_Return_Type() { string Add5If15(int val) => $"{val + 5}"; string Sub5IfNot15(int val) => $"{val - 5}"; Predicate <int> IsNot15 = x => x != 15; var composedResult = await GetFirstResult(2) .Apply(Add5) .IfThenElse(IsNot15, Add5If15, Sub5IfNot15) .Finally(); Assertions.ResultEquals("10", composedResult); }
public async void Can_Compose_With_Complex_Branching_With_Funcs() { int Add5If15(int val) => val + 5; int Sub5IfNot15(int val) => val - 5; Predicate <int> IsNot15 = x => x != 15; var composedResult = await GetFirstResult(2) .Apply(Add5) .IfThenElse(IsNot15, Add5If15, Sub5IfNot15) .Finally(); Assertions.ResultEquals(10, composedResult); }
public async void Can_Compose_With_Single_Branching_With_Func() { int Add5If10(int val) => val + 5; Predicate <int> Is10 = x => x == 10; var composedResult = await Begin(2) .Then(Add3) .Then(Add5) .Then(WaitAndReturn) .Then(Add5) .IfThen(Is10, Add5If10) .Finally(); Assertions.ResultEquals(15, composedResult); }
public async void Can_Compose_With_Single_Branching() { var Add5If15 = Begin(1).Then(Add5); Predicate <int> Is15 = x => x == 15; var composedResult = await Begin(2) .Then(Add3) .Then(Add5) .Apply(Add5If15) .Then(WaitAndReturn) .Then(Add5) .IfThen(Is15, Add5If15) .Finally(); Assertions.ResultEquals(20, composedResult); }
public async void Can_Begin_With_Tuples_And_Compose_Passing_Tuple_And_Result() { Task <Result <(int, string)> > ValidateIsTuple(int val, string data) => Begin((val, data)).Finally(); string Concat((int, string) data) => $"{data.Item2} {data.Item1}"; string ToUpper(string str) => str.ToUpper(); var intval = 2; var name = "number"; var value = await Begin((intval, name)) .Then(ValidateIsTuple) .Then(Concat) .Then(ToUpper) .Finally(); ; Assertions.ResultEquals("NUMBER 2", value); }
public async void Can_Begin_With_Tuples_And_Compose_Deconstructed() { (int, string) ValidateIsTuple((int, string) data) => data; string Concat(int val, string name) => $"{name} {val}"; string ToUpper(string str) => str.ToUpper(); var intval = 2; var name = "number"; var value = await Begin((intval, name)) .Then(ValidateIsTuple) .Then(Concat) .Then(ToUpper) .Finally(); ; Assertions.ResultEquals("NUMBER 2", value); }