public void Tap_unit_result_E_executes_action_on_failure_and_returns_self()
        {
            UnitResult <E> result = UnitResult.Failure(E.Value);

            var returned = result.AsTask().Tap(Action).Result;

            actionExecuted.Should().Be(false);
            result.Should().Be(returned);
        }
        public void OnFailure_unit_result_E_executes_E_action_on_failure_and_returns_self(bool isSuccess)
        {
            UnitResult <E> result = UnitResult.SuccessIf(isSuccess, E.Value);

            UnitResult <E> returned = result.OnFailure(ActionError);

            actionExecuted.Should().Be(!isSuccess);
            result.Should().Be(returned);
        }
        public void Tap_unit_result_E_executes_action_on_success_and_returns_self()
        {
            UnitResult <E> result = UnitResult.Success <E>();

            var returned = result.AsTask().Tap(Action).Result;

            actionExecuted.Should().Be(true);
            result.Should().Be(returned);
        }
Beispiel #4
0
        public void BindIf_E_executes_func_conditionally_and_returns_new_result(bool isSuccess, bool condition, bool isSuccessAction)
        {
            UnitResult <E> result = UnitResult.SuccessIf(isSuccess, E.Value);

            UnitResult <E> returned = result.BindIf(condition, GetErrorAction(isSuccessAction));

            actionExecuted.Should().Be(isSuccess && condition);
            returned.Should().Be(GetExpectedErrorResult(isSuccess, condition, isSuccessAction));
        }
        public async Task OnFailure_AsyncRight_unit_result_E_executes_E_action_on_failure_and_returns_self(bool isSuccess)
        {
            UnitResult <E> result = UnitResult.SuccessIf(isSuccess, E.Value);

            UnitResult <E> returned = await result.OnFailure(AsyncActionError);

            actionExecuted.Should().Be(!isSuccess);
            result.Should().Be(returned);
        }
Beispiel #6
0
        public async Task BindIf_AsyncLeft_E_executes_func_conditionally_and_returns_new_result(bool isSuccess, bool condition, bool isSuccessAction)
        {
            Task <UnitResult <E> > resultTask = UnitResult.SuccessIf(isSuccess, E.Value).AsTask();

            UnitResult <E> returned = await resultTask.BindIf(condition, GetErrorAction(isSuccessAction));

            actionExecuted.Should().Be(isSuccess && condition);
            returned.Should().Be(GetExpectedErrorResult(isSuccess, condition, isSuccessAction));
        }
Beispiel #7
0
        public async Task BindIf_AsyncLeft_computes_predicate_E_executes_func_conditionally_and_returns_new_result(bool isSuccess, bool condition, bool isSuccessAction)
        {
            UnitResult <E> result = UnitResult.SuccessIf(isSuccess, E.Value);

            UnitResult <E> returned = await result.BindIf(GetPredicate(condition), GetAsyncErrorAction(isSuccessAction));

            predicateExecuted.Should().Be(isSuccess);
            actionExecuted.Should().Be(isSuccess && condition);
            returned.Should().Be(GetExpectedErrorResult(isSuccess, condition, isSuccessAction));
        }
 protected void AssertCalled(UnitResult <E> result, K output)
 {
     funcUnitResultE.Should().Be(result);
     AssertCalled(output);
 }