Esempio n. 1
0
        public async Task Error500_ShouldReturn_500View()
        {
            var result = await _controller.Error500();

            var viewResult = Assert.IsType <ViewResult>(result);

            Assert.Equal("500", viewResult.ViewName);
        }
        public void Error500()
        {
            var controller = new ErrorController();

            controller.ControllerContext.HttpContext   = new DefaultHttpContext();
            controller.HttpContext.Response.StatusCode = ((int)HttpStatusCode.InternalServerError);
            controller.HttpContext.Features.Set <IExceptionHandlerPathFeature>(
                new ExceptionHandlerFeature
            {
                Error = new Exception("MySQL Connection error"),
                Path  = "/Home"
            });

            var result = controller.Error500() as ViewResult;
            var model  = result.Model as ErrorViewModel;

            Assert.Equal(500, model.StatusCode);
            Assert.True(model.ShowRequestId);
            Assert.Equal("MySQL Connection error", result.ViewData["ErrorMessage"]);
            Assert.Equal("/Home", result.ViewData["RouteOfException"]);
        }