Moqing的HttpContext [英] Moqing HttpContext

查看:98
本文介绍了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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