- 将AI模型相关端点、命令、处理器移动到模块内部统一管理 - 优化数据库迁移脚本,添加对不同环境表状态的兼容处理逻辑 - 为异常处理添加错误码枚举参数,统一错误处理方式 - 重构多处业务逻辑中的异常抛出方式,增强代码一致性 - 移除独立的组件清单分组和项目定义,简化前端物料面板数据结构 - 修复测试代码中实体引用路径错误问题 - 添加新的监控模块测试项目到解决方案文件中
40 lines
1.5 KiB
C#
40 lines
1.5 KiB
C#
using BuildFlow.Shared.Domain.Common;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Monitoring.Infrastructure.Persistence;
|
|
|
|
namespace BuildFlow.Monitoring.Tests;
|
|
|
|
/// <summary>Monitoring 模块测试数据库工厂,使用独立 InMemory 数据库并自动补齐审计字段。</summary>
|
|
internal static class MonitoringTestDb
|
|
{
|
|
public static MonitoringDbContext Create([System.Runtime.CompilerServices.CallerMemberName] string testName = "")
|
|
{
|
|
var services = new ServiceCollection();
|
|
services.AddDbContext<MonitoringDbContext>(options =>
|
|
options.UseInMemoryDatabase($"monitoring-{testName}-{Guid.NewGuid()}"));
|
|
var db = services.BuildServiceProvider().GetRequiredService<MonitoringDbContext>();
|
|
db.SavingChanges += FillAuditFields;
|
|
return db;
|
|
}
|
|
|
|
private static void FillAuditFields(object? sender, EventArgs args)
|
|
{
|
|
if (sender is not DbContext db) return;
|
|
|
|
foreach (var entry in db.ChangeTracker.Entries())
|
|
{
|
|
if (entry.Entity is IAuditable auditable)
|
|
{
|
|
auditable.CreatedBy ??= "test";
|
|
auditable.UpdatedBy ??= "test";
|
|
if (auditable.CreatedAt == default) auditable.CreatedAt = DateTime.UtcNow;
|
|
if (auditable.UpdatedAt == default) auditable.UpdatedAt = DateTime.UtcNow;
|
|
}
|
|
|
|
if (entry.Entity is IHasOperatorIP operatorEntity)
|
|
operatorEntity.OperatorIP ??= "127.0.0.1";
|
|
}
|
|
}
|
|
}
|