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 % :)
Simlar Posts

December 19th, 2006 at 6:59 am
Isn\’t it better to use HttpRuntime.Cache?
June 6th, 2007 at 1:18 am
using this we are unable to retrieve the Sever.MapPath()… How to solve this issue..
waiting for ur reply..
June 6th, 2007 at 7:07 am
It works! Thx!
June 6th, 2007 at 1:48 pm
im not using Server.MapPath(), where are you using that?