In case someone else finds this question: I've started checking all of my action method accept attributes in my unit tests. A bit of reflection does the trick just fine. Here's some code if you'd like to do this as well:
protected void CheckAcceptVerbs<TControllerType>(string methodName, HttpVerbs verbs)
{
CheckAcceptVerbs(methodName, typeof(TControllerType).GetMethod(methodName, BindingFlags.Public|BindingFlags.Instance,null,new Type[]{},null), verbs);
}
protected void CheckAcceptVerbs<TControllerType>(string methodName, Type[] ActionMethodParameterTypes, HttpVerbs verbs)
{
CheckAcceptVerbs(methodName, typeof(TControllerType).GetMethod(methodName, BindingFlags.Public | BindingFlags.Instance, null, ActionMethodParameterTypes, null), verbs);
}
private void CheckAcceptVerbs<TControllerType>(string methodName, MethodInfo actionMethod, HttpVerbs verbs)
{
Assert.IsNotNull(actionMethod, "Could not find action method " + methodName);
var attribute =
(AcceptVerbsAttribute)
actionMethod.GetCustomAttributes(false).FirstOrDefault(
c => c.GetType() == typeof(AcceptVerbsAttribute));
if (attribute == null)
{
Assert.AreEqual(HttpVerbs.Get, verbs);
return;
}
Assert.IsTrue(HttpVerbsEnumToArray(verbs).IsEqualTo(attribute.Verbs));
}
The first method is for action methods without parameters, the second is for those with parameters. You can also just use the third method directly, but I wrote the first two overloads as convenience functions.