title: How do I unit test a custom ActionFilter in ASP.Net MVC
body: <p>So I'm creating a custom ActionFilter that's based mostly on this project <a href="http://www.codeproject.com/KB/aspnet/aspnet_mvc_restapi.aspx">http://www.codeproject.com/KB/aspnet/aspnet_mvc_restapi.aspx</a>.</p>
  
  <p>I want a custom action filter that uses the http accept headers to return either JSON or Xml. A typical controller action will look like this:</p>
  
  <pre><code>[AcceptVerbs(HttpVerbs.Get)]
  [AcceptTypesAttribute(HttpContentTypes.Json, HttpContentTypes.Xml)]
  public ActionResult Index()
  {
      var articles = Service.GetRecentArticles();
  
      return View(articles);
  }
  </code></pre>
  
  <p>The custom filter overrides the OnActionExecuted and will serialize the object (in this example articles) as either JSON or Xml.</p>
  
  <p><strong>My question is: how do I test this?</strong></p>
  
  <ol>
  <li>What tests do I write? I'm a TDD novice and am not 100% sure what I should be testing and what not to test. I came up with <code>AcceptsTypeFilterJson_RequestHeaderAcceptsJson_ReturnsJson()</code>, <code>AcceptsTypeFilterXml_RequestHeaderAcceptsXml_ReturnsXml()</code> and <code>AcceptsTypeFilter_AcceptsHeaderMismatch_ReturnsError406()</code>.</li>
  <li>How do I test an ActionFilter in MVC that is testing the Http Accept Headers?</li>
  </ol>
  
  <p>Thanks. </p>