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(); }
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(); }
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); }
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); }
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>()); }
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"); }
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); }
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>()); }
public void Should_throw_if_ViewName_is_empty_string() { var rescue = new RescueAttribute(string.Empty); }
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")); }