帮助测试访问querystring的mvc3控制器 [英] Help testing mvc3 controller that accesses querystring

查看:167
本文介绍了帮助测试访问querystring的mvc3控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

刚刚开始学习mvc3。我已经建立了一个相当基本的网站(也使用EF代码优先,如果这有所作为),现在我正在努力进行构建测试



我的控制器通过去请求[any] 获取查询字符串数据,当我运行测试时,表示请求为null



我所看过的所有教程到目前为止,都让我失望了。进入嘲弄等等,他们似乎假定先前的知识(从来没有使用嘲笑,所以还不明白他们)



有没有人有一个很好的基本教程让我进行单元测试?或者可能给我一个例子

解决方案

这是反对MVC的设计模式直接使用HttpRequest。您可以访问作为参数的操作的查询字符串变量。


Just started learning mvc3. I've built a fairly basic website (also using EF-Code-First if that makes a difference), now I'm trying to progress to building tests for it

My controller gets querystring data by going Request["whatever"], and when I run the test it says request is null

All the tutorials I've looked at so far have kinda lost me. Going into mocks and such, which they seem to assume prior knowledge of (never used mocks, so don't understand them yet)

Does anyone have a nice and basic tutorial to get me into unit testing? Or perhaps could give me an example

解决方案

It is against MVC's design pattern to use HttpRequest directly. You can access the query string variables on your action as parameters.

这篇关于帮助测试访问querystring的mvc3控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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