Exemple #1
0
        public void When_PerformRescue_exact_exception_executed_first()
        {
            var rescue = new RescueAttribute("TestRescue");

            _viewEngine.CustomViews.Add("Rescues/InheritedRescueTestException");
            _viewEngine.CustomViews.Add("Rescues/RescueTestException");

            var context = new ExceptionContext(_controllerContext, new InheritedRescueTestException());

            rescue.OnException(context);

            Assert.That(context.ExceptionHandled);
            context.Result.AssertViewRendered().ForView("Rescues/InheritedRescueTestException");

            context = new ExceptionContext(_controllerContext, new RescueTestException());
            rescue.OnException(context);

            Assert.That(context.ExceptionHandled);
            context.Result.AssertViewRendered().ForView("Rescues/RescueTestException");

            rescue = new RescueAttribute("TestRescue", typeof(RescueTestException));

            _viewEngine.CustomViews.Clear();
            _viewEngine.CustomViews.Add("Rescues/RescueTestException");

            context = new ExceptionContext(_controllerContext, new InheritedRescueTestException());
            rescue.OnException(context);

            Assert.That(context.ExceptionHandled);
            context.Result.AssertViewRendered().ForView("Rescues/RescueTestException");
        }
Exemple #2
0
        public void When_OnActionExecuted_is_invoked_then_the_correct_view_should_be_rendered()
        {
            var rescue = new RescueAttribute("TestRescue");

            var context = new ExceptionContext(_controllerContext, _exception);

            rescue.OnException(context);
            Assert.That(context.ExceptionHandled);
            string expectedRescueView = "Rescues/TestRescue";

            context.Result.AssertViewRendered().ForView(expectedRescueView);
        }
Exemple #3
0
        public void If_rescue_exception_type_does_not_match_exception_type_then_nothing_should_be_rendered()
        {
            _exception = new RescueTestException();
            SetupController(_controller);
            var rescue  = new RescueAttribute("TestRescue", typeof(InvalidOperationException));
            var context = new ExceptionContext(_controllerContext, _exception);

            rescue.OnException(context);

            Assert.That(context.ExceptionHandled, Is.False);
            Assert.That(((RescueTestController)_controller).OnExceptionFired, Is.False);
        }
Exemple #4
0
        public void Ajax_Call_Should_Be_Ignored()
        {
            _exception = new RescueTestException();
            var rescue  = new RescueAttribute("TestRescue");
            var context = new ExceptionContext(_controllerContext, _exception);

            _controllerContext.HttpContext.Request.Headers["X-Requested-With"] = "XMLHttpRequest";

            rescue.OnException(context);

            Assert.IsFalse(context.ExceptionHandled);
            Assert.That(context.Result, Is.InstanceOf <EmptyResult>());
        }
Exemple #5
0
        public void When_PerformRescue_is_invoked_with_matching_view_it_should_be_rendered()
        {
            var rescue = new RescueAttribute("TestRescue");

            _viewEngine.CustomViews.Add("Rescues/RescueTestException");

            var context = new ExceptionContext(_controllerContext, new RescueTestException());

            rescue.OnException(context);

            Assert.That(context.ExceptionHandled);
            context.Result.AssertViewRendered().ForView("Rescues/RescueTestException");
        }
Exemple #6
0
        public void If_rescue_exception_type_matches_exception_type_then_view_should_be_rendered()
        {
            _exception = new RescueTestException();
            SetupController(_controller);
            var rescue  = new RescueAttribute("TestRescue", typeof(RescueTestException));
            var context = new ExceptionContext(_controllerContext, _exception);

            rescue.OnException(context);

            string expectedRescueView = "Rescues/TestRescue";

            context.Result.AssertViewRendered().ForView(expectedRescueView);
        }
Exemple #7
0
        public void Ignored_Exception_Types_Should_Be_Ignored()
        {
            _exception = new IgnoreTestException();
            var rescue = new RescueAttribute("TestRescue")
            {
                IgnoreTypes = new Type[] { typeof(IgnoreTestException) }
            };
            var context = new ExceptionContext(_controllerContext, _exception);

            rescue.OnException(context);

            Assert.IsFalse(context.ExceptionHandled);
            Assert.That(context.Result, Is.InstanceOf <EmptyResult>());
        }