How do I Test an entire Chain of Controller Calls Linked by RedirectToAction?
I'm very new to MVC (just 2 days in), but I'm wondering - is there any way to write a test for an entire chain of controller calls linked by RedirectToAction? i.e. test the whole call sequence one after another without manually coding each call.
e.g.something along the lines of:
MyTestMethod()
{
var myController = new MyController(someparam1);
ActionResult action = myController.DoSomething();
RedirectToAction ar = action as RedirectToAction;
// loop while the ActionResult is an RedirectToAction
while (ar!=null)
{
// automatically make direct call to next redirect method in
// chain, is something like this possible?
action = ar.NextMethodToCall(ar.NextMethodToCallParam1, ar.NextMethodToCallParam2);
ar = action as RedirectToAction;
}
}
So, to be clear, this is NOT a unit test, (which would only test that a single controller method returns the correct actionresult), but rather a test of the开发者_如何转开发 whole redirect chain.
NOTE - as this is only a test method, the MVC app will NOT be running at the time it is called. IIS will not even be installed on the test machine.
You could put some logging/test logic in the NextMethodToCall()
method.
After a little more reading on MVC, I've realised that what I really need is a more holistic approach to integration testing MVC apps without a browser or IIS install, e.g. something like this:
http://blog.stevensanderson.com/2009/06/11/integration-testing-your-aspnet-mvc-application/
精彩评论