Beispiel #1
0
        public void adding_an_error_and_a_warning_results_in_an_error()
        {
            var result_1 =
                PartialResult <int>
                .Warning("warn")
                .Failure("err")
                .Failure(new Exception("ex"));

            var result_2 =
                PartialResult <int>
                .Failure("fail")
                .Warning("warn");

            var result_3 =
                PartialResult <int>
                .Failure(new Exception("fail"))
                .Warning("warn");

            Assert.That(result_1.State, Is.EqualTo(PartialResultState.Failed));
            Assert.That(result_2.State, Is.EqualTo(PartialResultState.Failed));
            Assert.That(result_3.State, Is.EqualTo(PartialResultState.Failed));

            Assert.That(string.Join(",", result_1.CauseMessages), Is.EqualTo("warn,err,ex"));
            Assert.That(string.Join(",", result_2.CauseMessages), Is.EqualTo("fail,warn"));
            Assert.That(string.Join(",", result_3.CauseMessages), Is.EqualTo("fail,warn"));
        }
Beispiel #2
0
        public void adding_success_and_failure_results_in_failure()
        {
            var result_1 = PartialResult <int> .Success(1).Failure("err");

            var result_2 = PartialResult.Success(2).Failure("fail");
            var result_3 = PartialResult <int> .Failure("fail").Success(1);

            Assert.That(result_1.State, Is.EqualTo(PartialResultState.Failed));
            Assert.That(result_2.State, Is.EqualTo(PartialResultState.Failed));
            Assert.That(result_3.State, Is.EqualTo(PartialResultState.Failed));
        }
Beispiel #3
0
        public void can_change_the_contained_type_of_a_failure_result_to_help_error_propagation()
        {
            var expected = new Exception("hello");
            var original = PartialResult <int> .Failure(expected);

            // ReSharper disable SuggestVarOrType_Elsewhere
            PartialResult <string> propagated_1 = original.PropagateFailure <string>();
            PartialResult <float>  propagated_2 = propagated_1.PropagateFailure <float>();

            // ReSharper restore SuggestVarOrType_Elsewhere

            Assert.That(propagated_2.Causes.Single(), Is.EqualTo(expected));
        }
Beispiel #4
0
        public void failure_of_nothing_has_a_shortcut()
        {
            var result_1 = PartialResult.Failure("err");
            var result_2 = PartialResult.Failure(new Exception("err"));

            Assert.That(result_1.State, Is.EqualTo(PartialResultState.Failed));
            Assert.That(result_2.State, Is.EqualTo(PartialResultState.Failed));

            Assert.That(string.Join(",", result_1.CauseMessages), Is.EqualTo("err"));
            Assert.That(string.Join(",", result_2.CauseMessages), Is.EqualTo("err"));

            Assert.That(result_1.ResultData, Is.EqualTo(Nothing.Instance));
            Assert.That(result_2.ResultData, Is.EqualTo(Nothing.Instance));
        }