So I'm creating a custom ActionFilter that's based mostly on this project http://www.codeproject.com/KB/aspnet/aspnet_mvc_restapi.aspx.
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:
[AcceptVerbs(HttpVerbs.Get)]
[AcceptTypesAttribute(HttpContentTypes.Json, HttpContentTypes.Xml)]
public ActionResult Index()
{
var articles = Service.GetRecentArticles();
return View(articles);
}
The custom filter overrides the OnActionExecuted and will serialize the object (in this example articles) as either JSON or Xml.
My question is: how do I test this?
- 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
AcceptsTypeFilterJson_RequestHeaderAcceptsJson_ReturnsJson()
,AcceptsTypeFilterXml_RequestHeaderAcceptsXml_ReturnsXml()
andAcceptsTypeFilter_AcceptsHeaderMismatch_ReturnsError406()
. - How do I test an ActionFilter in MVC that is testing the Http Accept Headers?
Thanks.