public void GivenExceptionIsEntityAccessUnauthorizedException_WhenOnException_ThenExceptionHandled()
        {
            EntityAccessUnauthorizedException exception = new EntityAccessUnauthorizedException();
            ExceptionContext context = ControllerContextFactory.CreateExceptionContext(MockHttpContext, exception);

            Target.OnException(context);

            Assert.IsTrue(context.ExceptionHandled);
        }
        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 GivenExceptionIsEntityAccessUnauthorizedException_WhenOnException_ThenHttpDescriptionIsExceptionMessage()
        {
            string expected = "blah blah exception message and stuff";
            EntityAccessUnauthorizedException exception = new EntityAccessUnauthorizedException(expected);
            ExceptionContext context = ControllerContextFactory.CreateExceptionContext(MockHttpContext, exception);

            Target.OnException(context);

            HttpStatusCodeResult actual = context.Result as HttpStatusCodeResult;
            Assert.AreEqual(expected, actual.StatusDescription);
        }
        public void GivenExceptionHasBeenHandled_AndExceptionIsEntityAccessUnauthorizedException_WhenOnException_ThenResultNull_AndStatusNotChanged()
        {
            EntityAccessUnauthorizedException exception = new EntityAccessUnauthorizedException();
            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 GivenResponseHasBeenWrittenTo_ExceptionIsEntityAccessUnauthorizedException_WhenOnException_ThenResponseHasBeenCleared()
        {
            EntityAccessUnauthorizedException exception = new EntityAccessUnauthorizedException();
            ExceptionContext context = ControllerContextFactory.CreateExceptionContext(MockHttpContext, exception);

            Target.OnException(context);

            MockHttpContext.Response.AssertWasCalled(m => m.Clear());
        }