Esempio n. 1
0
        public void GivenExceptionWhenRuleIsNotAbleToHandleThenShouldThrow()
        {
            // Arrange
            var sut = new ExceptionRuleForErrorProvider <OurApplicationException>();

            // Act
            // Assert
            Assert.Throws <ArgumentException>(() => sut.GetError(new Exception(), new List <Error>(), false));
        }
Esempio n. 2
0
        public void GivenExceptionWhenRuleCanHandleExceptionTypeThenShouldReturnErrorBuiltUsingDefaultBuilder()
        {
            // Arrange
            var sut       = new ExceptionRuleForErrorProvider <Exception>();
            var exception = new OurApplicationException("Error");

            // Act
            var result = sut.GetError(exception, new List <Error>(), false);

            // Assert
            Assert.Equal("Error", result.Message);
            Assert.Equal("OurApplicationException", result.ErrorType);
            Assert.Empty(result.ChildErrors);
        }
Esempio n. 3
0
        public void GivenExceptionWhenCustomBuilderProvidedThenShouldReturnErrorBuiltUsingProvidedBuilder()
        {
            // Arrange
            var builderMock = Substitute.For <IErrorBuilder <ExceptionWithCustomContent> >();
            var sut         = new ExceptionRuleForErrorProvider <ExceptionWithCustomContent>(b => b.Use(builderMock));
            var exception   = new ExceptionWithCustomContent("Content");

            builderMock.Build(Arg.Any <ExceptionWithCustomContent>(), Arg.Any <IEnumerable <Error> >(), Arg.Any <bool>())
            .Returns(c =>
            {
                var ex = c.Arg <ExceptionWithCustomContent>();
                return(new Error(ex.Content, ex.GetType().FullName));
            });

            // Act
            var result = sut.GetError(exception, new List <Error>(), false);

            // Assert
            Assert.Equal("Content", result.Message);
            Assert.Equal(typeof(ExceptionWithCustomContent).FullName, result.ErrorType);
            Assert.Empty(result.ChildErrors);
        }