Esempio n. 1
0
        public void When_using_custom_exception_handler_it_must_create_error_document_and_log()
        {
            // Arrange
            var loggerFactory = new FakeLoggerFactory();
            var options       = new JsonApiOptions {
                IncludeExceptionStackTraceInErrors = true
            };
            var handler = new CustomExceptionHandler(loggerFactory, options);

            // Act
            var errorDocument = handler.HandleException(new NoPermissionException("YouTube"));

            // Assert
            Assert.Single(errorDocument.Errors);
            Assert.Equal("For support, email to: [email protected]?subject=YouTube",
                         errorDocument.Errors[0].Meta.Data["support"]);
            Assert.NotEmpty((string[])errorDocument.Errors[0].Meta.Data["StackTrace"]);

            Assert.Single(loggerFactory.Logger.Messages);
            Assert.Equal(LogLevel.Warning, loggerFactory.Logger.Messages[0].LogLevel);
            Assert.Contains("Access is denied.", loggerFactory.Logger.Messages[0].Text);
        }