using Microsoft.VisualStudio.TestTools.UnitTesting; using Newtonsoft.Json.Linq; namespace NavisworksTransport.UnitTests.Integration { /// /// 碰撞报告结构断言(覆盖计划 T06)。 /// /// 验证报告内容的完整性与数据一致性,不依赖具体碰撞数值(碰撞数随模型数据变化)。 /// 适用:虚拟物体碰撞测试、真实物体碰撞测试。 /// internal static class CollisionReportAssertions { public static void AssertReportStructure(JObject data, JObject route) { Assert.IsNotNull(data, "缺少测试结果 data"); Assert.IsNotNull(route, "缺少 route"); JObject report = (JObject)data["report"]; Assert.IsNotNull(report, "缺少碰撞报告"); // 路径关联 Assert.IsFalse(string.IsNullOrWhiteSpace((string)report["pathName"]), "报告路径名为空"); Assert.AreEqual((string)route["name"], (string)report["pathName"], "报告路径名不匹配"); Assert.IsFalse(string.IsNullOrWhiteSpace((string)report["routeId"]), "报告路径 ID 为空"); Assert.AreEqual((string)route["id"], (string)report["routeId"], "报告路径 ID 不匹配"); // 数据库记录关联 Assert.IsTrue((int)report["resultId"] > 0, "报告结果 ID 无效"); // 碰撞数据一致性(不依赖具体碰撞数) Assert.IsTrue((int)report["totalCollisions"] >= 0, "碰撞总数不能为负"); Assert.IsTrue((int)report["uniqueCollidedObjectsCount"] >= 0, "唯一碰撞对象数不能为负"); Assert.IsTrue( (int)report["uniqueCollidedObjectsCount"] <= (int)report["totalCollisions"], "去重对象数不应超过碰撞总数"); // 运动物体信息与截图 Assert.IsFalse(string.IsNullOrWhiteSpace((string)report["movingObjectInfo"]), "报告缺少运动物体信息"); Assert.IsTrue((bool)report["hasScreenshots"], "碰撞报告应包含截图"); Assert.IsTrue((int)report["screenshotCount"] > 0, "截图数量应大于 0"); } } }