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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With