Example #1
0
        public void GetHasCode_between_two_fail_HttpResultWithValue_is_not_equal_if_values_are_not_of_the_same_type()
        {
            var result1 = HttpResult.Fail <int>();
            var result2 = HttpResult.Fail <string>();

            result1.GetHashCode().ShouldNotBe(result2.GetHashCode());
        }
Example #2
0
        public void GetHasCode_between_ok_HttpResultWithValue_and_fail_HttpResultWithValue_is_not_equal()
        {
            var result1 = HttpResult.Ok("abc");
            var result2 = HttpResult.Fail <string>();

            result1.GetHashCode().ShouldNotBe(result2.GetHashCode());
        }
Example #3
0
        public void GetHasCode_between_two_fail_HttpResultWithValue_is_true()
        {
            var result1 = HttpResult.Fail <string>(Test.CreateHttpStateA());
            var result2 = HttpResult.Fail <string>(Test.CreateHttpStateB());

            result1.GetHashCode().ShouldBe(result2.GetHashCode());
        }
Example #4
0
        public void To_propagates_fail_status_to_HttpResultWithValue()
        {
            var result     = HttpResult.Fail <int>();
            var httpResult = result.ToHttpResult();

            httpResult.IsFailure.ShouldBe(result.IsFailure);
        }
Example #5
0
        public void To_propagates_error_to_HttpResultWithError_if_status_is_fail()
        {
            var result     = HttpResult.Fail <int, string>("error");
            var httpResult = result.ToHttpResultWithError();

            httpResult.Error.ShouldBe(result.Error);
        }
Example #6
0
        public void GetHasCode_between_ok_HttpResultWithValueAndError_and_fail_HttpResultWithValueAndError_is_not_equal()
        {
            var result1 = HttpResult.Ok <string, string>("value");
            var result2 = HttpResult.Fail <string, string>("error");

            result1.GetHashCode().ShouldNotBe(result2.GetHashCode());
        }
Example #7
0
        public void To_propagates_fail_status_to_HttpResultWithError()
        {
            var result     = HttpResult.Fail <int, string>("error");
            var httpResult = result.ToHttpResultWithError();

            httpResult.IsFailure.ShouldBe(result.IsFailure);
        }
Example #8
0
        public void GetHasCode_between_two_fail_HttpResultWithValueAndError_is_not_equal_if_errors_are_not_of_the_same_type()
        {
            var result1 = HttpResult.Fail <string, int>(1);
            var result2 = HttpResult.Fail <string, string>("error");

            result1.GetHashCode().ShouldNotBe(result2.GetHashCode());
        }
Example #9
0
        public void GetHasCode_between_ok_HttpResultSimple_and_fail_HttpResultSimple_is_not_equal()
        {
            var result1 = HttpResult.Ok();
            var result2 = HttpResult.Fail();

            result1.GetHashCode().ShouldNotBe(result2.GetHashCode());
        }
Example #10
0
        public async Task OnError_new_result_contains_error_from_function_if_result_is_fail()
        {
            var newError = "abc";
            var result   = await Task.FromResult(HttpResult.Fail())
                           .OnErrorToHttpResultWithError(() => newError);

            result.Error.ShouldBe(newError);
        }
Example #11
0
        public void To_propagates_HttpState_to_HttpResultWithError_if_status_is_fail()
        {
            var httpState  = Test.CreateHttpStateA();
            var result     = HttpResult.Fail <int, string>("error", httpState);
            var httpResult = result.ToHttpResultWithError();

            httpResult.HttpState.ShouldBe(result.HttpState);
        }
 public void Acessing_the_value_of_fail_result_throws_exception()
 {
     var result    = HttpResult.Fail <string>();
     var exception = Should.Throw <InvalidOperationException>(() =>
     {
         var value = result.Value;
     });
 }
        public void Equals_between_fail_HttpResultSimple_and_object_is_false_if_object_is_not_fail_HttpResultSimple()
        {
            var    result1 = HttpResult.Fail();
            object result2 = "abc";
            var    isEqual = result1.Equals(result2);

            isEqual.ShouldBeFalse();
        }
 public void Acessing_the_value_of_fail_HttpResultWithValueAndError_throws_exception()
 {
     var result    = HttpResult.Fail <string, string>("abc");
     var exception = Should.Throw <InvalidOperationException>(() =>
     {
         var value = result.Value;
     });
 }
Example #15
0
        public void To_propagates_HttpState_to_HttpResultWithValue_if_status_is_fail()
        {
            var httpState  = Test.CreateHttpStateA();
            var result     = HttpResult.Fail <int>(httpState);
            var httpResult = result.ToHttpResult();

            httpResult.HttpState.ShouldBe(httpState);
        }
        public void Equals_between_fail_HttpResultWithValueAndError_and_object_is_false_if_object_is_fail_HttpResultWithValueAndError_with_different_value()
        {
            var    result     = HttpResult.Fail <string, string>("abc");
            object someObject = HttpResult.Fail <string, string>("zzz");
            var    isEqual    = result.Equals(someObject);

            isEqual.ShouldBeFalse();
        }
        public void Equals_between_fail_HttpResultWithValueAndError_and_object_is_false_if_object_is_not__HttpResultWithValueAndError()
        {
            var    result     = HttpResult.Fail <string, string>("error");
            object someObject = "error";
            var    isEqual    = result.Equals(someObject);

            isEqual.ShouldBeFalse();
        }
