public void GivenExceptionIsEntityNotFoundException_WhenOnException_ThenExceptionHandled() { EntityNotFoundException exception = new EntityNotFoundException(); ExceptionContext context = ControllerContextFactory.CreateExceptionContext(MockHttpContext, exception); Target.OnException(context); Assert.IsTrue(context.ExceptionHandled); }
public void GivenResponseHasBeenWrittenTo_ExceptionIsEntityNotFoundException_WhenOnException_ThenResponseHasBeenCleared() { EntityNotFoundException exception = new EntityNotFoundException(); ExceptionContext context = ControllerContextFactory.CreateExceptionContext(MockHttpContext, exception); Target.OnException(context); MockHttpContext.Response.AssertWasCalled(m => m.Clear()); }
public void GivenExceptionIsUnreserved_AndCustomErrorsEnabled_WhenOnException_ThenDefaultToGeneralServerError() { Exception exception = new Exception(); ExceptionContext context = ControllerContextFactory.CreateExceptionContext(MockHttpContext, exception); MockHttpContext.Expect(m => m.IsCustomErrorEnabled).Return(true); Target.OnException(context); MockHttpContext.Response.AssertWasCalled(m => m.StatusCode = 500); }
public void GivenExceptionIsEntityAccessUnauthorizedException_WhenOnException_ThenHttpUnauthorized() { EntityAccessUnauthorizedException exception = new EntityAccessUnauthorizedException(); ExceptionContext context = ControllerContextFactory.CreateExceptionContext(MockHttpContext, exception); Target.OnException(context); HttpUnauthorizedResult actual = context.Result as HttpUnauthorizedResult; Assert.IsNotNull(actual); MockHttpContext.Response.AssertWasCalled(m => m.StatusCode = 401); }
public void GivenExceptionHasBeenHandled_AndExceptionIsEntityNotFoundException_WhenOnException_ThenResultNull_AndStatusNotChanged() { EntityNotFoundException exception = new EntityNotFoundException(); ExceptionContext context = ControllerContextFactory.CreateExceptionContext(MockHttpContext, exception); context.ExceptionHandled = true; Target.OnException(context); Assert.IsInstanceOfType(context.Result, typeof(EmptyResult)); MockHttpContext.Response.AssertWasNotCalled(m => m.StatusCode = Arg <int> .Is.Anything); }
public void GivenExceptionIsEntityNotFoundException_WhenOnException_ThenHttpDescriptionIsExceptionMessage() { string expected = "blah blah exception message and stuff"; EntityNotFoundException exception = new EntityNotFoundException(expected); ExceptionContext context = ControllerContextFactory.CreateExceptionContext(MockHttpContext, exception); Target.OnException(context); HttpStatusCodeResult actual = context.Result as HttpStatusCodeResult; Assert.AreEqual(expected, actual.StatusDescription); }