mirror of
https://github.com/GeWuYou/GFramework.git
synced 2026-04-02 20:09:00 +08:00
- 实现SchemaConfigGenerator源代码生成器 - 支持从JSON schema文件生成配置类型和表包装类 - 添加ConfigSchemaDiagnostics诊断系统 - 集成System.Text.Json包依赖 - 生成强类型的配置访问接口 - 支持多种数据类型包括整数、浮点数、布尔值、字符串和数组 - 实现id字段作为表主键的约束验证 - 添加完整的单元测试和快照验证
48 lines
1.6 KiB
C#
48 lines
1.6 KiB
C#
namespace GFramework.SourceGenerators.Tests.Config;
|
|
|
|
/// <summary>
|
|
/// 验证 schema 配置生成器的错误诊断行为。
|
|
/// </summary>
|
|
[TestFixture]
|
|
public class SchemaConfigGeneratorTests
|
|
{
|
|
/// <summary>
|
|
/// 验证缺失必填 id 字段时会产生命名明确的诊断。
|
|
/// </summary>
|
|
[Test]
|
|
public void Run_Should_Report_Diagnostic_When_Id_Property_Is_Missing()
|
|
{
|
|
const string source = """
|
|
namespace TestApp
|
|
{
|
|
public sealed class Dummy
|
|
{
|
|
}
|
|
}
|
|
""";
|
|
|
|
const string schema = """
|
|
{
|
|
"type": "object",
|
|
"required": ["name"],
|
|
"properties": {
|
|
"name": { "type": "string" }
|
|
}
|
|
}
|
|
""";
|
|
|
|
var result = SchemaGeneratorTestDriver.Run(
|
|
source,
|
|
("monster.schema.json", schema));
|
|
|
|
var diagnostics = result.Results.Single().Diagnostics;
|
|
var diagnostic = diagnostics.Single();
|
|
|
|
Assert.Multiple(() =>
|
|
{
|
|
Assert.That(diagnostic.Id, Is.EqualTo("GF_ConfigSchema_003"));
|
|
Assert.That(diagnostic.Severity, Is.EqualTo(DiagnosticSeverity.Error));
|
|
Assert.That(diagnostic.GetMessage(), Does.Contain("monster.schema.json"));
|
|
});
|
|
}
|
|
} |