MvcContrib TestHelpers don't seem to provide a full HTTPContext.Server object
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.
精彩评论