mirror of
https://github.com/dotnetcore/Util.git
synced 2026-10-29 03:26:31 +08:00
52 lines
1.6 KiB
C#
52 lines
1.6 KiB
C#
using Microsoft.AspNetCore.Builder;
|
|
using Microsoft.AspNetCore.Hosting;
|
|
using Microsoft.AspNetCore.TestHost;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.Hosting;
|
|
using Microsoft.Extensions.Logging;
|
|
using Util.Http;
|
|
using Xunit.DependencyInjection;
|
|
using Xunit.DependencyInjection.Logging;
|
|
|
|
namespace Util.AspNetCore.Tests {
|
|
/// <summary>
|
|
/// 启动配置
|
|
/// </summary>
|
|
public class Startup {
|
|
/// <summary>
|
|
/// 配置主机
|
|
/// </summary>
|
|
public void ConfigureHost( IHostBuilder hostBuilder ) {
|
|
hostBuilder.ConfigureWebHostDefaults( webHostBuilder => {
|
|
webHostBuilder.UseTestServer()
|
|
.Configure( t => {
|
|
t.UseRouting();
|
|
t.UseEndpoints( endpoints => {
|
|
endpoints.MapControllers();
|
|
} );
|
|
} );
|
|
} )
|
|
.AddUtil();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 配置服务
|
|
/// </summary>
|
|
public void ConfigureServices( IServiceCollection services ) {
|
|
services.AddControllers();
|
|
services.AddTransient<IHttpClient>( t => {
|
|
var client = new HttpClientService();
|
|
client.SetHttpClient( t.GetService<IHost>().GetTestClient() );
|
|
return client;
|
|
} );
|
|
}
|
|
|
|
/// <summary>
|
|
/// 配置日志提供程序
|
|
/// </summary>
|
|
public void Configure( ILoggerFactory loggerFactory, ITestOutputHelperAccessor accessor ) {
|
|
loggerFactory.AddProvider( new XunitTestOutputLoggerProvider( accessor ) );
|
|
}
|
|
}
|
|
}
|