How do I unit test an ActionFilter in ASP.NET MVC?

后端 未结 2 1559
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-02 22:58

There is an ActionFilter on my controller-class. The OnActionExecuting method gets called, when an action of the controller is called in a web appl

2条回答
  •  执念已碎
    2021-01-02 23:26

    to write a separate unit test which proves that the action is decorated with the correct attribute

    Here is how you can write such a unit test

    Type t = typeof(MyController);
    Assert.IsTrue(t.GetCustomAttributes(typeof(MyCustomAttribute)).Length > 0);
    

提交回复
热议问题