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()); + } } } }