Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -179,13 +179,24 @@ public void Check_for_redirect_to_incorrect_action_in_another_controller()
Assert.That(exception.Message, Is.EqualTo("Expected redirect to action 'SomeOtherAction', but instead was given a redirect to action 'SomeAction'."));
}

// TODO:
// Remove this test instead of commenting it.
// Give this issue 47 test a better name.

//[Test]
//public void Check_for_redirect_to_action_with_non_specified_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."));
//}

[Test]
public void Check_for_redirect_to_action_with_non_specified_controller()
public void Issue47()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check_for_redirect_to_action_within_same_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<ControllerResultTestController>(c => c.ActionWithNoParameters());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,10 @@ public RouteValueDictionary ShouldRedirectTo<TController>(MethodInfo methodInfo)
var redirectResult = (RedirectToRouteResult)ActionResult;

if (redirectResult.RouteValues["Controller"] == null)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be redirectResult.RouteValues["Controller"] == null && typeof(TController) == typeof(T)?

Otherwise, if the action returned a redirect to the same controller, but you were checking for a different one then it wouldn't throw when it should.

You can probably add a test case for that if there isn't one already.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure off-hand.

I will spend some time to understand the code more deeply this afternoon and then issue another commit.

Thank you.

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"]));
//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"]));
{
return redirectResult.RouteValues;
}

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