【发布时间】:2021-06-08 04:17:19
【问题描述】:
我想检查我的 ASP.NET Core API 控制器的所有端点是否具有如下所示的属性:
[SwaggerResponse(HttpStatusCode.OK,typeof(*different types*))]
我使用 xUnit 和 Fluent Assertions 来写这个:
[Fact]
public void EndpointsSwaggerAttribute()
{
typeof(BaseController).Methods().Should().BeDecoratedWith<SwaggerResponseAttribute>(s =>(s.StatusCode == HttpStatusCode.OK.ToString()));
}
但它并不完全有效。它总是通过测试。 Base Controller是一个继承ControllerBase的helper类,所有的controller都继承Base Controller。
【问题讨论】:
-
你只检查 BaseController 而不是所有的控制器 inheriting from BaseController
标签: c# asp.net-core swagger xunit fluent-assertions