Index: Ringtoets/Common/src/Ringtoets.Common.IO/Configurations/StructuresCalculationConfiguration.cs =================================================================== diff -u -rd393a6e22ba176f0ce9731629a37ce3272b1f433 -r43b7d2fe7b1c4209fd2afcd985a5c1f4b7bf14e9 --- Ringtoets/Common/src/Ringtoets.Common.IO/Configurations/StructuresCalculationConfiguration.cs (.../StructuresCalculationConfiguration.cs) (revision d393a6e22ba176f0ce9731629a37ce3272b1f433) +++ Ringtoets/Common/src/Ringtoets.Common.IO/Configurations/StructuresCalculationConfiguration.cs (.../StructuresCalculationConfiguration.cs) (revision 43b7d2fe7b1c4209fd2afcd985a5c1f4b7bf14e9) @@ -61,12 +61,12 @@ } /// - /// Gets or sets the stochast configuration for the model factor super critical flow. + /// Gets or sets the name of the structure. /// public string StructureName { get; set; } /// - /// Gets or sets the stochast configuration for the model factor super critical flow. + /// Gets or sets the name of the hydraulic boundary location. /// public string HydraulicBoundaryLocationName { get; set; } @@ -81,7 +81,7 @@ public MeanVariationCoefficientStochastConfiguration StormDuration { get; set; } /// - /// Gets or sets the stochast configuration for the structure's normal orientation. + /// Gets or sets the structure's normal orientation. /// public double? StructureNormalOrientation { get; set; } @@ -106,8 +106,7 @@ public MeanVariationCoefficientStochastConfiguration CriticalOvertoppingDischarge { get; set; } /// - /// Gets or sets the stochast configuration for the failure probability of structure - /// with erosion. + /// Gets or sets the failure probability of structure with erosion. /// public double? FailureProbabilityStructureWithErosion { get; set; } Index: Ringtoets/Common/src/Ringtoets.Common.IO/Exporters/CalculationConfigurationExporter.cs =================================================================== diff -u -r8437756db2a32c47155d3b4b490aaf9f33d21c7f -r43b7d2fe7b1c4209fd2afcd985a5c1f4b7bf14e9 --- Ringtoets/Common/src/Ringtoets.Common.IO/Exporters/CalculationConfigurationExporter.cs (.../CalculationConfigurationExporter.cs) (revision 8437756db2a32c47155d3b4b490aaf9f33d21c7f) +++ Ringtoets/Common/src/Ringtoets.Common.IO/Exporters/CalculationConfigurationExporter.cs (.../CalculationConfigurationExporter.cs) (revision 43b7d2fe7b1c4209fd2afcd985a5c1f4b7bf14e9) @@ -73,7 +73,7 @@ } catch (CriticalFileWriteException e) { - log.ErrorFormat(Resources.CalculationConfigurationExporter_Export_Exception_0_no_configuration_exported, e.Message); + log.ErrorFormat(Resources.CalculationConfigurationExporter_Export_ExceptionMessage_0_no_configuration_exported, e.Message); return false; } Index: Ringtoets/Common/src/Ringtoets.Common.IO/Exporters/SchemaCalculationConfigurationExporter.cs =================================================================== diff -u -re50b6ad32d33acb630c391bce2a6d359cc7e2b28 -r43b7d2fe7b1c4209fd2afcd985a5c1f4b7bf14e9 --- Ringtoets/Common/src/Ringtoets.Common.IO/Exporters/SchemaCalculationConfigurationExporter.cs (.../SchemaCalculationConfigurationExporter.cs) (revision e50b6ad32d33acb630c391bce2a6d359cc7e2b28) +++ Ringtoets/Common/src/Ringtoets.Common.IO/Exporters/SchemaCalculationConfigurationExporter.cs (.../SchemaCalculationConfigurationExporter.cs) (revision 43b7d2fe7b1c4209fd2afcd985a5c1f4b7bf14e9) @@ -27,7 +27,6 @@ using Ringtoets.Common.Data.Calculation; using Ringtoets.Common.IO.Configurations; using Ringtoets.Common.IO.Properties; -using Ringtoets.Common.IO.Readers; using Ringtoets.Common.IO.Writers; namespace Ringtoets.Common.IO.Exporters @@ -36,9 +35,11 @@ /// Base class for exporting a calculation configuration and storing it as an XML file. /// /// The - /// to use for exporting . - /// The type to export. - /// The type of the calculations after conversion for writing. + /// to use for exporting . + /// The type to export. + /// The type used to convert + /// into before writing to XML using a . + /// public abstract class SchemaCalculationConfigurationExporter : IFileExporter where TWriter : SchemaCalculationConfigurationWriter where TCalculation : class, ICalculation @@ -51,18 +52,19 @@ /// /// Creates a new instance of . /// - /// The calculation configuration to export. + /// The hierarchy of calculations to export. /// The path of the XML file to export to. /// Thrown when is null. - /// Thrown when is invalid. + /// Thrown when is invalid or when any element + /// of is null. protected SchemaCalculationConfigurationExporter(IEnumerable calculations, string filePath) { if (calculations == null) { throw new ArgumentNullException(nameof(calculations)); } - writer = (TWriter) Activator.CreateInstance(typeof(TWriter), filePath); + writer = CreateWriter(filePath); configuration = ToConfiguration(calculations); } @@ -74,14 +76,21 @@ } catch (CriticalFileWriteException e) { - log.ErrorFormat(Resources.CalculationConfigurationExporter_Export_Exception_0_no_configuration_exported, e.Message); + log.ErrorFormat(Resources.CalculationConfigurationExporter_Export_ExceptionMessage_0_no_configuration_exported, e.Message); return false; } return true; } /// + /// Creates the writer that will be used in the . + /// + /// The path of the file to export to. + /// A new . + protected abstract TWriter CreateWriter(string filePath); + + /// /// Converts the to a . /// /// The to convert. Index: Ringtoets/Common/src/Ringtoets.Common.IO/Properties/Resources.Designer.cs =================================================================== diff -u -rd393a6e22ba176f0ce9731629a37ce3272b1f433 -r43b7d2fe7b1c4209fd2afcd985a5c1f4b7bf14e9 --- Ringtoets/Common/src/Ringtoets.Common.IO/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision d393a6e22ba176f0ce9731629a37ce3272b1f433) +++ Ringtoets/Common/src/Ringtoets.Common.IO/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision 43b7d2fe7b1c4209fd2afcd985a5c1f4b7bf14e9) @@ -84,9 +84,10 @@ /// /// Looks up a localized string similar to {0} Er is geen configuratie geëxporteerd.. /// - public static string CalculationConfigurationExporter_Export_Exception_0_no_configuration_exported { + public static string CalculationConfigurationExporter_Export_ExceptionMessage_0_no_configuration_exported { get { - return ResourceManager.GetString("CalculationConfigurationExporter_Export_Exception_0_no_configuration_exported", resourceCulture); + return ResourceManager.GetString("CalculationConfigurationExporter_Export_ExceptionMessage_0_no_configuration_expor" + + "ted", resourceCulture); } } Index: Ringtoets/Common/src/Ringtoets.Common.IO/Properties/Resources.resx =================================================================== diff -u -rd393a6e22ba176f0ce9731629a37ce3272b1f433 -r43b7d2fe7b1c4209fd2afcd985a5c1f4b7bf14e9 --- Ringtoets/Common/src/Ringtoets.Common.IO/Properties/Resources.resx (.../Resources.resx) (revision d393a6e22ba176f0ce9731629a37ce3272b1f433) +++ Ringtoets/Common/src/Ringtoets.Common.IO/Properties/Resources.resx (.../Resources.resx) (revision 43b7d2fe7b1c4209fd2afcd985a5c1f4b7bf14e9) @@ -513,7 +513,7 @@ Valideren van ingelezen data. - + {0} Er is geen configuratie geëxporteerd. Index: Ringtoets/Common/src/Ringtoets.Common.IO/Writers/SchemaCalculationConfigurationWriter.cs =================================================================== diff -u -re50b6ad32d33acb630c391bce2a6d359cc7e2b28 -r43b7d2fe7b1c4209fd2afcd985a5c1f4b7bf14e9 --- Ringtoets/Common/src/Ringtoets.Common.IO/Writers/SchemaCalculationConfigurationWriter.cs (.../SchemaCalculationConfigurationWriter.cs) (revision e50b6ad32d33acb630c391bce2a6d359cc7e2b28) +++ Ringtoets/Common/src/Ringtoets.Common.IO/Writers/SchemaCalculationConfigurationWriter.cs (.../SchemaCalculationConfigurationWriter.cs) (revision 43b7d2fe7b1c4209fd2afcd985a5c1f4b7bf14e9) @@ -26,7 +26,6 @@ using Core.Common.Utils; using Core.Common.Utils.Properties; using Ringtoets.Common.IO.Configurations; -using Ringtoets.Common.IO.Readers; using Ringtoets.Common.IO.Schema; namespace Ringtoets.Common.IO.Writers @@ -62,8 +61,7 @@ /// /// The calculation configuration to write. /// Thrown when any parameter is null. - /// Thrown when unable to write the file to the file path provided to - /// the . + /// Thrown when unable to write the file to the provided file path. public void Write(IEnumerable configuration) { if (configuration == null) @@ -104,6 +102,79 @@ protected abstract void WriteCalculation(T calculation, XmlWriter writer); /// + /// Writes a distribution configuration when it has a value. + /// + /// The writer to use for writing. + /// The name of the distribution. + /// The configuration for the distribution that can be null. + protected static void WriteDistributionWhenAvailable(XmlWriter writer, string distributionName, MeanVariationCoefficientStochastConfiguration configuration) + { + if (configuration != null) + { + writer.WriteDistribution(distributionName, configuration); + } + } + + /// + /// Writes a distribution configuration when it has a value. + /// + /// The writer to use for writing. + /// The name of the distribution. + /// The configuration for the distribution that can be null. + protected static void WriteDistributionWhenAvailable(XmlWriter writer, string distributionName, MeanStandardDeviationStochastConfiguration configuration) + { + if (configuration != null) + { + writer.WriteDistribution(distributionName, configuration); + } + } + + /// + /// Writes an element with some content when the content has a value. + /// + /// The writer to use for writing. + /// The name of the element. + /// The content of the element that can be null. + protected static void WriteElementWhenContentAvailable(XmlWriter writer, string elementName, string elementContent) + { + if (elementContent != null) + { + writer.WriteElementString( + elementName, + elementContent); + } + } + + /// + /// Writes an element with some content when the content has a value. + /// + /// The writer to use for writing. + /// The name of the element. + /// The content of the element that can be null. + protected static void WriteElementWhenContentAvailable(XmlWriter writer, string elementName, double? elementContent) + { + if (elementContent.HasValue) + { + writer.WriteElementString( + elementName, + XmlConvert.ToString(elementContent.Value)); + } + } + + /// + /// Writes a wave reduction configuration when it has a value. + /// + /// The writer to use for writing. + /// The configuration for the wave reduction that can be null. + protected static void WriteWaveReductionWhenAvailable(XmlWriter writer, WaveReductionConfiguration configuration) + { + if (configuration != null) + { + writer.WriteWaveReduction(configuration); + } + } + + /// /// Writes the in XML format to file. /// /// The calculation group(s) and/or calculation(s) to write. Index: Ringtoets/Common/src/Ringtoets.Common.IO/Writers/StructureCalculationConfigurationWriter.cs =================================================================== diff -u -rd393a6e22ba176f0ce9731629a37ce3272b1f433 -r43b7d2fe7b1c4209fd2afcd985a5c1f4b7bf14e9 --- Ringtoets/Common/src/Ringtoets.Common.IO/Writers/StructureCalculationConfigurationWriter.cs (.../StructureCalculationConfigurationWriter.cs) (revision d393a6e22ba176f0ce9731629a37ce3272b1f433) +++ Ringtoets/Common/src/Ringtoets.Common.IO/Writers/StructureCalculationConfigurationWriter.cs (.../StructureCalculationConfigurationWriter.cs) (revision 43b7d2fe7b1c4209fd2afcd985a5c1f4b7bf14e9) @@ -51,84 +51,34 @@ writer.WriteStartElement(ConfigurationSchemaIdentifiers.CalculationElement); writer.WriteAttributeString(ConfigurationSchemaIdentifiers.NameAttribute, configuration.Name); - if (configuration.HydraulicBoundaryLocationName != null) - { - writer.WriteElementString( - ConfigurationSchemaIdentifiers.HydraulicBoundaryLocationElement, - configuration.HydraulicBoundaryLocationName); - } + WriteParameters(configuration, writer); - if (configuration.StructureName != null) - { - writer.WriteElementString( - ConfigurationSchemaIdentifiers.StructureElement, - configuration.StructureName); - } + WriteWaveReductionWhenAvailable(writer, configuration.WaveReduction); - if (configuration.StructureNormalOrientation.HasValue) - { - writer.WriteElementString( - ConfigurationSchemaIdentifiers.Orientation, - XmlConvert.ToString(configuration.StructureNormalOrientation.Value)); - } + WriteStochasts(configuration, writer); - if (configuration.FailureProbabilityStructureWithErosion.HasValue) - { - writer.WriteElementString( - ConfigurationSchemaIdentifiers.FailureProbabilityStructureWithErosionElement, - XmlConvert.ToString(configuration.FailureProbabilityStructureWithErosion.Value)); - } + writer.WriteEndElement(); + } - if (configuration.ForeshoreProfileName != null) - { - writer.WriteElementString( - ConfigurationSchemaIdentifiers.ForeshoreProfileNameElement, - configuration.ForeshoreProfileName); - } + private void WriteParameters(T configuration, XmlWriter writer) + { + WriteElementWhenContentAvailable(writer, + ConfigurationSchemaIdentifiers.HydraulicBoundaryLocationElement, + configuration.HydraulicBoundaryLocationName); + WriteElementWhenContentAvailable(writer, + ConfigurationSchemaIdentifiers.StructureElement, + configuration.StructureName); + WriteElementWhenContentAvailable(writer, + ConfigurationSchemaIdentifiers.Orientation, + configuration.StructureNormalOrientation); + WriteElementWhenContentAvailable(writer, + ConfigurationSchemaIdentifiers.FailureProbabilityStructureWithErosionElement, + configuration.FailureProbabilityStructureWithErosion); + WriteElementWhenContentAvailable(writer, + ConfigurationSchemaIdentifiers.ForeshoreProfileNameElement, + configuration.ForeshoreProfileName); - if (configuration.WaveReduction != null) - { - writer.WriteWaveReduction(configuration.WaveReduction); - } - WriteSpecificStructureParameters(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); - } - - WriteSpecificStochasts(configuration, writer); - - writer.WriteEndElement(); - - writer.WriteEndElement(); } /// @@ -140,11 +90,42 @@ protected abstract void WriteSpecificStructureParameters(T configuration, XmlWriter writer); /// - /// Writes stochats definitions specific for a structure of type . + /// Writes stochasts definitions specific for a structure of type . /// /// The instance of type for which /// to write the stochasts. /// The writer that should be used to write the parameters. protected abstract void WriteSpecificStochasts(T configuration, XmlWriter writer); + + private void WriteStochasts(T configuration, XmlWriter writer) + { + writer.WriteStartElement(ConfigurationSchemaIdentifiers.StochastsElement); + + WriteDistributionWhenAvailable(writer, + ConfigurationSchemaIdentifiers.FlowWidthAtBottomProtectionStochastName, + configuration.FlowWidthAtBottomProtection); + WriteDistributionWhenAvailable(writer, + ConfigurationSchemaIdentifiers.WidthFlowAperturesStochastName, + configuration.WidthFlowApertures); + WriteDistributionWhenAvailable(writer, + ConfigurationSchemaIdentifiers.StorageStructureAreaStochastName, + configuration.StorageStructureArea); + WriteDistributionWhenAvailable(writer, + ConfigurationSchemaIdentifiers.CriticalOvertoppingDischargeStochastName, + configuration.CriticalOvertoppingDischarge); + WriteDistributionWhenAvailable(writer, + ConfigurationSchemaIdentifiers.ModelFactorSuperCriticalFlowStochastName, + configuration.ModelFactorSuperCriticalFlow); + WriteDistributionWhenAvailable(writer, + ConfigurationSchemaIdentifiers.AllowedLevelIncreaseStorageStochastName, + configuration.AllowedLevelIncreaseStorage); + WriteDistributionWhenAvailable(writer, + ConfigurationSchemaIdentifiers.StormDurationStochastName, + configuration.StormDuration); + + WriteSpecificStochasts(configuration, writer); + + writer.WriteEndElement(); + } } } \ No newline at end of file Index: Ringtoets/Common/test/Ringtoets.Common.IO.Test/Exporters/SchemaCalculationConfigurationExporterTest.cs =================================================================== diff -u --- Ringtoets/Common/test/Ringtoets.Common.IO.Test/Exporters/SchemaCalculationConfigurationExporterTest.cs (revision 0) +++ Ringtoets/Common/test/Ringtoets.Common.IO.Test/Exporters/SchemaCalculationConfigurationExporterTest.cs (revision 43b7d2fe7b1c4209fd2afcd985a5c1f4b7bf14e9) @@ -0,0 +1,63 @@ +// 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 NUnit.Framework; +using Ringtoets.Common.Data.Calculation; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.Common.IO.Exporters; +using Ringtoets.Common.IO.TestUtil; + +namespace Ringtoets.Common.IO.Test.Exporters +{ + [TestFixture] + public class SchemaCalculationConfigurationExporterTest + : CustomSchemaCalculationConfigurationExporterDesignGuidelinesTestFixture< + SimpleStructuresCalculationConfigurationExporter, + TestSchemaCalculationConfigurationWriter, + TestCalculation, + TestConfigurationItem> + { + protected override TestCalculation CreateCalculation() + { + return new TestCalculation("some name"); + } + + protected override SimpleStructuresCalculationConfigurationExporter CallConfigurationFilePathConstructor(IEnumerable calculations, string filePath) + { + return new SimpleStructuresCalculationConfigurationExporter(calculations, filePath); + } + } + + public class SimpleStructuresCalculationConfigurationExporter + : SchemaCalculationConfigurationExporter { + public SimpleStructuresCalculationConfigurationExporter(IEnumerable calculations, string filePath) : base(calculations, filePath) {} + protected override TestSchemaCalculationConfigurationWriter CreateWriter(string filePath) + { + return new TestSchemaCalculationConfigurationWriter(filePath); + } + + protected override TestConfigurationItem ToConfiguration(TestCalculation calculation) + { + throw new System.NotImplementedException(); + } + } +} \ No newline at end of file Index: Ringtoets/Common/test/Ringtoets.Common.IO.Test/Ringtoets.Common.IO.Test.csproj =================================================================== diff -u -rcc1268d7cb906524d4cabcd4cbd9ae16676cf059 -r43b7d2fe7b1c4209fd2afcd985a5c1f4b7bf14e9 --- Ringtoets/Common/test/Ringtoets.Common.IO.Test/Ringtoets.Common.IO.Test.csproj (.../Ringtoets.Common.IO.Test.csproj) (revision cc1268d7cb906524d4cabcd4cbd9ae16676cf059) +++ Ringtoets/Common/test/Ringtoets.Common.IO.Test/Ringtoets.Common.IO.Test.csproj (.../Ringtoets.Common.IO.Test.csproj) (revision 43b7d2fe7b1c4209fd2afcd985a5c1f4b7bf14e9) @@ -62,6 +62,7 @@ + Index: Ringtoets/Common/test/Ringtoets.Common.IO.Test/Writers/SchemaCalculationConfigurationWriterTest.cs =================================================================== diff -u -re50b6ad32d33acb630c391bce2a6d359cc7e2b28 -r43b7d2fe7b1c4209fd2afcd985a5c1f4b7bf14e9 --- Ringtoets/Common/test/Ringtoets.Common.IO.Test/Writers/SchemaCalculationConfigurationWriterTest.cs (.../SchemaCalculationConfigurationWriterTest.cs) (revision e50b6ad32d33acb630c391bce2a6d359cc7e2b28) +++ Ringtoets/Common/test/Ringtoets.Common.IO.Test/Writers/SchemaCalculationConfigurationWriterTest.cs (.../SchemaCalculationConfigurationWriterTest.cs) (revision 43b7d2fe7b1c4209fd2afcd985a5c1f4b7bf14e9) @@ -23,13 +23,11 @@ using System.IO; using System.Linq; using System.Xml; -using Core.Common.IO.Exceptions; using Core.Common.TestUtil; using NUnit.Framework; using Rhino.Mocks; using Ringtoets.Common.Data.Calculation; using Ringtoets.Common.IO.Configurations; -using Ringtoets.Common.IO.Readers; using Ringtoets.Common.IO.TestUtil; using Ringtoets.Common.IO.Writers; @@ -38,7 +36,7 @@ [TestFixture] public class SchemaCalculationConfigurationWriterTest : CustomSchemaCalculationConfigurationWriterDesignGuidelinesTestFixture< - SimpleSchemaCalculationConfigurationWriter, + TestSchemaCalculationConfigurationWriter, TestConfigurationItem> { [Test] @@ -54,7 +52,7 @@ try { // Call - new SimpleSchemaCalculationConfigurationWriter(filePath).Write(configuration); + new TestSchemaCalculationConfigurationWriter(filePath).Write(configuration); // Assert Assert.IsTrue(File.Exists(filePath)); @@ -70,6 +68,203 @@ } } + [Test] + public void WriteDistributionWhenAvailable_MeanStandardDeviationStochastConfigurationNull_WriterNotCalled() + { + // Setup + var mocks = new MockRepository(); + var xmlWriter = mocks.StrictMock(); + mocks.ReplayAll(); + + // Call + ExposedSchemaCalculationConfigurationWriter.PublicWriteDistributionWhenAvailable( + xmlWriter, + "some name", + (MeanStandardDeviationStochastConfiguration)null); + + // Assert + mocks.VerifyAll(); + } + + [Test] + public void WriteDistributionWhenAvailable_MeanStandardDeviationStochastConfigurationSet_WriterCalledWithExpectedParameters() + { + // Setup + const string name = "some name"; + var configuration = new MeanStandardDeviationStochastConfiguration(); + + var mocks = new MockRepository(); + var xmlWriter = mocks.StrictMock(); + xmlWriter.Expect(w => w.WriteDistribution(name, configuration)); + mocks.ReplayAll(); + + // Call + ExposedSchemaCalculationConfigurationWriter.PublicWriteDistributionWhenAvailable( + xmlWriter, + name, + configuration); + + // Assert + mocks.VerifyAll(); + } + + [Test] + public void WriteDistributionWhenAvailable_MeanVariationCoefficientStochastConfigurationNull_WriterNotCalled() + { + // Setup + var mocks = new MockRepository(); + var xmlWriter = mocks.StrictMock(); + mocks.ReplayAll(); + + // Call + ExposedSchemaCalculationConfigurationWriter.PublicWriteDistributionWhenAvailable( + xmlWriter, + "some name", + (MeanVariationCoefficientStochastConfiguration)null); + + // Assert + mocks.VerifyAll(); + } + + [Test] + public void WriteDistributionWhenAvailable_MeanVariationCoefficientStochastConfigurationSet_WriterCalledWithExpectedParameters() + { + // Setup + const string name = "some name"; + var configuration = new MeanVariationCoefficientStochastConfiguration(); + + var mocks = new MockRepository(); + var xmlWriter = mocks.StrictMock(); + xmlWriter.Expect(w => w.WriteDistribution(name, configuration)); + mocks.ReplayAll(); + + // Call + ExposedSchemaCalculationConfigurationWriter.PublicWriteDistributionWhenAvailable( + xmlWriter, + name, + configuration); + + // Assert + mocks.VerifyAll(); + } + + [Test] + public void WriteElementWhenContentAvailable_StringNull_WriterNotCalled() + { + // Setup + var mocks = new MockRepository(); + var xmlWriter = mocks.StrictMock(); + mocks.ReplayAll(); + + // Call + ExposedSchemaCalculationConfigurationWriter.PublicWriteElementWhenContentAvailable( + xmlWriter, + "some name", + (string)null); + + // Assert + mocks.VerifyAll(); + } + + [Test] + public void WriteElementWhenContentAvailable_StringSet_WriterCalledWithExpectedParameters() + { + // Setup + const string name = "some name"; + const string value = "some value"; + + var mocks = new MockRepository(); + var xmlWriter = mocks.StrictMock(); + xmlWriter.Expect(w => w.WriteElementString(name, value)); + mocks.ReplayAll(); + + // Call + ExposedSchemaCalculationConfigurationWriter.PublicWriteElementWhenContentAvailable( + xmlWriter, + name, + value); + + // Assert + mocks.VerifyAll(); + } + + [Test] + public void WriteElementWhenContentAvailable_DoubleNull_WriterNotCalled() + { + // Setup + var mocks = new MockRepository(); + var xmlWriter = mocks.StrictMock(); + mocks.ReplayAll(); + + // Call + ExposedSchemaCalculationConfigurationWriter.PublicWriteElementWhenContentAvailable( + xmlWriter, + "some name", + (double?)null); + + // Assert + mocks.VerifyAll(); + } + + [Test] + public void WriteElementWhenContentAvailable_DoubleSet_WriterCalledWithExpectedParameters() + { + // Setup + const string name = "some name"; + const double value = 3.2; + + var mocks = new MockRepository(); + var xmlWriter = mocks.StrictMock(); + xmlWriter.Expect(w => w.WriteElementString(name, XmlConvert.ToString(value))); + mocks.ReplayAll(); + + // Call + ExposedSchemaCalculationConfigurationWriter.PublicWriteElementWhenContentAvailable( + xmlWriter, + name, + value); + + // Assert + mocks.VerifyAll(); + } + + [Test] + public void WriteWaveReductionWhenAvailable_WaveReductionConfigurationNull_WriterNotCalled() + { + // Setup + var mocks = new MockRepository(); + var xmlWriter = mocks.StrictMock(); + mocks.ReplayAll(); + + // Call + ExposedSchemaCalculationConfigurationWriter.PublicWriteWaveReductionWhenAvailable( + xmlWriter, + null); + + // Assert + mocks.VerifyAll(); + } + + [Test] + public void WriteWaveReductionWhenAvailable_WaveReductionConfigurationSet_WriterCalledWithExpectedParameters() + { + // Setup + var configuration = new WaveReductionConfiguration(); + + var mocks = new MockRepository(); + var xmlWriter = mocks.StrictMock(); + xmlWriter.Expect(w => w.WriteWaveReduction(configuration)); + mocks.ReplayAll(); + + // Call + ExposedSchemaCalculationConfigurationWriter.PublicWriteWaveReductionWhenAvailable( + xmlWriter, + configuration); + + // Assert + mocks.VerifyAll(); + } + private static IEnumerable GetCalculationConfigurations() { var calculation1 = new TestConfigurationItem @@ -120,26 +315,44 @@ .SetName("Calculation and group with nesting"); } - protected override SimpleSchemaCalculationConfigurationWriter CreateWriterInstance(string filePath) + protected override TestSchemaCalculationConfigurationWriter CreateWriterInstance(string filePath) { - return new SimpleSchemaCalculationConfigurationWriter(filePath); + return new TestSchemaCalculationConfigurationWriter(filePath); } } - public class SimpleSchemaCalculationConfigurationWriter : SchemaCalculationConfigurationWriter + public class ExposedSchemaCalculationConfigurationWriter : SchemaCalculationConfigurationWriter { - public const string CalculationElementTag = "calculation"; + public ExposedSchemaCalculationConfigurationWriter(string filePath) : base(filePath) {} - public SimpleSchemaCalculationConfigurationWriter(string filePath) : base(filePath) {} + public static void PublicWriteDistributionWhenAvailable(XmlWriter writer, string distributionName, MeanVariationCoefficientStochastConfiguration configuration) + { + WriteDistributionWhenAvailable(writer, distributionName, configuration); + } + public static void PublicWriteDistributionWhenAvailable(XmlWriter writer, string distributionName, MeanStandardDeviationStochastConfiguration configuration) + { + WriteDistributionWhenAvailable(writer, distributionName, configuration); + } + + public static void PublicWriteElementWhenContentAvailable(XmlWriter writer, string elementName, string elementContent) + { + WriteElementWhenContentAvailable(writer, elementName, elementContent); + } + + public static void PublicWriteElementWhenContentAvailable(XmlWriter writer, string elementName, double? elementContent) + { + WriteElementWhenContentAvailable(writer, elementName, elementContent); + } + + public static void PublicWriteWaveReductionWhenAvailable(XmlWriter writer, WaveReductionConfiguration configuration) + { + WriteWaveReductionWhenAvailable(writer, configuration); + } + protected override void WriteCalculation(TestConfigurationItem calculation, XmlWriter writer) { - writer.WriteElementString(CalculationElementTag, calculation.Name); + throw new System.NotImplementedException(); } } - - public class TestConfigurationItem : IConfigurationItem - { - public string Name { get; set; } - } } \ No newline at end of file Index: Ringtoets/Common/test/Ringtoets.Common.IO.Test/Writers/StructureCalculationConfigurationWriterTest.cs =================================================================== diff -u -rd393a6e22ba176f0ce9731629a37ce3272b1f433 -r43b7d2fe7b1c4209fd2afcd985a5c1f4b7bf14e9 --- Ringtoets/Common/test/Ringtoets.Common.IO.Test/Writers/StructureCalculationConfigurationWriterTest.cs (.../StructureCalculationConfigurationWriterTest.cs) (revision d393a6e22ba176f0ce9731629a37ce3272b1f433) +++ Ringtoets/Common/test/Ringtoets.Common.IO.Test/Writers/StructureCalculationConfigurationWriterTest.cs (.../StructureCalculationConfigurationWriterTest.cs) (revision 43b7d2fe7b1c4209fd2afcd985a5c1f4b7bf14e9) @@ -37,26 +37,13 @@ TestDataPath.Ringtoets.Common.IO, nameof(StructureCalculationConfigurationWriter)); - public static IEnumerable GetStructureCalculationsWithProperties() - { - yield return new TestCaseData( - new SimpleStructuresCalculationConfiguration("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"); - var writer = new SimpleStructureCalculationConfigurationWriter(filePath); + var writer = new SimpleStructureCalculationConfigurationWriter(filePath, false); { // Call TestDelegate test = () => writer.Write(null); @@ -68,21 +55,20 @@ } [Test] - [TestCaseSource(nameof(GetStructureCalculationsWithProperties))] - public void Write_WithoutDifferentSetParameters_WritesSetStructureProperties(StructuresCalculationConfiguration structuresCalculation, string fileName) + public void Write_WithAllParametersSet_WritesCalculationWithAllParametersAndStochasts() { // Setup - string filePath = TestHelper.GetScratchPadPath(nameof(Write_WithoutDifferentSetParameters_WritesSetStructureProperties)); + string filePath = TestHelper.GetScratchPadPath(nameof(Write_WithAllParametersSet_WritesCalculationWithAllParametersAndStochasts)); try { - var writer = new SimpleStructureCalculationConfigurationWriter(filePath); + var writer = new SimpleStructureCalculationConfigurationWriter(filePath, true); // Call - writer.Write(new [] { structuresCalculation }); + writer.Write(new [] { CreateStructureWithAllParametersSet("some other name") }); // Assert string actualXml = File.ReadAllText(filePath); - string expectedXml = GetTestFileContent(fileName); + string expectedXml = GetTestFileContent("structureCalculationWithAllParametersSet.xml"); Assert.AreEqual(expectedXml, actualXml); } finally @@ -91,6 +77,29 @@ } } + [Test] + public void Write_WithoutParametersSet_WritesCalculationWithOnlyEmptyStochasts() + { + // Setup + string filePath = TestHelper.GetScratchPadPath(nameof(Write_WithoutParametersSet_WritesCalculationWithOnlyEmptyStochasts)); + try + { + var writer = new SimpleStructureCalculationConfigurationWriter(filePath, false); + + // Call + writer.Write(new [] { new SimpleStructuresCalculationConfiguration("some name") }); + + // Assert + string actualXml = File.ReadAllText(filePath); + string expectedXml = GetTestFileContent("structureCalculationWithoutParametersSet.xml"); + Assert.AreEqual(expectedXml, actualXml); + } + finally + { + File.Delete(filePath); + } + } + private static SimpleStructuresCalculationConfiguration CreateStructureWithAllParametersSet(string name) { return new SimpleStructuresCalculationConfiguration(name) @@ -145,15 +154,6 @@ }; } - 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)); @@ -163,18 +163,30 @@ { public SimpleStructuresCalculationConfiguration(string name) : base(name) {} } + private class SimpleStructureCalculationConfigurationWriter : StructureCalculationConfigurationWriter { - public SimpleStructureCalculationConfigurationWriter(string filePath) : base(filePath) {} + private readonly bool writeExtraParameterAndStochast; + public SimpleStructureCalculationConfigurationWriter(string filePath, bool writeExtraParameterAndStochast) : base(filePath) + { + this.writeExtraParameterAndStochast = writeExtraParameterAndStochast; + } + protected override void WriteSpecificStructureParameters(SimpleStructuresCalculationConfiguration configuration, XmlWriter writer) { - // no specific parameters + if (writeExtraParameterAndStochast) + { + writer.WriteElementString("testName", "testValue"); + } } protected override void WriteSpecificStochasts(SimpleStructuresCalculationConfiguration configuration, XmlWriter writer) { - // no specific stochasts + if (writeExtraParameterAndStochast) + { + writer.WriteDistribution("testStochastName", new MeanStandardDeviationStochastConfiguration()); + } } } } Index: Ringtoets/Common/test/Ringtoets.Common.IO.Test/test-data/StructureCalculationConfigurationWriter/structureCalculationWithAllParametersSet.xml =================================================================== diff -u -rcc1268d7cb906524d4cabcd4cbd9ae16676cf059 -r43b7d2fe7b1c4209fd2afcd985a5c1f4b7bf14e9 --- Ringtoets/Common/test/Ringtoets.Common.IO.Test/test-data/StructureCalculationConfigurationWriter/structureCalculationWithAllParametersSet.xml (.../structureCalculationWithAllParametersSet.xml) (revision cc1268d7cb906524d4cabcd4cbd9ae16676cf059) +++ Ringtoets/Common/test/Ringtoets.Common.IO.Test/test-data/StructureCalculationConfigurationWriter/structureCalculationWithAllParametersSet.xml (.../structureCalculationWithAllParametersSet.xml) (revision 43b7d2fe7b1c4209fd2afcd985a5c1f4b7bf14e9) @@ -6,6 +6,7 @@ 5.6 2.1 Voorland + testValue false caisson @@ -41,6 +42,7 @@ 21.22 1.2 + \ No newline at end of file Index: Ringtoets/Common/test/Ringtoets.Common.IO.TestUtil/CustomSchemaCalculationConfigurationExporterDesignGuidelinesTestFixture.cs =================================================================== diff -u -rcc1268d7cb906524d4cabcd4cbd9ae16676cf059 -r43b7d2fe7b1c4209fd2afcd985a5c1f4b7bf14e9 --- Ringtoets/Common/test/Ringtoets.Common.IO.TestUtil/CustomSchemaCalculationConfigurationExporterDesignGuidelinesTestFixture.cs (.../CustomSchemaCalculationConfigurationExporterDesignGuidelinesTestFixture.cs) (revision cc1268d7cb906524d4cabcd4cbd9ae16676cf059) +++ Ringtoets/Common/test/Ringtoets.Common.IO.TestUtil/CustomSchemaCalculationConfigurationExporterDesignGuidelinesTestFixture.cs (.../CustomSchemaCalculationConfigurationExporterDesignGuidelinesTestFixture.cs) (revision 43b7d2fe7b1c4209fd2afcd985a5c1f4b7bf14e9) @@ -23,15 +23,13 @@ using System.Collections.Generic; using System.IO; using System.Linq; -using System.Reflection; using System.Security.AccessControl; using System.Text; using Core.Common.TestUtil; using NUnit.Framework; using Ringtoets.Common.Data.Calculation; using Ringtoets.Common.IO.Configurations; using Ringtoets.Common.IO.Exporters; -using Ringtoets.Common.IO.Readers; using Ringtoets.Common.IO.Writers; namespace Ringtoets.Common.IO.TestUtil @@ -62,8 +60,7 @@ TestDelegate test = () => CallConfigurationFilePathConstructor(Enumerable.Empty(), filePath); // Assert - var activatorException = Assert.Throws(test); - var exception = (ArgumentException) activatorException.InnerException; + var exception = Assert.Throws(test); AssertInvalidFilePath(exception); } Index: Ringtoets/Common/test/Ringtoets.Common.IO.TestUtil/Ringtoets.Common.IO.TestUtil.csproj =================================================================== diff -u -rcc1268d7cb906524d4cabcd4cbd9ae16676cf059 -r43b7d2fe7b1c4209fd2afcd985a5c1f4b7bf14e9 --- Ringtoets/Common/test/Ringtoets.Common.IO.TestUtil/Ringtoets.Common.IO.TestUtil.csproj (.../Ringtoets.Common.IO.TestUtil.csproj) (revision cc1268d7cb906524d4cabcd4cbd9ae16676cf059) +++ Ringtoets/Common/test/Ringtoets.Common.IO.TestUtil/Ringtoets.Common.IO.TestUtil.csproj (.../Ringtoets.Common.IO.TestUtil.csproj) (revision 43b7d2fe7b1c4209fd2afcd985a5c1f4b7bf14e9) @@ -44,6 +44,7 @@ + @@ -54,6 +55,8 @@ + + Index: Ringtoets/Common/test/Ringtoets.Common.IO.TestUtil/TestConfigurationItem.cs =================================================================== diff -u --- Ringtoets/Common/test/Ringtoets.Common.IO.TestUtil/TestConfigurationItem.cs (revision 0) +++ Ringtoets/Common/test/Ringtoets.Common.IO.TestUtil/TestConfigurationItem.cs (revision 43b7d2fe7b1c4209fd2afcd985a5c1f4b7bf14e9) @@ -0,0 +1,33 @@ +// 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.Common.IO.TestUtil +{ + /// + /// A simple implementation of that can be used for testing purposes. + /// + public class TestConfigurationItem : IConfigurationItem + { + public string Name { get; set; } + } +} \ No newline at end of file Index: Ringtoets/Common/test/Ringtoets.Common.IO.TestUtil/TestSchemaCalculationConfigurationWriter.cs =================================================================== diff -u --- Ringtoets/Common/test/Ringtoets.Common.IO.TestUtil/TestSchemaCalculationConfigurationWriter.cs (revision 0) +++ Ringtoets/Common/test/Ringtoets.Common.IO.TestUtil/TestSchemaCalculationConfigurationWriter.cs (revision 43b7d2fe7b1c4209fd2afcd985a5c1f4b7bf14e9) @@ -0,0 +1,47 @@ +// 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.Common.IO.TestUtil +{ + /// + /// Simple that can be used for testing purposes. + /// + public class TestSchemaCalculationConfigurationWriter : SchemaCalculationConfigurationWriter + { + private const string calculationElementTag = "calculation"; + + /// + /// Creates a new instance of + /// + /// The path of the file to write to. + /// Thrown when is invalid. + public TestSchemaCalculationConfigurationWriter(string filePath) : base(filePath) {} + + protected override void WriteCalculation(TestConfigurationItem calculation, XmlWriter writer) + { + writer.WriteElementString(calculationElementTag, calculation.Name); + } + } +} \ No newline at end of file Index: Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.IO/HeightStructuresCalculationConfigurationExporter.cs =================================================================== diff -u -rd393a6e22ba176f0ce9731629a37ce3272b1f433 -r43b7d2fe7b1c4209fd2afcd985a5c1f4b7bf14e9 --- Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.IO/HeightStructuresCalculationConfigurationExporter.cs (.../HeightStructuresCalculationConfigurationExporter.cs) (revision d393a6e22ba176f0ce9731629a37ce3272b1f433) +++ Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.IO/HeightStructuresCalculationConfigurationExporter.cs (.../HeightStructuresCalculationConfigurationExporter.cs) (revision 43b7d2fe7b1c4209fd2afcd985a5c1f4b7bf14e9) @@ -120,5 +120,10 @@ return calculationConfiguration; } + + protected override HeightStructuresCalculationConfigurationWriter CreateWriter(string filePath) + { + return new HeightStructuresCalculationConfigurationWriter(filePath); + } } } \ No newline at end of file Index: Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.IO/HeightStructuresCalculationConfigurationWriter.cs =================================================================== diff -u -rd393a6e22ba176f0ce9731629a37ce3272b1f433 -r43b7d2fe7b1c4209fd2afcd985a5c1f4b7bf14e9 --- Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.IO/HeightStructuresCalculationConfigurationWriter.cs (.../HeightStructuresCalculationConfigurationWriter.cs) (revision d393a6e22ba176f0ce9731629a37ce3272b1f433) +++ Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.IO/HeightStructuresCalculationConfigurationWriter.cs (.../HeightStructuresCalculationConfigurationWriter.cs) (revision 43b7d2fe7b1c4209fd2afcd985a5c1f4b7bf14e9) @@ -43,17 +43,14 @@ /// does not end with a directory or path separator (empty file name). /// public HeightStructuresCalculationConfigurationWriter(string filePath) : base(filePath) {} - - protected override void WriteSpecificStructureParameters(HeightStructuresCalculationConfiguration configuration, XmlWriter writer) - { - } + protected override void WriteSpecificStructureParameters(HeightStructuresCalculationConfiguration configuration, XmlWriter writer) {} + protected override void WriteSpecificStochasts(HeightStructuresCalculationConfiguration configuration, XmlWriter writer) { - if (configuration.LevelCrestStructure != null) - { - writer.WriteDistribution(HeightStructuresConfigurationSchemaIdentifiers.LevelCrestStructureStochastName, configuration.LevelCrestStructure); - } + WriteDistributionWhenAvailable(writer, + HeightStructuresConfigurationSchemaIdentifiers.LevelCrestStructureStochastName, + configuration.LevelCrestStructure); } } } \ No newline at end of file