Skip to content

Beginnings of #47 #50

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 18, 2015
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