refactor: AdminApi 剔除租户侧能力

This commit is contained in:
2026-01-29 23:24:44 +00:00
parent 71e5a9dc29
commit 4f8424adb6
139 changed files with 622 additions and 4691 deletions

View File

@@ -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;
}