我有自定义操作过滤器,我想在dotnet核心weabpi中为此编写单元测试。
请帮助。
public class ApplicationIdValidationAttribute: IActionFilter
{
public void OnActionExecuting(ActionExecutingContext context)
{
var param = context.ActionArguments["Id"];
var modelState = context.ModelState;
if (param!=null && string.IsNullOrEmpty(param.ToString()))
{
modelState.AddModelError("id", "Application id is required");
context.Result = new BadRequestObjectResult(new ModelStateRequestValidationAdaptor(modelState));
return;
}
if (!Guid.TryParse(param?.ToString(), out Guid applicationGuid))
{
modelState.AddModelError("id", "Application id is not a valid Guid");
context.Result = new BadRequestObjectResult(new ModelStateRequestValidationAdaptor(modelState));
return;
}
}
public void OnActionExecuted(ActionExecutedContext context)
{
}
}