// Copyright (C) Stichting Deltares 2024. All rights reserved. // // This file is part of the application DAM - UI. // // DAM - UI is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program. If not, see . // // All names, logos, and references to "Deltares" are registered trademarks of // Stichting Deltares and remain full property of Stichting Deltares at all times. // All rights reserved. using System.Collections.Generic; using System.IO; using System.Linq; using Deltares.Dam.Data; using Deltares.Dam.Data.DataPlugins.Configuration; using Deltares.Dam.TestHelper; using Deltares.Geotechnics.Soils; using KellermanSoftware.CompareNetObjects; using NUnit.Framework; namespace Deltares.Dam.Tests; [TestFixture] public class LoadCompatibilityTest { private string tmpTestFolder; private const string dataFolder = @"..\..\..\..\..\data"; private CompareLogic compare; /// /// Code that is run before each test /// [SetUp] public void Initialize() { compare = new CompareLogic { Config = { MaxDifferences = 100, CompareChildren = false, DoublePrecision = 0.000001, MembersToIgnore = new List { // "SurfaceLineId", // "SheetPilePoint", // "SheetPilePointX", // "SheetPilePointY", // "SheetPilePointZ", // "LocalXZSheetPilePoint", // "SurfaceLine", // "LocalXZSurfaceLine", // "SoilLayer1D", // "SoilList", // "MapForSoilGeometries2D" } } }; } [OneTimeSetUp] public void FixtureSetup() { tmpTestFolder = Path.Combine(Directory.GetCurrentDirectory(), "LoadCompatibilityTests"); if (Directory.Exists(tmpTestFolder)) { Directory.Delete(tmpTestFolder, true); } Directory.CreateDirectory(tmpTestFolder); } [OneTimeTearDown] public void FixtureTearDown() { if (Directory.Exists(tmpTestFolder)) { Directory.Delete(tmpTestFolder, true); } } [Test] [Category("Integration")] public void CanSaveAndLoadTutorialDesignStability() { string definitionFilename = Path.Combine(dataFolder, @"Tutorials\DAMDesign\Stability\DAM Tutorial Design.defx"); string projectFilename = Path.Combine(tmpTestFolder, "TestTutorialDesignStability.damx"); // Create damx from defx DataSourceContainer dataSourceContainer = DataSourceContainer.Deserialize(definitionFilename); string damProjectFolder = Path.GetDirectoryName(definitionFilename); var damProject = new DamProject(); damProject.ProjectFileName = projectFilename; damProject.DamProjectData.DamProjectType = DamProjectType.Design; damProject.DamProjectData.DamDataSourceFileName = definitionFilename; if (dataSourceContainer.MapSoilProfile2D != null) { damProject.AssignGeometry2DMapnameIfNotAssigned(Path.Combine(damProjectFolder, dataSourceContainer.MapSoilProfile2D)); } var dikeRings = new List { "Dike from CSV" }; damProject.Import(damProjectFolder, dataSourceContainer, dikeRings, DamProjectType.Design, null); // Save in current XML format DamProject.SaveData(projectFilename, damProject.DamProjectData); // Load from current XML format DamProjectData currentProjectData = ProjectLoader.LoadProjectData(projectFilename); // Compare segments Assert.That(currentProjectData.WaterBoard.Segments, Has.Count.EqualTo(23)); Segment segmentDWP1 = currentProjectData.WaterBoard.Segments.Single(s => s.Name == "DWP_1"); Assert.That(segmentDWP1.SoilProfileProbabilities, Has.Count.EqualTo(1)); Assert.That(segmentDWP1.SoilProfileProbabilities[0].SoilGeometryName, Is.EqualTo("DWP_1.stix")); Segment segmentDWP11 = currentProjectData.WaterBoard.Segments.Single(s => s.Name == "DWP_11"); Assert.That(segmentDWP11.SoilProfileProbabilities, Has.Count.EqualTo(3)); Assert.Multiple(() => { Assert.That(segmentDWP11.SoilProfileProbabilities[0].SoilGeometryName, Is.EqualTo("DWP_11_1.stix")); Assert.That(segmentDWP11.SoilProfileProbabilities[1].SoilGeometryName, Is.EqualTo("DWP_11_2.stix")); Assert.That(segmentDWP11.SoilProfileProbabilities[2].SoilGeometryName, Is.EqualTo("DWP_11_3.stix")); }); // Compare locations Assert.That(currentProjectData.Locations, Has.Count.EqualTo(23)); Location locationDWP1 = currentProjectData.Locations.Single(s => s.Name == "DWP_1"); Assert.Multiple(() => { Assert.That(locationDWP1.SegmentId, Is.EqualTo("DWP_1")); Assert.That(locationDWP1.Scenarios.Count, Is.EqualTo(1)); Assert.That(locationDWP1.SurfaceLineId, Is.EqualTo("DWP_1")); }); Location locationDWP10 = currentProjectData.Locations.Single(s => s.Name == "DWP_10"); Assert.Multiple(() => { Assert.That(locationDWP10.SegmentId, Is.EqualTo("DWP_10")); Assert.That(locationDWP10.Scenarios.Count, Is.EqualTo(3)); Assert.That(locationDWP10.SurfaceLineId, Is.EqualTo("DWP_10")); }); } [Test] [Category("Integration")] public void CanLoadDesignStabilityVersion_25_1_1() { string fullProjectFilename = Path.Combine(dataFolder, @"Versions\V 25.1.1\DAMDesign\Stability\DAM Tutorial Design.damx"); string newProjectFilename = Path.Combine(tmpTestFolder, "TestDesignStabilityFromVersion_25_1_1.damx"); DamProjectData projectData = ProjectLoader.LoadProjectData(fullProjectFilename); Assert.Multiple(() => { Assert.That(projectData.DamProjectType, Is.EqualTo(DamProjectType.Design)); Assert.That(projectData.Locations, Has.Count.EqualTo(23)); }); // Save in current XML format DamProject.SaveData(newProjectFilename, projectData); // Load from current XML format DamProjectData currentProjectData = ProjectLoader.LoadProjectData(newProjectFilename); // Compare all if expected that all is the same ComparisonResult result = compare.Compare(projectData, currentProjectData); Assert.That(result.Differences, Is.Empty, result.DifferencesString); // Or compare only specific parts with compare e.g. a single location. const string locationName = "DWP_1"; Location expectedLocation = projectData.Locations.Single(s => s.Name == locationName); Location actualLocation = currentProjectData.Locations.Single(s => s.Name == locationName); result = compare.Compare(expectedLocation.Scenarios[0], actualLocation.Scenarios[0]); Assert.That(result.Differences, Is.Empty, result.DifferencesString); } [Test] [Category("Integration")] public void CanLoadDesignPipingVersion_25_1_1() { string fullProjectFilename = Path.Combine(dataFolder, @"Versions\V 25.1.1\DAMDesign\Piping\PipingVoorbeeld1\PipingVoorbeeld1.damx"); string newProjectFilename = Path.Combine(tmpTestFolder, "TestDesignPipingFromVersion_25_1_1.damx"); DamProjectData projectData = ProjectLoader.LoadProjectData(fullProjectFilename); Assert.Multiple(() => { Assert.That(projectData.DamProjectType, Is.EqualTo(DamProjectType.Design)); Assert.That(projectData.Locations, Has.Count.EqualTo(1)); }); // Save in current XML format DamProject.SaveData(newProjectFilename, projectData); // Load from current XML format DamProjectData currentProjectData = ProjectLoader.LoadProjectData(newProjectFilename); // Compare all if expected that all is the same ComparisonResult result = compare.Compare(projectData, currentProjectData); Assert.That(result.Differences, Is.Empty, result.DifferencesString); // Or by comparing with e.g. CompareSegments1D for a single location. const string locationName = "Profiel 1"; Location expectedLocation = projectData.Locations.Single(s => s.Name == locationName); Location actualLocation = currentProjectData.Locations.Single(s => s.Name == locationName); CompareSegments1D(expectedLocation, actualLocation); } /// /// Compares the segments. /// /// The expected location. /// The actual location. private static void CompareSegments1D(Location expectedLocation, Location actualLocation) { for (var index = 0; index < expectedLocation.Segment.SoilProfileProbabilities.Count; index++) { CompareSoilProfiles1D(expectedLocation.Segment.SoilProfileProbabilities[index].SoilProfile, actualLocation.Segment.SoilProfileProbabilities[index].SoilProfile); } } /// /// Compares the soil profiles. /// /// The expected soil profile 1D. /// The actual soil profile 1D. private static void CompareSoilProfiles1D(SoilProfile1D expectedSoilProfile1D, SoilProfile1D actualSoilProfile1D) { int expectedCount = expectedSoilProfile1D.Layers.Count; int actualCount = actualSoilProfile1D.Layers.Count; Assert.That(expectedCount, Is.EqualTo(actualCount)); for (var index = 0; index < expectedCount; index++) { Assert.Multiple(() => { Assert.That(actualSoilProfile1D.Layers[index].Soil.Name, Is.EqualTo(expectedSoilProfile1D.Layers[index].Soil.Name), $"Non-matching name in layer {index}"); Assert.That(actualSoilProfile1D.Layers[index].IsAquifer, Is.EqualTo(expectedSoilProfile1D.Layers[index].IsAquifer), $"Non-matching isAquifer in layer {index}"); }); } } }