开发者

MvcContrib TestHelpers don't seem to provide a full HTTPContext.Server object

开发者 https://www.devze.com 2023-01-07 21:04 出处:网络
So the MvcContrib TestHelpers create mock versions of the following HttpContext HttpRequest HttpResponse

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?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号