Skip to content

Commit 8cd793a

Browse files
committed
Merge pull request #15 from michal-franc/nre_fix
Fix to NRE when redirect to action without specified controller
2 parents 37df132 + 432091b commit 8cd793a

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

TestStack.FluentMVCTesting.Tests/ControllerResultTestTests.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,15 @@ public void Check_for_redirect_to_incorrect_action_in_another_controller()
233233
);
234234
Assert.That(exception.Message, Is.EqualTo("Expected redirect to action 'SomeOtherAction', but instead was given a redirect to action 'SomeAction'."));
235235
}
236+
237+
[Test]
238+
public void Check_for_redirect_to_action_with_non_specified_controller()
239+
{
240+
var exception = Assert.Throws<ActionResultAssertionException>(() =>
241+
_controller.WithCallTo(c => c.RedirectToAnotherActionNoController()).ShouldRedirectTo<SomeOtherController>(c => c.SomeOtherAction())
242+
);
243+
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."));
244+
}
236245
#endregion
237246

238247
#region View tests

TestStack.FluentMVCTesting.Tests/TestControllers/ControllerResultTestController.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,11 @@ public ActionResult RedirectToAnotherController()
7878
return RedirectToAction("SomeAction", "SomeOther");
7979
}
8080

81+
public ActionResult RedirectToAnotherActionNoController()
82+
{
83+
return RedirectToAction("SomeAction");
84+
}
85+
8186
#region Redirect Actions
8287
public ActionResult ActionWithNoParameters()
8388
{

TestStack.FluentMvcTesting/ControllerResultTest.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,9 @@ public RouteValueDictionary ShouldRedirectTo<TController>(MethodInfo methodInfo)
160160

161161
var redirectResult = (RedirectToRouteResult)_actionResult;
162162

163+
if (redirectResult.RouteValues["Controller"] == null)
164+
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"]));
165+
163166
if (redirectResult.RouteValues["Controller"].ToString() != controllerName)
164167
throw new ActionResultAssertionException(string.Format("Expected redirect to controller '{0}', but instead was given a redirect to controller '{1}'.", controllerName, redirectResult.RouteValues["Controller"]));
165168

0 commit comments

Comments
 (0)