// Copyright (C) Stichting Deltares 2023. All rights reserved. // // This file is part of the application DAM - Live. // // DAM - Live 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 Deltares.DamLive.Application; using Deltares.Dam.Data; using Deltares.DamLive.Io; using Deltares.DamLive.Data; using KellermanSoftware.CompareNetObjects; using NUnit.Framework; using StabilitySearchMethod = Deltares.Dam.Data.StabilitySearchMethod; namespace Deltares.DamLive.Tests; [TestFixture] public class FillDomainFromXmlCalculationParametersTests { [Test] [TestCase(FailureMechanismSystemType.Piping, PipingModelType.Bligh)] [TestCase(FailureMechanismSystemType.Piping, PipingModelType.Wti2017)] [TestCase(FailureMechanismSystemType.StabilityOutside, PipingModelType.Bligh, StabilityModelType.Bishop, StabilitySearchMethod.Grid)] [TestCase(FailureMechanismSystemType.StabilityInside, PipingModelType.Bligh, StabilityModelType.UpliftVan, StabilitySearchMethod.Grid)] [TestCase(FailureMechanismSystemType.StabilityInside, PipingModelType.Bligh, StabilityModelType.UpliftVan, StabilitySearchMethod.BeeSwarm)] public void CanWriteAndReadCalculationParametersDataToXml(FailureMechanismSystemType mechanismType, PipingModelType pipingModel = PipingModelType.Bligh, StabilityModelType stabModel = StabilityModelType.Bishop, StabilitySearchMethod searchMethod = StabilitySearchMethod.Grid) { const string filename = "CalculationParameters.xml"; CalculationParameters expectedData = CreateExampleCalculationParameters(mechanismType, pipingModel, stabModel, searchMethod); // Write file XmlCalculationParameters writeXml = FillXmlCalculationParametersFromDomain.CreateCalculationParameters(expectedData); CalculationParametersXmlSerialization.SaveAsXmlFile(filename, writeXml); // Load file XmlCalculationParameters readXml = CalculationParametersXmlSerialization.LoadFromXmlFile(filename); CalculationParameters actualData = FillDomainFromXmlCalculationParameters.CreateCalculationParameters(readXml); CompareCalculationParametersData(actualData, expectedData); } private static CalculationParameters CreateExampleCalculationParameters(FailureMechanismSystemType mechanismType, PipingModelType pipingModel, StabilityModelType stabModel, StabilitySearchMethod searchMethod) { var calculationModules = new CalculationModules { PipingBligh = mechanismType == FailureMechanismSystemType.Piping && pipingModel == PipingModelType.Bligh, PipingWti = mechanismType == FailureMechanismSystemType.Piping && pipingModel == PipingModelType.Wti2017, StabilityOutside = mechanismType == FailureMechanismSystemType.StabilityOutside, StabilityInside = mechanismType == FailureMechanismSystemType.StabilityInside }; MStabParameters stabilityParameters = null; if (mechanismType is FailureMechanismSystemType.StabilityOutside or FailureMechanismSystemType.StabilityInside) { stabilityParameters = new MStabParameters { Model = stabModel, SearchMethod = searchMethod }; } var calculationParameters = new CalculationParameters { CalculationModules = calculationModules, StabilityParameters = stabilityParameters }; return calculationParameters; } private static void CompareCalculationParametersData(CalculationParameters actual, CalculationParameters expected) { var compare = new CompareLogic { Config = { MaxDifferences = 100 } }; ComparisonResult result = compare.Compare(expected, actual); Assert.That(result.Differences, Is.Empty, "Differences found read/write Input object:" + result.DifferencesString); } }