同步OpenAuth.Core,单元测试使用WebApi配置文件

This commit is contained in:
yubaolee
2021-01-27 13:42:38 +08:00
parent 1ed50271bf
commit 24f8eaf8c0
6 changed files with 43 additions and 51 deletions

View File

@@ -1,4 +1,5 @@
using Infrastructure;
using System;
using Infrastructure;
using Microsoft.AspNetCore.Http;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
@@ -52,15 +53,19 @@ namespace OpenAuth.Repository
}
//如果没有租户id或租户用的是默认的OpenAuthDBContext,则不做任何调整
if (string.IsNullOrEmpty(tenantId) || tenantId == "OpenAuthDBContext")
if (string.IsNullOrEmpty(tenantId))
{
return;
tenantId = "OpenAuthDBContext";
}
string connect = _configuration.GetConnectionString(tenantId);
if (string.IsNullOrEmpty(connect)) return;
if (string.IsNullOrEmpty(connect))
{
throw new Exception($"未能找到租户{tenantId}对应的连接字符串信息");
}
var dbType =_appConfiguration.Value.DbType;
//这个地方如果用IOption在单元测试的时候会获取不到AppSetting的值😅
var dbType = _configuration.GetSection("AppSetting")["DbType"];
if (dbType == Define.DBTYPE_SQLSERVER)
{
optionsBuilder.UseSqlServer(connect);