mirror of
https://gitee.com/dotnetchina/OpenAuth.Net.git
synced 2025-09-20 10:37:55 +08:00
增加SqlSugar启动
This commit is contained in:
@@ -15,6 +15,7 @@ using Microsoft.Extensions.Options;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using OpenAuth.Repository.Interface;
|
||||
using SqlSugar;
|
||||
|
||||
namespace OpenAuth.Repository.Test
|
||||
{
|
||||
@@ -65,6 +66,58 @@ namespace OpenAuth.Repository.Test
|
||||
serviceCollection.AddScoped(x => httpContextAccessorMock.Object);
|
||||
|
||||
serviceCollection.AddDbContext<OpenAuthDBContext>();
|
||||
|
||||
var dbtypes = config.GetSection("AppSetting:DbTypes").GetChildren()
|
||||
.ToDictionary(x => x.Key, x => x.Value);
|
||||
|
||||
var connectionString = config.GetSection("ConnectionStrings")["OpenAuthDBContext"];
|
||||
Console.WriteLine($"单元测试数据库信息:{dbtypes[httpContextAccessorMock.Object.GetTenantId()]}/{connectionString}");
|
||||
|
||||
serviceCollection.AddScoped<ISqlSugarClient>(s =>
|
||||
{
|
||||
|
||||
SqlSugarClient sqlSugar;
|
||||
if(dbtypes.ContainsValue(Define.DBTYPE_SQLSERVER))
|
||||
{
|
||||
sqlSugar = new SqlSugarClient (new ConnectionConfig()
|
||||
{
|
||||
DbType = SqlSugar.DbType.SqlServer,
|
||||
ConnectionString = connectionString,
|
||||
IsAutoCloseConnection = true,
|
||||
});
|
||||
}
|
||||
else if(dbtypes.ContainsValue(Define.DBTYPE_MYSQL)) //mysql
|
||||
{
|
||||
sqlSugar = new SqlSugarClient (new ConnectionConfig()
|
||||
{
|
||||
DbType = SqlSugar.DbType.MySql,
|
||||
ConnectionString = connectionString,
|
||||
IsAutoCloseConnection = true,
|
||||
});
|
||||
}
|
||||
else if(dbtypes.ContainsValue(Define.DBTYPE_PostgreSQL)) //PostgreSQL
|
||||
{
|
||||
sqlSugar = new SqlSugarClient (new ConnectionConfig()
|
||||
{
|
||||
DbType = SqlSugar.DbType.PostgreSQL,
|
||||
ConnectionString = connectionString,
|
||||
IsAutoCloseConnection = true,
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
sqlSugar = new SqlSugarClient (new ConnectionConfig()
|
||||
{
|
||||
DbType = SqlSugar.DbType.Oracle,
|
||||
ConnectionString = connectionString,
|
||||
IsAutoCloseConnection = true,
|
||||
});
|
||||
}
|
||||
|
||||
return sqlSugar;
|
||||
});
|
||||
|
||||
|
||||
|
||||
var builder = new ContainerBuilder();
|
||||
|
||||
@@ -75,12 +128,6 @@ namespace OpenAuth.Repository.Test
|
||||
|
||||
var _container = builder.Build();
|
||||
_autofacServiceProvider = new AutofacServiceProvider(_container);
|
||||
|
||||
var dbtypes = config.GetSection("AppSetting:DbTypes").GetChildren()
|
||||
.ToDictionary(x => x.Key, x => x.Value);
|
||||
|
||||
Console.WriteLine($"单元测试数据库信息:{dbtypes[httpContextAccessorMock.Object.GetTenantId()]}/{config.GetSection("ConnectionStrings")["OpenAuthDBContext"]}");
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user