我可以在我的单元测试方法中访问 HttpRuntime
吗?当我每次尝试访问时,它都显示 HttpRuntime 在当前上下文中不存在。在我想要测试访问缓存变量的目标方法中
HttpRuntime.Cache[key];
这可能吗?还是我在这里遗漏了什么?
谢谢
最佳答案
您可以使用 SimpleWorkerRequest 对象在单元测试中创建一个 HttpContext。
TextWriter writer = new StringWriter(); HttpWorkerRequest httpRequest = new SimpleWorkerRequest("virtualDir", "physicalDir", "page", "", writer); HttpContext.Current = new HttpContext(httpRequest); HttpContext.Current.Cache[key] = some value..
关于visual-studio-2008 - Visual Studio 单元测试中的 HttpRuntime,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5025194/