using System; using System.IO; using System.Threading.Tasks; using Microsoft.VisualStudio.TestTools.UnitTesting; using Newtonsoft.Json.Linq; namespace NavisworksTransport.UnitTests.Integration { /// /// 剖面盒导出集成测试(覆盖计划 T16)。 /// /// 验证 SectionBoxExporter 的指定包围盒导出链路: /// - 导出 NWD 文件成功(文件存在且非空) /// - 包围盒内对象数 > 0、文件大小 > 0 /// - 隐藏节点计算完成(hiddenNodeCount >= 0) /// /// 使用指定包围盒模式(bbox),不依赖 UI 剖面盒状态;包围盒覆盖模型 Hoisting/Rail 区域。 /// [TestClass] [TestCategory("NavisworksIntegration")] public class SectionBoxExportAutomationTests { // 模型单位:覆盖 Hoisting/Rail 区域的包围盒(已验证含 57 个对象) private const double MinX = -240, MinY = 10, MinZ = -20; private const double MaxX = -170, MaxY = 30, MaxZ = 25; [TestMethod] [Timeout(240000)] public async Task SectionBoxBBoxExport_ProducesValidNwd() { using (var client = new NavisworksTestAutomationClient()) { await client.EnsureServiceReadyAsync(TimeSpan.FromSeconds(90)).ConfigureAwait(false); string tempDir = Path.Combine(Path.GetTempPath(), "NavisworksTransportIntegrationTests", Guid.NewGuid().ToString("N")); Directory.CreateDirectory(tempDir); try { string exportPath = Path.Combine(tempDir, "sectionbox-export.nwd"); JObject response = await client.ExportSectionBoxAsync( exportPath, MinX, MinY, MinZ, MaxX, MaxY, MaxZ).ConfigureAwait(false); Assert.IsTrue(response.Value("ok"), "剖面盒导出失败: " + (string)response["error"]); JObject data = (JObject)response["data"]; // 文件已生成且非空 Assert.IsFalse(string.IsNullOrWhiteSpace((string)data["filePath"]), "导出文件路径为空"); Assert.IsTrue(File.Exists(exportPath), "导出文件不存在: " + exportPath); Assert.IsTrue((long)data["fileSize"] > 0, "导出文件大小应大于 0"); Assert.IsTrue(new FileInfo(exportPath).Length > 0, "导出文件实际为空"); // 包围盒内对象与隐藏节点 Assert.IsTrue((int)data["objectCount"] > 0, "包围盒内应找到对象"); Assert.IsTrue((int)data["hiddenNodeCount"] >= 0, "隐藏节点数不能为负"); Assert.AreEqual("bbox", (string)data["mode"], "导出模式应为 bbox"); } finally { SafeDelete(tempDir); } } } private static void SafeDelete(string directory) { if (!Directory.Exists(directory)) { return; } try { Directory.Delete(directory, true); } catch { } } } }