From 39c0d4965c2844b1927c131a3f72a81cdc137b5d Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Tue, 8 Oct 2019 20:15:34 +0800 Subject: [PATCH] =?UTF-8?q?test:=20=E5=A2=9E=E5=8A=A0=20HttpHeaderOperatio?= =?UTF-8?q?n=20=E5=8D=95=E5=85=83=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- appveyor.test.ps1 | 2 +- .../Extensions/HttpHeaderOperation.cs | 2 -- .../Api/HttpHeaderOperationTest.cs | 21 +++++++++++++++++++ 3 files changed, 22 insertions(+), 3 deletions(-) create mode 100644 test/UnitTest/Bootstrap.Admin/Api/HttpHeaderOperationTest.cs diff --git a/appveyor.test.ps1 b/appveyor.test.ps1 index 4fa1c7b0..84c2ecff 100644 --- a/appveyor.test.ps1 +++ b/appveyor.test.ps1 @@ -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() { diff --git a/src/admin/Bootstrap.Admin/Extensions/HttpHeaderOperation.cs b/src/admin/Bootstrap.Admin/Extensions/HttpHeaderOperation.cs index 5c9fae1f..f479233d 100644 --- a/src/admin/Bootstrap.Admin/Extensions/HttpHeaderOperation.cs +++ b/src/admin/Bootstrap.Admin/Extensions/HttpHeaderOperation.cs @@ -17,8 +17,6 @@ namespace Bootstrap.Admin /// public void Apply(OpenApiOperation operation, OperationFilterContext context) { - if (operation.Parameters == null) operation.Parameters = new List(); - if (context.MethodInfo.GetCustomAttributes(typeof(AllowAnonymousAttribute), true).Length == 0) { operation.Parameters.Add(new OpenApiParameter() diff --git a/test/UnitTest/Bootstrap.Admin/Api/HttpHeaderOperationTest.cs b/test/UnitTest/Bootstrap.Admin/Api/HttpHeaderOperationTest.cs new file mode 100644 index 00000000..12b34cec --- /dev/null +++ b/test/UnitTest/Bootstrap.Admin/Api/HttpHeaderOperationTest.cs @@ -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); + } + } +}