public void GivenAnError_ThenAJSONViewResult_Isreturned() { var controller = new TestableBaseController(this.logger.Object, this.userService.Object, this.appEnvironmentService.Object); this.SetControllerContext(controller); var error = controller.JsonError(new Exception(), new ErrorCode(), String.Empty); error.Should().BeOfType <JsonResult>(); }
public void GivenThereIsNoCustomError_ThenTheError_IsHandled() { var controller = new TestableBaseController(this.logger.Object, this.userService.Object, this.appEnvironmentService.Object); var filterContext = new ExceptionContext(); MockHttpContext.Setup(h => h.IsCustomErrorEnabled).Returns(false); filterContext.HttpContext = MockHttpContext.Object; controller.OnException(filterContext); filterContext.ExceptionHandled.Should().BeFalse(); }
public void GivenThereIsACustomError_AndItIsNotAnHttpRequestValidationException_ThenTheViewIsSetToError() { var controller = new TestableBaseController(this.logger.Object, this.userService.Object, this.appEnvironmentService.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"); }
public void GivenAnError_ThenTheJSONViewResultContains_TheCorrectData() { var controller = new TestableBaseController(this.logger.Object, this.userService.Object, this.appEnvironmentService.Object); this.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"); }
public void GivenThereIsNoFilterContext_ThenTheError_IsNotHandled() { var controller = new TestableBaseController(this.logger.Object, this.userService.Object, this.appEnvironmentService.Object); controller.OnException(null); }