Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to unit test Response.Redirect?

I need to test my controller which does Response.Redirect() at the last line. But in that moment the Response object is null. What I need to do to unit test it?
I don't use NUnit or other tools but built-in.

like image 849
LINQ2Vodka Avatar asked Jul 08 '11 11:07

LINQ2Vodka


1 Answers

That's not nearly enough information for a specific answer, but here's some information that might be useful.

First off, I'll assume your controller returns ActionResult, which is a base class for all the actual results, including System.Web.Mvc.RedirectResult. RedirectResult has a property called Url which is what you need to test.

Secondly, from what I can understand, your Response object is null, probably because your testing environment/setup does not initialise it. You should consider using a mocking library to help you out on that, such as Moq.

like image 195
Vlad Ciobanu Avatar answered Oct 01 '22 03:10

Vlad Ciobanu