Index: Ringtoets/Common/src/Ringtoets.Common.IO/Ringtoets.Common.IO.csproj =================================================================== diff -u -rad17f1b8f41d6b4b75c9f39b427dddf31b47cef0 -r3c686d6ea57d86134a4338e75d3c7663f379716e --- Ringtoets/Common/src/Ringtoets.Common.IO/Ringtoets.Common.IO.csproj (.../Ringtoets.Common.IO.csproj) (revision ad17f1b8f41d6b4b75c9f39b427dddf31b47cef0) +++ Ringtoets/Common/src/Ringtoets.Common.IO/Ringtoets.Common.IO.csproj (.../Ringtoets.Common.IO.csproj) (revision 3c686d6ea57d86134a4338e75d3c7663f379716e) @@ -117,6 +117,7 @@ + Index: Ringtoets/Common/src/Ringtoets.Common.IO/Writers/StructureCalculationConfigurationXmlWriterExtensions.cs =================================================================== diff -u --- Ringtoets/Common/src/Ringtoets.Common.IO/Writers/StructureCalculationConfigurationXmlWriterExtensions.cs (revision 0) +++ Ringtoets/Common/src/Ringtoets.Common.IO/Writers/StructureCalculationConfigurationXmlWriterExtensions.cs (revision 3c686d6ea57d86134a4338e75d3c7663f379716e) @@ -0,0 +1,154 @@ +// 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; +using System.Xml; +using Ringtoets.Common.IO.Configurations; +using Ringtoets.Common.IO.Schema; + +namespace Ringtoets.Common.IO.Writers +{ + /// + /// Extension methods for an , related to writing . + /// + public static class StructureCalculationConfigurationXmlWriterExtensions + { + /// + /// Action which is performed for writing parameters specific to . + /// + /// The type of of + /// which parameters are written. + /// The instance of type for which + /// to write the parameters. + /// The writer that should be used to write the parameters. + public delegate void WriteSpecificStructureParameters(T configuration, XmlWriter writer); + + /// + /// Writes the properties of structure configurations to file. + /// + /// The type of of + /// which parameters are written. + /// The writer to use for writing out the configuration + /// The structure configuration properties to write. + /// Action which writes properties specific for a structure of type . + /// Action which writes stochats definitions specific for a structure of type . + public static void WriteStructure( + this XmlWriter writer, + T configuration, + WriteSpecificStructureParameters writeProperties, + WriteSpecificStructureParameters writeStochasts) + where T : StructureCalculationConfiguration + { + if (configuration == null) + { + throw new ArgumentNullException(nameof(configuration)); + } + if (writeProperties == null) + { + throw new ArgumentNullException(nameof(writeProperties)); + } + if (writeStochasts == null) + { + throw new ArgumentNullException(nameof(writeStochasts)); + } + + writer.WriteStartElement(ConfigurationSchemaIdentifiers.CalculationElement); + writer.WriteAttributeString(ConfigurationSchemaIdentifiers.NameAttribute, configuration.Name); + + if (configuration.HydraulicBoundaryLocationName != null) + { + writer.WriteElementString( + ConfigurationSchemaIdentifiers.HydraulicBoundaryLocationElement, + configuration.HydraulicBoundaryLocationName); + } + + if (configuration.StructureName != null) + { + writer.WriteElementString( + ConfigurationSchemaIdentifiers.StructureElement, + configuration.StructureName); + } + + if (configuration.StructureNormalOrientation.HasValue) + { + writer.WriteElementString( + ConfigurationSchemaIdentifiers.Orientation, + XmlConvert.ToString(configuration.StructureNormalOrientation.Value)); + } + + if (configuration.FailureProbabilityStructureWithErosion.HasValue) + { + writer.WriteElementString( + ConfigurationSchemaIdentifiers.FailureProbabilityStructureWithErosionElement, + XmlConvert.ToString(configuration.FailureProbabilityStructureWithErosion.Value)); + } + + if (configuration.ForeshoreProfileName != null) + { + writer.WriteElementString( + ConfigurationSchemaIdentifiers.ForeshoreProfileNameElement, + configuration.ForeshoreProfileName); + } + + if (configuration.WaveReduction != null) + { + writer.WriteWaveReduction(configuration.WaveReduction); + } + + writeProperties(configuration, writer); + + writer.WriteStartElement(ConfigurationSchemaIdentifiers.StochastsElement); + + if (configuration.FlowWidthAtBottomProtection != null) + { + writer.WriteDistribution(ConfigurationSchemaIdentifiers.FlowWidthAtBottomProtectionStochastName, configuration.FlowWidthAtBottomProtection); + } + if (configuration.WidthFlowApertures != null) + { + writer.WriteDistribution(ConfigurationSchemaIdentifiers.WidthFlowAperturesStochastName, configuration.WidthFlowApertures); + } + if (configuration.StorageStructureArea != null) + { + writer.WriteDistribution(ConfigurationSchemaIdentifiers.StorageStructureAreaStochastName, configuration.StorageStructureArea); + } + if (configuration.CriticalOvertoppingDischarge != null) + { + writer.WriteDistribution(ConfigurationSchemaIdentifiers.CriticalOvertoppingDischargeStochastName, configuration.CriticalOvertoppingDischarge); + } + if (configuration.ModelFactorSuperCriticalFlow != null) + { + writer.WriteDistribution(ConfigurationSchemaIdentifiers.ModelFactorSuperCriticalFlowStochastName, configuration.ModelFactorSuperCriticalFlow); + } + if (configuration.AllowedLevelIncreaseStorage != null) + { + writer.WriteDistribution(ConfigurationSchemaIdentifiers.AllowedLevelIncreaseStorageStochastName, configuration.AllowedLevelIncreaseStorage); + } + if (configuration.StormDuration != null) + { + writer.WriteDistribution(ConfigurationSchemaIdentifiers.StormDurationStochastName, configuration.StormDuration); + } + + writeStochasts(configuration, writer); + + writer.WriteEndElement(); + } + } +} \ No newline at end of file Index: Ringtoets/Common/src/Ringtoets.Common.IO/Writers/XmlWriterExtensions.cs =================================================================== diff -u -r4011a127978bb211ddb1101a2c608ed9c991d06d -r3c686d6ea57d86134a4338e75d3c7663f379716e --- Ringtoets/Common/src/Ringtoets.Common.IO/Writers/XmlWriterExtensions.cs (.../XmlWriterExtensions.cs) (revision 4011a127978bb211ddb1101a2c608ed9c991d06d) +++ Ringtoets/Common/src/Ringtoets.Common.IO/Writers/XmlWriterExtensions.cs (.../XmlWriterExtensions.cs) (revision 3c686d6ea57d86134a4338e75d3c7663f379716e) @@ -144,96 +144,19 @@ writer.WriteEndElement(); } - /// - /// Writes the common properties of structure configurations to file, without closing the element. - /// - /// The writer to use to write the properties. - /// The common properties to write. - public static void WriteStartCommonStructureProperties(this XmlWriter writer, StructureCalculationConfiguration structureCalculation) + public static void WriteStartFolder(this XmlWriter writer, string name) { if (writer == null) { throw new ArgumentNullException(nameof(writer)); } - if (structureCalculation == null) + if (name == null) { - throw new ArgumentNullException(nameof(structureCalculation)); + throw new ArgumentNullException(nameof(name)); } - writer.WriteStartElement(ConfigurationSchemaIdentifiers.CalculationElement); - writer.WriteAttributeString(ConfigurationSchemaIdentifiers.NameAttribute, structureCalculation.Name); - - if (structureCalculation.FailureProbabilityStructureWithErosion.HasValue) - { - writer.WriteElementString( - ConfigurationSchemaIdentifiers.FailureProbabilityStructureWithErosionElement, - XmlConvert.ToString(structureCalculation.FailureProbabilityStructureWithErosion.Value)); - } - if (structureCalculation.StructureNormalOrientation.HasValue) - { - writer.WriteElementString( - ConfigurationSchemaIdentifiers.Orientation, - XmlConvert.ToString(structureCalculation.StructureNormalOrientation.Value)); - } - - if (structureCalculation.HydraulicBoundaryLocationName != null) - { - writer.WriteElementString( - ConfigurationSchemaIdentifiers.HydraulicBoundaryLocationElement, - structureCalculation.HydraulicBoundaryLocationName); - } - - if (structureCalculation.StructureName != null) - { - writer.WriteElementString( - ConfigurationSchemaIdentifiers.StructureElement, - structureCalculation.StructureName); - } - - if (structureCalculation.ForeshoreProfileName != null) - { - writer.WriteElementString( - ConfigurationSchemaIdentifiers.ForeshoreProfileNameElement, - structureCalculation.ForeshoreProfileName); - } - - if (structureCalculation.WaveReduction != null) - { - writer.WriteWaveReduction(structureCalculation.WaveReduction); - } - - writer.WriteStartElement(ConfigurationSchemaIdentifiers.StochastsElement); - - if (structureCalculation.FlowWidthAtBottomProtection != null) - { - writer.WriteDistribution(ConfigurationSchemaIdentifiers.FlowWidthAtBottomProtectionStochastName, structureCalculation.FlowWidthAtBottomProtection); - } - if (structureCalculation.WidthFlowApertures != null) - { - writer.WriteDistribution(ConfigurationSchemaIdentifiers.WidthFlowAperturesStochastName, structureCalculation.WidthFlowApertures); - } - if (structureCalculation.StorageStructureArea != null) - { - writer.WriteDistribution(ConfigurationSchemaIdentifiers.StorageStructureAreaStochastName, structureCalculation.StorageStructureArea); - } - if (structureCalculation.CriticalOvertoppingDischarge != null) - { - writer.WriteDistribution(ConfigurationSchemaIdentifiers.CriticalOvertoppingDischargeStochastName, structureCalculation.CriticalOvertoppingDischarge); - } - if (structureCalculation.ModelFactorSuperCriticalFlow != null) - { - writer.WriteDistribution(ConfigurationSchemaIdentifiers.ModelFactorSuperCriticalFlowStochastName, structureCalculation.ModelFactorSuperCriticalFlow); - } - if (structureCalculation.AllowedLevelIncreaseStorage != null) - { - writer.WriteDistribution(ConfigurationSchemaIdentifiers.AllowedLevelIncreaseStorageStochastName, structureCalculation.AllowedLevelIncreaseStorage); - } - if (structureCalculation.StormDuration != null) - { - writer.WriteDistribution(ConfigurationSchemaIdentifiers.StormDurationStochastName, structureCalculation.StormDuration); - } - - writer.WriteEndElement(); + writer.WriteStartElement(ConfigurationSchemaIdentifiers.FolderElement); + writer.WriteAttributeString(ConfigurationSchemaIdentifiers.NameAttribute, name); } } } \ No newline at end of file Index: Ringtoets/Common/test/Ringtoets.Common.IO.Test/Ringtoets.Common.IO.Test.csproj =================================================================== diff -u -rad17f1b8f41d6b4b75c9f39b427dddf31b47cef0 -r3c686d6ea57d86134a4338e75d3c7663f379716e --- Ringtoets/Common/test/Ringtoets.Common.IO.Test/Ringtoets.Common.IO.Test.csproj (.../Ringtoets.Common.IO.Test.csproj) (revision ad17f1b8f41d6b4b75c9f39b427dddf31b47cef0) +++ Ringtoets/Common/test/Ringtoets.Common.IO.Test/Ringtoets.Common.IO.Test.csproj (.../Ringtoets.Common.IO.Test.csproj) (revision 3c686d6ea57d86134a4338e75d3c7663f379716e) @@ -108,6 +108,7 @@ + Index: Ringtoets/Common/test/Ringtoets.Common.IO.Test/Writers/StructureCalculationConfigurationXmlWriterExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Common/test/Ringtoets.Common.IO.Test/Writers/StructureCalculationConfigurationXmlWriterExtensionsTest.cs (revision 0) +++ Ringtoets/Common/test/Ringtoets.Common.IO.Test/Writers/StructureCalculationConfigurationXmlWriterExtensionsTest.cs (revision 3c686d6ea57d86134a4338e75d3c7663f379716e) @@ -0,0 +1,219 @@ +// 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; +using System.Collections.Generic; +using System.IO; +using System.Xml; +using Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.Common.IO.Configurations; +using Ringtoets.Common.IO.Writers; + +namespace Ringtoets.Common.IO.Test.Writers +{ + [TestFixture] + public class StructureCalculationConfigurationXmlWriterExtensionsTest + { + private static readonly string testDirectory = TestHelper.GetTestDataPath( + TestDataPath.Ringtoets.Common.IO, + nameof(StructureCalculationConfigurationXmlWriterExtensions)); + + public static IEnumerable GetStructureCalculationsWithProperties() + { + yield return new TestCaseData( + new SimpleStructureCalculationConfiguration("some name"), + "structureCalculationWithoutParametersSet.xml") + .SetName("Structure calculation without any of its paramters set."); + + yield return new TestCaseData( + CreateStructureWithAllParametersSet("some other name"), + "structureCalculationWithAllParametersSet.xml") + .SetName("Structure calculation with all of its paramters set."); + } + + [Test] + public void Write_WithoutConfiguration_ThrowsArgumentNullException() + { + // Setup + string filePath = TestHelper.GetScratchPadPath("test.xml"); + + using (var writer = CreateXmlWriter(filePath)) + { + // Call + TestDelegate test = () => writer.WriteStructure( + (SimpleStructureCalculationConfiguration) null, + delegate { }, + delegate { }); + + // Assert + var exception = Assert.Throws(test); + Assert.AreEqual("configuration", exception.ParamName); + } + } + + [Test] + public void Write_WithoutWriteProperties_ThrowsArgumentNullException() + { + // Setup + string filePath = TestHelper.GetScratchPadPath("test.xml"); + + using (var writer = CreateXmlWriter(filePath)) + { + // Call + TestDelegate test = () => writer.WriteStructure( + new SimpleStructureCalculationConfiguration(""), + null, + delegate { }); + + // Assert + var exception = Assert.Throws(test); + Assert.AreEqual("writeProperties", exception.ParamName); + } + } + + [Test] + public void Write_WithoutWriteStochasts_ThrowsArgumentNullException() + { + // Setup + string filePath = TestHelper.GetScratchPadPath("test.xml"); + + using (var writer = CreateXmlWriter(filePath)) + { + // Call + TestDelegate test = () => writer.WriteStructure( + new SimpleStructureCalculationConfiguration(""), + delegate { }, + null); + + // Assert + var exception = Assert.Throws(test); + Assert.AreEqual("writeStochasts", exception.ParamName); + } + } + + [Test] + [TestCaseSource(nameof(GetStructureCalculationsWithProperties))] + public void Write_WithoutDifferentSetParameters_WritesSetStructureProperties(StructureCalculationConfiguration structureCalculation, string fileName) + { + // Setup + string filePath = TestHelper.GetScratchPadPath(nameof(Write_WithoutDifferentSetParameters_WritesSetStructureProperties)); + try + { + // Call + bool writePropertiesCalled = false; + bool writeStochastsCalled = false; + + using (var writer = CreateXmlWriter(filePath)) + { + writer.WriteStructure( + structureCalculation, + (configuration, xmlWriter) => writePropertiesCalled = true, + (configuration, xmlWriter) => writeStochastsCalled = true); + } + + // Assert + Assert.IsTrue(writePropertiesCalled); + Assert.IsTrue(writeStochastsCalled); + string actualXml = File.ReadAllText(filePath); + string expectedXml = GetTestFileContent(fileName); + Assert.AreEqual(expectedXml, actualXml); + } + finally + { + File.Delete(filePath); + } + } + + private static SimpleStructureCalculationConfiguration CreateStructureWithAllParametersSet(string name) + { + return new SimpleStructureCalculationConfiguration(name) + { + AllowedLevelIncreaseStorage = new MeanStandardDeviationStochastConfiguration + { + Mean = 1.2, + StandardDeviation = 3.4 + }, + CriticalOvertoppingDischarge = new MeanVariationCoefficientStochastConfiguration + { + Mean = 22.2, + VariationCoefficient = 2.1 + }, + FailureProbabilityStructureWithErosion = 2.1, + FlowWidthAtBottomProtection = new MeanStandardDeviationStochastConfiguration + { + Mean = 5.4, + StandardDeviation = 1.1 + }, + ForeshoreProfileName = "Voorland", + HydraulicBoundaryLocationName = "Randvoorwaardelocatie", + ModelFactorSuperCriticalFlow = new MeanStandardDeviationStochastConfiguration + { + Mean = 322.2, + StandardDeviation = 91.2 + }, + StorageStructureArea = new MeanVariationCoefficientStochastConfiguration + { + Mean = 11.122, + VariationCoefficient = 32.111 + }, + StormDuration = new MeanVariationCoefficientStochastConfiguration + { + Mean = 21.22, + VariationCoefficient = 1.2 + }, + StructureNormalOrientation = 5.6, + StructureName = "Kunstwerk", + WaveReduction = new WaveReductionConfiguration + { + BreakWaterType = ReadBreakWaterType.Caisson, + UseBreakWater = false, + BreakWaterHeight = 111111.2, + UseForeshoreProfile = true + }, + WidthFlowApertures = new MeanStandardDeviationStochastConfiguration + { + Mean = 121.3, + StandardDeviation = 222.1 + } + }; + } + + private static XmlWriter CreateXmlWriter(string filePath) + { + return XmlWriter.Create(filePath, new XmlWriterSettings + { + Indent = true, + ConformanceLevel = ConformanceLevel.Fragment + }); + } + + private string GetTestFileContent(string testFile) + { + return File.ReadAllText(Path.Combine(testDirectory, testFile)); + } + + private class SimpleStructureCalculationConfiguration : StructureCalculationConfiguration + { + public SimpleStructureCalculationConfiguration(string name) : base(name) {} + } + } +} \ No newline at end of file Index: Ringtoets/Common/test/Ringtoets.Common.IO.Test/Writers/XmlWriterExtensionsTest.cs =================================================================== diff -u -r2e8cb240a4a86135989a372887d8b9b1043bfb2d -r3c686d6ea57d86134a4338e75d3c7663f379716e --- Ringtoets/Common/test/Ringtoets.Common.IO.Test/Writers/XmlWriterExtensionsTest.cs (.../XmlWriterExtensionsTest.cs) (revision 2e8cb240a4a86135989a372887d8b9b1043bfb2d) +++ Ringtoets/Common/test/Ringtoets.Common.IO.Test/Writers/XmlWriterExtensionsTest.cs (.../XmlWriterExtensionsTest.cs) (revision 3c686d6ea57d86134a4338e75d3c7663f379716e) @@ -159,69 +159,70 @@ .SetName("Wave reduction without use foreshore profile set."); } - public static IEnumerable GetStructureCalculations() + [Test] + public void WriteStartFolder_WithNameAndWriter_WritesFolderStart() { - yield return new TestCaseData( - new SimpleStructureCalculationConfiguration("some name"), - "structureCalculationWithoutParametersSet.xml") - .SetName("Structure calculation without any of its paramters set."); + // Setup + string filePath = TestHelper.GetScratchPadPath(nameof(WriteStartFolder_WithNameAndWriter_WritesFolderStart)); + const string name = "folder"; - yield return new TestCaseData( - new SimpleStructureCalculationConfiguration("some other name") - { - AllowedLevelIncreaseStorage = new MeanStandardDeviationStochastConfiguration - { - Mean = 1.2, - StandardDeviation = 3.4 - }, - CriticalOvertoppingDischarge = new MeanVariationCoefficientStochastConfiguration - { - Mean = 22.2, - VariationCoefficient = 2.1 - }, - FailureProbabilityStructureWithErosion = 2.1, - FlowWidthAtBottomProtection = new MeanStandardDeviationStochastConfiguration - { - Mean = 5.4, - StandardDeviation = 1.1 - }, - ForeshoreProfileName = "Voorland", - HydraulicBoundaryLocationName = "Randvoorwaardelocatie", - ModelFactorSuperCriticalFlow = new MeanStandardDeviationStochastConfiguration - { - Mean = 322.2, - StandardDeviation = 91.2 - }, - StorageStructureArea = new MeanVariationCoefficientStochastConfiguration - { - Mean = 11.122, - VariationCoefficient = 32.111 - }, - StormDuration = new MeanVariationCoefficientStochastConfiguration - { - Mean = 21.22, - VariationCoefficient = 1.2 - }, - StructureNormalOrientation = 5.6, - StructureName = "Kunstwerk", - WaveReduction = new WaveReductionConfiguration - { - BreakWaterType = ReadBreakWaterType.Caisson, - UseBreakWater = false, - BreakWaterHeight = 111111.2, - UseForeshoreProfile = true - }, - WidthFlowApertures = new MeanStandardDeviationStochastConfiguration - { - Mean = 121.3, - StandardDeviation = 222.1 - } - }, - "structureCalculationWithAllParametersSet.xml") - .SetName("Structure calculation with all of its paramters set."); + try + { + using (XmlWriter xmlWriter = CreateXmlWriter(filePath)) + { + // Call + xmlWriter.WriteStartFolder(name); + + // Assert + Assert.AreEqual(WriteState.Element, xmlWriter.WriteState); + } + + string actualXml = File.ReadAllText(filePath); + string expectedXml = GetTestFileContent("simpleFolder.xml"); + Assert.AreEqual(expectedXml, actualXml); + } + finally + { + File.Delete(filePath); + } } [Test] + public void WriteStartFolder_WithoutWriter_ThrowsArgumentNullException() + { + // Call + TestDelegate testDelegate = () => ((XmlWriter) null).WriteStartFolder("name"); + + // Assert + var exception = Assert.Throws(testDelegate); + Assert.AreEqual("writer", exception.ParamName); + } + + [Test] + public void WriteStartFolder_WithoutName_ThrowsArgumentNullException() + { + // Setup + string filePath = TestHelper.GetScratchPadPath(nameof(WriteDistribution_WithDifferentSetParameters_WritesStochastWithSetParameters)); + + try + { + using (XmlWriter xmlWriter = CreateXmlWriter(filePath)) + { + // Call + TestDelegate testDelegate = () => xmlWriter.WriteStartFolder(null); + + // Assert + var exception = Assert.Throws(testDelegate); + Assert.AreEqual("name", exception.ParamName); + } + } + finally + { + File.Delete(filePath); + } + } + + [Test] [TestCaseSource(nameof(GetDistributions))] public void WriteDistribution_WithDifferentSetParameters_WritesStochastWithSetParameters(MeanStandardDeviationStochastConfiguration distribution, string fileName) { @@ -252,7 +253,7 @@ public void WriteDistribution_StandardDeviationDistributionWithoutWriter_ThrowsArgumentNullException() { // Call - TestDelegate testDelegate = () => ((XmlWriter)null).WriteDistribution("name", new MeanStandardDeviationStochastConfiguration()); + TestDelegate testDelegate = () => ((XmlWriter) null).WriteDistribution("name", new MeanStandardDeviationStochastConfiguration()); // Assert var exception = Assert.Throws(testDelegate); @@ -338,7 +339,7 @@ public void WriteDistribution_VariationCoefficientDistributionWithoutWriter_ThrowsArgumentNullException() { // Call - TestDelegate testDelegate = () => ((XmlWriter)null).WriteDistribution("name", new MeanVariationCoefficientStochastConfiguration()); + TestDelegate testDelegate = () => ((XmlWriter) null).WriteDistribution("name", new MeanVariationCoefficientStochastConfiguration()); // Assert var exception = Assert.Throws(testDelegate); @@ -380,7 +381,7 @@ using (XmlWriter xmlWriter = CreateXmlWriter(filePath)) { // Call - TestDelegate testDelegate = () => xmlWriter.WriteDistribution("name", (MeanVariationCoefficientStochastConfiguration)null); + TestDelegate testDelegate = () => xmlWriter.WriteDistribution("name", (MeanVariationCoefficientStochastConfiguration) null); // Assert var exception = Assert.Throws(testDelegate); @@ -423,7 +424,7 @@ public void WriteWaveReduction_WithoutWriter_ThrowsArgumentNullException() { // Call - TestDelegate testDelegate = () => ((XmlWriter)null).WriteWaveReduction(new WaveReductionConfiguration()); + TestDelegate testDelegate = () => ((XmlWriter) null).WriteWaveReduction(new WaveReductionConfiguration()); // Assert var exception = Assert.Throws(testDelegate); @@ -453,68 +454,7 @@ File.Delete(filePath); } } - - [Test] - [TestCaseSource(nameof(GetStructureCalculations))] - public void WriteCommonStructureProperties_WithoutDifferentSetParameters_WritesSetStructureProperties(StructureCalculationConfiguration structureCalculation, string fileName) - { - // Setup - string filePath = TestHelper.GetScratchPadPath(nameof(WriteCommonStructureProperties_WithoutDifferentSetParameters_WritesSetStructureProperties)); - - try - { - using (XmlWriter xmlWriter = CreateXmlWriter(filePath)) - { - // Call - xmlWriter.WriteStartCommonStructureProperties(structureCalculation); - } - - // Assert - string actualXml = File.ReadAllText(filePath); - string expectedXml = GetTestFileContent(fileName); - Assert.AreEqual(expectedXml, actualXml); - } - finally - { - File.Delete(filePath); - } - } - - [Test] - public void WriteCommonStructureProperties_WithoutWriter_ThrowsArgumentNullException() - { - // Call - TestDelegate testDelegate = () => ((XmlWriter)null).WriteStartCommonStructureProperties(new SimpleStructureCalculationConfiguration("")); - - // Assert - var exception = Assert.Throws(testDelegate); - Assert.AreEqual("writer", exception.ParamName); - } - - [Test] - public void WriteCommonStructureProperties_WithoutStructureCalculation_ThrowsArgumentNullException() - { - // Setup - string filePath = TestHelper.GetScratchPadPath(nameof(WriteCommonStructureProperties_WithoutDifferentSetParameters_WritesSetStructureProperties)); - - try - { - using (XmlWriter xmlWriter = CreateXmlWriter(filePath)) - { - // Call - TestDelegate testDelegate = () => xmlWriter.WriteStartCommonStructureProperties(null); - - // Assert - var exception = Assert.Throws(testDelegate); - Assert.AreEqual("structureCalculation", exception.ParamName); - } - } - finally - { - File.Delete(filePath); - } - } - + private string GetTestFileContent(string testFile) { return File.ReadAllText(Path.Combine(testDirectory, testFile)); Index: Ringtoets/Common/test/Ringtoets.Common.IO.Test/test-data/CalculationConfigurationWriter/simpleFolder.xml =================================================================== diff -u --- Ringtoets/Common/test/Ringtoets.Common.IO.Test/test-data/CalculationConfigurationWriter/simpleFolder.xml (revision 0) +++ Ringtoets/Common/test/Ringtoets.Common.IO.Test/test-data/CalculationConfigurationWriter/simpleFolder.xml (revision 3c686d6ea57d86134a4338e75d3c7663f379716e) @@ -0,0 +1 @@ + \ No newline at end of file Index: Ringtoets/Common/test/Ringtoets.Common.IO.Test/test-data/StructureCalculationConfigurationXmlWriterExtensions/structureCalculationWithAllParametersSet.xml =================================================================== diff -u --- Ringtoets/Common/test/Ringtoets.Common.IO.Test/test-data/StructureCalculationConfigurationXmlWriterExtensions/structureCalculationWithAllParametersSet.xml (revision 0) +++ Ringtoets/Common/test/Ringtoets.Common.IO.Test/test-data/StructureCalculationConfigurationXmlWriterExtensions/structureCalculationWithAllParametersSet.xml (revision 3c686d6ea57d86134a4338e75d3c7663f379716e) @@ -0,0 +1,43 @@ + + Randvoorwaardelocatie + Kunstwerk + 5.6 + 2.1 + Voorland + + false + caisson + 111111.2 + true + + + + 5.4 + 1.1 + + + 121.3 + 222.1 + + + 11.122 + 32.111 + + + 22.2 + 2.1 + + + 322.2 + 91.2 + + + 1.2 + 3.4 + + + 21.22 + 1.2 + + + \ No newline at end of file Index: Ringtoets/Common/test/Ringtoets.Common.IO.Test/test-data/StructureCalculationConfigurationXmlWriterExtensions/structureCalculationWithoutParametersSet.xml =================================================================== diff -u --- Ringtoets/Common/test/Ringtoets.Common.IO.Test/test-data/StructureCalculationConfigurationXmlWriterExtensions/structureCalculationWithoutParametersSet.xml (revision 0) +++ Ringtoets/Common/test/Ringtoets.Common.IO.Test/test-data/StructureCalculationConfigurationXmlWriterExtensions/structureCalculationWithoutParametersSet.xml (revision 3c686d6ea57d86134a4338e75d3c7663f379716e) @@ -0,0 +1,3 @@ + + + \ No newline at end of file Index: Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.IO/HeightStructureCalculationConfiguration.cs =================================================================== diff -u --- Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.IO/HeightStructureCalculationConfiguration.cs (revision 0) +++ Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.IO/HeightStructureCalculationConfiguration.cs (revision 3c686d6ea57d86134a4338e75d3c7663f379716e) @@ -0,0 +1,42 @@ +// 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 Ringtoets.Common.IO.Configurations; + +namespace Ringtoets.HeightStructures.IO +{ + /// + /// Configuration of a height structure calculation. + /// + public class HeightStructureCalculationConfiguration : StructureCalculationConfiguration + { + /// + /// Creates a new instance of + /// + /// + public HeightStructureCalculationConfiguration(string name) : base(name) {} + + /// + /// Gets or sets the stochast configuration for the level of the crest for the structure. + /// + public MeanStandardDeviationStochastConfiguration LevelCrestStructure { get; set; } + } +} \ No newline at end of file Index: Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.IO/HeightStructuresCalculationConfigurationWriter.cs =================================================================== diff -u --- Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.IO/HeightStructuresCalculationConfigurationWriter.cs (revision 0) +++ Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.IO/HeightStructuresCalculationConfigurationWriter.cs (revision 3c686d6ea57d86134a4338e75d3c7663f379716e) @@ -0,0 +1,45 @@ +// 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; +using System.Xml; +using Ringtoets.Common.IO.Writers; + +namespace Ringtoets.HeightStructures.IO +{ + public static class HeightStructuresCalculationConfigurationXmlWriterExtensions + { + public static void WriteHeightStructure(this XmlWriter writer, HeightStructureCalculationConfiguration configuration) + { + writer.WriteStructure(configuration, WriteProperties, WriteStochasts); + } + + private static void WriteStochasts(HeightStructureCalculationConfiguration configuration, XmlWriter writer) + { + if (configuration.LevelCrestStructure != null) + { + writer.WriteDistribution(HeightStructuresConfigurationSchemaIdentifiers.LevelCrestStructureStochastName, configuration.LevelCrestStructure); + } + } + + private static void WriteProperties(HeightStructureCalculationConfiguration configuration, XmlWriter writer) {} + } +} \ No newline at end of file Index: Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.IO/HeightStructuresConfigurationSchemaIdentifiers.cs =================================================================== diff -u --- Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.IO/HeightStructuresConfigurationSchemaIdentifiers.cs (revision 0) +++ Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.IO/HeightStructuresConfigurationSchemaIdentifiers.cs (revision 3c686d6ea57d86134a4338e75d3c7663f379716e) @@ -0,0 +1,38 @@ +// 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. + +namespace Ringtoets.HeightStructures.IO +{ + /// + /// Container of identifiers related to height structure calculation configuration schema definitions. + /// + public static class HeightStructuresConfigurationSchemaIdentifiers + { + #region stochasts + + /// + /// The identifier for the level crest structure stochast name. + /// + internal const string LevelCrestStructureStochastName = "kerendehoogte"; + + #endregion + } +} \ No newline at end of file Index: Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.IO/Ringtoets.HeightStructures.IO.csproj =================================================================== diff -u -r91e6f4f761a8efdc9c847c99cdca18f514a67ed1 -r3c686d6ea57d86134a4338e75d3c7663f379716e --- Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.IO/Ringtoets.HeightStructures.IO.csproj (.../Ringtoets.HeightStructures.IO.csproj) (revision 91e6f4f761a8efdc9c847c99cdca18f514a67ed1) +++ Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.IO/Ringtoets.HeightStructures.IO.csproj (.../Ringtoets.HeightStructures.IO.csproj) (revision 3c686d6ea57d86134a4338e75d3c7663f379716e) @@ -38,11 +38,15 @@ + Properties\GlobalAssembly.cs + + + Index: Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Data.TestUtil/TestHeightStructuresCalculation.cs =================================================================== diff -u -r85d3615793ddf3f8f72eb02409a23286396f5cf1 -r3c686d6ea57d86134a4338e75d3c7663f379716e --- Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Data.TestUtil/TestHeightStructuresCalculation.cs (.../TestHeightStructuresCalculation.cs) (revision 85d3615793ddf3f8f72eb02409a23286396f5cf1) +++ Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Data.TestUtil/TestHeightStructuresCalculation.cs (.../TestHeightStructuresCalculation.cs) (revision 3c686d6ea57d86134a4338e75d3c7663f379716e) @@ -36,12 +36,18 @@ { InputParameters.Structure = new TestHeightStructure(); InputParameters.LevelCrestStructure.Mean = (RoundedDouble) 5.74; + InputParameters.LevelCrestStructure.StandardDeviation = (RoundedDouble) 0.94; InputParameters.StorageStructureArea.Mean = (RoundedDouble) 1.0; + InputParameters.StorageStructureArea.CoefficientOfVariation = (RoundedDouble) 1.10; InputParameters.StructureNormalOrientation = (RoundedDouble) 115; InputParameters.AllowedLevelIncreaseStorage.Mean = (RoundedDouble) 1.0; + InputParameters.AllowedLevelIncreaseStorage.StandardDeviation = (RoundedDouble) 0.12; InputParameters.FlowWidthAtBottomProtection.Mean = (RoundedDouble) 18; + InputParameters.FlowWidthAtBottomProtection.StandardDeviation = (RoundedDouble) 8.2; InputParameters.CriticalOvertoppingDischarge.Mean = (RoundedDouble) 1; + InputParameters.CriticalOvertoppingDischarge.CoefficientOfVariation = (RoundedDouble) 0.88; InputParameters.WidthFlowApertures.Mean = (RoundedDouble) 18; + InputParameters.WidthFlowApertures.StandardDeviation = (RoundedDouble) 2; InputParameters.FailureProbabilityStructureWithErosion = 1.0; InputParameters.DeviationWaveDirection = (RoundedDouble) 0; } Index: Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.IO.Test/HeightStructureCalculationConfigurationTest.cs =================================================================== diff -u --- Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.IO.Test/HeightStructureCalculationConfigurationTest.cs (revision 0) +++ Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.IO.Test/HeightStructureCalculationConfigurationTest.cs (revision 3c686d6ea57d86134a4338e75d3c7663f379716e) @@ -0,0 +1,57 @@ +// 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; +using NUnit.Framework; +using Ringtoets.Common.IO.Configurations; + +namespace Ringtoets.HeightStructures.IO.Test +{ + [TestFixture] + public class HeightStructureCalculationConfigurationTest + { + [Test] + public void Constructor_WithName_ExpectedValues() + { + // Call + var configuration = new HeightStructureCalculationConfiguration("some name"); + + // Assert + Assert.IsInstanceOf(configuration); + Assert.AreEqual("some name", configuration.Name); + Assert.IsNull(configuration.LevelCrestStructure); + } + + [Test] + public void SimpleProperties_SetNewValues_NewValuesSet() + { + // Setup + var levelCrestStructure = new MeanStandardDeviationStochastConfiguration(); + var configuration = new HeightStructureCalculationConfiguration("some name"); + + // Call + configuration.LevelCrestStructure = levelCrestStructure; + + // Assert + Assert.AreSame(levelCrestStructure, configuration.LevelCrestStructure); + } + } +} \ No newline at end of file Index: Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.IO.Test/HeightStructuresCalculationConfigurationXmlWriterExtensionsTest.cs =================================================================== diff -u --- Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.IO.Test/HeightStructuresCalculationConfigurationXmlWriterExtensionsTest.cs (revision 0) +++ Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.IO.Test/HeightStructuresCalculationConfigurationXmlWriterExtensionsTest.cs (revision 3c686d6ea57d86134a4338e75d3c7663f379716e) @@ -0,0 +1,146 @@ +// 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 + }); + } + } +} \ No newline at end of file Index: Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.IO.Test/Ringtoets.HeightStructures.IO.Test.csproj =================================================================== diff -u -r6a5d7b40b7ba4dcb73e393075338352d194e97c2 -r3c686d6ea57d86134a4338e75d3c7663f379716e --- Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.IO.Test/Ringtoets.HeightStructures.IO.Test.csproj (.../Ringtoets.HeightStructures.IO.Test.csproj) (revision 6a5d7b40b7ba4dcb73e393075338352d194e97c2) +++ Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.IO.Test/Ringtoets.HeightStructures.IO.Test.csproj (.../Ringtoets.HeightStructures.IO.Test.csproj) (revision 3c686d6ea57d86134a4338e75d3c7663f379716e) @@ -44,11 +44,14 @@ + Properties\GlobalAssembly.cs + + @@ -75,6 +78,10 @@ {52BA7627-CBAB-4209-BE77-3B5F31378277} Ringtoets.Common.IO + + {33508D7C-1602-4C0D-8503-73AAE98C19E5} + Ringtoets.Common.IO.TestUtil + {1C0017D8-35B5-4CA0-8FC7-A83F46DBDC99} Ringtoets.HeightStructures.Data @@ -83,6 +90,10 @@ {D63FCFEC-34E8-4C68-8B4F-99338D2447AC} Ringtoets.HeightStructures.IO + + {F67E8AE8-1FF0-4680-9817-99E025CD9FF6} + Ringtoets.HeightStructures.Data.TestUtil +