mirror of
https://github.com/GeWuYou/GFramework.git
synced 2026-05-08 09:34:30 +08:00
test(config): 添加YAML配置加载器的not约束运行时行为验证测试
- 实现标量值命中not子schema时的异常抛出验证 - 验证值未命中not子schema时的正常加载行为 - 测试对象完整命中禁用schema时的约束失败触发 - 验证对象仅命中not schema属性子集时的正确处理 - 添加not声明为非对象值时的解析阶段拒绝验证 - 创建临时目录隔离测试环境避免用例间污染 - 实现配置文件和schema文件的动态创建功能 - 提供标量和对象两种not约束场景的测试加载器
This commit is contained in:
parent
ebc53510ab
commit
a14e736fb9
@ -67,10 +67,8 @@ public sealed class YamlConfigLoaderNegationTests
|
||||
}
|
||||
""");
|
||||
|
||||
var loader = new YamlConfigLoader(_rootPath)
|
||||
.RegisterTable<int, MonsterConfigStub>("monster", "monster", "schemas/monster.schema.json",
|
||||
static config => config.Id);
|
||||
var registry = new ConfigRegistry();
|
||||
var loader = CreateMonsterLoader();
|
||||
var registry = CreateRegistry();
|
||||
|
||||
var exception = Assert.ThrowsAsync<ConfigLoadException>(async () => await loader.LoadAsync(registry));
|
||||
|
||||
@ -117,10 +115,8 @@ public sealed class YamlConfigLoaderNegationTests
|
||||
}
|
||||
""");
|
||||
|
||||
var loader = new YamlConfigLoader(_rootPath)
|
||||
.RegisterTable<int, MonsterConfigStub>("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<int, MonsterRewardConfigStub>("monster", "monster", "schemas/monster.schema.json",
|
||||
static config => config.Id);
|
||||
var registry = new ConfigRegistry();
|
||||
var loader = CreateMonsterRewardLoader();
|
||||
var registry = CreateRegistry();
|
||||
|
||||
var exception = Assert.ThrowsAsync<ConfigLoadException>(async () => await loader.LoadAsync(registry));
|
||||
|
||||
@ -230,10 +224,8 @@ public sealed class YamlConfigLoaderNegationTests
|
||||
}
|
||||
""");
|
||||
|
||||
var loader = new YamlConfigLoader(_rootPath)
|
||||
.RegisterTable<int, MonsterRewardConfigStub>("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<int, MonsterConfigStub>("monster", "monster", "schemas/monster.schema.json",
|
||||
static config => config.Id);
|
||||
var registry = new ConfigRegistry();
|
||||
var loader = CreateMonsterLoader();
|
||||
var registry = CreateRegistry();
|
||||
|
||||
var exception = Assert.ThrowsAsync<ConfigLoadException>(async () => await loader.LoadAsync(registry));
|
||||
|
||||
@ -321,6 +311,37 @@ public sealed class YamlConfigLoaderNegationTests
|
||||
CreateConfigFile(relativePath, content);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建用于标量 <c>not</c> 场景的加载器,统一测试夹具中的注册方式。
|
||||
/// </summary>
|
||||
/// <returns>已注册怪物表与 schema 路径的加载器。</returns>
|
||||
private YamlConfigLoader CreateMonsterLoader()
|
||||
{
|
||||
return new YamlConfigLoader(_rootPath)
|
||||
.RegisterTable<int, MonsterConfigStub>("monster", "monster", "schemas/monster.schema.json",
|
||||
static config => config.Id);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建用于对象 <c>not</c> 场景的加载器,避免重复维护同一注册参数。
|
||||
/// </summary>
|
||||
/// <returns>已注册奖励对象测试表的加载器。</returns>
|
||||
private YamlConfigLoader CreateMonsterRewardLoader()
|
||||
{
|
||||
return new YamlConfigLoader(_rootPath)
|
||||
.RegisterTable<int, MonsterRewardConfigStub>("monster", "monster", "schemas/monster.schema.json",
|
||||
static config => config.Id);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建新的配置注册表,明确每个用例都从干净状态开始。
|
||||
/// </summary>
|
||||
/// <returns>空的配置注册表。</returns>
|
||||
private static ConfigRegistry CreateRegistry()
|
||||
{
|
||||
return new ConfigRegistry();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 用于标量 <c>not</c> 回归测试的最小配置类型。
|
||||
/// </summary>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user