Http objects and Unit testing
Following yesterday's Unit testing and Caching blog I've decided to spend a little time writing support for all Http-based objects, like Response, Request, Server as well as Context.Items and Cache.
So, now I have a new class called Context in the Utils assembly that replaces every HttpContext.Current reference in the entire application. There were a lot of them, but now I have a common place to simulate HttpRequest etc for my code.
When my code looks for a cookie it looks in Context.Request.Cookies instead of HttpContext.Current.Request.Cookies. Today my class just implements a singleton HttpRequest object and passes all calls through that.
It's not perfect because the only public constructor for HttpRequest won't let you set the HttpWorkerRequest and therefore all calls to properties such as AppliationPath (which I use) come back null. But it's a good start and my unit tests are running well.
I'm tempted to ask if anyone wants to help turn this Context class into something more useful, and share it around? It seems that it would be useful to anyone writing class libraries that have to use HttpContext.