HttpRuntime in VisualStudio UnitTest

Can I access HttpRuntimein my unit Test method. When I try to access every time it shows that HttpRuntime does not exist in the current context. In my target method I want to check for cache variable access


   HttpRuntime.Cache[key]; 

Is it possible? or am I missing something here?

thank

+3
source share
2 answers

You can create an HttpContext inside your unit test using the 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..
+1

, HttpRuntime, , HttpRuntime. , HttpRuntime .

+1

Source: https://habr.com/ru/post/1792710/


All Articles