using System.Collections.Generic; using Deltares.Dam.Data; using Deltares.Dam.Data.DamEngineIo; using Deltares.DamEngine.Io; using Deltares.DamEngine.Io.XmlInput; using Deltares.Geometry; using Deltares.Geotechnics.SurfaceLines; using KellermanSoftware.CompareNetObjects; using NUnit.Framework; using Location = Deltares.Dam.Data.Location; namespace Deltares.Dam.Tests.DamEngineIo { [TestFixture] public class FillXmlInputFromDamUiTests { [Test] public void CanWriteAndReadDamProjectDataToXml() { const string inputFilename = "InputFile.xml"; DamProjectData expectedDamProjectData = CreateExampleDamProjectData(); Input input = FillXmlInputFromDamUi.CreateInput(expectedDamProjectData); DamXmlSerialization.SaveInputAsXmlFile(inputFilename, input); input = DamXmlSerialization.LoadInputFromXmlFile(inputFilename); DamProjectData actualDamProjectData = FillDamUiFromXmlInput.CreateDamProjectData(input); CompareDamProjectData(actualDamProjectData, expectedDamProjectData); } private DamProjectData CreateExampleDamProjectData() { var damProjectData = new DamProjectData(); damProjectData.DamProjectType = DamProjectType.Design; damProjectData.WaterBoard = new WaterBoard(); damProjectData.WaterBoard.Dikes = new List(); damProjectData.WaterBoard.Dikes.Add(new Dike()); Dike dike = damProjectData.WaterBoard.Dikes[0]; AddLocations(dike); FillSurfaceLines(dike); return damProjectData; } private static void AddLocations(Dike dike) { const int locationCount = 3; for (int i = 0; i < locationCount; i++) { var location = new Location(); location.PLLineCreationMethod = (PLLineCreationMethod) i; location.IntrusionVerticalWaterPressure = (IntrusionVerticalWaterPressureType) i; location.PolderLevel = 1.0 * i + 0.11; location.DampingFactorPL4 = 1.0 * i + 0.12; location.DampingFactorPL3 = 1.0 * i + 0.13; location.PenetrationLength = 1.0 * i + 0.14; location.PlLineOffsetBelowDikeCrestMiddle = 1.0 * i + 0.15; location.UsePlLineOffsetFactorBelowShoulderCrest = true; location.PlLineOffsetFactorBelowShoulderCrest = 1.0 * i + 0.16; location.PlLineOffsetDryBelowDikeCrestMiddle = 1.0 * i + 0.17; location.UsePlLineOffsetDryFactorBelowShoulderCrest = true; location.PlLineOffsetDryFactorBelowShoulderCrest = 1.0 * i + 0.18; location.SlopeDampingPiezometricHeightPolderSide = 1.0 * i + 0.19; location.PlLineOffsetBelowDikeTopAtRiver = 1.0 * i + 0.20; location.PlLineOffsetBelowDikeTopAtPolder = 1.0 * i + 0.21; location.PlLineOffsetBelowShoulderBaseInside = 1.0 * i + 0.22; location.PlLineOffsetBelowDikeToeAtPolder = 1.0 * i + 0.23; location.HeadPL2 = 1.0 * i + 0.24; location.HeadPl3 = 1.0 * i + 0.25; location.HeadPl4 = 1.0 * i + 0.21; dike.Locations.Add(location); } } private void FillSurfaceLines(Dike dike) { const int surfaceLineCount = 2; for (int i = 0; i < surfaceLineCount; i++) { var surfaceLine = new SurfaceLine2(); surfaceLine.CharacteristicPoints.Geometry = surfaceLine.Geometry; AddPointsToSurfaceLines(surfaceLine); dike.SurfaceLines2.Add(surfaceLine); } } private void AddPointsToSurfaceLines(SurfaceLine2 surfaceLine) { AddPointToSurfaceLine(surfaceLine, 0.0, 0.0, CharacteristicPointType.SurfaceLevelOutside); AddPointToSurfaceLine(surfaceLine, 2.0, 0.5, CharacteristicPointType.None); AddPointToSurfaceLine(surfaceLine, 4.0, 0.0, CharacteristicPointType.DikeToeAtRiver); AddPointToSurfaceLine(surfaceLine, 9.0, 5.0, CharacteristicPointType.DikeTopAtRiver); AddPointToSurfaceLine(surfaceLine, 10.0, 5.2, CharacteristicPointType.None); AddPointToSurfaceLine(surfaceLine, 13.0, 5.4, CharacteristicPointType.DikeTopAtPolder); AddPointToSurfaceLine(surfaceLine, 18.0, 1.0, CharacteristicPointType.DikeToeAtPolder); AddPointToSurfaceLine(surfaceLine, 24.0, 1.0, CharacteristicPointType.SurfaceLevelInside); } private void AddPointToSurfaceLine(SurfaceLine2 surfaceLine, double xCoordinate, double zCoordinate, CharacteristicPointType characteristicPointType) { var geometryPoint = new GeometryPoint() { X = xCoordinate, Y = 0.0, Z = zCoordinate, }; surfaceLine.AddCharacteristicPoint(geometryPoint, characteristicPointType); } private void CompareDamProjectData(DamProjectData actual, DamProjectData expected) { var compare = new CompareLogic { Config = { MaxDifferences = 100 } }; compare.Config.MembersToIgnore = new List { "SheetPilePoint", "SheetPilePointX", "SheetPilePointY", "SheetPilePointZ", "LocalXZSheetPilePoint", "SoilbaseDB", "SurfaceLine", "LocalXZSurfaceLine", "SoilLayer1D", "SoildatabaseName", "SoilList", "MapForSoilGeometries2D" }; var result = compare.Compare(expected, actual); Assert.AreEqual(0, result.Differences.Count, "Differences found read/write Input object"); } } }