Request.UrlReferrer.OriginalString and Request.RawUrl are things which should be generally accessible in an ASP.NET MVC Controller yet blow up in unit testing. StackOverflow suggests there are ways to mock them with both MOQ and NSubstitute but I haven't tried either because we don't use MOQ where I work and the NSubstitute example looks more complicated than I had hoped. While I am writing of testing controllers I want to mention that this shows off how to test against a model a Controller hands back by getting an ActionResult casting it to a ViewResult and then casting .ViewData.Model off of that to your POCO's type. I wanted to write of it because I had to Google it this morning when I couldn't find an example at my own blog. As it turns out, I did have an example.
No comments:
Post a Comment