MvcContrib TestHelpers 似乎没有提供完整的 HTTPContext.Server 对象
因此,当使用此类代码时,MvcContrib TestHelpers
- 创建以下HttpContext
- HttpRequest
- HttpResponse
- HttpSession
- Form
- TempData
- QueryString
- ApplicationPath
- PathInfo
在假控制器内
var _controller = new FooController();
var _builder = new TestControllerBuilder();
_builder.InitializeController(_controller);
的模拟版本,但您会注意到它们不会创建假/模拟 Server 对象。想必有充分的理由不这样做。但我试图删除 Server.MapPath() 方法,因为我的 SUT 中的方法使用它,当然在测试期间它返回 NULL。
TestHelpers 使用 rhino 模拟(v3.5),我也是。我知道存根方法的语法,但是如何将 Server 假/模拟对象放入我的控制器中,以便我可以存根方法?
So the MvcContrib TestHelpers create mock versions of the following
- HttpContext
- HttpRequest
- HttpResponse
- HttpSession
- Form
- TempData
- QueryString
- ApplicationPath
- PathInfo
within a fake controller when using this kind of code
var _controller = new FooController();
var _builder = new TestControllerBuilder();
_builder.InitializeController(_controller);
But you'll notice they don't create a fake/mock Server object. Presumably there is a good reason why not. But I'm trying to stub out the Server.MapPath() method because the method in my SUT uses it and of course during the test its returning NULL.
The TestHelpers use rhino mocks (v3.5) and so am I. I know the syntax to stub out a method but how do I get the Server fake/mock object into my controller so I can stub out the method?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
HttpServerUtility 类是密封的,但 Microsoft 提供了一个抽象的 HttpServerUtilityBase,可用于模拟(并且 MVCContrib 使用它)。 Simon 的问题是由于 MVCContrib 中的错误造成的。请参阅:尝试存根 Server.MapPath 与 MvcContrib 测试助手和 Rhino Mocks 3.5 以获得解决方案。
The HttpServerUtility class is sealed, but Microsoft provides an abstract HttpServerUtilityBase which can be used for mocking (and which MVCContrib uses). Simon's problem is due to a bug in MVCContrib. See: Trying to stub Server.MapPath with MvcContrib Test helpers and Rhino Mocks 3.5 for a solution.