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();
wr = new SimpleWorkerRequest(“/webapp”, “c:inetpubwwwrootwebapp”, “default.aspx”, “”, tw);
.Current = new HttpContext(wr);

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

By Steve Novoselac

Director of Digital Technology @TrekBikes, Father, Musician, Cyclist, Homebrewer

4 replies on “VS2005 Unit Testing HttpContext Cache”

using this we are unable to retrieve the Sever.MapPath()… How to solve this issue..
waiting for ur reply..


Leave a Reply

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

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

Facebook photo

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

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.