build-flow.api/tests/BuildFlow.Scripting.Tests/ScriptingTestDbFactory.cs
xiangning 3b13099378 refactor(domain): 重构领域实体结构并更新枚举命名
- 将通用 Entities 命名空间拆分为具体业务实体子目录
- 更新所有实体类型引用为具体的 Entity 后缀类型
- 将 ModelType、ModelProvider、GroupMemberRole 等枚举重命名为 Enum 后缀
- 重构 AiModel 相关配置和映射逻辑适配新的实体结构
- 更新测试代码中的实体类型引用和枚举使用
- 调整应用层处理器中的实体创建和查询逻辑
- 修改 appsettings.json 中的基础设施主机配置为动态占位符模式
2026-07-19 14:02:32 +08:00

29 lines
1.1 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using BuildFlow.Shared.Domain.Common;
using Microsoft.EntityFrameworkCore;
using Scripting.Infrastructure.Persistence;
namespace BuildFlow.Scripting.Tests;
/// <summary>
/// InMemory ScriptingDbContext 工厂(镜像 Workflow.Tests.TestDbFactory)。
/// 传入测试用 ICurrentUserContext,让 ScriptingDbContext.OnConfiguring 注册 AuditInterceptor,
/// 自动填充审计字段(CreatedBy/UpdatedBy/OperatorIP 等),与生产行为一致。
/// </summary>
public static class ScriptingTestDbFactory
{
private sealed class TestCurrentUserContext : ICurrentUserContext
{
public string UserId => "test-user";
public string IPAddress => "127.0.0.1";
}
public static ScriptingDbContext Create(ICurrentUserContext? currentUser = null)
{
var options = new DbContextOptionsBuilder<ScriptingDbContext>()
.UseInMemoryDatabase($"scripting-test-{Guid.NewGuid()}")
.Options;
// 用 2 参构造激活 AuditInterceptor,保证 ScriptExecutionLogEntity 等实体的审计字段被自动填充
return new ScriptingDbContext(options, currentUser ?? new TestCurrentUserContext());
}
}