我有一个基地控制器,其余的OnActionExecutionAsync
方法设置一些公共控制器属性,然后在OnActionExecuted
方法 此工作正常设置一些常见视图模型的属性,但我现在需要为它编写一些单元测试。没有TDD的我..单元测试基地控制器OnActionExecutionAsync和OnActionExecuted方法
代码我是:
public override async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next)
{
//set some controller properties
await base.OnActionExecutionAsync(context, next);
}
public override void OnActionExecuted(ActionExecutedContext filterContext)
{
//set some other viewmodel properties
base.OnActionExecuted(filterContext);
}
的问题我已经与OnActionExecutionAsync
测试中,比它被嘲笑的背景下右痛等,是该方法完成时它会自动调用OnActionExecuted
方法,并且由于ActionExecutedContext
为空而倒下。 我假设我需要拨打await base.OnActionExecutionAsync(context, next);
,而不是简单地await next();
?继续使用管道,虽然已经检查了github中的Controller
代码,但似乎基本实现只在调用ActionExecutingContext的结果为空时调用OnActionExecuted
aspnet core controller on GitHub 任何想法如何让我的测试在没有跳到OnActionExecuted
的情况下工作?