From 7f3be8495c79bb0a8a7398ce023c8f27e8cb6080 Mon Sep 17 00:00:00 2001 From: tian <11429339@qq.com> Date: Tue, 23 Jun 2026 23:12:40 +0800 Subject: [PATCH] =?UTF-8?q?=EF=BB=BFfix(tests):=20=E4=BF=AE=E5=A4=8D=20Ali?= =?UTF-8?q?asTreeTests=20=E7=BC=96=E8=AF=91=E9=94=99=E8=AF=AF=E5=B9=B6?= =?UTF-8?q?=E6=9B=B4=E6=96=B0=E8=BF=87=E6=97=B6=E6=97=A7=E6=A0=BC=E5=BC=8F?= =?UTF-8?q?=E5=85=BC=E5=AE=B9=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - SetAlias 调用补全缺失的 alias 参数(DeleteByPathPrefix 测试) - 移除 4 个旧格式兼容测试,改为期望抛 FormatException (FromKey 已按 AGENTS.md "不向后兼容" 原则移除旧格式支持) --- UnitTests/Core/AliasTreeTests.cs | 38 ++++++++++++++------------------ 1 file changed, 17 insertions(+), 21 deletions(-) diff --git a/UnitTests/Core/AliasTreeTests.cs b/UnitTests/Core/AliasTreeTests.cs index 52e08de..1b9d99e 100644 --- a/UnitTests/Core/AliasTreeTests.cs +++ b/UnitTests/Core/AliasTreeTests.cs @@ -59,19 +59,18 @@ namespace NavisworksTransport.UnitTests.Core } [TestMethod] - public void FromKey_OldFormat_ShouldRetroCompatible() + [ExpectedException(typeof(FormatException))] + public void FromKey_OldFormat_ShouldThrow() { - var id = AliasNodeIdentity.FromKey("building/floor/wall#2"); - Assert.AreEqual("", id.IndexPath); - Assert.AreEqual("building/floor/wall#2", id.DisplayPath); + // 旧格式(无 || 分隔符)已不再支持,按 AGENTS.md "不向后兼容" 原则抛 FormatException + AliasNodeIdentity.FromKey("building/floor/wall#2"); } [TestMethod] - public void FromKey_OldFormatNoIndex_ShouldParse() + [ExpectedException(typeof(FormatException))] + public void FromKey_OldFormatNoIndex_ShouldThrow() { - var id = AliasNodeIdentity.FromKey("building/floor"); - Assert.AreEqual("", id.IndexPath); - Assert.AreEqual("building/floor", id.DisplayPath); + AliasNodeIdentity.FromKey("building/floor"); } [TestMethod] @@ -99,10 +98,10 @@ namespace NavisworksTransport.UnitTests.Core } [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] @@ -279,9 +278,9 @@ namespace NavisworksTransport.UnitTests.Core public void DeleteByPathPrefix_ShouldRemoveAllUnderPath() { var store = CreateStore(); - store.SetAlias(Id("building/floor/1")); - store.SetAlias(Id("building/floor/2")); - store.SetAlias(Id("building/roof/3")); + store.SetAlias(Id("building/floor/1"), "别名1"); + store.SetAlias(Id("building/floor/2"), "别名2"); + store.SetAlias(Id("building/roof/3"), "别名3"); store.DeleteAliasesByPathPrefix("building/floor"); @@ -343,19 +342,16 @@ namespace NavisworksTransport.UnitTests.Core Assert.AreEqual(0, store.Count); } - // ── 新格式 → 旧格式 兼容 ── + // ── 旧格式已不支持(AGENTS.md "不向后兼容" 原则)── [TestMethod] - public void OldFormatKey_StillWorks() + [ExpectedException(typeof(FormatException))] + public void OldFormatKey_ShouldThrow() { var store = CreateStore(); string oldKey = "building/floor/wall#0"; + // 旧格式 key 无 || 分隔符,FromKey 应抛 FormatException 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)); } } }