// Copyright (C) Stichting Deltares 2016. All rights reserved. // // This file is part of Ringtoets. // // Ringtoets is free software: you can redistribute it and/or modify // it under the terms of the GNU 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 General Public License for more details. // // You should have received a copy of the GNU 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 System.IO; using System.Xml; using Core.Common.Base.Data; using Core.Common.TestUtil; using NUnit.Framework; using Ringtoets.Common.IO; using Ringtoets.Common.IO.Configurations; namespace Ringtoets.HeightStructures.IO.Test { [TestFixture] public class HeightStructuresCalculationConfigurationXmlWriterExtensionsTest { private readonly string testDataPath = TestHelper.GetTestDataPath( TestDataPath.Ringtoets.HeightStructures.IO, nameof(HeightStructuresCalculationConfigurationXmlWriterExtensions)); private static IEnumerable Calculations { get { yield return new TestCaseData("completeConfiguration", CreateFullCalculation()) .SetName("Calculation configuration with all parameters set"); yield return new TestCaseData("sparseConfiguration", new HeightStructureCalculationConfiguration("sparse config")) .SetName("Calculation configuration with none of its parameters set"); } } [Test] [TestCaseSource(nameof(Calculations))] public void Write_ValidCalculationCalculation_ValidFile(string expectedFileName, HeightStructureCalculationConfiguration calculation) { // Setup string filePath = TestHelper.GetScratchPadPath("test.xml"); try { // Call using (var writer = CreateXmlWriter(filePath)) { writer.WriteHeightStructure(calculation); } // Assert Assert.IsTrue(File.Exists(filePath)); string actualXml = File.ReadAllText(filePath); string expectedXmlFilePath = Path.Combine(testDataPath, $"{expectedFileName}.xml"); string expectedXml = File.ReadAllText(expectedXmlFilePath); Assert.AreEqual(expectedXml, actualXml); } finally { File.Delete(filePath); } } private static HeightStructureCalculationConfiguration CreateFullCalculation() { return new HeightStructureCalculationConfiguration("Berekening 1") { HydraulicBoundaryLocationName = "Locatie1", StructureName = "kunstwerk1", ForeshoreProfileName = "profiel1", FailureProbabilityStructureWithErosion = 1e-6, StructureNormalOrientation = 67.1, WaveReduction = new WaveReductionConfiguration { UseBreakWater = true, BreakWaterType = ReadBreakWaterType.Dam, BreakWaterHeight = 1.234, UseForeshoreProfile = true }, StormDuration = new MeanVariationCoefficientStochastConfiguration { Mean = (RoundedDouble) 6.0 }, ModelFactorSuperCriticalFlow = new MeanStandardDeviationStochastConfiguration { Mean = (RoundedDouble) 1.10 }, FlowWidthAtBottomProtection = new MeanStandardDeviationStochastConfiguration { Mean = (RoundedDouble) 15.2, StandardDeviation = (RoundedDouble) 0.1 }, WidthFlowApertures = new MeanStandardDeviationStochastConfiguration { Mean = (RoundedDouble) 13.2, StandardDeviation = (RoundedDouble) 0.3 }, StorageStructureArea = new MeanVariationCoefficientStochastConfiguration { Mean = (RoundedDouble) 15000, VariationCoefficient = (RoundedDouble) 0.01 }, AllowedLevelIncreaseStorage = new MeanStandardDeviationStochastConfiguration { Mean = (RoundedDouble) 0.2, StandardDeviation = (RoundedDouble) 0.01 }, LevelCrestStructure = new MeanStandardDeviationStochastConfiguration { Mean = (RoundedDouble) 4.3, StandardDeviation = (RoundedDouble) 0.2 }, CriticalOvertoppingDischarge = new MeanVariationCoefficientStochastConfiguration { Mean = (RoundedDouble) 2, VariationCoefficient = (RoundedDouble) 0.1 } }; } private static XmlWriter CreateXmlWriter(string filePath) { return XmlWriter.Create(filePath, new XmlWriterSettings { Indent = true }); } } }