// Copyright (C) Stichting Deltares 2017. All rights reserved. // // This file is part of the Dam Engine. // // The Dam Engine is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero 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 Affero General Public License for more details. // // You should have received a copy of the GNU Affero 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 Deltares.DamEngine.Data.General; using Deltares.DamEngine.Data.General.Results; using Deltares.DamEngine.Data.Standard.Calculation; using Deltares.DamEngine.Io; using Deltares.DamEngine.Io.XmlOutput; using KellermanSoftware.CompareNetObjects; using NUnit.Framework; using DesignResult = Deltares.DamEngine.Data.General.Results.DesignResult; using UpliftSituation = Deltares.DamEngine.Data.Design.UpliftSituation; namespace Deltares.DamEngine.Interface.Tests { [TestFixture] public class FillXmlOutputFromDamTests { [Test] public void CanWriteAndReadDamProjectDataToXml() { const string outputFilename = "OutputFile.xml"; DamProjectData expectedDamProjectData = CreateExampleDamProjectData(); Output output = FillXmlOutputFromDam.CreateOutput(expectedDamProjectData); DamXmlSerialization.SaveOutputAsXmlFile(outputFilename, output); output = DamXmlSerialization.LoadOutputFromXmlFile(outputFilename); DamProjectData actualDamProjectData = FillDamFromXmlOutput.CreateDamProjectData(output); CompareDamProjectData(actualDamProjectData, expectedDamProjectData); } [Test] public void CanWriteAndReadDamProjectDataToXmlString() { DamProjectData expectedDamProjectData = CreateExampleDamProjectData(); Output output = FillXmlOutputFromDam.CreateOutput(expectedDamProjectData); var xmlString = DamXmlSerialization.SaveOutputAsXmlString(output); output = DamXmlSerialization.LoadOutputFromXmlString(xmlString); DamProjectData actualDamProjectData = FillDamFromXmlOutput.CreateDamProjectData(output); CompareDamProjectData(actualDamProjectData, expectedDamProjectData); } private DamProjectData CreateExampleDamProjectData() { const int resultsCount = 3; var damProjectData = new DamProjectData { DesignCalculations = new List() }; for (int i = 0; i < resultsCount; i++) { var result = new DesignResult("location " + i, "Scenario " + (i * 2)) { BaseFileName = "my basefilename " + i, ProfileName = "profile" + i }; result.CalculationResult = CalculationResult.RunFailed; result.PipingDesignResults = new PipingDesignResults(PipingModelType.Bligh) { ResultMessage = "no run made", FailureProbability = 2, UpliftFactor = 1.3 * i, HeaveFactor = 1.1 * i, BlighFactor = 1.03 * i, BlighHcritical = 0.4, LocalExitPointX = 34.21 }; var situation = new UpliftSituation { IsUplift = true, Pl3MinUplift = 0.1, Pl3HeadAdjusted = 0.2, Pl3LocationXMinUplift = 0.3, Pl4MinUplift = 0.1 * i, Pl4HeadAdjusted = 0.2 * i, Pl4LocationXMinUplift = 0.3 * i }; result.PipingDesignResults.UpliftSituation = situation; damProjectData.DesignCalculations.Add(result); } 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"); } } }