|
|
@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
using Microsoft.AspNetCore.Hosting;
|
|
|
|
|
|
|
|
using Microsoft.AspNetCore.Mvc.Testing;
|
|
|
|
|
|
|
|
using Microsoft.AspNetCore.TestHost;
|
|
|
|
|
|
|
|
using Microsoft.Extensions.Configuration;
|
|
|
|
|
|
|
|
using Microsoft.Extensions.Hosting;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace XUnitDIStudy.Test.IntegrationTest
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// 自定义WebApp工厂
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
|
|
public class CustomWebAppFactory<TStartup> : WebApplicationFactory<TStartup> where TStartup : class
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
protected override IHostBuilder CreateHostBuilder()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return base
|
|
|
|
|
|
|
|
.CreateHostBuilder()
|
|
|
|
|
|
|
|
.ConfigureHostConfiguration(config =>
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
config.AddEnvironmentVariables("ASPNETCORE");
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected override IWebHostBuilder CreateWebHostBuilder()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return base
|
|
|
|
|
|
|
|
.CreateWebHostBuilder()
|
|
|
|
|
|
|
|
.UseEnvironment("Testing");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected override TestServer CreateServer(IWebHostBuilder builder)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return base.CreateServer(builder);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected override void ConfigureWebHost(IWebHostBuilder builder)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
//Startup.ConfigureServices之后执行
|
|
|
|
|
|
|
|
builder.ConfigureServices(services =>
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//后执行
|
|
|
|
|
|
|
|
builder.ConfigureTestServices(services =>
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|