protected UnitResult <E2> GetErrorUnitResult(E _)
        {
            funcExecuted.Should().BeFalse();

            funcExecuted = true;
            return(UnitResult.Failure(E2.Value));
        }
예제 #2
0
        public async Task Finally_LeftAsync_unit_result_E_executes_on_failure_returns_K()
        {
            UnitResult <E> result = UnitResult.Failure(E.Value);
            K output = await result.AsTask().Finally(Func_Unit_Result_E);

            AssertCalled(result, output);
        }
예제 #3
0
        public void Finally_unit_result_E_executes_on_failure_returns_K()
        {
            UnitResult <E> result = UnitResult.Failure(E.Value);
            K output = result.Finally(Func_Unit_Result_E);

            AssertCalled(result, output);
        }
예제 #4
0
        protected UnitResult <E> FailureErrorAction()
        {
            actionExecuted.Should().BeFalse();

            actionExecuted = true;
            return(UnitResult.Failure(E.Value2));
        }
예제 #5
0
        public async Task Compensate_E_returns_E2_failure_and_does_not_execute_func()
        {
            Task <UnitResult <E> > input = UnitResult.Failure(E.Value).AsTask();

            UnitResult <E2> output = await input.Compensate(GetSuccessUnitResultAsync);

            AssertSuccess(output);
        }
예제 #6
0
        public async Task Compensate_E_returns_E2_success_and_execute_func()
        {
            Task <UnitResult <E> > input = UnitResult.Failure(E.Value).AsTask();

            UnitResult <E2> output = await input.Compensate(GetErrorUnitResultAsync);

            AssertFailure(output, executed: true);
        }
        public async Task Compensate_E_returns_success_and_execute_func()
        {
            UnitResult <E> input = UnitResult.Failure(E.Value);

            Result output = await input.Compensate(GetErrorResultAsync);

            AssertFailure(output, executed: true);
        }
예제 #8
0
        public void Bind_E_returns_failure_and_does_not_execute_func()
        {
            UnitResult <E> input = UnitResult.Failure <E>(E.Value);

            UnitResult <E> output = input.Bind(GetResult_T_E);

            AssertFailure(output);
        }
예제 #9
0
        public void Compensate_E_returns_E2_failure_and_does_not_execute_func()
        {
            UnitResult <E> input = UnitResult.Failure(E.Value);

            UnitResult <E2> output = input.Compensate(GetSuccessUnitResult);

            AssertSuccess(output);
        }
        public async Task Compensate_E_returns_failure_and_does_not_execute_func()
        {
            UnitResult <E> input = UnitResult.Failure(E.Value);

            Result output = await input.Compensate(GetSuccessResultAsync);

            AssertSuccess(output);
        }
예제 #11
0
        public void Compensate_E_returns_E2_success_and_execute_func()
        {
            UnitResult <E> input = UnitResult.Failure(E.Value);

            UnitResult <E2> output = input.Compensate(GetErrorUnitResult);

            AssertFailure(output, executed: true);
        }
        public void Bind_E_returns_unit_result_failure_and_does_not_execute_func()
        {
            UnitResult <E> input = UnitResult.Failure(E.Value);

            UnitResult <E> output = input.AsTask().Bind(GetUnitResult_E_Task).Result;

            AssertFailure(output);
        }
예제 #13
0
        public void Map_unit_result_E_executes_on_failure_returns_new_failure()
        {
            UnitResult <E> result = UnitResult.Failure(E.Value);
            Result <K, E>  actual = result.Map(Func_K);

            actual.IsSuccess.Should().BeFalse();
            actual.Error.Should().Be(E.Value);
            funcExecuted.Should().BeFalse();
        }
        public void UnitResult_can_convert_failedResult_with_value_to_failedResult_without_value()
        {
            var failedResultWithValue = UnitResult.Failure(E.Value);

            Result <K, E> failedResultWithoutValue = failedResultWithValue.ConvertFailure <K>();

            failedResultWithoutValue.IsFailure.Should().BeTrue();
            failedResultWithoutValue.Error.Should().BeEquivalentTo(E.Value);
        }
예제 #15
0
        public async Task Map_AsyncBoth_unit_result_E_executes_on_failure_returns_failure()
        {
            Task <UnitResult <E> > result = UnitResult.Failure(E.Value).AsTask();
            Result <K, E>          actual = await result.Map(Task_Func_K);

            actual.IsSuccess.Should().BeFalse();
            actual.Error.Should().Be(E.Value);
            funcExecuted.Should().BeFalse();
        }
        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);
        }
