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");
        }
 protected override void given_the_context_of()
 {
     methodFactory = Mock<IMethodFactory>();
     info = typeof(MethodHost).GetMethod("Rescue");
     attribute = new RescueAttribute("Rescue");
     container = Stub<IServiceLocator>();
     container.Stub(x => x.GetInstance<IMethodFactory>()).Return(methodFactory).Repeat.Any();
 }
Exemple #3
0
 protected override void given_the_context_of()
 {
     methodFactory = Mock <IMethodFactory>();
     info          = typeof(MethodHost).GetMethod("Rescue");
     attribute     = new RescueAttribute("Rescue");
     container     = Stub <IServiceLocator>();
     container.Stub(x => x.GetInstance(typeof(IMethodFactory), null)).Return(methodFactory).Repeat.Any();
 }
Exemple #4
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 #5
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 #6
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 #7
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 #8
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 #9
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>());
        }
Exemple #10
0
 public void Should_throw_if_ViewName_is_empty_string()
 {
     var rescue = new RescueAttribute(string.Empty);
 }
Exemple #11
0
        public void ViewName_should_return_name_of_view_appended_to_Rescues_directory()
        {
            var rescue = new RescueAttribute("TestRescue");

            Assert.That(rescue.ViewName, Is.EqualTo("Rescues/TestRescue"));
        }