using GFramework.Game.Config; namespace GFramework.Game.Tests.Config; /// /// 验证内存配置表的基础只读查询行为。 /// [TestFixture] public class InMemoryConfigTableTests { /// /// 验证已存在主键可以被正确查询。 /// [Test] public void Get_Should_Return_Config_When_Key_Exists() { var table = new InMemoryConfigTable( new[] { new MonsterConfigStub(1, "Slime"), new MonsterConfigStub(2, "Goblin") }, static config => config.Id); var result = table.Get(2); Assert.That(result.Name, Is.EqualTo("Goblin")); } /// /// 验证重复主键会在加载期被拒绝,避免运行期覆盖旧值。 /// [Test] public void Constructor_Should_Throw_When_Duplicate_Key_Is_Detected() { Assert.Throws(() => new InMemoryConfigTable( new[] { new MonsterConfigStub(1, "Slime"), new MonsterConfigStub(1, "Goblin") }, static config => config.Id)); } /// /// 验证 All 返回的集合包含完整快照。 /// [Test] public void All_Should_Return_All_Configs() { var table = new InMemoryConfigTable( new[] { new MonsterConfigStub(1, "Slime"), new MonsterConfigStub(2, "Goblin") }, static config => config.Id); var all = table.All(); Assert.That(all, Has.Count.EqualTo(2)); Assert.That(all.Select(static config => config.Name), Is.EquivalentTo(new[] { "Slime", "Goblin" })); } /// /// 用于配置表测试的最小配置类型。 /// /// 配置主键。 /// 配置名称。 private sealed record MonsterConfigStub(int Id, string Name); }