Пример #1
0
        public void ShouldReturnGenericErrorWhenInProduction(Exception exception)
        {
            // Arrange
            var environment = A.Fake <IHostingEnvironment>(opts =>
            {
                opts.ConfigureFake(env => env.EnvironmentName = "Production");
            });

            var filter        = new ExceptionFilter(environment);
            var filterContext = FilterContextProvider.GetExceptionContext(exception);

            // Act
            filter.OnException(filterContext);

            // Assert
            filterContext.HttpContext.Response.StatusCode.ShouldBe((int)HttpStatusCode.InternalServerError);

            var result = filterContext.Result as JsonResult;

            result.ShouldNotBeNull();
            result.Value.ShouldBeOfType <Error>();

            var error = (Error)result.Value;

            error.Type.ShouldBe(ErrorType.Critical);
            error.Messages.ShouldNotBeEmpty();
        }
Пример #2
0
        public void ShouldReturnSerializedExceptionWhenInDevelopment(Exception exception)
        {
            // Arrange
            var environmentMock = new Mock <IHostingEnvironment>();

            environmentMock
            .Setup(e => e.EnvironmentName)
            .Returns("Development");

            var filter        = new ExceptionFilter(environmentMock.Object);
            var filterContext = FilterContextProvider.GetExceptionContext(exception);

            // Act
            filter.OnException(filterContext);

            // Assert
            filterContext.HttpContext.Response.StatusCode.ShouldBe((int)HttpStatusCode.InternalServerError);

            var result = filterContext.Result as JsonResult;

            result.ShouldNotBeNull();
            result.Value.ShouldBeOfType <Exception>();
            ((Exception)result.Value).Message.ShouldBe(exception.Message);
        }