Can I access HttpRuntime in my unit Test method. When I try to access every time it shows HttpRuntime does not exist in the current context. In my target method which I do want to test accessing a Cache variable
HttpRuntime.Cache[key];
Is it possible ? or am I missing anything here?
Thanks
You can create an HttpContext inside your unit test with a SimpleWorkerRequest object.
TextWriter writer = new StringWriter(); HttpWorkerRequest httpRequest = new SimpleWorkerRequest("virtualDir", "physicalDir", "page", "", writer); HttpContext.Current = new HttpContext(httpRequest); HttpContext.Current.Cache[key] = some value..