public void GetHasCode_between_two_fail_HttpResultWithError_is_not_equal_if_both_errors_are_not_equal() { var result1 = HttpResultWithError.Fail("abc"); var result2 = HttpResultWithError.Fail("zzz"); result1.GetHashCode().ShouldNotBe(result2.GetHashCode()); }
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 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 Acessing_the_error_of_ok_HttpResultWithError_throws_exception() { var result = HttpResultWithError.Ok <string>(); var exception = Should.Throw <InvalidOperationException>(() => { var value = result.Error; }); }
public void Acessing_the_error_of_fail_HttpResultWithError_returns_error() { var error = "abc"; var result = HttpResultWithError.Fail(error); var isEqual = result.Error.Equals(error); isEqual.ShouldBeTrue(); }
public void Dispose_can_be_called_multiple_times() { var httpResult = HttpResultWithError.Ok <string>(); httpResult.Dispose(); httpResult.Dispose(); httpResult.Dispose(); }
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 async Task OnError_new_result_contains_error_from_function_if_result_is_fail() { var newError = -1; var result = await Task.FromResult(HttpResultWithError.Fail("error")) .OnErrorToHttpResultWithError(error => newError); result.Error.ShouldBe(newError); }
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 OnSuccess_propagates_error_if_result_is_fail() { var error = "error"; var result = HttpResultWithError.Fail(error) .OnSuccessToHttpResultWithValueAndError(() => 1); result.Error.ShouldBe(error); }
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 Equality_operator_between_two_fail_HttpResultWithError_with_different_error_is_false() { var result1 = HttpResultWithError.Fail("abc"); var result2 = HttpResultWithError.Fail("zzz"); var isEqual = result1 == result2; isEqual.ShouldBeFalse(); }
public static Task <HttpResultWithError <TError> > OnSuccessToHttpResultWithError <TError>( this ResultWithError <TError> resultWithError, Func <Task <HttpResultWithError <TError> > > onSuccessFunc) { return(resultWithError.IsFailure ? Task.FromResult(HttpResultWithError.Fail(resultWithError.Error, HttpState.Empty)) : onSuccessFunc()); }
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 OnSuccess_new_result_contains_error_from_function_if_result_is_ok() { var error = "abc"; var result = await Result.Ok <int, string>(1) .OnSuccessToHttpResultWithError(i => Task.FromResult(HttpResultWithError.Fail(error))); result.Error.ShouldBe(error); }
public async Task OnSuccess_propagates_error_if_result_is_fail() { var error = "error"; var result = await Result.Fail <int, string>(error) .OnSuccessToHttpResultWithError(i => Task.FromResult(HttpResultWithError.Fail("new error"))); result.Error.ShouldBe(error); }
public void Equals_between_fail_HttpResultWithError_and_object_is_false_if_object_is_fail_HttpResultWithError_with_different_error() { var result = HttpResultWithError.Fail("abc"); object someObject = HttpResultWithError.Fail("zzz"); var isEqual = result.Equals(someObject); isEqual.ShouldBeFalse(); }
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 Equals_between_two_fail_HttpResultWithError_is_false_if_the_errors_are_not_equal() { var result = HttpResultWithError.Fail("abc"); var result2 = HttpResultWithError.Fail("zzz"); var isEqual = result.Equals(result2); isEqual.ShouldBeFalse(); }
public void Inequality_operator_between_two_fail_HttpResultWithError_with_different_error_is_true() { var result1 = HttpResultWithError.Fail("abc"); var result2 = HttpResultWithError.Fail("zzz"); var isDifferent = result1 != result2; isDifferent.ShouldBeTrue(); }
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 GetHasCode_between_two_fail_HttpResultWithError_is_equal_if_error_are_equal() { var error = "abc"; var result1 = HttpResultWithError.Fail(error); var result2 = HttpResultWithError.Fail(error); var result3 = HttpResultWithError.Fail(error, Test.CreateHttpStateA()); var result4 = HttpResultWithError.Fail(error, 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 Equals_between_two_fail_HttpResultWithError_is_true_if_the_error_are_equal() { var result1 = HttpResultWithError.Fail("error"); var result2 = HttpResultWithError.Fail("error"); var result3 = HttpResultWithError.Fail("error", Test.CreateHttpStateA()); var result4 = HttpResultWithError.Fail("error", Test.CreateHttpStateB()); var isEqual1 = result1.Equals(result2); var isEqual2 = result3.Equals(result4); isEqual1.ShouldBeTrue(); isEqual2.ShouldBeTrue(); }
public void Equals_between_fail_HttpResultWithError_and_object_is_true_if_object_is_fail_HttpResultWithError_with_equal_error() { var error = "error"; var result1 = HttpResultWithError.Fail(error); object someObject1 = HttpResultWithError.Fail(error); var result2 = HttpResultWithError.Fail(error, Test.CreateHttpStateA()); object someObject2 = HttpResultWithError.Fail(error, Test.CreateHttpStateB()); var isEqual1 = result1.Equals(someObject1); var isEqual2 = result2.Equals(someObject2); isEqual1.ShouldBeTrue(); isEqual2.ShouldBeTrue(); }
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 static HttpResult <TValue, TError> OnSuccessToHttpResultWithValueAndError <TValue, TError>( this HttpResultWithError <TError> httpResultWithError, Func <TValue> onSuccessFunc) { if (httpResultWithError.IsFailure) { return(HttpResult.Fail <TValue, TError>(httpResultWithError.Error, httpResultWithError.HttpState)); } var newValue = onSuccessFunc(); return(HttpResult.Ok <TValue, TError>(newValue, httpResultWithError.HttpState)); }
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(); }