0
如何檢查我的ActionFilterAttribute
在ASP.NET MVC3中的控制器/動作的可用性?NUnit檢查可用性我的ActionFilterAttribute控制器/動作
我正在使用NUnit。
如何檢查我的ActionFilterAttribute
在ASP.NET MVC3中的控制器/動作的可用性?NUnit檢查可用性我的ActionFilterAttribute控制器/動作
我正在使用NUnit。
您可以使用反射:
// arrange
Expression<Action<HomeController>> expression = (HomeController c) => c.Index();
var mc = expression.Body as MethodCallExpression;
// act
var actual = mc.Method.GetCustomAttributes(typeof(MyActionFilterAttribute), false);
// assert
Assert.IsTrue(actual.Any());
這證實了MyActionFilterAttribiute
已被用來裝飾家庭控制器上的索引操作:
public class HomeController: Controller
{
[MyActionFilter]
public ActionResult Index()
{
...
}
}
謝謝!我該如何檢查ASP.NET MVC3中CONTROLLER(而不是action)ActionFilterAttribute的可用性? –
同樣的方法,使用反射。 –