From 7abb4acbcb5c6429e5802e6102eff05a74b770db Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Sun, 29 Sep 2019 15:17:14 +0800 Subject: [PATCH] =?UTF-8?q?test:=20=E5=81=A5=E5=BA=B7=E6=A3=80=E6=9F=A5?= =?UTF-8?q?=E6=9B=B4=E6=94=B9=E4=B8=BA=20NETCore=203.0=20=E5=8D=95?= =?UTF-8?q?=E5=85=83=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Bootstrap.Admin/Api/HealthCheckTest.cs | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/test/UnitTest/Bootstrap.Admin/Api/HealthCheckTest.cs b/test/UnitTest/Bootstrap.Admin/Api/HealthCheckTest.cs index eeca537a..972c93ca 100644 --- a/test/UnitTest/Bootstrap.Admin/Api/HealthCheckTest.cs +++ b/test/UnitTest/Bootstrap.Admin/Api/HealthCheckTest.cs @@ -1,5 +1,4 @@ using Bootstrap.Admin.HealthChecks; -using Microsoft.AspNetCore; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Diagnostics.HealthChecks; using Microsoft.AspNetCore.Hosting; @@ -8,8 +7,8 @@ using Microsoft.AspNetCore.Mvc.Testing; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Diagnostics.HealthChecks; +using Microsoft.Extensions.Hosting; using Newtonsoft.Json; -using System.IO; using System.Net.Http; using UnitTest; using Xunit; @@ -88,18 +87,19 @@ namespace Bootstrap.Admin.Api services.AddDbAdapter(); var builder = services.AddHealthChecks(); builder.AddCheck("db"); - services.AddMvcCore(); + services.AddControllers(); } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. - public void Configure(IApplicationBuilder app, IWebHostEnvironment env) + public void Configure(IApplicationBuilder app) { + app.UseRouting(); app.Use(async (context, next) => { context.User = new System.Security.Claims.ClaimsPrincipal(new System.Security.Principal.GenericIdentity("Argo")); await next(); }); - app.UseHealthChecks("/Healths", new HealthCheckOptions() + app.UseEndpoints(builder => builder.MapHealthChecks("/Healths", new HealthCheckOptions() { ResponseWriter = (context, report) => { @@ -112,8 +112,7 @@ namespace Bootstrap.Admin.Api [HealthStatus.Degraded] = StatusCodes.Status200OK, [HealthStatus.Unhealthy] = StatusCodes.Status200OK } - }); - app.UseMvcWithDefaultRoute(); + })); } } @@ -132,6 +131,6 @@ namespace Bootstrap.Admin.Api /// /// /// - protected override IWebHostBuilder CreateWebHostBuilder() => WebHost.CreateDefaultBuilder(null); + protected override IHostBuilder CreateHostBuilder() => Host.CreateDefaultBuilder().ConfigureWebHostDefaults(builder => builder.UseStartup()); } }