【发布时间】:2019-10-06 11:18:34
【问题描述】:
我正在尝试为 OnActionExecutionAsync 模拟 ActionExecutingContext。
我需要为下面的代码编写单元测试用例。
public async Task OnActionExecutionAsync(
ActionExecutingContext context,
ActionExecutionDelegate next)
{
var controllerInfo = actionExecutingcontext.ActionDescriptor as ControllerActionDescriptor;
MyCustomAttribute[] myCustomAttribute = (MyCustomAttribute[])controllerInfo.MethodInfo.GetCustomAttributes(typeof(MyCustomAttribute), inherit: true);
}
我发现这个How to mock ActionExecutingContext with Moq? 很有用,但它没有解释如何模拟methodInfo 和GetCustomAttributes。
【问题讨论】:
标签: c# asp.net asp.net-mvc unit-testing moq