Example #18
0
        public void Equals_between_fail_HttpResultWithValue_and_object_is_false_if_object_is_not_an_HttpResultWithValue()
        {
            var    result     = HttpResult.Fail <string>();
            object someObject = "zzz";
            var    isEqual    = result.Equals(someObject);

            isEqual.ShouldBeFalse();
        }
        public void Acessing_the_error_of_fail_HttpResultWithValueAndError_returns_error()
        {
            var error   = "abc";
            var result  = HttpResult.Fail <string, string>(error);
            var isEqual = result.Error.Equals(error);

            isEqual.ShouldBeTrue();
        }
Example #20
0
        public async Task OnError_propagates_http_state_f_result_is_fail()
        {
            var httpState = Test.CreateHttpStateA();
            var result    = await Task.FromResult(HttpResult.Fail(httpState))
                            .OnErrorToHttpResultWithError(() => "error");

            result.HttpState.ShouldBe(httpState);
        }
        public async Task OnSuccess_propagates_error_if_result_is_fail()
        {
            var error  = "error";
            var result = await Task.FromResult(HttpResult.Fail <int, string>(error))
                         .OnSuccessToHttpResultWithValueAndError(i => Task.FromResult(HttpResult.Ok <int, string>(2)));

            result.Error.ShouldBe(error);
        }
        public void Equals_between_two_fail_HttpResultWithValue_is_true()
        {
            var result1 = HttpResult.Fail <string>(Test.CreateHttpStateA());
            var result2 = HttpResult.Fail <string>(Test.CreateHttpStateB());
            var isEqual = result1.Equals(result2);

            isEqual.ShouldBeTrue();
        }
        public void Equality_operator_between_two_fail_HttpResultWithValueAndError_with_different_error_is_false()
        {
            var result1 = HttpResult.Fail <string, string>("abc");
            var result2 = HttpResult.Fail <string, string>("zzz");
            var isEqual = result1 == result2;

            isEqual.ShouldBeFalse();
        }
Example #24
0
 public static Task <HttpResult <TValue, TError> > OnSuccessToHttpResultWithValueAndError <TValue, TError>(
     this ResultWithError <TError> resultWithError,
     Func <Task <HttpResult <TValue, TError> > > onSuccessFunc)
 {
     return(resultWithError.IsFailure
         ? Task.FromResult(HttpResult.Fail <TValue, TError>(resultWithError.Error, HttpState.Empty))
         : onSuccessFunc());
 }
        public void Equality_operator_between_two_fail_HttpResultWithValueAndError_is_true_if_the_error_are_equal()
        {
            var result1 = HttpResult.Fail <string, string>("abc", Test.CreateHttpStateA());
            var result2 = HttpResult.Fail <string, string>("abc", Test.CreateHttpStateB());
            var isEqual = result1 == result2;

            isEqual.ShouldBeTrue();
        }
Example #26
0
 public static Task <HttpResult <KValue, TError> > OnSuccessToHttpResultWithValueAndError <TValue, TError, KValue>(
     this HttpResult <TValue, TError> httpResult,
     Func <TValue, Task <HttpResult <KValue, TError> > > onSuccessFunc)
 {
     return(httpResult.IsFailure
         ? Task.FromResult(HttpResult.Fail <KValue, TError>(httpResult.Error, httpResult.HttpState))
         : onSuccessFunc(httpResult.Value));
 }
        public void Equality_operator_between_ok_result_and_fail_result_is_false()
        {
            var okResult    = HttpResult.Ok <string, string>("abc");
            var errorResult = HttpResult.Fail <string, string>("abc");
            var isEqual     = okResult == errorResult;

            isEqual.ShouldBeFalse();
        }
        public void Equality_operator_between_ok_HttpResultSimple_and_fail_HttpResultSimple_is_false()
        {
            var okResult   = HttpResult.Ok();
            var failResult = HttpResult.Fail();
            var isEqual    = okResult == failResult;

            isEqual.ShouldBeFalse();
        }
        public void Inequality_operator_between_ok_HttpResultWithValue_and_fail_HttpResultWithValue_is_true()
        {
            var okResult    = HttpResult.Ok("abc");
            var errorResult = HttpResult.Fail <string>();
            var isEqual     = okResult != errorResult;

            isEqual.ShouldBeTrue();
        }
Example #30
0
        public async Task OnError_new_result_contains_error_from_function_if_result_is_fail()
        {
            var newError = "abc";
            var result   = await Task.FromResult(HttpResult.Fail <int, string>("error"))
                           .OnErrorToHttpResultWithValueAndError(i => newError);

            result.Error.ShouldBe(newError);
        }