单元测试控制器动作HttpAcceptAttribute动词的最佳方式是什么?测试MVC控制器动作HttpAcceptAttribute动词
到目前为止,我有以下,但即使是母亲不能爱它,也不是很灵活,它是如此丑陋。有没有更好的办法?
[Fact] // using xUnit, mocking controller in class
public void FilterControllerTestRemoveFilterByProductAttributeIsOfTypePost()
{
Type[] paramTypes = new[] { typeof(int) };
var method = typeof(FilterController).GetMethod("MyMethod", paramTypes);
var attributes = method.GetCustomAttributes(typeof(AcceptVerbsAttribute), false).Cast<AcceptVerbsAttribute>().SingleOrDefault();
Assert.NotNull(attributes);
Assert.Equal(1, attributes.Verbs.Count());
Assert.True(attributes.Verbs.First().Equals(HttpVerbs.Post.ToString(), StringComparison.InvariantCultureIgnoreCase));
}
感谢 的Mac
有趣,很干净的方法,非常感谢 – 2009-10-18 18:42:56