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