Index: Ringtoets/Common/src/Ringtoets.Common.IO/Exporters/ConfigurationExporter.cs =================================================================== diff -u -r5735c9b5c663a0bc7762d1b1eb1483e5c4cfe526 -r020439f88aaed9dd51967acbc8518f37c95791d1 --- Ringtoets/Common/src/Ringtoets.Common.IO/Exporters/ConfigurationExporter.cs (.../ConfigurationExporter.cs) (revision 5735c9b5c663a0bc7762d1b1eb1483e5c4cfe526) +++ Ringtoets/Common/src/Ringtoets.Common.IO/Exporters/ConfigurationExporter.cs (.../ConfigurationExporter.cs) (revision 020439f88aaed9dd51967acbc8518f37c95791d1) @@ -65,7 +65,7 @@ { try { - new TWriter().Write(calculationGroup, filePath); + new TWriter().Write(calculationGroup.Children, filePath); } catch (CriticalFileWriteException e) { Index: Ringtoets/Common/src/Ringtoets.Common.IO/Writers/CalculationConfigurationWriter.cs =================================================================== diff -u -r2923096aeb41e1fb5d4ba0ad43ccb9f95ca7407a -r020439f88aaed9dd51967acbc8518f37c95791d1 --- Ringtoets/Common/src/Ringtoets.Common.IO/Writers/CalculationConfigurationWriter.cs (.../CalculationConfigurationWriter.cs) (revision 2923096aeb41e1fb5d4ba0ad43ccb9f95ca7407a) +++ Ringtoets/Common/src/Ringtoets.Common.IO/Writers/CalculationConfigurationWriter.cs (.../CalculationConfigurationWriter.cs) (revision 020439f88aaed9dd51967acbc8518f37c95791d1) @@ -40,18 +40,18 @@ public abstract class CalculationConfigurationWriter where T : class, ICalculation { /// - /// Writes a piping configuration to an XML file. + /// Writes a configuration to an XML file. /// - /// The root calculation group containing the piping configuration to write. + /// The configuration to write. /// The path to the target XML file. /// Thrown when any parameter is null. /// Thrown when unable to write to . - /// The itself will not be part of the written XML, only its children. - public void Write(CalculationGroup rootCalculationGroup, string filePath) + /// The itself will not be part of the written XML, only its children. + public void Write(IEnumerable configuration, string filePath) { - if (rootCalculationGroup == null) + if (configuration == null) { - throw new ArgumentNullException(nameof(rootCalculationGroup)); + throw new ArgumentNullException(nameof(configuration)); } if (filePath == null) { @@ -70,7 +70,7 @@ writer.WriteStartDocument(); writer.WriteStartElement(ConfigurationSchemaIdentifiers.ConfigurationElement); - WriteConfiguration(rootCalculationGroup, writer); + WriteConfiguration(configuration, writer); writer.WriteEndElement(); writer.WriteEndDocument(); @@ -138,9 +138,9 @@ } } - private void WriteConfiguration(CalculationGroup calculationGroup, XmlWriter writer) + private void WriteConfiguration(IEnumerable configuration, XmlWriter writer) { - foreach (ICalculationBase child in calculationGroup.Children) + foreach (ICalculationBase child in configuration) { var innerGroup = child as CalculationGroup; if (innerGroup != null) @@ -189,7 +189,7 @@ writer.WriteStartElement(ConfigurationSchemaIdentifiers.FolderElement); writer.WriteAttributeString(ConfigurationSchemaIdentifiers.NameAttribute, calculationGroup.Name); - WriteConfiguration(calculationGroup, writer); + WriteConfiguration(calculationGroup.Children, writer); writer.WriteEndElement(); } Index: Ringtoets/Common/test/Ringtoets.Common.IO.Test/Writers/CalculationConfigurationWriterTest.cs =================================================================== diff -u -r2923096aeb41e1fb5d4ba0ad43ccb9f95ca7407a -r020439f88aaed9dd51967acbc8518f37c95791d1 --- Ringtoets/Common/test/Ringtoets.Common.IO.Test/Writers/CalculationConfigurationWriterTest.cs (.../CalculationConfigurationWriterTest.cs) (revision 2923096aeb41e1fb5d4ba0ad43ccb9f95ca7407a) +++ Ringtoets/Common/test/Ringtoets.Common.IO.Test/Writers/CalculationConfigurationWriterTest.cs (.../CalculationConfigurationWriterTest.cs) (revision 020439f88aaed9dd51967acbc8518f37c95791d1) @@ -41,21 +41,21 @@ public class CalculationConfigurationWriterTest { [Test] - public void Write_CalculationGroupNull_ThrowArgumentNullException() + public void Write_ConfigurationNull_ThrowArgumentNullException() { // Call TestDelegate test = () => new SimpleCalculationConfigurationWriter().Write(null, string.Empty); // Assert var exception = Assert.Throws(test); - Assert.AreEqual("rootCalculationGroup", exception.ParamName); + Assert.AreEqual("configuration", exception.ParamName); } [Test] public void Write_FilePathNull_ThrowArgumentNullException() { // Call - TestDelegate test = () => new SimpleCalculationConfigurationWriter().Write(new CalculationGroup(), null); + TestDelegate test = () => new SimpleCalculationConfigurationWriter().Write(Enumerable.Empty(), null); // Assert var exception = Assert.Throws(test); @@ -69,7 +69,7 @@ public void Write_FilePathInvalid_ThrowCriticalFileWriteException(string filePath) { // Call - TestDelegate call = () => new SimpleCalculationConfigurationWriter().Write(new CalculationGroup(), filePath); + TestDelegate call = () => new SimpleCalculationConfigurationWriter().Write(Enumerable.Empty(), filePath); // Assert var exception = Assert.Throws(call); @@ -84,7 +84,7 @@ var filePath = new string('a', 249); // Call - TestDelegate call = () => new SimpleCalculationConfigurationWriter().Write(new CalculationGroup(), filePath); + TestDelegate call = () => new SimpleCalculationConfigurationWriter().Write(Enumerable.Empty(), filePath); // Assert var exception = Assert.Throws(call); @@ -103,7 +103,7 @@ disposeHelper.LockDirectory(FileSystemRights.Write); // Call - TestDelegate call = () => new SimpleCalculationConfigurationWriter().Write(new CalculationGroup(), filePath); + TestDelegate call = () => new SimpleCalculationConfigurationWriter().Write(Enumerable.Empty(), filePath); // Assert var exception = Assert.Throws(call); @@ -123,7 +123,7 @@ fileDisposeHelper.LockFiles(); // Call - TestDelegate call = () => new SimpleCalculationConfigurationWriter().Write(new CalculationGroup(), path); + TestDelegate call = () => new SimpleCalculationConfigurationWriter().Write(Enumerable.Empty(), path); // Assert var exception = Assert.Throws(call); @@ -137,9 +137,6 @@ { // Setup string filePath = TestHelper.GetScratchPadPath("test_distributions_write.xml"); - string expectedXmlFilePath = TestHelper.GetTestDataPath( - TestDataPath.Ringtoets.Common.IO, - Path.Combine(nameof(CalculationConfigurationWriter), "distributions.xml")); try { @@ -325,7 +322,7 @@ [Test] [TestCaseSource(nameof(CalculationConfigurations))] - public void Write_DifferentCalculationAndCalculationGroupConfigurations_ValidFile(CalculationGroup rootGroup, string expectedFileContentsFileName) + public void Write_DifferentCalculationAndCalculationGroupConfigurations_ValidFile(IEnumerable configuration, string expectedFileContentsFileName) { // Setup string filePath = TestHelper.GetScratchPadPath("test.xml"); @@ -336,7 +333,7 @@ try { // Call - new SimpleCalculationConfigurationWriter().Write(rootGroup, filePath); + new SimpleCalculationConfigurationWriter().Write(configuration, filePath); // Assert Assert.IsTrue(File.Exists(filePath)); @@ -388,31 +385,35 @@ }; yield return new TestCaseData( - CreateRootGroupWithChildren(calculationGroup1), + new [] + { + calculationGroup1 + }, "singleGroup.xml") .SetName("Single group"); yield return new TestCaseData( - CreateRootGroupWithChildren(calculation1), + new[] + { + calculation1 + }, "singleCalculation.xml") .SetName("Single calculation"); yield return new TestCaseData( - CreateRootGroupWithChildren(calculationGroup1, calculation1), + new ICalculationBase[] + { + calculationGroup1, + calculation1 + }, "calculationGroupAndCalculation.xml") .SetName("Calculation group and calculation"); yield return new TestCaseData( - CreateRootGroupWithChildren(calculation1, calculationGroup2), + new ICalculationBase[] + { + calculation1, + calculationGroup2 + }, "calculationAndGroupWithNesting.xml") .SetName("Calculation and group with nesting"); } - - private static CalculationGroup CreateRootGroupWithChildren(params ICalculationBase[] children) - { - var group = new CalculationGroup("root", false); - foreach (ICalculationBase child in children) - { - group.Children.Add(child); - } - return group; - } } } \ No newline at end of file Index: Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.IO.Test/GrassCoverErosionInwardsConfigurationWriterTest.cs =================================================================== diff -u -r2923096aeb41e1fb5d4ba0ad43ccb9f95ca7407a -r020439f88aaed9dd51967acbc8518f37c95791d1 --- Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.IO.Test/GrassCoverErosionInwardsConfigurationWriterTest.cs (.../GrassCoverErosionInwardsConfigurationWriterTest.cs) (revision 2923096aeb41e1fb5d4ba0ad43ccb9f95ca7407a) +++ Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.IO.Test/GrassCoverErosionInwardsConfigurationWriterTest.cs (.../GrassCoverErosionInwardsConfigurationWriterTest.cs) (revision 020439f88aaed9dd51967acbc8518f37c95791d1) @@ -22,6 +22,7 @@ using System; using System.Collections.Generic; using System.IO; +using System.Linq; using System.Security.AccessControl; using Core.Common.Base.Data; using Core.Common.IO.Exceptions; @@ -46,21 +47,21 @@ } [Test] - public void Write_CalculationGroupNull_ThrowArgumentNullException() + public void Write_ConfigurationNull_ThrowArgumentNullException() { // Call TestDelegate test = () => new GrassCoverErosionInwardsConfigurationWriter().Write(null, string.Empty); // Assert var exception = Assert.Throws(test); - Assert.AreEqual("rootCalculationGroup", exception.ParamName); + Assert.AreEqual("configuration", exception.ParamName); } [Test] public void Write_FilePathNull_ThrowArgumentNullException() { // Call - TestDelegate test = () => new GrassCoverErosionInwardsConfigurationWriter().Write(new CalculationGroup(), null); + TestDelegate test = () => new GrassCoverErosionInwardsConfigurationWriter().Write(Enumerable.Empty(), null); // Assert var exception = Assert.Throws(test); @@ -74,7 +75,7 @@ public void Write_FilePathInvalid_ThrowCriticalFileWriteException(string filePath) { // Call - TestDelegate call = () => new GrassCoverErosionInwardsConfigurationWriter().Write(new CalculationGroup(), filePath); + TestDelegate call = () => new GrassCoverErosionInwardsConfigurationWriter().Write(Enumerable.Empty(), filePath); // Assert var exception = Assert.Throws(call); @@ -89,7 +90,7 @@ var filePath = new string('a', 249); // Call - TestDelegate call = () => new GrassCoverErosionInwardsConfigurationWriter().Write(new CalculationGroup(), filePath); + TestDelegate call = () => new GrassCoverErosionInwardsConfigurationWriter().Write(Enumerable.Empty(), filePath); // Assert var exception = Assert.Throws(call); @@ -108,7 +109,7 @@ disposeHelper.LockDirectory(FileSystemRights.Write); // Call - TestDelegate call = () => new GrassCoverErosionInwardsConfigurationWriter().Write(new CalculationGroup(), filePath); + TestDelegate call = () => new GrassCoverErosionInwardsConfigurationWriter().Write(Enumerable.Empty(), filePath); // Assert var exception = Assert.Throws(call); @@ -128,7 +129,7 @@ fileDisposeHelper.LockFiles(); // Call - TestDelegate call = () => new GrassCoverErosionInwardsConfigurationWriter().Write(new CalculationGroup(), path); + TestDelegate call = () => new GrassCoverErosionInwardsConfigurationWriter().Write(Enumerable.Empty(), path); // Assert var exception = Assert.Throws(call); @@ -158,12 +159,9 @@ var writer = new GrassCoverErosionInwardsConfigurationWriter(); // Call - writer.Write(new CalculationGroup + writer.Write(new[] { - Children = - { calculation - } }, filePath); // Assert @@ -196,12 +194,9 @@ var writer = new GrassCoverErosionInwardsConfigurationWriter(); // Call - writer.Write(new CalculationGroup + writer.Write(new[] { - Children = - { - calculation - } + calculation }, filePath); // Assert @@ -244,19 +239,14 @@ } }; - var rootGroup = new CalculationGroup("root", false) + try { - Children = + // Call + new GrassCoverErosionInwardsConfigurationWriter().Write(new[] { calculationGroup - } - }; + }, filePath); - try - { - // Call - new GrassCoverErosionInwardsConfigurationWriter().Write(rootGroup, filePath); - // Assert Assert.IsTrue(File.Exists(filePath)); Index: Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.IO.Test/GrassCoverErosionOutwardsConfigurationWriterTest.cs =================================================================== diff -u -r633aedbd4c882f2811c3e8e6653ef352301c40b5 -r020439f88aaed9dd51967acbc8518f37c95791d1 --- Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.IO.Test/GrassCoverErosionOutwardsConfigurationWriterTest.cs (.../GrassCoverErosionOutwardsConfigurationWriterTest.cs) (revision 633aedbd4c882f2811c3e8e6653ef352301c40b5) +++ Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.IO.Test/GrassCoverErosionOutwardsConfigurationWriterTest.cs (.../GrassCoverErosionOutwardsConfigurationWriterTest.cs) (revision 020439f88aaed9dd51967acbc8518f37c95791d1) @@ -78,20 +78,16 @@ }; var calculationGroup = new CalculationGroup("NestedGroup", false); - var rootGroup = new CalculationGroup - { - Children = - { - calculation, - calculationGroup - } - }; try { var writer = new GrassCoverErosionOutwardsConfigurationWriter(); // Call - writer.Write(rootGroup, filePath); + writer.Write(new ICalculationBase[] + { + calculation, + calculationGroup + }, filePath); // Assert string actualXml = File.ReadAllText(filePath); Index: Ringtoets/Piping/test/Ringtoets.Piping.IO.Test/Exporters/PipingConfigurationWriterTest.cs =================================================================== diff -u -r97c94a903e0fd98edd8cd4120340f91f06d3955c -r020439f88aaed9dd51967acbc8518f37c95791d1 --- Ringtoets/Piping/test/Ringtoets.Piping.IO.Test/Exporters/PipingConfigurationWriterTest.cs (.../PipingConfigurationWriterTest.cs) (revision 97c94a903e0fd98edd8cd4120340f91f06d3955c) +++ Ringtoets/Piping/test/Ringtoets.Piping.IO.Test/Exporters/PipingConfigurationWriterTest.cs (.../PipingConfigurationWriterTest.cs) (revision 020439f88aaed9dd51967acbc8518f37c95791d1) @@ -22,6 +22,7 @@ using System; using System.Collections.Generic; using System.IO; +using System.Linq; using System.Security.AccessControl; using Core.Common.Base.Data; using Core.Common.IO.Exceptions; @@ -68,21 +69,21 @@ } [Test] - public void Write_CalculationGroupNull_ThrowArgumentNullException() + public void Write_ConfigurationNull_ThrowArgumentNullException() { // Call TestDelegate test = () => new PipingConfigurationWriter().Write(null, string.Empty); // Assert var exception = Assert.Throws(test); - Assert.AreEqual("rootCalculationGroup", exception.ParamName); + Assert.AreEqual("configuration", exception.ParamName); } [Test] public void Write_FilePathNull_ThrowArgumentNullException() { // Call - TestDelegate test = () => new PipingConfigurationWriter().Write(new CalculationGroup(), null); + TestDelegate test = () => new PipingConfigurationWriter().Write(Enumerable.Empty(), null); // Assert var exception = Assert.Throws(test); @@ -96,7 +97,7 @@ public void Write_FilePathInvalid_ThrowCriticalFileWriteException(string filePath) { // Call - TestDelegate call = () => new PipingConfigurationWriter().Write(new CalculationGroup(), filePath); + TestDelegate call = () => new PipingConfigurationWriter().Write(Enumerable.Empty(), filePath); // Assert var exception = Assert.Throws(call); @@ -111,7 +112,7 @@ var filePath = new string('a', 249); // Call - TestDelegate call = () => new PipingConfigurationWriter().Write(new CalculationGroup(), filePath); + TestDelegate call = () => new PipingConfigurationWriter().Write(Enumerable.Empty(), filePath); // Assert var exception = Assert.Throws(call); @@ -130,8 +131,8 @@ disposeHelper.LockDirectory(FileSystemRights.Write); // Call - TestDelegate call = () => new PipingConfigurationWriter().Write(new CalculationGroup(), filePath); - + TestDelegate call = () => new PipingConfigurationWriter().Write(Enumerable.Empty(), filePath); + // Assert var exception = Assert.Throws(call); Assert.AreEqual($"Er is een onverwachte fout opgetreden tijdens het schrijven van het bestand '{filePath}'.", exception.Message); @@ -150,7 +151,7 @@ fileDisposeHelper.LockFiles(); // Call - TestDelegate call = () => new PipingConfigurationWriter().Write(new CalculationGroup(), path); + TestDelegate call = () => new PipingConfigurationWriter().Write(Enumerable.Empty(), path); // Assert var exception = Assert.Throws(call); @@ -201,19 +202,14 @@ } }; - var rootGroup = new CalculationGroup("root", false) + try { - Children = + // Call + new PipingConfigurationWriter().Write(new[] { calculationGroup - } - }; + }, filePath); - try - { - // Call - new PipingConfigurationWriter().Write(rootGroup, filePath); - // Assert Assert.IsTrue(File.Exists(filePath)); @@ -238,19 +234,14 @@ // Setup string filePath = TestHelper.GetScratchPadPath("test.xml"); - var rootCalculationGroup = new CalculationGroup("group", false) + try { - Children = + // Call + new PipingConfigurationWriter().Write(new[] { calculation - } - }; + }, filePath); - try - { - // Call - new PipingConfigurationWriter().Write(rootCalculationGroup, filePath); - // Assert Assert.IsTrue(File.Exists(filePath)); Index: Ringtoets/StabilityStoneCover/test/Ringtoets.StabilityStoneCover.IO.Test/StabilityStoneCoverConfigurationWriterTest.cs =================================================================== diff -u -r633aedbd4c882f2811c3e8e6653ef352301c40b5 -r020439f88aaed9dd51967acbc8518f37c95791d1 --- Ringtoets/StabilityStoneCover/test/Ringtoets.StabilityStoneCover.IO.Test/StabilityStoneCoverConfigurationWriterTest.cs (.../StabilityStoneCoverConfigurationWriterTest.cs) (revision 633aedbd4c882f2811c3e8e6653ef352301c40b5) +++ Ringtoets/StabilityStoneCover/test/Ringtoets.StabilityStoneCover.IO.Test/StabilityStoneCoverConfigurationWriterTest.cs (.../StabilityStoneCoverConfigurationWriterTest.cs) (revision 020439f88aaed9dd51967acbc8518f37c95791d1) @@ -78,20 +78,16 @@ }; var calculationGroup = new CalculationGroup("NestedGroup", false); - var rootGroup = new CalculationGroup - { - Children = - { - calculation, - calculationGroup - } - }; try { var writer = new StabilityStoneCoverConfigurationWriter(); // Call - writer.Write(rootGroup, filePath); + writer.Write(new ICalculationBase[] + { + calculation, + calculationGroup + }, filePath); // Assert string actualXml = File.ReadAllText(filePath); Index: Ringtoets/WaveImpactAsphaltCover/test/Ringtoets.WaveImpactAsphaltCover.IO.Test/WaveImpactAsphaltCoverConfigurationWriterTest.cs =================================================================== diff -u -r7348fb685e44d6eb4abf2854c8298c0a2189d67e -r020439f88aaed9dd51967acbc8518f37c95791d1 --- Ringtoets/WaveImpactAsphaltCover/test/Ringtoets.WaveImpactAsphaltCover.IO.Test/WaveImpactAsphaltCoverConfigurationWriterTest.cs (.../WaveImpactAsphaltCoverConfigurationWriterTest.cs) (revision 7348fb685e44d6eb4abf2854c8298c0a2189d67e) +++ Ringtoets/WaveImpactAsphaltCover/test/Ringtoets.WaveImpactAsphaltCover.IO.Test/WaveImpactAsphaltCoverConfigurationWriterTest.cs (.../WaveImpactAsphaltCoverConfigurationWriterTest.cs) (revision 020439f88aaed9dd51967acbc8518f37c95791d1) @@ -78,20 +78,16 @@ }; var calculationGroup = new CalculationGroup("NestedGroup", false); - var rootGroup = new CalculationGroup - { - Children = - { - calculation, - calculationGroup - } - }; try { var writer = new WaveImpactAsphaltCoverConfigurationWriter(); // Call - writer.Write(rootGroup, filePath); + writer.Write(new ICalculationBase[] + { + calculation, + calculationGroup + }, filePath); // Assert string actualXml = File.ReadAllText(filePath);