Ejemplo n.º 1
0
        public void GivenAppExceptionRuleWhenUnknownExceptionProvidedThenShouldAdviceToSkip()
        {
            // Arrange
            var sut       = new ExceptionRuleForErrorProvider <ApplicationExceptionBase>();
            var exception = new ThirdPartyFailureException("Error");

            // Act
            var result = sut.CanHandle(exception);

            // Assert
            Assert.False(result);
        }
Ejemplo n.º 2
0
        public void ShouldReturnExceptionOfAddionalOrThirdPartyLibraryNestedExceptionTypes()
        {
            // Arrange
            var options = Substitute.For <IErrorProviderOptions>();

            options.IncludeSystemLevelExceptions.Returns(false);
            options.ExceptionsToHandle.Returns(new List <IExceptionRule>
            {
                new ExceptionRuleForErrorProvider <ApplicationExceptionBase>(),
                new ExceptionRuleForErrorProvider <ThirdPartyFailureException>()
            });

            var internalThirdPartyLibError = new ThirdPartyFailureException("External library error");
            var internalError = new OurApplicationException("Internal app error 1", internalThirdPartyLibError);
            var exception     = new OurApplicationException("Our App Error", internalError);

            var sut = new ErrorProvider();

            // Act
            var result = sut.ExtractErrorsFor(exception, options);

            // Assert
            Assert.Equal("Our App Error", result.Message);
            Assert.Equal("OurApplicationException", result.ErrorType);
            Assert.Collection(result.ChildErrors,
                              t1 =>
            {
                Assert.Equal("Internal app error 1", t1.Message);
                Assert.Equal("OurApplicationException", t1.ErrorType);
                Assert.Collection(t1.ChildErrors, l1 =>
                {
                    Assert.Equal("External library error", l1.Message);
                    Assert.Equal("ThirdPartyFailureException", l1.ErrorType);
                    Assert.Empty(l1.ChildErrors);
                });
            }
                              );
        }