Ejemplo n.º 1
0
        public void Try_ShouldReturnAnExceptionalPopulatedWithAnExceptionOrACorrectValueIfNoneOcurred()
        {
            // Note: new List<int>()[4] will always throw System.ArgumentOutOfRangeException
            //Act
            var result = FunctionalErrorHandling.Try(() => new List <int>()[4]);

            //Assert
            Assert.True(result.Exception);
        }
Ejemplo n.º 2
0
        public void Safely_ShouldReturnAnEitherPopulatedWithALeftValueIfAnExceptionOcurredOrARightValueOtherwise()
        {
            // Note: new List<int>()[4] will always throw System.ArgumentOutOfRangeException
            //Act
            var result = FunctionalErrorHandling.Safely(() => new List <int>()[4], e => "An exception ocurred");

            //Assert
            Assert.Equal(expected: Left("An exception ocurred"), actual: result);
        }