|
|
|
@ -1,14 +1,27 @@
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
//using System;
|
|
|
|
|
//using System.Collections.Generic;
|
|
|
|
|
//using System.Linq;
|
|
|
|
|
//using System.Text;
|
|
|
|
|
//using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
//using Microsoft.AspNetCore.Builder;
|
|
|
|
|
//using Microsoft.AspNetCore.Hosting;
|
|
|
|
|
//using Microsoft.AspNetCore.TestHost;
|
|
|
|
|
//using Microsoft.Extensions.Configuration;
|
|
|
|
|
//using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
//using Microsoft.Extensions.Hosting;
|
|
|
|
|
|
|
|
|
|
using Microsoft.AspNetCore.Builder;
|
|
|
|
|
using Microsoft.AspNetCore.Hosting;
|
|
|
|
|
using Microsoft.AspNetCore.Http;
|
|
|
|
|
using Microsoft.AspNetCore.TestHost;
|
|
|
|
|
using Microsoft.Extensions.Configuration;
|
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
using Microsoft.Extensions.Hosting;
|
|
|
|
|
|
|
|
|
|
using Xunit;
|
|
|
|
|
using Xunit.DependencyInjection.AspNetCoreTesting;
|
|
|
|
|
using Xunit.DependencyInjection.Logging;
|
|
|
|
|
|
|
|
|
|
namespace HttpClientStudy.UnitTest
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
@ -31,29 +44,37 @@ namespace HttpClientStudy.UnitTest
|
|
|
|
|
/// <param name="hostBuilder"></param>
|
|
|
|
|
public void ConfigureHost(IHostBuilder hostBuilder)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
hostBuilder
|
|
|
|
|
.ConfigureHostConfiguration(builder => { })
|
|
|
|
|
.ConfigureAppConfiguration((context, builder) => { });
|
|
|
|
|
.ConfigureWebHost
|
|
|
|
|
(webHostBuilder => webHostBuilder
|
|
|
|
|
.UseTestServerAndAddDefaultHttpClient()
|
|
|
|
|
.UseStartup<WebApiStartup>()
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
//hostBuilder
|
|
|
|
|
// .ConfigureHostConfiguration(builder => { })
|
|
|
|
|
// .ConfigureAppConfiguration((context, builder) => { });
|
|
|
|
|
|
|
|
|
|
//hostBuilder.ConfigureWebHost(webHostBuilder =>
|
|
|
|
|
//{
|
|
|
|
|
// webHostBuilder
|
|
|
|
|
// .UseTestServer()
|
|
|
|
|
// .ConfigureTestServices(a => { });
|
|
|
|
|
// //webHostBuilder.UseTestServer(options => options.PreserveExecutionContext = true);
|
|
|
|
|
hostBuilder.ConfigureWebHost(webHostBuilder =>
|
|
|
|
|
{
|
|
|
|
|
webHostBuilder
|
|
|
|
|
.UseTestServer(options => options.PreserveExecutionContext = true)
|
|
|
|
|
.ConfigureTestServices(a => { })
|
|
|
|
|
.UseStartup<WebApiStartup>();
|
|
|
|
|
|
|
|
|
|
// //配置默认配置项
|
|
|
|
|
// //webHostBuilder.ConfigureAppConfiguration((context, configBuilder) =>
|
|
|
|
|
// //{
|
|
|
|
|
// // configBuilder.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true);
|
|
|
|
|
// // configBuilder.AddJsonFile($"appsettings.{context.HostingEnvironment.EnvironmentName}.json", optional: true, reloadOnChange: true);
|
|
|
|
|
// //});
|
|
|
|
|
//配置默认配置项
|
|
|
|
|
//webHostBuilder.ConfigureAppConfiguration((context, configBuilder) =>
|
|
|
|
|
//{
|
|
|
|
|
// configBuilder.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true);
|
|
|
|
|
// configBuilder.AddJsonFile($"appsettings.{context.HostingEnvironment.EnvironmentName}.json", optional: true, reloadOnChange: true);
|
|
|
|
|
//});
|
|
|
|
|
|
|
|
|
|
// //webHostBuilder.ConfigureServices(services =>
|
|
|
|
|
// //{
|
|
|
|
|
// // services.AddHealthChecks();
|
|
|
|
|
// //});
|
|
|
|
|
//});
|
|
|
|
|
//webHostBuilder.ConfigureServices(services =>
|
|
|
|
|
//{
|
|
|
|
|
// services.AddHealthChecks();
|
|
|
|
|
//});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
@ -64,5 +85,15 @@ namespace HttpClientStudy.UnitTest
|
|
|
|
|
{
|
|
|
|
|
//services.AddTransient<IDependency, DependencyClass>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private class WebApiStartup
|
|
|
|
|
{
|
|
|
|
|
public void ConfigureServices(IServiceCollection services) => services.AddLogging(lb => lb.AddXunitOutput());
|
|
|
|
|
|
|
|
|
|
public void Configure(IApplicationBuilder app)
|
|
|
|
|
{
|
|
|
|
|
app.Run(static context => context.Response.WriteAsync("xxxxxx"));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|