예제 #17
0
        public void Can_create_a_unit_version()
        {
            var error = new MyErrorClass();

            UnitResult <MyErrorClass> result = UnitResult.Failure(error);

            result.Error.Should().Be(error);
            result.IsFailure.Should().Be(true);
            result.IsSuccess.Should().Be(false);
        }
        public void Combine_array_unit_results_error_together()
        {
            UnitResult <Error> result1 = UnitResult.Success <Error>();
            UnitResult <Error> result2 = UnitResult.Failure <Error>(new Error("Failure 1"));
            UnitResult <Error> result3 = UnitResult.Failure <Error>(new Error("Failure 2"));

            UnitResult <Error> result = Result.Combine(result1, result2, result3);

            result.IsSuccess.Should().BeFalse();
            result.Error.Errors.Should().BeEquivalentTo(new[] { "Failure 1", "Failure 2" });
        }
        public void Deserialization_of_unit_result_when_failure()
        {
            DeserializationTestObject errorObject = new DeserializationTestObject {
                Number = 500, String = "Error message"
            };
            UnitResult <DeserializationTestObject> failResult = UnitResult.Failure(errorObject);
            var serialized = Serialize(failResult);

            UnitResult <DeserializationTestObject> result = Deserialize <UnitResult <DeserializationTestObject> >(serialized);

            result.Error.Should().BeEquivalentTo(errorObject);
        }
        public void Combine_all_unit_results_errors_together()
        {
            IEnumerable <UnitResult <Error> > results = new UnitResult <Error>[]
            {
                UnitResult.Success <Error>(),
                UnitResult.Failure <Error>(new Error("Failure 1")),
                UnitResult.Failure <Error>(new Error("Failure 2")),
            };

            UnitResult <Error> result = Result.Combine(results, ComposeErrors);

            result.IsSuccess.Should().BeFalse();
            result.Error.Errors.Should().BeEquivalentTo(new[] { "Failure 1", "Failure 2" });
        }
예제 #21
0
        public void Cannot_create_without_error_message()
        {
            Action action1 = () => { Result.Failure(null); };
            Action action2 = () => { Result.Failure(string.Empty); };
            Action action3 = () => { Result.Failure <MyClass>(null); };
            Action action4 = () => { Result.Failure <MyClass>(string.Empty); };
            Action action5 = () => { UnitResult.Failure <MyClass>(null); };

            action1.Should().Throw <ArgumentNullException>();
            action2.Should().Throw <ArgumentNullException>();
            action3.Should().Throw <ArgumentNullException>();
            action4.Should().Throw <ArgumentNullException>();
            action5.Should().Throw <ArgumentNullException>();
        }
        public async Task MapError_E_unit_result_returns_new_failure()
        {
            Task <UnitResult <E> > result = UnitResult.Failure(E.Value).AsTask();
            var invocations = 0;

            UnitResult <E2> actual = await result.MapError(error =>
            {
                error.Should().Be(E.Value);

                invocations++;
                return(Task.FromResult(E2.Value));
            });

            actual.IsSuccess.Should().BeFalse();
            actual.Error.Should().Be(E2.Value);
            invocations.Should().Be(1);
        }
        public void MapError_unit_result_returns_new_failure()
        {
            UnitResult <E> result      = UnitResult.Failure(E.Value);
            var            invocations = 0;

            Result actual = result.MapError(error =>
            {
                error.Should().Be(E.Value);

                invocations++;
                return("error");
            });

            actual.IsSuccess.Should().BeFalse();
            actual.Error.Should().Be("error");
            invocations.Should().Be(1);
        }
        public void GetObjectData_of_failed_unit_result()
        {
            TestObject errorObject = new TestObject {
                Number = 500, String = "Error message"
            };
            UnitResult <TestObject> result             = UnitResult.Failure(errorObject);
            ISerializable           serializableObject = result;

            var serializationInfo = new SerializationInfo(typeof(Result), new FormatterConverter());

            serializableObject.GetObjectData(serializationInfo, new StreamingContext());

            serializationInfo.GetBoolean(nameof(Result.IsSuccess)).Should().BeFalse();
            serializationInfo.GetBoolean(nameof(Result.IsFailure)).Should().BeTrue();
            serializationInfo
            .GetValue(nameof(Result <object, TestObject> .Error), typeof(TestObject))
            .Should().Be(errorObject);
        }
예제 #25
0
        public void ToString_returns_failure_with_generic_error_when_unit_result_failure()
        {
            UnitResult <ErrorType> subject = UnitResult.Failure(ErrorType.Error1);

            Assert.Equal("Failure(Error1)", subject.ToString());
        }