I followed an example that talked about inheriting from your controller and overriding RedirectToAction so it would log the values it received rather than doing anything. Here's the code that was recommended:
//using the Specific Subclass patternprivate class TestContentController : ContentController
{
public string RedirectToActionValues { get; set; }
protected override void RedirectToAction(object values)
{
RedirectToActionValues = values.ToString();
}
}
The catch is that this only works for redirects to an action, not an action and a controller. For redirects to a controller, the "values" object is of type "RedirectDataWithController". For a simple redirect, I assume it's a simple string. I can't access RedirectDataWithController since it is sealed and internal. I ended up getting around that with code like this:
//using the Specific Subclass patternprivate class TestContentController : ContentController
{
public string RedirectToActionValue { get; set; }
public string RedirectToControllerValue { get; set; }
protected override void RedirectToAction(object values)
{
RedirectToActionValue = ReflectionHelper.InspectPropertyOfRedirectDataWithController(values, "Action");
RedirectToControllerValue = ReflectionHelper.InspectPropertyOfRedirectDataWithController(values, "Controller");
}
}
My ReflectionHelper looks like this (yes, it's messy):
I followed an example that talked about inheriting from your controller and overriding RedirectToAction so it would log the values it received rather than doing anything
Please see http://bradwilson.typepad.com/blog/2010/07/aspnet-mvc-filters-and-statefulness.html
Also see my browser history in MVC at http://msprogrammer.serviciipeweb.ro/category/browserhistory/ - work in progress
Andrei, Why are you replying to 4-5 year old thread?
"And whoever is removed away from the Fire and admitted to Paradise, he indeed is successful." (The Holy Quran)
Excellent Windows VPS Hosting Imran Baloch MVP, MVB, MCP, MCTS, MCPD
emarthinsen
Member
136 Points
39 Posts
Unit Testing RedirectToAction where Controller and Action are specified
Jan 15, 2008 07:38 AM|LINK
Hello-
I'm trying to test the following line of code:
RedirectToAction("Index", "Home");I followed an example that talked about inheriting from your controller and overriding RedirectToAction so it would log the values it received rather than doing anything. Here's the code that was recommended:
The catch is that this only works for redirects to an action, not an action and a controller. For redirects to a controller, the "values" object is of type "RedirectDataWithController". For a simple redirect, I assume it's a simple string. I can't access RedirectDataWithController since it is sealed and internal. I ended up getting around that with code like this:
My ReflectionHelper looks like this (yes, it's messy):
This all feels like a big hack. Is there a better way to do this?
Regards-
Eric
ignatandrei
All-Star
135210 Points
21690 Posts
Moderator
MVP
Re: Unit Testing RedirectToAction where Controller and Action are specified
Nov 18, 2012 08:39 PM|LINK
Please see http://bradwilson.typepad.com/blog/2010/07/aspnet-mvc-filters-and-statefulness.html
Also see my browser history in MVC at http://msprogrammer.serviciipeweb.ro/category/browserhistory/ - work in progress
imran_ku07
All-Star
45815 Points
7698 Posts
MVP
Re: Unit Testing RedirectToAction where Controller and Action are specified
Nov 19, 2012 01:58 PM|LINK
Andrei, Why are you replying to 4-5 year old thread?
Excellent Windows VPS Hosting
Imran Baloch MVP, MVB, MCP, MCTS, MCPD