fix(tests): 修复 AliasTreeTests 编译错误并更新过时旧格式兼容测试

- SetAlias 调用补全缺失的 alias 参数(DeleteByPathPrefix 测试)
- 移除 4 个旧格式兼容测试,改为期望抛 FormatException
  (FromKey 已按 AGENTS.md "不向后兼容" 原则移除旧格式支持)
This commit is contained in:
tian 2026-06-23 23:12:40 +08:00
parent f86e8c8bf4
commit 7f3be8495c

View File

@ -59,19 +59,18 @@ namespace NavisworksTransport.UnitTests.Core
} }
[TestMethod] [TestMethod]
public void FromKey_OldFormat_ShouldRetroCompatible() [ExpectedException(typeof(FormatException))]
public void FromKey_OldFormat_ShouldThrow()
{ {
var id = AliasNodeIdentity.FromKey("building/floor/wall#2"); // 旧格式(无 || 分隔符)已不再支持,按 AGENTS.md "不向后兼容" 原则抛 FormatException
Assert.AreEqual("", id.IndexPath); AliasNodeIdentity.FromKey("building/floor/wall#2");
Assert.AreEqual("building/floor/wall#2", id.DisplayPath);
} }
[TestMethod] [TestMethod]
public void FromKey_OldFormatNoIndex_ShouldParse() [ExpectedException(typeof(FormatException))]
public void FromKey_OldFormatNoIndex_ShouldThrow()
{ {
var id = AliasNodeIdentity.FromKey("building/floor"); AliasNodeIdentity.FromKey("building/floor");
Assert.AreEqual("", id.IndexPath);
Assert.AreEqual("building/floor", id.DisplayPath);
} }
[TestMethod] [TestMethod]
@ -99,10 +98,10 @@ namespace NavisworksTransport.UnitTests.Core
} }
[TestMethod] [TestMethod]
public void TryParseKey_OldFormat_ShouldSucceed() public void TryParseKey_OldFormat_ShouldReturnFalse()
{ {
Assert.IsTrue(AliasNodeIdentity.TryParseKey("path#0", out var id)); // 旧格式(无 || 分隔符)已不再支持
Assert.AreEqual("", id.IndexPath); Assert.IsFalse(AliasNodeIdentity.TryParseKey("path#0", out _));
} }
[TestMethod] [TestMethod]
@ -279,9 +278,9 @@ namespace NavisworksTransport.UnitTests.Core
public void DeleteByPathPrefix_ShouldRemoveAllUnderPath() public void DeleteByPathPrefix_ShouldRemoveAllUnderPath()
{ {
var store = CreateStore(); var store = CreateStore();
store.SetAlias(Id("building/floor/1")); store.SetAlias(Id("building/floor/1"), "别名1");
store.SetAlias(Id("building/floor/2")); store.SetAlias(Id("building/floor/2"), "别名2");
store.SetAlias(Id("building/roof/3")); store.SetAlias(Id("building/roof/3"), "别名3");
store.DeleteAliasesByPathPrefix("building/floor"); store.DeleteAliasesByPathPrefix("building/floor");
@ -343,19 +342,16 @@ namespace NavisworksTransport.UnitTests.Core
Assert.AreEqual(0, store.Count); Assert.AreEqual(0, store.Count);
} }
// ── 新格式 → 旧格式 兼容 ── // ── 旧格式已不支持AGENTS.md "不向后兼容" 原则)──
[TestMethod] [TestMethod]
public void OldFormatKey_StillWorks() [ExpectedException(typeof(FormatException))]
public void OldFormatKey_ShouldThrow()
{ {
var store = CreateStore(); var store = CreateStore();
string oldKey = "building/floor/wall#0"; string oldKey = "building/floor/wall#0";
// 旧格式 key 无 || 分隔符FromKey 应抛 FormatException
store.SetAlias(AliasNodeIdentity.FromKey(oldKey), "别名"); store.SetAlias(AliasNodeIdentity.FromKey(oldKey), "别名");
Assert.AreEqual("别名", store.GetAlias(AliasNodeIdentity.FromKey(oldKey)));
// 同一个节点用新格式读取
var newId = new AliasNodeIdentity("", "building/floor/wall#0");
Assert.AreEqual("别名", store.GetAlias(newId));
} }
} }
} }