diff --git a/TestStack.FluentMVCTesting.Tests/ControllerResultTestTests/ShouldRedirectToTests.cs b/TestStack.FluentMVCTesting.Tests/ControllerResultTestTests/ShouldRedirectToTests.cs index 3e8f57f..c7b4ecb 100644 --- a/TestStack.FluentMVCTesting.Tests/ControllerResultTestTests/ShouldRedirectToTests.cs +++ b/TestStack.FluentMVCTesting.Tests/ControllerResultTestTests/ShouldRedirectToTests.cs @@ -180,12 +180,18 @@ public void Check_for_redirect_to_incorrect_action_in_another_controller() } [Test] - public void Check_for_redirect_to_action_with_non_specified_controller() + public void Check_for_redirect_to_action_within_same_controller() + { + _controller.WithCallTo(c => c.RedirectToActionWithNoParameters()).ShouldRedirectTo(c => c.ActionWithNoParameters()); + } + + [Test] + public void Check_for_redirect_to_action_within_different_controller() { var exception = Assert.Throws(() => - _controller.WithCallTo(c => c.RedirectToAnotherActionNoController()).ShouldRedirectTo(c => c.SomeOtherAction()) - ); - Assert.That(exception.Message, Is.EqualTo("Expected redirect to action 'SomeOtherAction' in 'SomeOther' controller, but instead was given redirect to action 'SomeAction' within the same controller.")); + _controller.WithCallTo(c => c.RedirectToActionWithNoParameters()).ShouldRedirectTo(c => c.SomeAction())); + Console.WriteLine(exception); + Assert.That(exception.Message, Is.EqualTo("Expected redirect to action 'SomeAction' in 'SomeOther' controller, but instead was given redirect to action 'ActionWithNoParameters' within the same controller.")); } } } \ No newline at end of file diff --git a/TestStack.FluentMvcTesting/ControllerResultTest/ShouldRedirectTo.cs b/TestStack.FluentMvcTesting/ControllerResultTest/ShouldRedirectTo.cs index e435197..3f183e6 100644 --- a/TestStack.FluentMvcTesting/ControllerResultTest/ShouldRedirectTo.cs +++ b/TestStack.FluentMvcTesting/ControllerResultTest/ShouldRedirectTo.cs @@ -116,8 +116,15 @@ public RouteValueDictionary ShouldRedirectTo(MethodInfo methodInfo) var redirectResult = (RedirectToRouteResult)ActionResult; + if (redirectResult.RouteValues["Controller"] == null && typeof(TController) == typeof(T)) + { + return redirectResult.RouteValues; + } + if (redirectResult.RouteValues["Controller"] == null) + { throw new ActionResultAssertionException(string.Format("Expected redirect to action '{0}' in '{1}' controller, but instead was given redirect to action '{2}' within the same controller.", actionName, controllerName, redirectResult.RouteValues["Action"])); + } if (redirectResult.RouteValues["Controller"].ToString() != controllerName) throw new ActionResultAssertionException(string.Format("Expected redirect to controller '{0}', but instead was given a redirect to controller '{1}'.", controllerName, redirectResult.RouteValues["Controller"]));