I need to unit test my POST action methods, so I need a list of them. I am using reflection to find those methods with [AcceptVerbs(HttpVerbs.Post)].
// get controller's methods
typeof(FooController).GetMethods()
// get controller's action methods
.Where(q => q.IsPublic && q.IsVirtual && q.ReturnType == typeof(ActionResult))
// get actions decorated with AcceptVerbsAttribute
.Where(q => q.CustomAttributes
.Any(w => (w.AttributeType == _typeof(AcceptVerbsAttribute)))
)
// ...everything is ok till here...
// filter for those with the HttpVerbs.Post ctor arg
.Where(q => q.CustomAttributes
.Any(w => w.ConstructorArguments.Any(e => e.Value.Equals(HttpVerbs.Post))))
;
This however gives me an empty list. The problem is in the last check for the attribute’s ctor. How do I fix it?
It is worth noting there are two ways for declaring the action’s method as POST: using AcceptVerbsAttribute as above, and HttpPostAttribute.
Change the following:
To
And that should work.