mirror of
https://gitee.com/dotnetchina/OpenAuth.Net.git
synced 2025-09-19 01:58:01 +08:00
调整为多租户模式
This commit is contained in:
@@ -1,8 +1,13 @@
|
||||
using System.Reflection;
|
||||
using Autofac;
|
||||
using Autofac.Extensions.DependencyInjection;
|
||||
using Infrastructure;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using OpenAuth.Repository.Interface;
|
||||
|
||||
@@ -26,6 +31,22 @@ namespace OpenAuth.Repository.Test
|
||||
serviceCollection.AddScoped(typeof(IRepository<,>), typeof(BaseRepository<,>));
|
||||
serviceCollection.AddScoped(typeof(IUnitWork<>), typeof(UnitWork<>));
|
||||
|
||||
//模拟配置文件
|
||||
var optionMock = new Mock<IOptions<AppSetting>>();
|
||||
optionMock.Setup(x => x.Value).Returns(new AppSetting { DbType = Define.DBTYPE_MYSQL });
|
||||
serviceCollection.AddScoped(x => optionMock.Object);
|
||||
|
||||
//模拟多租户id
|
||||
var configMock = new Mock<IConfiguration>();
|
||||
configMock.Setup(x => x.GetSection("ConnectionStrings")[Define.TENANT_ID]).Returns("");
|
||||
serviceCollection.AddScoped(x => configMock.Object);
|
||||
|
||||
var httpContextAccessorMock = new Mock<IHttpContextAccessor>();
|
||||
httpContextAccessorMock.Setup(x => x.HttpContext.Request.Query[Define.TOKEN_NAME]).Returns("tokentest");
|
||||
httpContextAccessorMock.Setup(x => x.HttpContext.Request.Query[Define.TENANT_ID]).Returns("OpenAuthDBContext");
|
||||
|
||||
serviceCollection.AddScoped(x => httpContextAccessorMock.Object);
|
||||
|
||||
serviceCollection.AddDbContext<OpenAuthDBContext>(options =>
|
||||
options.UseSqlServer("Data Source=.;Initial Catalog=OpenAuthDB;User=sa;Password=000000;Integrated Security=True"));
|
||||
|
||||
|
Reference in New Issue
Block a user