build-flow.api/tests/BuildFlow.Workflow.Tests/Form/FormRelationOptionsTests.cs
xiangning fb40c47d5b refactor(monitoring): 重构监控模块数据模型为文档模式
- 将 AlertRule 和 ExternalSystem 实体改为使用 JsonData 存储业务字段
- 移除独立的 ExternalSystemCredential 表,凭证信息合并到 ExternalSystem.JsonData
- 添加强类型视图 Data 属性用于访问 JsonData 中的业务数据
- 更新数据库配置将字段存储改为 jsonb 类型并调整索引策略
- 重构告警评估器使用 JsonData 强类型视图读取规则数据
- 更新连接器凭证解析器从 JsonData 中获取凭证信息
- 在 appsettings.json 中添加 monitoring 模块配置
- 将 monitoring 模块集成到主应用程序中并注册服务
- 更新相关处理器使用新的数据模型结构
2026-07-17 12:19:24 +08:00

117 lines
3.7 KiB
C#

using FluentAssertions;
using Workflow.Application.Form.Derivation;
using Workflow.Application.Form.Relation.Handlers;
using Workflow.Application.Form.Relation.Queries;
using Workflow.Domain.Entities;
using Workflow.Domain.Enums;
using Xunit;
namespace BuildFlow.Workflow.Tests.Form;
public class FormRelationOptionsTests
{
[Fact]
public async Task GetFormRelationOptionsQuery_ShouldReturnOptionsFromPublishedCustomFormData()
{
await using var db = TestDbFactory.Create();
var supplierFormId = Guid.NewGuid();
db.FormDefinitions.Add(new FormDefinition
{
Id = supplierFormId,
Name = "供应商",
Code = "supplier",
Status = FormStatus.Published,
Version = 1,
SchemaJson = "{}",
});
db.FormData.AddRange(
new FormData
{
FormDefinitionId = supplierFormId,
InstanceId = Guid.NewGuid(),
DataJson = """{"id":"supplier-1","name":"上海供应商","code":"SH001"}""",
},
new FormData
{
FormDefinitionId = supplierFormId,
InstanceId = Guid.NewGuid(),
DataJson = """{"id":"supplier-2","name":"北京供应商","code":"BJ001"}""",
});
await db.SaveChangesAsync();
var handler = new GetFormRelationOptionsQueryHandler(db);
var result = await handler.Handle(
new GetFormRelationOptionsQuery(
"supplier",
"id",
"name",
"上海",
1,
20,
["code"]),
CancellationToken.None);
result.Total.Should().Be(1);
result.Items.Should().ContainSingle().Which.Should().BeEquivalentTo(new
{
Value = "supplier-1",
Label = "上海供应商",
Snapshot = new Dictionary<string, object?> { ["code"] = "SH001" },
});
}
[Fact]
public async Task FormValueDerivationService_ShouldResolveRelationSnapshotFromCustomFormData()
{
await using var db = TestDbFactory.Create();
var supplierFormId = Guid.NewGuid();
db.FormDefinitions.Add(new FormDefinition
{
Id = supplierFormId,
Name = "供应商",
Code = "supplier",
Status = FormStatus.Published,
Version = 1,
SchemaJson = "{}",
});
db.FormData.Add(new FormData
{
FormDefinitionId = supplierFormId,
InstanceId = Guid.NewGuid(),
DataJson = """{"id":"supplier-1","name":"上海供应商","code":"SH001"}""",
});
await db.SaveChangesAsync();
var service = new FormValueDerivationService([], [], db);
var result = await service.DeriveAsync(
"""
{
"type": "object",
"properties": {
"supplier": {
"type": "object",
"title": "供应商",
"x-component": "RelationPicker",
"x-field-kind": "relation",
"x-relation": {
"sourceCode": "supplier",
"idField": "id",
"labelField": "name",
"snapshotFields": ["code", "name"],
"updatePolicy": "snapshotOnly"
}
}
}
}
""",
"""{"supplier":"supplier-1"}""",
new FormDerivationContext(null, Guid.NewGuid(), null),
CancellationToken.None);
result.DataJson.Should().Contain("\"label\":\"上海供应商\"");
result.DataJson.Should().Contain("\"code\":\"SH001\"");
}
}