using System.Net.Sockets; using Deltares.DamEngine.Data.General; using Deltares.DamEngine.Io; using Deltares.DamEngine.Io.XmlInput; using Deltares.DamEngine.Interface; using KellermanSoftware.CompareNetObjects; using NUnit.Framework; namespace Deltares.DamEngine.Interface.Tests { [TestFixture] public class FillDamFromXmlInputTests { [Test] public void CanWriteAndReadDamProjectDataToXml() { const string inputFilename = "InputFile.xml"; DamProjectData expectedDamProjectData = CreateExampleDamProjectData(); Input input = FillXmlInputFromDam.CreateInput(expectedDamProjectData); DamXmlSerialization.SaveInputAsXml(inputFilename, input); input = DamXmlSerialization.LoadInputFromXml(inputFilename); DamProjectData actualDamProjectData = FillDamFromXmlInput.CreateDamProjectData(input); CompareDamProjectData(actualDamProjectData, expectedDamProjectData); } private DamProjectData CreateExampleDamProjectData() { const int locationCount = 3; var damProjectData = new DamProjectData(); damProjectData.DamProjectType = DamProjectType.Design; damProjectData.Dike = new Dike(); for (int i = 0; i < locationCount; i++) { var location = new Data.General.Location(); location.ModelParametersForPLLines.PLLineCreationMethod = (PLLineCreationMethod) i; location.IntrusionVerticalWaterPressure = (IntrusionVerticalWaterPressureType) i; location.PolderLevel = 1.0 * i + 0.11; location.ModelParametersForPLLines.DampingFactorPL4 = 1.0 * i + 0.12; location.ModelParametersForPLLines.DampingFactorPL3 = 1.0 * i + 0.13; location.ModelParametersForPLLines.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.Dike.Locations.Add(location); } return damProjectData; } private void CompareDamProjectData(DamProjectData actual, DamProjectData expected) { var compare = new CompareLogic { Config = { MaxDifferences = 100 } }; var result = compare.Compare(expected, actual); Assert.AreEqual(0, result.Differences.Count, "Differences found read/write Input object"); } } }