Index: Ringtoets/Common/src/Ringtoets.Common.IO/Writers/SchemaCalculationConfigurationWriter.cs =================================================================== diff -u -r43b7d2fe7b1c4209fd2afcd985a5c1f4b7bf14e9 -rd894f307cf5b3dbf88dfdb926d6a70364f2d356d --- Ringtoets/Common/src/Ringtoets.Common.IO/Writers/SchemaCalculationConfigurationWriter.cs (.../SchemaCalculationConfigurationWriter.cs) (revision 43b7d2fe7b1c4209fd2afcd985a5c1f4b7bf14e9) +++ Ringtoets/Common/src/Ringtoets.Common.IO/Writers/SchemaCalculationConfigurationWriter.cs (.../SchemaCalculationConfigurationWriter.cs) (revision d894f307cf5b3dbf88dfdb926d6a70364f2d356d) @@ -107,8 +107,19 @@ /// The writer to use for writing. /// The name of the distribution. /// The configuration for the distribution that can be null. + /// Thrown when or + /// is null. protected static void WriteDistributionWhenAvailable(XmlWriter writer, string distributionName, MeanVariationCoefficientStochastConfiguration configuration) { + if (writer == null) + { + throw new ArgumentNullException(nameof(writer)); + } + if (distributionName == null) + { + throw new ArgumentNullException(nameof(distributionName)); + } + if (configuration != null) { writer.WriteDistribution(distributionName, configuration); @@ -121,8 +132,19 @@ /// The writer to use for writing. /// The name of the distribution. /// The configuration for the distribution that can be null. + /// Thrown when or + /// is null. protected static void WriteDistributionWhenAvailable(XmlWriter writer, string distributionName, MeanStandardDeviationStochastConfiguration configuration) { + if (writer == null) + { + throw new ArgumentNullException(nameof(writer)); + } + if (distributionName == null) + { + throw new ArgumentNullException(nameof(distributionName)); + } + if (configuration != null) { writer.WriteDistribution(distributionName, configuration); @@ -135,8 +157,19 @@ /// The writer to use for writing. /// The name of the element. /// The content of the element that can be null. + /// Thrown when or + /// is null. protected static void WriteElementWhenContentAvailable(XmlWriter writer, string elementName, string elementContent) { + if (writer == null) + { + throw new ArgumentNullException(nameof(writer)); + } + if (elementName == null) + { + throw new ArgumentNullException(nameof(elementName)); + } + if (elementContent != null) { writer.WriteElementString( @@ -151,8 +184,19 @@ /// The writer to use for writing. /// The name of the element. /// The content of the element that can be null. + /// Thrown when or + /// is null. protected static void WriteElementWhenContentAvailable(XmlWriter writer, string elementName, double? elementContent) { + if (writer == null) + { + throw new ArgumentNullException(nameof(writer)); + } + if (elementName == null) + { + throw new ArgumentNullException(nameof(elementName)); + } + if (elementContent.HasValue) { writer.WriteElementString( @@ -166,8 +210,14 @@ /// /// The writer to use for writing. /// The configuration for the wave reduction that can be null. + /// Thrown when is null. protected static void WriteWaveReductionWhenAvailable(XmlWriter writer, WaveReductionConfiguration configuration) { + if (writer == null) + { + throw new ArgumentNullException(nameof(writer)); + } + if (configuration != null) { writer.WriteWaveReduction(configuration); Index: Ringtoets/Common/test/Ringtoets.Common.IO.Test/Writers/SchemaCalculationConfigurationWriterTest.cs =================================================================== diff -u -r43b7d2fe7b1c4209fd2afcd985a5c1f4b7bf14e9 -rd894f307cf5b3dbf88dfdb926d6a70364f2d356d --- Ringtoets/Common/test/Ringtoets.Common.IO.Test/Writers/SchemaCalculationConfigurationWriterTest.cs (.../SchemaCalculationConfigurationWriterTest.cs) (revision 43b7d2fe7b1c4209fd2afcd985a5c1f4b7bf14e9) +++ Ringtoets/Common/test/Ringtoets.Common.IO.Test/Writers/SchemaCalculationConfigurationWriterTest.cs (.../SchemaCalculationConfigurationWriterTest.cs) (revision d894f307cf5b3dbf88dfdb926d6a70364f2d356d) @@ -19,6 +19,7 @@ // 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.Linq; @@ -69,6 +70,39 @@ } [Test] + public void WriteDistributionWhenAvailable_MeanStandardDeviationStochastConfigurationWriterNull_ThrowsArgumentNullException() + { + // Call + TestDelegate test = () => ExposedSchemaCalculationConfigurationWriter.PublicWriteDistributionWhenAvailable( + null, + "some name", + (MeanStandardDeviationStochastConfiguration)null); + + // Assert + var exception = Assert.Throws(test); + Assert.AreEqual("writer", exception.ParamName); + } + + [Test] + public void WriteDistributionWhenAvailable_MeanStandardDeviationStochastConfigurationDistributionNameNull_ThrowsArgumentNullException() + { + // Setup + var mocks = new MockRepository(); + var xmlWriter = mocks.StrictMock(); + mocks.ReplayAll(); + + // Call + TestDelegate test = () => ExposedSchemaCalculationConfigurationWriter.PublicWriteDistributionWhenAvailable( + xmlWriter, + null, + (MeanStandardDeviationStochastConfiguration)null); + + // Assert + var exception = Assert.Throws(test); + Assert.AreEqual("distributionName", exception.ParamName); + } + + [Test] public void WriteDistributionWhenAvailable_MeanStandardDeviationStochastConfigurationNull_WriterNotCalled() { // Setup @@ -109,6 +143,39 @@ } [Test] + public void WriteDistributionWhenAvailable_MeanVariationCoefficientStochastConfigurationWriterNull_ThrowsArgumentNullException() + { + // Call + TestDelegate test = () => ExposedSchemaCalculationConfigurationWriter.PublicWriteDistributionWhenAvailable( + null, + "some name", + (MeanVariationCoefficientStochastConfiguration)null); + + // Assert + var exception = Assert.Throws(test); + Assert.AreEqual("writer", exception.ParamName); + } + + [Test] + public void WriteDistributionWhenAvailable_MeanVariationCoefficientStochastConfigurationDistributionNameNull_ThrowsArgumentNullException() + { + // Setup + var mocks = new MockRepository(); + var xmlWriter = mocks.StrictMock(); + mocks.ReplayAll(); + + // Call + TestDelegate test = () => ExposedSchemaCalculationConfigurationWriter.PublicWriteDistributionWhenAvailable( + xmlWriter, + null, + (MeanVariationCoefficientStochastConfiguration)null); + + // Assert + var exception = Assert.Throws(test); + Assert.AreEqual("distributionName", exception.ParamName); + } + + [Test] public void WriteDistributionWhenAvailable_MeanVariationCoefficientStochastConfigurationNull_WriterNotCalled() { // Setup @@ -149,6 +216,39 @@ } [Test] + public void WriteElementWhenContentAvailable_StringWriterNull_ThrowsArgumentNullException() + { + // Call + TestDelegate test = () => ExposedSchemaCalculationConfigurationWriter.PublicWriteElementWhenContentAvailable( + null, + "some name", + (string)null); + + // Assert + var exception = Assert.Throws(test); + Assert.AreEqual("writer", exception.ParamName); + } + + [Test] + public void WriteElementWhenContentAvailable_StringElementNameNull_ThrowsArgumentNullException() + { + // Setup + var mocks = new MockRepository(); + var xmlWriter = mocks.StrictMock(); + mocks.ReplayAll(); + + // Call + TestDelegate test = () => ExposedSchemaCalculationConfigurationWriter.PublicWriteElementWhenContentAvailable( + xmlWriter, + null, + (string)null); + + // Assert + var exception = Assert.Throws(test); + Assert.AreEqual("elementName", exception.ParamName); + } + + [Test] public void WriteElementWhenContentAvailable_StringNull_WriterNotCalled() { // Setup @@ -189,6 +289,39 @@ } [Test] + public void WriteElementWhenContentAvailable_DoubleWriterNull_ThrowsArgumentNullException() + { + // Call + TestDelegate test = () => ExposedSchemaCalculationConfigurationWriter.PublicWriteElementWhenContentAvailable( + null, + "some name", + (double?)null); + + // Assert + var exception = Assert.Throws(test); + Assert.AreEqual("writer", exception.ParamName); + } + + [Test] + public void WriteElementWhenContentAvailable_DoubleElementNameNull_ThrowsArgumentNullException() + { + // Setup + var mocks = new MockRepository(); + var xmlWriter = mocks.StrictMock(); + mocks.ReplayAll(); + + // Call + TestDelegate test = () => ExposedSchemaCalculationConfigurationWriter.PublicWriteElementWhenContentAvailable( + xmlWriter, + null, + (double?)null); + + // Assert + var exception = Assert.Throws(test); + Assert.AreEqual("elementName", exception.ParamName); + } + + [Test] public void WriteElementWhenContentAvailable_DoubleNull_WriterNotCalled() { // Setup @@ -229,6 +362,19 @@ } [Test] + public void WriteWaveReductionWhenAvailable_WriterNull_ThrowsArgumentNullException() + { + // Call + TestDelegate test = () => ExposedSchemaCalculationConfigurationWriter.PublicWriteWaveReductionWhenAvailable( + null, + null); + + // Assert + var exception = Assert.Throws(test); + Assert.AreEqual("writer", exception.ParamName); + } + + [Test] public void WriteWaveReductionWhenAvailable_WaveReductionConfigurationNull_WriterNotCalled() { // Setup