test: 增加 HttpHeaderOperation 单元测试

This commit is contained in:
Argo Zhang 2019-10-08 20:15:34 +08:00
parent 6434cea61c
commit 39c0d4965c
No known key found for this signature in database
GPG Key ID: 152E398953DDF19F
3 changed files with 22 additions and 3 deletions

View File

@ -38,7 +38,7 @@
function runUnitTest() {
write-host "dotnet test test\UnitTest" -ForegroundColor Cyan
dotnet test test\UnitTest --filter "FullyQualifiedName!~MySql" /p:CollectCoverage=true /p:CoverletOutputFormat=opencover /p:Include="[Bootstrap*]*" /p:ExcludeByFile="..\..\src\admin\Bootstrap.Admin\Program.cs%2c..\..\src\admin\Bootstrap.Admin\Startup.cs%2c..\..\src\admin\Bootstrap.Admin\HttpHeaderOperation.cs" /p:CoverletOutput=..\..\
dotnet test test\UnitTest --filter "FullyQualifiedName!~MySql" /p:CollectCoverage=true /p:CoverletOutputFormat=opencover /p:Include="[Bootstrap*]*" /p:ExcludeByFile="..\..\src\admin\Bootstrap.Admin\Program.cs%2c..\..\src\admin\Bootstrap.Admin\Startup.cs" /p:CoverletOutput=..\..\
}
function coverallUnitTest() {

View File

@ -17,8 +17,6 @@ namespace Bootstrap.Admin
/// <param name="context"></param>
public void Apply(OpenApiOperation operation, OperationFilterContext context)
{
if (operation.Parameters == null) operation.Parameters = new List<OpenApiParameter>();
if (context.MethodInfo.GetCustomAttributes(typeof(AllowAnonymousAttribute), true).Length == 0)
{
operation.Parameters.Add(new OpenApiParameter()

View File

@ -0,0 +1,21 @@
using Microsoft.AspNetCore.Mvc.ApiExplorer;
using Microsoft.OpenApi.Models;
using Swashbuckle.AspNetCore.SwaggerGen;
using Xunit;
namespace Bootstrap.Admin.Api
{
public class HttpHeaderOperationTest
{
[Fact]
public void Apply_Ok()
{
var oper = new HttpHeaderOperation();
var api = new OpenApiOperation();
var desc = new ApiDescription();
var mi = typeof(HttpHeaderOperationTest).GetMethod("Apply_Ok");
var context = new OperationFilterContext(desc, null, null, mi);
oper.Apply(api, context);
}
}
}