using System; using System.Collections.Generic; using System.IO; using Autodesk.Navisworks.Api; using Microsoft.VisualStudio.TestTools.UnitTesting; namespace NavisworksTransport.UnitTests.Core { [TestClass] public class PathPersistenceTests { [TestMethod] public void PathDataManager_ShouldImport_RailPreferredNormal_FromJson() { var tempDir = Path.Combine(Path.GetTempPath(), "NavisworksTransportTests", Guid.NewGuid().ToString("N")); Directory.CreateDirectory(tempDir); var filePath = Path.Combine(tempDir, "route.json"); try { File.WriteAllText(filePath, @"{ ""PathPlanningData"": { ""version"": ""1.0"", ""generator"": ""test"", ""timestamp"": ""2026-03-25T00:00:00"", ""ProjectInfo"": { ""name"": ""test"", ""description"": ""test"", ""units"": ""meters"", ""coordinateSystem"": ""Global"" }, ""Routes"": [ { ""id"": ""route-1"", ""name"": ""rail-test"", ""description"": """", ""pathType"": ""Rail"", ""railMountMode"": ""OverRail"", ""railPathDefinitionMode"": ""RailCenterLine"", ""railPreferredNormal"": { ""x"": -0.2, ""y"": 0.5, ""z"": 0.8 }, ""totalLength"": 10.0, ""objectLimits"": { ""maxLength"": 0, ""maxWidth"": 0, ""maxHeight"": 0, ""safetyMargin"": 0 }, ""gridSize"": 1.0, ""liftHeight"": 0.0, ""created"": ""2026-03-25T00:00:00"", ""points"": [ { ""id"": ""p1"", ""name"": ""start"", ""type"": ""StartPoint"", ""index"": 0, ""x"": 0, ""y"": 0, ""z"": 0, ""created"": ""2026-03-25T00:00:00"" }, { ""id"": ""p2"", ""name"": ""end"", ""type"": ""EndPoint"", ""index"": 1, ""x"": 10, ""y"": 0, ""z"": 0, ""created"": ""2026-03-25T00:00:00"" } ] } ] } }"); var manager = new PathDataManager(); var importedRoutes = manager.ImportFromJson(filePath); Assert.AreEqual(1, importedRoutes.Count); Assert.IsNotNull(importedRoutes[0].RailPreferredNormal); } finally { SafeDelete(tempDir); } } [TestMethod] public void PathDataManager_ShouldImport_RailPreferredNormal_FromXml() { var tempDir = Path.Combine(Path.GetTempPath(), "NavisworksTransportTests", Guid.NewGuid().ToString("N")); Directory.CreateDirectory(tempDir); var filePath = Path.Combine(tempDir, "route.xml"); try { File.WriteAllText(filePath, @" "); var manager = new PathDataManager(); var importedRoutes = manager.ImportFromXml(filePath); Assert.AreEqual(1, importedRoutes.Count); Assert.IsNotNull(importedRoutes[0].RailPreferredNormal); } finally { SafeDelete(tempDir); } } private static void SafeDelete(string directory) { if (!Directory.Exists(directory)) { return; } try { Directory.Delete(directory, true); } catch { } } } }