Need help mocking a ASP.NET Controller in RhinoMocks
- by Pure.Krome
Hi folks,
I'm trying to mock up a fake ASP.NET Controller. I don't have any concrete controllers, so I was hoping to just mock a Controller and it will work.
This is what I have, currently.
_fakeRequestBase = MockRepository.GenerateMock<HttpRequestBase>();
_fakeRequestBase.Stub(x => x.HttpMethod).Return("GET");
_fakeContextBase = MockRepository.GenerateMock<HttpContextBase>();
_fakeContextBase.Stub(x => x.Request).Return(_fakeRequestBase);
var controllerContext = new ControllerContext(_fakeContextBase, new RouteData(),
MockRepository.GenerateMock<ControllerBase>());
_fakeController = MockRepository.GenerateMock<Controller>();
_fakeController.Stub(x => x.ControllerContext).Return(controllerContext);
Everything works except the last line, which throws a runtime error and is asking me for some Rhino.Mocks source code or something (which I don't have).
See how I'm trying to mock up an abstract Controller - is that allowed?
Can someone help me?