Skip to content

Commit 73ba914

Browse files
committed
Correct implementation of #47
1 parent ab5380b commit 73ba914

File tree

2 files changed

+16
-17
lines changed

2 files changed

+16
-17
lines changed

TestStack.FluentMVCTesting.Tests/ControllerResultTestTests/ShouldRedirectToTests.cs

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -179,24 +179,19 @@ public void Check_for_redirect_to_incorrect_action_in_another_controller()
179179
Assert.That(exception.Message, Is.EqualTo("Expected redirect to action 'SomeOtherAction', but instead was given a redirect to action 'SomeAction'."));
180180
}
181181

182-
// TODO:
183-
// Remove this test instead of commenting it.
184-
// Give this issue 47 test a better name.
185-
186-
//[Test]
187-
//public void Check_for_redirect_to_action_with_non_specified_controller()
188-
//{
189-
// var exception = Assert.Throws<ActionResultAssertionException>(() =>
190-
// _controller.WithCallTo(c => c.RedirectToAnotherActionNoController()).ShouldRedirectTo<SomeOtherController>(c => c.SomeOtherAction())
191-
// );
192-
// 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."));
193-
//}
182+
[Test]
183+
public void Check_for_redirect_to_action_within_same_controller()
184+
{
185+
_controller.WithCallTo(c => c.RedirectToActionWithNoParameters()).ShouldRedirectTo<ControllerResultTestController>(c => c.ActionWithNoParameters());
186+
}
194187

195188
[Test]
196-
public void Issue47()
189+
public void Check_for_redirect_to_action_within_different_controller()
197190
{
198-
_controller.WithCallTo(c => c.RedirectToActionWithNoParameters())
199-
.ShouldRedirectTo<ControllerResultTestController>(c => c.ActionWithNoParameters());
191+
var exception = Assert.Throws<ActionResultAssertionException>(() =>
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."));
200195
}
201196
}
202197
}

TestStack.FluentMvcTesting/ControllerResultTest/ShouldRedirectTo.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,12 +116,16 @@ public RouteValueDictionary ShouldRedirectTo<TController>(MethodInfo methodInfo)
116116

117117
var redirectResult = (RedirectToRouteResult)ActionResult;
118118

119-
if (redirectResult.RouteValues["Controller"] == null)
120-
//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"]));
119+
if (redirectResult.RouteValues["Controller"] == null && typeof(TController) == typeof(T))
121120
{
122121
return redirectResult.RouteValues;
123122
}
124123

124+
if (redirectResult.RouteValues["Controller"] == null)
125+
{
126+
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+
}
128+
125129
if (redirectResult.RouteValues["Controller"].ToString() != controllerName)
126130
throw new ActionResultAssertionException(string.Format("Expected redirect to controller '{0}', but instead was given a redirect to controller '{1}'.", controllerName, redirectResult.RouteValues["Controller"]));
127131

0 commit comments

Comments
 (0)