Skip to content

Commit 18774c5

Browse files
ByteBlastByteBlast
ByteBlast
authored and
ByteBlast
committed
Merge pull request #50 from ByteBlast/master
Implementation of #47
2 parents 6944eba + 73ba914 commit 18774c5

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

TestStack.FluentMVCTesting.Tests/ControllerResultTestTests/ShouldRedirectToTests.cs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -180,12 +180,18 @@ public void Check_for_redirect_to_incorrect_action_in_another_controller()
180180
}
181181

182182
[Test]
183-
public void Check_for_redirect_to_action_with_non_specified_controller()
183+
public void Check_for_redirect_to_action_within_same_controller()
184+
{
185+
_controller.WithCallTo(c => c.RedirectToActionWithNoParameters()).ShouldRedirectTo<ControllerResultTestController>(c => c.ActionWithNoParameters());
186+
}
187+
188+
[Test]
189+
public void Check_for_redirect_to_action_within_different_controller()
184190
{
185191
var exception = Assert.Throws<ActionResultAssertionException>(() =>
186-
_controller.WithCallTo(c => c.RedirectToAnotherActionNoController()).ShouldRedirectTo<SomeOtherController>(c => c.SomeOtherAction())
187-
);
188-
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."));
192+
_controller.WithCallTo(c => c.RedirectToActionWithNoParameters()).ShouldRedirectTo<SomeOtherController>(c => c.SomeAction()));
193+
Console.WriteLine(exception);
194+
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."));
189195
}
190196
}
191197
}

TestStack.FluentMvcTesting/ControllerResultTest/ShouldRedirectTo.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,15 @@ public RouteValueDictionary ShouldRedirectTo<TController>(MethodInfo methodInfo)
116116

117117
var redirectResult = (RedirectToRouteResult)ActionResult;
118118

119+
if (redirectResult.RouteValues["Controller"] == null && typeof(TController) == typeof(T))
120+
{
121+
return redirectResult.RouteValues;
122+
}
123+
119124
if (redirectResult.RouteValues["Controller"] == null)
125+
{
120126
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"]));
127+
}
121128

122129
if (redirectResult.RouteValues["Controller"].ToString() != controllerName)
123130
throw new ActionResultAssertionException(string.Format("Expected redirect to controller '{0}', but instead was given a redirect to controller '{1}'.", controllerName, redirectResult.RouteValues["Controller"]));

0 commit comments

Comments
 (0)