118 lines
4.3 KiB
C#
118 lines
4.3 KiB
C#
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,
|
|
@"<?xml version=""1.0"" encoding=""UTF-8""?>
|
|
<PathPlanningData xmlns=""http://www.3ds.com/delmia/pathplanning"" version=""1.0"" generator=""test"" timestamp=""2026-03-25T00:00:00"">
|
|
<ProjectInfo name=""test"" description=""test"" units=""meters"" coordinateSystem=""Global"" />
|
|
<Routes>
|
|
<Route id=""route-1"" name=""rail-test"" description="""" pathType=""Rail"" railMountMode=""OverRail"" railPathDefinitionMode=""RailCenterLine"" railPreferredNormalX=""0.0"" railPreferredNormalY=""1.0"" railPreferredNormalZ=""-0.5"" totalLength=""10.0"" maxObjectLength=""0.0"" maxObjectWidth=""0.0"" maxObjectHeight=""0.0"" safetyMargin=""0.0"" gridSize=""1.0"" liftHeight=""0.0"" created=""2026-03-25T00:00:00"">
|
|
<Points>
|
|
<Point id=""p1"" name=""start"" type=""StartPoint"" index=""0"" x=""0"" y=""0"" z=""0"" created=""2026-03-25T00:00:00"" />
|
|
<Point id=""p2"" name=""end"" type=""EndPoint"" index=""1"" x=""10"" y=""0"" z=""0"" created=""2026-03-25T00:00:00"" />
|
|
</Points>
|
|
</Route>
|
|
</Routes>
|
|
</PathPlanningData>");
|
|
|
|
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
|
|
{
|
|
}
|
|
}
|
|
}
|
|
}
|