I've had this happen a couple of times now and the first time was a little worrying that I'd bricked my iPhone. Basically I was running an application on my phone via XCode and when rebuilding an updated version it failed with a "busy" error message. Stopping XCode and unconnecting my phone had no effect, the phone was stuck displaying the loading screen of the application and wouldn't respond to any key commands. To fix you have to hard reboot, holding the power and home button until the phone reboots - doesn't lose any of the data you have on your phone (a concern the first time I did it).
When unit testing ASP.NET MVC2 projects the issue of injecting HttpContext is quickly encountered. There seem to be many different ways / recommendations for mocking HttpContextBase to improve the testability of controllers and their actions. My investigations into that will probably be a separate blog post in the near future but for now I want to cover something that had me stuck for longer than it probably should have. That is how to mock non abstract/interfaced classes within HttpRequestBase and HttpResponseBase – namely the HttpCookieCollection class. The code sample below illustrates how it can be used within a mocked instance of HttpRequestBase. Cookies can be added / modified within the unit test code prior to being passed into the code being tested. After it’s been called, using a combination of MOQ’s Verify and NUnit’s Assert it is possible to check how many times the collection is accessed (but you have to include the set up calls) and that the relevant cookies have …
Comments
Post a Comment