refactor: AdminApi 剔除租户侧能力
This commit is contained in:
@@ -4,9 +4,13 @@ using TakeoutSaaS.Infrastructure.Dictionary.Persistence;
|
||||
|
||||
namespace TakeoutSaaS.Integration.Tests.Fixtures;
|
||||
|
||||
/// <summary>
|
||||
/// 集成测试用 SQLite 内存数据库(字典库)。
|
||||
/// </summary>
|
||||
public sealed class DictionarySqliteTestDatabase : IDisposable
|
||||
{
|
||||
private readonly SqliteConnection _connection;
|
||||
private readonly TestIdGenerator _idGenerator = new();
|
||||
private bool _initialized;
|
||||
|
||||
public DictionarySqliteTestDatabase()
|
||||
@@ -24,10 +28,14 @@ public sealed class DictionarySqliteTestDatabase : IDisposable
|
||||
public DictionaryDbContext CreateContext(long tenantId, long userId = 0)
|
||||
{
|
||||
EnsureCreated();
|
||||
// 1. AdminApi 不使用租户上下文;tenantId 参数仅用于兼容测试调用方签名
|
||||
_ = tenantId;
|
||||
|
||||
// 2. (空行后) 按需注入当前用户与 ID 生成器
|
||||
return new DictionaryDbContext(
|
||||
Options,
|
||||
new TestTenantProvider(tenantId),
|
||||
userId == 0 ? null : new TestCurrentUserAccessor(userId));
|
||||
userId == 0 ? null : new TestCurrentUserAccessor(userId),
|
||||
_idGenerator);
|
||||
}
|
||||
|
||||
public void EnsureCreated()
|
||||
@@ -37,7 +45,8 @@ public sealed class DictionarySqliteTestDatabase : IDisposable
|
||||
return;
|
||||
}
|
||||
|
||||
using var context = new DictionaryDbContext(Options, new TestTenantProvider(1));
|
||||
// 1. 创建并初始化数据库结构
|
||||
using var context = new DictionaryDbContext(Options, idGenerator: _idGenerator);
|
||||
context.Database.EnsureCreated();
|
||||
_initialized = true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user