From a14e736fb9e1a305be25c71796a7f4c95b74e76e Mon Sep 17 00:00:00 2001 From: GeWuYou <95328647+GeWuYou@users.noreply.github.com> Date: Thu, 16 Apr 2026 11:11:52 +0800 Subject: [PATCH] =?UTF-8?q?test(config):=20=E6=B7=BB=E5=8A=A0YAML=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E5=8A=A0=E8=BD=BD=E5=99=A8=E7=9A=84not=E7=BA=A6?= =?UTF-8?q?=E6=9D=9F=E8=BF=90=E8=A1=8C=E6=97=B6=E8=A1=8C=E4=B8=BA=E9=AA=8C?= =?UTF-8?q?=E8=AF=81=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 实现标量值命中not子schema时的异常抛出验证 - 验证值未命中not子schema时的正常加载行为 - 测试对象完整命中禁用schema时的约束失败触发 - 验证对象仅命中not schema属性子集时的正确处理 - 添加not声明为非对象值时的解析阶段拒绝验证 - 创建临时目录隔离测试环境避免用例间污染 - 实现配置文件和schema文件的动态创建功能 - 提供标量和对象两种not约束场景的测试加载器 --- .../Config/YamlConfigLoaderNegationTests.cs | 61 +++++++++++++------ 1 file changed, 41 insertions(+), 20 deletions(-) diff --git a/GFramework.Game.Tests/Config/YamlConfigLoaderNegationTests.cs b/GFramework.Game.Tests/Config/YamlConfigLoaderNegationTests.cs index 7d58b0db..169a03bb 100644 --- a/GFramework.Game.Tests/Config/YamlConfigLoaderNegationTests.cs +++ b/GFramework.Game.Tests/Config/YamlConfigLoaderNegationTests.cs @@ -67,10 +67,8 @@ public sealed class YamlConfigLoaderNegationTests } """); - var loader = new YamlConfigLoader(_rootPath) - .RegisterTable("monster", "monster", "schemas/monster.schema.json", - static config => config.Id); - var registry = new ConfigRegistry(); + var loader = CreateMonsterLoader(); + var registry = CreateRegistry(); var exception = Assert.ThrowsAsync(async () => await loader.LoadAsync(registry)); @@ -117,10 +115,8 @@ public sealed class YamlConfigLoaderNegationTests } """); - var loader = new YamlConfigLoader(_rootPath) - .RegisterTable("monster", "monster", "schemas/monster.schema.json", - static config => config.Id); - var registry = new ConfigRegistry(); + var loader = CreateMonsterLoader(); + var registry = CreateRegistry(); await loader.LoadAsync(registry); @@ -173,10 +169,8 @@ public sealed class YamlConfigLoaderNegationTests } """); - var loader = new YamlConfigLoader(_rootPath) - .RegisterTable("monster", "monster", "schemas/monster.schema.json", - static config => config.Id); - var registry = new ConfigRegistry(); + var loader = CreateMonsterRewardLoader(); + var registry = CreateRegistry(); var exception = Assert.ThrowsAsync(async () => await loader.LoadAsync(registry)); @@ -230,10 +224,8 @@ public sealed class YamlConfigLoaderNegationTests } """); - var loader = new YamlConfigLoader(_rootPath) - .RegisterTable("monster", "monster", "schemas/monster.schema.json", - static config => config.Id); - var registry = new ConfigRegistry(); + var loader = CreateMonsterRewardLoader(); + var registry = CreateRegistry(); await loader.LoadAsync(registry); @@ -277,10 +269,8 @@ public sealed class YamlConfigLoaderNegationTests } """); - var loader = new YamlConfigLoader(_rootPath) - .RegisterTable("monster", "monster", "schemas/monster.schema.json", - static config => config.Id); - var registry = new ConfigRegistry(); + var loader = CreateMonsterLoader(); + var registry = CreateRegistry(); var exception = Assert.ThrowsAsync(async () => await loader.LoadAsync(registry)); @@ -321,6 +311,37 @@ public sealed class YamlConfigLoaderNegationTests CreateConfigFile(relativePath, content); } + /// + /// 创建用于标量 not 场景的加载器,统一测试夹具中的注册方式。 + /// + /// 已注册怪物表与 schema 路径的加载器。 + private YamlConfigLoader CreateMonsterLoader() + { + return new YamlConfigLoader(_rootPath) + .RegisterTable("monster", "monster", "schemas/monster.schema.json", + static config => config.Id); + } + + /// + /// 创建用于对象 not 场景的加载器,避免重复维护同一注册参数。 + /// + /// 已注册奖励对象测试表的加载器。 + private YamlConfigLoader CreateMonsterRewardLoader() + { + return new YamlConfigLoader(_rootPath) + .RegisterTable("monster", "monster", "schemas/monster.schema.json", + static config => config.Id); + } + + /// + /// 创建新的配置注册表,明确每个用例都从干净状态开始。 + /// + /// 空的配置注册表。 + private static ConfigRegistry CreateRegistry() + { + return new ConfigRegistry(); + } + /// /// 用于标量 not 回归测试的最小配置类型。 ///