예제 #1
0
        public void Finally_unit_result_E_executes_on_success_returns_K()
        {
            UnitResult <E> result = UnitResult.Success <E>();
            K output = result.Finally(Func_Unit_Result_E);

            AssertCalled(result, output);
        }
        public void Can_create_a_unit_result_using_UnitResult_entry_point()
        {
            UnitResult <MyErrorClass> result = UnitResult.Success <MyErrorClass>();

            result.IsFailure.Should().Be(false);
            result.IsSuccess.Should().Be(true);
        }
예제 #3
0
        protected UnitResult <E> SuccessErrorAction()
        {
            actionExecuted.Should().BeFalse();

            actionExecuted = true;
            return(UnitResult.Success <E>());
        }
        protected UnitResult <E2> GetSuccessUnitResult(E _)
        {
            funcExecuted.Should().BeFalse();

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

            AssertCalled(result, output);
        }
예제 #6
0
        public async Task Compensate_E_returns_E2_success_and_does_not_execute_func()
        {
            Task <UnitResult <E> > input = UnitResult.Success <E>().AsTask();

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

            AssertSuccess(output, executed: false);
        }
        public async Task Compensate_E_returns_success_and_does_not_execute_func()
        {
            UnitResult <E> input = UnitResult.Success <E>();

            Result output = await input.Compensate(GetErrorResultAsync);

            AssertSuccess(output, executed: false);
        }
        public void Bind_E_selects_new_unit_result()
        {
            UnitResult <E> input = UnitResult.Success <E>();

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

            AssertSuccess(output);
        }
예제 #9
0
        public void Compensate_E_returns_E2_success_and_does_not_execute_func()
        {
            UnitResult <E> input = UnitResult.Success <E>();

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

            AssertSuccess(output, executed: false);
        }
        public void UnitResult_can_not_convert_okResult_with_value_to_okResult_with_value()
        {
            var okResultWithValue = UnitResult.Success <E>();

            Action action = () => okResultWithValue.ConvertFailure <K>();

            action.Should().Throw <InvalidOperationException>();
        }
예제 #11
0
        public void Bind_E_selects_new_result()
        {
            UnitResult <E> input = UnitResult.Success <E>();

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

            AssertSuccess(output);
        }
예제 #12
0
        public void Map_unit_result_E_executes_on_success_returns_success()
        {
            UnitResult <E> result = UnitResult.Success <E>();
            Result <K, E>  actual = result.Map(Func_K);

            actual.IsSuccess.Should().BeTrue();
            actual.Value.Should().Be(K.Value);
            funcExecuted.Should().BeTrue();
        }
        public void Deserialization_of_unit_result_when_success()
        {
            UnitResult <DeserializationTestObject> failResult = UnitResult.Success <DeserializationTestObject>();
            var serialized = Serialize(failResult);

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

            result.IsSuccess.Should().Be(true);
        }
예제 #14
0
        public async Task Map_AsyncBoth_unit_result_E_executes_on_success_returns_success()
        {
            Task <UnitResult <E> > result = UnitResult.Success <E>().AsTask();
            Result <K, E>          actual = await result.Map(Task_Func_K);

            actual.IsSuccess.Should().BeTrue();
            actual.Value.Should().Be(K.Value);
            funcExecuted.Should().BeTrue();
        }
        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);
        }
        public void Combine_array_unit_results_compose_method_returns_Ok_if_no_failures()
        {
            UnitResult <Error> result1 = UnitResult.Success <Error>();
            UnitResult <Error> result2 = UnitResult.Success <Error>();
            UnitResult <Error> result3 = UnitResult.Success <Error>();

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

            result.IsSuccess.Should().BeTrue();
        }
        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 GetObjectData_of_successful_unit_result()
        {
            UnitResult <TestObject> result             = UnitResult.Success <TestObject>();
            ISerializable           serializableObject = result;

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

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

            serializationInfo.GetBoolean(nameof(Result.IsSuccess)).Should().BeTrue();
            serializationInfo.GetBoolean(nameof(Result.IsFailure)).Should().BeFalse();
        }
        public void Combine_unit_results_returns_Ok_if_no_failures()
        {
            IEnumerable <UnitResult <Error> > results = new UnitResult <Error>[]
            {
                UnitResult.Success <Error>(),
                UnitResult.Success <Error>(),
                UnitResult.Success <Error>(),
            };

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

            result.IsSuccess.Should().BeTrue();
        }
        public async Task MapError_E_unit_result_returns_success()
        {
            Task <UnitResult <E> > result = UnitResult.Success <E>().AsTask();
            var invocations = 0;

            UnitResult <E2> actual = await result.MapError(error =>
            {
                invocations++;
                return(Task.FromResult(E2.Value));
            });

            actual.IsSuccess.Should().BeTrue();
            invocations.Should().Be(0);
        }
        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" });
        }
        public void MapError_unit_result_returns_success()
        {
            UnitResult <E> result      = UnitResult.Success <E>();
            var            invocations = 0;

            Result actual = result.MapError(error =>
            {
                invocations++;
                return($"{error} {error}");
            });

            actual.IsSuccess.Should().BeTrue();
            invocations.Should().Be(0);
        }
예제 #23
0
        public async Task MapError_unit_result_returns_success()
        {
            Task <UnitResult <E> > result = UnitResult.Success <E>().AsTask();
            var invocations = 0;

            Result actual = await result.MapError(error =>
            {
                invocations++;
                return($"{error} {error}");
            });

            actual.IsSuccess.Should().BeTrue();
            invocations.Should().Be(0);
        }
 protected UnitResult <E> GetUnitResult_E()
 {
     funcExecuted = true;
     return(UnitResult.Success <E>());
 }
 protected UnitResult <E> GetUnitResult_E_WithParam(T value)
 {
     funcExecuted = true;
     funcParam    = value;
     return(UnitResult.Success <E>());
 }