在MvcContrib TestHelpers新手的问题 [英] Newbie question on MvcContrib TestHelpers

查看:74
本文介绍了在MvcContrib TestHelpers新手的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚开始使用TestHelpers在MvcContrib。我想尝试和测试我的控制器上的操作方法本身的测试,如果IsAjaxRequest()是真实的。

I'm just starting to use the TestHelpers in MvcContrib. I want to try and test an action method on my controller that itself tests if IsAjaxRequest() is true.

我用同样的code,它是TestHelper样本建立TestControllerBuilder所示

I've used the same code that is shown in the TestHelper samples to set up the TestControllerBuilder

_controller = new StarsController();    
_builder = new TestControllerBuilder();
_builder.InitializeController(_controller);

这样_controller拥有所有的伪造/嘲笑的HttpContext里面,这实在是太棒了。但是现在我该怎么做才能迫使伪造内部Request对象IsAjaxRequest()返回true?

So that _controller has all the faked/mocked HttpContext inside it, which is really great. But what do I do now to force IsAjaxRequest() on the internally faked Request object to return true?

推荐答案

您需要存根出的Htt prequest.Headers属性返回包含X-要求,以一个条目的值的NameValueCollection XMLHtt prequest。

You need to stub out the HttpRequest.Headers property to return a NameValueCollection that contains an entry for "X-Requested-With" with the value "XMLHttpRequest".

这篇关于在MvcContrib TestHelpers新手的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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