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_Success_Given_A_Value()
        {
            var nothing = Nothing.Of();

            var failable =
                nothing
                .Do(() => Failable.From("success"))
                .Match(
                    success: (value) => Assert.True(true), // pass
                    failure: (error) => throw error        // fail
                    );
        }
Ejemplo n.º 3
0
        public void Should_Run_Success_Given_A_Value()
        {
            Maybe <string> maybe = "value";

            _ =
                maybe
                .ToFailable()
                .Pipe(
                    Do <string>((value) => Failable.From(value))
                    )
                .Match(
                    success: (value) => Assert.True(true),                              // pass
                    failure: (_) => throw new Exception("It should not run this block") // fail
                    );
        }
Ejemplo n.º 4
0
        public void Should_Create_Success()
        {
            var value = Failable.From(true);

            Assert.True(value.Succeeded);
        }
Ejemplo n.º 5
0
        public void Should_Create_Failure()
        {
            var value = Failable.From(new Exception());

            Assert.True(value.Failed);
        }