How do I use Rhino.Mocks to mock a ControllerContext
I am trying to use Rhino.Mocks to mock up a ControllerContext object to gain access to runtime objects like User, Request, Response, and Session in my controller unit tests. I've written the below method in an attempt to mock up a controller. private TestController CreateTestControllerAs(string userName) { var mock = MockRepository.GenerateStub<ControllerContext>(); mock.Stub(con => con.HttpContext.User.Identity.Name).Return(userName); mock.Stub(con => con.HttpContext.Request.IsAuthenticated).Return(true); var controller = CreateTestController(); // left out of example for brevity controller