using System.Collections.Generic; using Deltares.Dam.Data; using Deltares.Dam.Data.DamEngineIo; using Deltares.DamEngine.Io; using Deltares.DamEngine.Io.XmlInput; 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() { const int locationCount = 3; var damProjectData = new DamProjectData(); damProjectData.DamProjectType = DamProjectType.Design; damProjectData.WaterBoard = new WaterBoard(); damProjectData.WaterBoard.Dikes = new List(); damProjectData.WaterBoard.Dikes.Add(new Dike()); 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; damProjectData.WaterBoard.Dikes[0].Locations.Add(location); } return damProjectData; } 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"); } } }