From ab5380becd98e703950b14874945718ecb695b9a Mon Sep 17 00:00:00 2001 From: ByteBlast Date: Wed, 14 Jan 2015 18:27:06 +0000 Subject: [PATCH 1/2] Beginnings of #47 --- .../ShouldRedirectToTests.cs | 21 ++++++++++++++----- .../ControllerResultTest/ShouldRedirectTo.cs | 5 ++++- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/TestStack.FluentMVCTesting.Tests/ControllerResultTestTests/ShouldRedirectToTests.cs b/TestStack.FluentMVCTesting.Tests/ControllerResultTestTests/ShouldRedirectToTests.cs index 3e8f57f..4569e71 100644 --- a/TestStack.FluentMVCTesting.Tests/ControllerResultTestTests/ShouldRedirectToTests.cs +++ b/TestStack.FluentMVCTesting.Tests/ControllerResultTestTests/ShouldRedirectToTests.cs @@ -179,13 +179,24 @@ public void Check_for_redirect_to_incorrect_action_in_another_controller() Assert.That(exception.Message, Is.EqualTo("Expected redirect to action 'SomeOtherAction', but instead was given a redirect to action 'SomeAction'.")); } + // TODO: + // Remove this test instead of commenting it. + // Give this issue 47 test a better name. + + //[Test] + //public void Check_for_redirect_to_action_with_non_specified_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.")); + //} + [Test] - public void Check_for_redirect_to_action_with_non_specified_controller() + public void Issue47() { - 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.ActionWithNoParameters()); } } } \ No newline at end of file diff --git a/TestStack.FluentMvcTesting/ControllerResultTest/ShouldRedirectTo.cs b/TestStack.FluentMvcTesting/ControllerResultTest/ShouldRedirectTo.cs index e435197..00d3085 100644 --- a/TestStack.FluentMvcTesting/ControllerResultTest/ShouldRedirectTo.cs +++ b/TestStack.FluentMvcTesting/ControllerResultTest/ShouldRedirectTo.cs @@ -117,7 +117,10 @@ public RouteValueDictionary ShouldRedirectTo(MethodInfo methodInfo) var redirectResult = (RedirectToRouteResult)ActionResult; 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"])); + //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"])); + { + return redirectResult.RouteValues; + } 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"])); From 73ba914f139f6761369eddac137643a46a5126a4 Mon Sep 17 00:00:00 2001 From: ByteBlast Date: Sat, 17 Jan 2015 21:41:22 +0000 Subject: [PATCH 2/2] Correct implementation of #47 --- .../ShouldRedirectToTests.cs | 25 ++++++++----------- .../ControllerResultTest/ShouldRedirectTo.cs | 8 ++++-- 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/TestStack.FluentMVCTesting.Tests/ControllerResultTestTests/ShouldRedirectToTests.cs b/TestStack.FluentMVCTesting.Tests/ControllerResultTestTests/ShouldRedirectToTests.cs index 4569e71..c7b4ecb 100644 --- a/TestStack.FluentMVCTesting.Tests/ControllerResultTestTests/ShouldRedirectToTests.cs +++ b/TestStack.FluentMVCTesting.Tests/ControllerResultTestTests/ShouldRedirectToTests.cs @@ -179,24 +179,19 @@ public void Check_for_redirect_to_incorrect_action_in_another_controller() Assert.That(exception.Message, Is.EqualTo("Expected redirect to action 'SomeOtherAction', but instead was given a redirect to action 'SomeAction'.")); } - // TODO: - // Remove this test instead of commenting it. - // Give this issue 47 test a better name. - - //[Test] - //public void Check_for_redirect_to_action_with_non_specified_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.")); - //} + [Test] + public void Check_for_redirect_to_action_within_same_controller() + { + _controller.WithCallTo(c => c.RedirectToActionWithNoParameters()).ShouldRedirectTo(c => c.ActionWithNoParameters()); + } [Test] - public void Issue47() + public void Check_for_redirect_to_action_within_different_controller() { - _controller.WithCallTo(c => c.RedirectToActionWithNoParameters()) - .ShouldRedirectTo(c => c.ActionWithNoParameters()); + var exception = Assert.Throws(() => + _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 00d3085..3f183e6 100644 --- a/TestStack.FluentMvcTesting/ControllerResultTest/ShouldRedirectTo.cs +++ b/TestStack.FluentMvcTesting/ControllerResultTest/ShouldRedirectTo.cs @@ -116,12 +116,16 @@ public RouteValueDictionary ShouldRedirectTo(MethodInfo methodInfo) var redirectResult = (RedirectToRouteResult)ActionResult; - 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"] == 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"]));