public void Creating_a_result_success_has_no_error_message()
        {
            var result = ResultSimple.Ok(new MyClass1());

            result.Error.Should().BeNullOrEmpty();
            result.IsFailure.Should().BeFalse();
        }
        public void Creating_a_result_failure_has_an_error_message()
        {
            var result = ResultSimple.Fail <MyClass1>("ups");

            result.IsFailure.Should().BeTrue();
            result.Error.Should().Be("ups");
        }
        public void OnFailure_with_success_does_not_run_action()
        {
            var myBool   = false;
            var myresult = ResultSimple.Ok(new MyClass());

            myresult.OnFailure(error => myBool = true);
            myBool.Should().BeFalse();
        }
        public void OnFailure_with_failure_runs_action()
        {
            var myBool   = false;
            var myresult = ResultSimple.Fail <MyClass>("ups");

            myresult.OnFailure(error => myBool = true);
            myBool.Should().BeTrue();
        }
        public void OnSuccess_with_failure_returns_error()
        {
            var myresult = ResultSimple.Fail <MyClass>("ups");
            var result   = myresult
                           .OnSuccess(x => ResultSimple.Ok(new MyClass {
                Property = "changed"
            }));

            result.Error.Should().Be("ups");
        }
        public void OnSuccess_with_success_runs_function()
        {
            var myresult = ResultSimple.Ok(new MyClass {
                Property = "original"
            });
            var result = myresult
                         .OnSuccess(x => ResultSimple.Ok(new MyClass {
                Property = "changed"
            }));

            result.Value.Property.Should().Be("changed");
        }
        public void OnBoth_with_failure_runs_function()
        {
            var myresult = ResultSimple.Fail <MyClass>("ups");
            var result   = myresult
                           .OnBoth(x => x.IsFailure
                    ? new Dummy {
                Name = x.Error
            }
                    : new Dummy {
                Name = x.Value.Property
            });

            result.Name.Should().Be("ups");
        }
        public void OnBoth_with_success_runs_function()
        {
            var myresult = ResultSimple.Ok(new MyClass {
                Property = "original"
            });
            var result = myresult
                         .OnBoth(x => x.IsFailure
                    ? new Dummy {
                Name = x.Error
            }
                    : new Dummy {
                Name = x.Value.Property
            });

            result.Name.Should().Be("original");
        }