VS2005 Unit Testing HttpContext Cache

been searching for a while on how to test HttpContext and Cache in VS2005 Unit Tests, using the built in unit testing suite. Found this today..just add

TextWriter tw = new StringWriter();
HttpWorkerRequest
wr = new SimpleWorkerRequest(“/webapp”, “c:\inetpub\wwwroot\webapp\”, “default.aspx”, “”, tw);
HttpContext
.Current = new HttpContext(wr);

to you test method and the correct “using” statements, and boom – it works – up goes your code coverage % :)

Advertisements

4 thoughts on “VS2005 Unit Testing HttpContext Cache”

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s