public void GetHasCode_between_ok_HttpResultWithError_and_fail_HttpResultWithError_is_not_equal() { var result1 = HttpResultWithError.Ok <string>(); var result2 = HttpResultWithError.Fail("abc"); result1.GetHashCode().ShouldNotBe(result2.GetHashCode()); }
public void GetHasCode_between_two_ok_HttpResultWithError_of_different_types_is_not_equal() { var result1 = HttpResultWithError.Ok <int>(); var result2 = HttpResultWithError.Ok <string>(); result1.GetHashCode().ShouldNotBe(result2.GetHashCode()); }
public void Acessing_the_error_of_ok_HttpResultWithError_throws_exception() { var result = HttpResultWithError.Ok <string>(); var exception = Should.Throw <InvalidOperationException>(() => { var value = result.Error; }); }
public void Dispose_can_be_called_multiple_times() { var httpResult = HttpResultWithError.Ok <string>(); httpResult.Dispose(); httpResult.Dispose(); httpResult.Dispose(); }
public void Equals_between_ok_HttpResultWithError_and_object_is_false_if_object_is_not_ok_HttpResultWithError() { var result = HttpResultWithError.Ok <string>(); object someObject = "zzz"; var isEqual = result.Equals(someObject); isEqual.ShouldBeFalse(); }
public void OnSuccess_new_result_contains_value_from_function_if_result_is_ok() { var newValue = 1; var result = HttpResultWithError.Ok <string>() .OnSuccessToHttpResultWithValueAndError(() => newValue); result.Value.ShouldBe(newValue); }
public void Equality_operator_between_ok_HttpResultWithError_and_fail_HttpResultWithError_is_false() { var okResult = HttpResultWithError.Ok <string>(); var errorResult = HttpResultWithError.Fail("abc"); var isEqual = okResult == errorResult; isEqual.ShouldBeFalse(); }
public async Task OnError_propagates_http_state_if_result_is_ok() { var httpState = Test.CreateHttpStateA(); var result = await Task.FromResult(HttpResultWithError.Ok <string>(httpState)) .OnErrorToHttpResultWithError(error => - 1); result.HttpState.ShouldBe(httpState); }
public void OnSuccess_propagates_http_state_if_result_is_ok() { var httpState = Test.CreateHttpStateA(); var result = HttpResultWithError.Ok <string>(httpState) .OnSuccessToHttpResultWithValueAndError(() => "error"); result.HttpState.ShouldBe(httpState); }
public void Equals_between_ok_HttpResultWithError_and_fail_HttpResultWithError_is_false() { var result = HttpResultWithError.Fail("abc"); var result2 = HttpResultWithError.Ok <string>(); var isEqual = result.Equals(result2); isEqual.ShouldBeFalse(); }
public void GetHasCode_between_two_ok_HttpResultWithError_of_same_type_is_true() { var result1 = HttpResultWithError.Ok <string>(); var result2 = HttpResultWithError.Ok <string>(); var result3 = HttpResultWithError.Ok <string>(Test.CreateHttpStateA()); var result4 = HttpResultWithError.Ok <string>(Test.CreateHttpStateB()); result1.GetHashCode().ShouldBe(result2.GetHashCode()); result3.GetHashCode().ShouldBe(result4.GetHashCode()); }
public void Equals_between_ok_HttpResultWithError_and_object_is_true_if_object_is_ok_HttpResultWithError() { var result1 = HttpResultWithError.Ok <string>(); object someObject1 = HttpResultWithError.Ok <string>(); var result2 = HttpResultWithError.Ok <string>(Test.CreateHttpStateA()); object someObject2 = HttpResultWithError.Ok <string>(Test.CreateHttpStateB()); var isEqual1 = result1.Equals(someObject1); var isEqual2 = result2.Equals(someObject2); isEqual1.ShouldBeTrue(); isEqual2.ShouldBeTrue(); }
public void Equals_between_two_ok_HttpResultWithError_is_true() { var result1 = HttpResultWithError.Ok <string>(); var result2 = HttpResultWithError.Ok <string>(); var result3 = HttpResultWithError.Ok <string>(Test.CreateHttpStateA()); var result4 = HttpResultWithError.Ok <string>(Test.CreateHttpStateA()); var isEqual1 = result1.Equals(result2); var isEqual2 = result3.Equals(result4); isEqual1.ShouldBeTrue(); isEqual2.ShouldBeTrue(); }
public void Inequality_operator_between_two_ok_HttpResultWithError_is_false() { var result1 = HttpResultWithError.Ok <string>(); var result2 = HttpResultWithError.Ok <string>(); var result3 = HttpResultWithError.Ok <string>(Test.CreateHttpStateA()); var result4 = HttpResultWithError.Ok <string>(Test.CreateHttpStateB()); var isDifferent1 = result1 != result2; var isDifferent2 = result3 != result4; isDifferent1.ShouldBeFalse(); isDifferent2.ShouldBeFalse(); }
public void Combine_if_all_HttpResultWithError_are_ok_returns_ok_HttpResultWithError() { var resultsLists = new List <HttpResultWithError <string> > { HttpResultWithError.Ok <string>(), HttpResultWithError.Ok <string>(), HttpResultWithError.Ok <string>() }; var combinedResult = HttpResult.Combine(resultsLists.ToArray()); combinedResult.IsSuccess.ShouldBeTrue(); }
public async Task OnError_does_not_execute_function_if_result_is_ok() { var functionExecuted = false; var result = await Task.FromResult(HttpResultWithError.Ok <string>()) .OnErrorToHttpResultWithError(error => OnErrorFunc(error)); functionExecuted.ShouldBeFalse(); int OnErrorFunc(string error) { functionExecuted = true; return(1); } }
public async Task OnSuccess_does_not_execute_function_if_result_is_fail() { var functionExecuted = false; var result = await Result.Fail <int, string>("error") .OnSuccessToHttpResultWithError(i => OnSuccessFunc(i)); functionExecuted.ShouldBeFalse(); Task <HttpResultWithError <string> > OnSuccessFunc(int value) { functionExecuted = true; return(Task.FromResult(HttpResultWithError.Ok <string>())); } }
public async Task OnSuccess_propagates_value_into_function_if_result_is_ok() { var propagatedValue = 0; var value = 1; var result = await Result.Ok <int, string>(value) .OnSuccessToHttpResultWithError(i => OnSuccessFunc(i)); propagatedValue.ShouldBe(value); Task <HttpResultWithError <string> > OnSuccessFunc(int val) { propagatedValue = val; return(Task.FromResult(HttpResultWithError.Ok <string>())); } }
public async Task OnSuccess_new_result_does_not_contain_http_state_because_previous_fail_result_does_not_have_them() { var result = await ResultWithError.Fail("error") .OnSuccessToHttpResultWithError(OnSuccessFunc()); result.HttpState.ShouldBe(HttpState.Empty); Func <Task <HttpResultWithError <string> > > OnSuccessFunc() { return(() => { var httpResult = HttpResultWithError.Ok <string>(); return Task.FromResult(httpResult); }); } }
public void OnSuccess_executes_function_if_result_is_ok() { var functionExecuted = false; var result = HttpResultWithError.Ok <string>() .OnSuccessToHttpResultWithValueAndError(OnSuccessFunc()); functionExecuted.ShouldBeTrue(); Func <int> OnSuccessFunc() { return(() => { functionExecuted = true; return 1; }); } }
public async Task OnSuccess_propagates_error_if_result_is_fail() { var error = "error"; var result = await ResultWithError.Fail(error) .OnSuccessToHttpResultWithError(OnSuccessFunc()); result.Error.ShouldBe(error); Func <Task <HttpResultWithError <string> > > OnSuccessFunc() { return(() => { var httpResult = HttpResultWithError.Ok <string>(); return Task.FromResult(httpResult); }); } }
public void OnSuccess_does_not_execute_function_if_result_is_fail() { var functionExecuted = false; var result = ResultWithError.Fail("error") .OnSuccessToHttpResultWithError(OnSuccessFunc()); functionExecuted.ShouldBeFalse(); Func <Task <HttpResultWithError <string> > > OnSuccessFunc() { return(() => { functionExecuted = true; var httpResult = HttpResultWithError.Ok <string>(); return Task.FromResult(httpResult); }); } }
public void Combine_returns_first_fail_HttpResultWithError_if_at_least_one_HttpResultWithError_is_a_fail() { var firstHttpState = Test.CreateHttpStateA(); var secondHttpState = Test.CreateHttpStateB(); var firstFailure = HttpResultWithError.Fail("error", firstHttpState); var resultsLists = new List <HttpResultWithError <string> > { HttpResultWithError.Ok <string>(HttpState.Empty), firstFailure, HttpResultWithError.Ok <string>(HttpState.Empty), HttpResultWithError.Fail("second error", secondHttpState) }; var combinedResult = HttpResult.Combine(resultsLists.ToArray()); combinedResult.IsFailure.ShouldBeTrue(); combinedResult.Error.ShouldBe(firstFailure.Error); combinedResult.HttpState.ShouldBe(firstFailure.HttpState); }
public void Ok_HttpResultWithError_IsSuccess_is_true() { var result = HttpResultWithError.Ok <string>(); result.IsSuccess.ShouldBeTrue(); }
public void Constructor_null_httpState_throws_ArgumentNullException() { var exception = Should.Throw <ArgumentNullException>(() => HttpResultWithError.Ok <string>(null)); exception.Message.ShouldContain("httpState"); }
public void Ok_HttpResultWithError_IsFailure_is_false() { var result = HttpResultWithError.Ok <string>(); result.IsFailure.ShouldBeFalse(); }
public static HttpResultWithError <TError> ToHttpResultWithError <TValue, TError>(this HttpResult <TValue, TError> result) { return(result.IsSuccess ? HttpResultWithError.Ok <TError>(result.HttpState) : HttpResultWithError.Fail(result.Error, result.HttpState)); }
public void OK_HttpResult_withouth_passing_in_HttpState_has_maybe_nothing_for_that_field() { var httpResult = HttpResultWithError.Ok <string>(); httpResult.HttpState.ShouldBe(HttpState.Empty); }