예제 #1
0
 public void GivenAnError_ThenAJSONViewResultIsreturned()
 {
     var controller = new TestableBaseController(_logger.Object);
     SetControllerContext(controller);
     var error = controller.JsonError(new Exception(), new ErrorCode(), "");
     error.Should().BeOfType<JsonResult>();
 }
예제 #2
0
 public void GivenThereIsACustomError_AndItIsNotAnHttpRequestValidationException_ThenTheViewIsSetToError()
 {
     var controller = new TestableBaseController(_logger.Object);
     var filterContext = new ExceptionContext();
     MockHttpContext.Setup(h => h.IsCustomErrorEnabled).Returns(true);
     filterContext.HttpContext = MockHttpContext.Object;
     filterContext.Exception = new Exception();
     controller.OnException(filterContext);
     filterContext.Result.As<ViewResult>().ViewName.Should().Be("Error");
 }
예제 #3
0
 public void GivenAnError_ThenTheJSONViewResultContainsTheCorrectData()
 {
     var controller = new TestableBaseController(_logger.Object);
     SetControllerContext(controller);
     const ErrorCode code = new ErrorCode();
     var ex = new Exception("error message");
     var error = controller.JsonError(ex, code, "message");
     error.As<JsonResult>().Data.As<ErrorViewModel>().DisplayMessage.Should().Be("message");
     error.As<JsonResult>().Data.As<ErrorViewModel>().ErrorCode.Should().Be(code);
     error.As<JsonResult>().Data.As<ErrorViewModel>().ErrorMessage.Should().Be("error message");
 }
예제 #4
0
 public void GivenThereIsNoFilterContext_ThenTheErrorIsNotHandled()
 {
     var controller = new TestableBaseController(_logger.Object);
     controller.OnException(null);
 }
예제 #5
0
 public void GivenThereIsNoCustomError_ThenTheErrorIsHandled()
 {
     var controller = new TestableBaseController(_logger.Object);
     var filterContext = new ExceptionContext();
     MockHttpContext.Setup(h => h.IsCustomErrorEnabled).Returns(false);
     filterContext.HttpContext = MockHttpContext.Object;
     controller.OnException(filterContext);
     filterContext.ExceptionHandled.Should().BeFalse();
 }