When trying to test my MVC 2 controllers, I am having a hard time testing the result of TempData
when I'm doing a redirect. It works ok if the result of the controller action is a ViewResult
, however, in a redirect, it is RedirectToRouteResult
.
So my test is something like this:
var controller = new SubscriptionController(this.dataStorageMock.Object)
{
ControllerContext = MvcMockHelpers.GetControllerContextMock("POST")
};
var actionResult = controller.Create(formCollection);
var redirectResult = (RedirectToRouteResult)actionResult;
// TODO: Need to ensure TempData contains a key "info".
One option is to do the following:
Assert.That(controller.TempData.ContainsKey("info"));
If the result had been a ViewResult
it could have been tested like this:
var viewResult = (ViewResult)actionResult;
Assert.That(viewResult.TempData.ContainsKey("info"));
Is there a way to test RedirectToRouteResult
the same way as the ViewResult
can be tested?
Thanks