I want to test the OnException
, OnActionExecuted
event of an MVC controller.
If I use mock like this:
var httpContext = MockRepository.GenerateMock<HttpContextBase>();
var request = MockRepository.GenerateMock<HttpRequestBase>();
httpContext.Expect(c => c.Request).Return(request).Repeat.AtLeastOnce();
request.Expect(r => r.IsAuthenticated ).Return(true).Repeat.AtLeastOnce();
var controller = new MyController() ;
controller.ControllerContext = new ControllerContext(httpContext,
new RouteData(),
controller);
var result = controller.Execute() as ViewResult;
…the action method is executing, but the events are not invoked.