Index: DamClients/DamUI/trunk/src/Dam/Deltares.Dam.Tests/LoadCompatibilityTest.cs =================================================================== diff -u -r6028 -r6034 --- DamClients/DamUI/trunk/src/Dam/Deltares.Dam.Tests/LoadCompatibilityTest.cs (.../LoadCompatibilityTest.cs) (revision 6028) +++ DamClients/DamUI/trunk/src/Dam/Deltares.Dam.Tests/LoadCompatibilityTest.cs (.../LoadCompatibilityTest.cs) (revision 6034) @@ -25,6 +25,7 @@ using Deltares.Dam.Data; using Deltares.Dam.Data.DataPlugins.Configuration; using Deltares.Dam.TestHelper; +using Deltares.Geotechnics.Soils; using KellermanSoftware.CompareNetObjects; using NUnit.Framework; @@ -34,8 +35,41 @@ 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"); @@ -46,19 +80,20 @@ Directory.CreateDirectory(tmpTestFolder); } - [TearDown] + [OneTimeTearDown] public void FixtureTearDown() { if (Directory.Exists(tmpTestFolder)) { - Directory.Delete(tmpTestFolder, true); + //Directory.Delete(tmpTestFolder, true); } } - + [Test] + [Category("Integration")] public void CanSaveAndLoadTutorialDesignStability() { - const string definitionFilename = @"..\..\..\..\..\data\Tutorials\DAMDesign\Stability\DAM Tutorial Design.defx"; + string definitionFilename = Path.Combine(dataFolder, @"Tutorials\DAMDesign\Stability\DAM Tutorial Design.defx"); string projectFilename = Path.Combine(tmpTestFolder, "TestTutorialDesignStability.damx"); // Create damx from defx @@ -114,5 +149,101 @@ 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}"); + }); + } + } }