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 async Task Create_error_generic_async_predicate_is_false_Failure_unit_result_expected() { var error = new Error(); UnitResult <Error> result = await UnitResult.SuccessIf(() => Task.FromResult(false), error); result.IsFailure.Should().BeTrue(); result.Error.Should().Be(error); }
public void Create_error_generic_predicate_is_false_Failure_unit_result_expected() { var error = new Error(); UnitResult <Error> result = UnitResult.SuccessIf(() => false, error); result.IsFailure.Should().BeTrue(); result.Error.Should().Be(error); }
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); }
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)); }
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 static UnitResult <E> GetExpectedErrorResult(bool isSuccess, bool condition, bool isSuccessAction) { var success = CheckSuccess(isSuccess, condition, isSuccessAction); var resultChanged = isSuccess && condition; if (!resultChanged) { return(UnitResult.SuccessIf(success, E.Value)); } return(UnitResult.SuccessIf(success, E.Value2)); }
public async Task Create_error_generic_async_predicate_is_true_Success_unit_result_expected() { UnitResult <Error> result = await UnitResult.SuccessIf(() => Task.FromResult(true), new Error()); result.IsSuccess.Should().BeTrue(); }
public void Create_error_generic_predicate_is_true_Success_unit_result_expected() { UnitResult <Error> result = UnitResult.SuccessIf(() => true, new Error()); result.IsSuccess.Should().BeTrue(); }