Moqing的HttpContext [英] Moqing HttpContext
问题描述
我有一个单元测试,测试一个MVC控制器的结果。不幸的是,控制器使用,使用 HttpContext.Request.IsLocal
第三方库。我不能重构第三方库,使之使用 HttpContextBase
。
I have a unit test that tests an MVC controller's result. Unfortunately the controller uses a third party library that uses HttpContext.Request.IsLocal
. I cannot refactor the third party library to make it use HttpContextBase
.
我需要模拟这让 HttpContext.Request.IsLocal
返回true。关于如何实现这一目标的任何想法?
I need to mock this so that HttpContext.Request.IsLocal
returns true. Any Ideas on how to achieve this?
推荐答案
如果您使用的是premium或以上vs2012版本,尝试寻找在microsoft.fakes。它应该满足您的情况。
If you are using premium or above version of vs2012, try looking at microsoft.fakes. it should cater to your situation.
一些阅读:
http://msdn.microsoft.com/en-us/library/ hh549175.aspx
这篇关于Moqing的HttpContext的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!