This should be achieved by mocking the IController interface rather than the
abstract Controller class as in...

_fakeController = MockRepository.GenerateMock<IController>();

instead of...

_fakeController = MockRepository.GenerateMock<Controller>();

I'm not at a computer with VS installed right now else I'd double-check that
this advise actually works, but that's where I'd start IMO.

Steve Bohlen
[email protected]
http://blog.unhandled-exceptions.com
http://twitter.com/sbohlen


On Tue, Jun 1, 2010 at 10:54 PM, Justin A <[email protected]
> wrote:

> 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.
>
> Why don't I have any concrete controllers? Because i'm trying to unit
> test a pile of ControllerExtensions.
>
> This is what I currently have:
>
> _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? Is that why this is failing?
>
> Can someone help me?
>
> --
> You received this message because you are subscribed to the Google Groups
> "Rhino.Mocks" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected]<rhinomocks%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/rhinomocks?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Rhino.Mocks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rhinomocks?hl=en.

Reply via email to