// 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 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.Wti2017, StabilityModelType.Bishop, StabilitySearchMethod.Grid)] [TestCase(FailureMechanismSystemType.StabilityInside, PipingModelType.Wti2017, StabilityModelType.UpliftVan, StabilitySearchMethod.Grid)] [TestCase(FailureMechanismSystemType.StabilityInside, PipingModelType.Wti2017, StabilityModelType.UpliftVan, StabilitySearchMethod.BeeSwarm)] public void CanWriteAndReadCalculationParametersDataToXml(FailureMechanismSystemType mechanismType, PipingModelType pipingModel = PipingModelType.Wti2017, StabilityModelType stabModel = StabilityModelType.UpliftVan, StabilitySearchMethod searchMethod = StabilitySearchMethod.BeeSwarm) { const string filename = "CalculationParameters.xml"; DamFailureMechanismeCalculationSpecification expectedData = CreateExampleCalculationParameters(mechanismType, pipingModel, stabModel, searchMethod); // Write file XmlCalculationParameters writeXml = FillXmlCalculationParametersFromDomain.CreateCalculationParameters(expectedData); CalculationParametersXmlSerialization.SaveAsXmlFile(filename, writeXml); // Load file XmlCalculationParameters readXml = CalculationParametersXmlSerialization.LoadFromXmlFile(filename); DamFailureMechanismeCalculationSpecification actualData = FillDomainFromXmlCalculationParameters.CreateCalculationParameters(readXml); CompareCalculationParametersData(actualData, expectedData); } private static DamFailureMechanismeCalculationSpecification CreateExampleCalculationParameters(FailureMechanismSystemType mechanismType, PipingModelType pipingModel, StabilityModelType stabModel, StabilitySearchMethod searchMethod) { var calculationSpecification = new DamFailureMechanismeCalculationSpecification { FailureMechanismSystemType = mechanismType, PipingModelType = pipingModel, StabilityModelType = stabModel, SearchMethod = searchMethod }; return calculationSpecification; } private static void CompareCalculationParametersData(DamFailureMechanismeCalculationSpecification actual, DamFailureMechanismeCalculationSpecification 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); } }