Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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<ControllerResultTestController>(c => c.ActionWithNoParameters());
}

[Test]
public void Check_for_redirect_to_action_within_different_controller()
{
var exception = Assert.Throws<ActionResultAssertionException>(() =>
_controller.WithCallTo(c => c.RedirectToAnotherActionNoController()).ShouldRedirectTo<SomeOtherController>(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<SomeOtherController>(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."));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,15 @@ public RouteValueDictionary ShouldRedirectTo<TController>(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"]));
Expand Down