title: How to test ActionFilterAttribute - OnActionExecuted
body: <p>I am trying to unit test a custom ActionFilterAttribute. For example:</p>
  
  <pre><code>public class ActionAuthorizationAttribute: ActionFilterAttribute 
  {
  
    protected override void  OnActionExecuted(ActionExecutedContext filterContext)
    {
      filterContext.HttpContext.Response.Redirect("SecurityException");
    }
  }
  </code></pre>
  
  <p>How can I write a unit test that would test that any action that would have this attribute would redirect to SecurityException.</p>
  
  <p><strong>My Attempt</strong></p>
  
  <pre><code>[TestClass]
  public class TestControllerResponse
  {
    [TestMethod]
    public void TestPermissionAccepted()
    {
      var controller = new TestController();
      var result = controller.Index() as RedirectToRouteResult;
      Assert.IsNotNull(result);
      Assert.AreEqual("SecurityException", result.RouteValues["action"]);
    }
  }
  
  protected class TestController : Controller
  {
    [ActionAuthorization]
    public ActionResult Index()
    {
      return RedirectToAction("UnfortunatelyIWasCalled");
    }
  
  }
  </code></pre>
  
  <p>Unfortunately, the test fails. The index action redirects to "UnfortunatelyIWasCalled" instead of "SecurityException". </p>