mirror of
https://github.com/dotnetcore/Util.git
synced 2026-10-28 19:18:08 +08:00
64 lines
2.3 KiB
C#
64 lines
2.3 KiB
C#
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.Hosting;
|
|
using Microsoft.Extensions.Logging;
|
|
using Util.Aop;
|
|
using Util.Data.Dapper.Tests.Infrastructure;
|
|
using Util.Data.EntityFrameworkCore;
|
|
using Util.Data.Metadata;
|
|
using Util.Data.Sql;
|
|
using Util.Helpers;
|
|
using Util.Sessions;
|
|
using Util.Tests.Infrastructure;
|
|
using Util.Tests.UnitOfWorks;
|
|
using Xunit.DependencyInjection;
|
|
using Xunit.DependencyInjection.Logging;
|
|
|
|
namespace Util.Data.Dapper.Tests {
|
|
/// <summary>
|
|
/// 启动配置
|
|
/// </summary>
|
|
public class Startup {
|
|
/// <summary>
|
|
/// 配置主机
|
|
/// </summary>
|
|
public void ConfigureHost( IHostBuilder hostBuilder ) {
|
|
hostBuilder.ConfigureDefaults( null )
|
|
.ConfigureServices( ( context, services ) => {
|
|
services.AddTransient<IMetadataService, SqlServerMetadataService>();
|
|
} )
|
|
.AddUtil( options => {
|
|
Environment.SetDevelopment();
|
|
options.UseAop()
|
|
.UseSqlServerSqlQuery( Config.GetConnectionString( "connection" ) )
|
|
.UseSqlServerSqlExecutor( Config.GetConnectionString( "connection" ) )
|
|
.UseSqlServerUnitOfWork<ITestUnitOfWork, SqlServerUnitOfWork>( Config.GetConnectionString( "connection" ) );
|
|
} );
|
|
}
|
|
|
|
/// <summary>
|
|
/// 配置服务
|
|
/// </summary>
|
|
public void ConfigureServices( IServiceCollection services ) {
|
|
services.AddSingleton<ISession, TestSession>();
|
|
InitDatabase( services );
|
|
}
|
|
|
|
/// <summary>
|
|
/// 初始化数据库
|
|
/// </summary>
|
|
private void InitDatabase( IServiceCollection services ) {
|
|
var unitOfWork = (SqlServerUnitOfWork)services.BuildServiceProvider().GetService<ITestUnitOfWork>();
|
|
unitOfWork.EnsureDeleted();
|
|
unitOfWork.EnsureCreated();
|
|
DatabaseScript.InitProcedures( unitOfWork?.Database );
|
|
}
|
|
|
|
/// <summary>
|
|
/// 配置日志提供程序
|
|
/// </summary>
|
|
public void Configure( ILoggerFactory loggerFactory, ITestOutputHelperAccessor accessor ) {
|
|
loggerFactory.AddProvider( new XunitTestOutputLoggerProvider( accessor, ( s, logLevel ) => logLevel >= LogLevel.Trace ) );
|
|
}
|
|
}
|
|
}
|