Controller.ControllerContext is not virtual so you can't stub it. It looks like your extension methods are checking the HttpMethod for "GET" -- is that why you're stubbing that property? Perhaps if you showed us a sample of what you're trying to test, we could come up with some alternatives.
--- Patrick Steele http://weblogs.asp.net/psteele 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]. > 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.
