Ejemplo n.º 1
0
        private static Failable <T> Where <T>(T value, Func <T, bool> predicate, Exception error)
        {
            #pragma warning disable CS8604
            if (predicate(value) is false)
            {
                return(Failable.FromException <T>(error));
            }

            return(Failable.From(value));
        }
Ejemplo n.º 2
0
        public void Should_Run_Failure_Given_Failure_Value()
        {
            var nothing = Nothing.Of();

            var failable =
                nothing
                .Do(() => Failable.FromException <string>(new Exception("It could not create a failable")))
                .Match(
                    success: (value) => throw new Exception("Test has failed. It should run failure"),    // fail
                    failure: (error) => Assert.Equal("It could not create a failable", error.Message)     // pass
                    );
        }
Ejemplo n.º 3
0
        public void Should_Not_Select_From_Exception()
        {
            Failable <bool> input = Failable.FromException <bool>(new Exception("It should not create a value"));

            Failable <bool> value =
                input
                .Select();

            value.Match(
                success: (value) => throw new Exception("Test has failed. It should not run the select function"),
                failure: (error) => Assert.Equal("It should not create a value", error.Message)
                );
        }