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_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 async Task OnError_propagates_http_state_if_result_is_fail()
        {
            var httpState = Test.CreateHttpStateA();
            var result    = await Task.FromResult(HttpResultWithError.Fail("error", 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();
        }
Exemplo n.º 6
0
        public void OnSuccess_propagates_http_state_if_result_is_fail()
        {
            var httpState = Test.CreateHttpStateA();
            var result    = HttpResultWithError.Fail("error", httpState)
                            .OnSuccessToHttpResultWithValueAndError(() => "error");

            result.HttpState.ShouldBe(httpState);
        }
Exemplo n.º 7
0
 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());
 }
Exemplo n.º 8
0
        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 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();
        }
Exemplo n.º 10
0
        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);
        }
Exemplo n.º 11
0
        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();
        }
Exemplo n.º 12
0
        public void OnSuccess_propagates_error_if_result_is_fail()
        {
            var error  = "error";
            var result = HttpResultWithError.Fail(error)
                         .OnSuccessToHttpResultWithValueAndError(() => 1);

            result.Error.ShouldBe(error);
        }
Exemplo n.º 13
0
        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 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();
        }
Exemplo n.º 15
0
        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);
        }
Exemplo n.º 16
0
        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 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_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();
        }
Exemplo n.º 19
0
        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 async Task OnError_executes_function_if_result_is_fail()
        {
            var functionExecuted = false;
            var result           = await Task.FromResult(HttpResultWithError.Fail("error"))
                                   .OnErrorToHttpResultWithError(error => OnErrorFunc(error));

            functionExecuted.ShouldBeTrue();

            int OnErrorFunc(string error)
            {
                functionExecuted = true;
                return(1);
            }
        }
Exemplo n.º 21
0
        public void Equality_operator_between_two_fail_HttpResultWithError_is_true_if_the_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());

            var isEqual1 = result1 == result2;
            var isEqual2 = result3 == result4;

            isEqual1.ShouldBeTrue();
            isEqual2.ShouldBeTrue();
        }
Exemplo n.º 22
0
        public void Inequality_operator_between_two_fail_HttpResultWithError_is_false_if_the_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());

            var isDifferent1 = result1 != result2;
            var isDifferent2 = result3 != result4;

            isDifferent1.ShouldBeFalse();
            isDifferent2.ShouldBeFalse();
        }
Exemplo n.º 23
0
        public void OnSuccess_does_not_execute_function_if_result_is_fail()
        {
            var functionExecuted = false;
            var result           = HttpResultWithError.Fail("error")
                                   .OnSuccessToHttpResultWithValueAndError(OnSuccessFunc());

            functionExecuted.ShouldBeFalse();

            Func <int> OnSuccessFunc()
            {
                return(() =>
                {
                    functionExecuted = true;
                    return 1;
                });
            }
        }
        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 Creating_fail_HttpResultWithError_with_null_as_error_throws_exception()
        {
            var exception = Should.Throw <ArgumentNullException>(() => HttpResultWithError.Fail <string>(null));

            exception.Message.ShouldStartWith(HttpResultMessages.FailureResultMustHaveError);
        }
 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 Fail_HttpResultWithError_IsFailure_equals_true()
        {
            var result = HttpResultWithError.Fail("abc");

            result.IsFailure.ShouldBeTrue();
        }
        public void Fail_HttpResult_withouth_passing_in_HttpState_has_maybe_nothing_for_that_field()
        {
            var httpResult = HttpResultWithError.Fail("abc");

            httpResult.HttpState.ShouldBe(HttpState.Empty);
        }
        public void Fail_HttpResultWithError_IsSuccess_is_false()
        {
            var result = HttpResultWithError.Fail("abc");

            result.IsSuccess.ShouldBeFalse();
        }