Index: Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.IO/Exporters/GrassCoverErosionInwardsCalculationConfigurationExporter.cs =================================================================== diff -u --- Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.IO/Exporters/GrassCoverErosionInwardsCalculationConfigurationExporter.cs (revision 0) +++ Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.IO/Exporters/GrassCoverErosionInwardsCalculationConfigurationExporter.cs (revision 96cd93f1a08294e5af3fec5f5ae0b59cbe914c4b) @@ -0,0 +1,48 @@ +// 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 Ringtoets.Common.Data.Calculation; +using Ringtoets.Common.IO.Exporters; +using Ringtoets.GrassCoverErosionInwards.Data; +using Ringtoets.GrassCoverErosionInwards.IO.Writers; + +namespace Ringtoets.GrassCoverErosionInwards.IO.Exporters +{ + /// + /// Exports a grass cover erosion inwards configuration and stores it as an XML file. + /// + public class GrassCoverErosionInwardsCalculationConfigurationExporter + : CalculationConfigurationExporter + { + + /// + /// Creates a new instance of . + /// + /// The configuration to export. + /// The path of the XML file to export to. + /// Thrown when is null. + /// Thrown when is invalid. + public GrassCoverErosionInwardsCalculationConfigurationExporter(IEnumerable configuration, string filePath) + : base(configuration, filePath) { } + } +} \ No newline at end of file Fisheye: Tag 96cd93f1a08294e5af3fec5f5ae0b59cbe914c4b refers to a dead (removed) revision in file `Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.IO/GrassCoverErosionInwardsCalculationConfigurationExporter.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 96cd93f1a08294e5af3fec5f5ae0b59cbe914c4b refers to a dead (removed) revision in file `Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.IO/GrassCoverErosionInwardsCalculationConfigurationWriter.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.IO/Ringtoets.GrassCoverErosionInwards.IO.csproj =================================================================== diff -u -rf9f7e585da06fc8ab1b8ab92ce4dd64bd66d8f04 -r96cd93f1a08294e5af3fec5f5ae0b59cbe914c4b --- Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.IO/Ringtoets.GrassCoverErosionInwards.IO.csproj (.../Ringtoets.GrassCoverErosionInwards.IO.csproj) (revision f9f7e585da06fc8ab1b8ab92ce4dd64bd66d8f04) +++ Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.IO/Ringtoets.GrassCoverErosionInwards.IO.csproj (.../Ringtoets.GrassCoverErosionInwards.IO.csproj) (revision 96cd93f1a08294e5af3fec5f5ae0b59cbe914c4b) @@ -40,9 +40,9 @@ Properties\GlobalAssembly.cs - + - + Index: Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.IO/Writers/GrassCoverErosionInwardsCalculationConfigurationWriter.cs =================================================================== diff -u --- Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.IO/Writers/GrassCoverErosionInwardsCalculationConfigurationWriter.cs (revision 0) +++ Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.IO/Writers/GrassCoverErosionInwardsCalculationConfigurationWriter.cs (revision 96cd93f1a08294e5af3fec5f5ae0b59cbe914c4b) @@ -0,0 +1,93 @@ +// 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.Xml; +using Ringtoets.Common.Data.Probabilistics; +using Ringtoets.Common.IO.Schema; +using Ringtoets.Common.IO.Writers; +using Ringtoets.GrassCoverErosionInwards.Data; + +namespace Ringtoets.GrassCoverErosionInwards.IO.Writers +{ + /// + /// Writer for writing a grass cover erosion inwards configuration to XML. + /// + public class GrassCoverErosionInwardsCalculationConfigurationWriter : CalculationConfigurationWriter + { + protected override void WriteCalculation(GrassCoverErosionInwardsCalculation calculation, XmlWriter writer) + { + writer.WriteStartElement(ConfigurationSchemaIdentifiers.CalculationElement); + writer.WriteAttributeString(ConfigurationSchemaIdentifiers.NameAttribute, calculation.Name); + + GrassCoverErosionInwardsInput input = calculation.InputParameters; + + if (input.HydraulicBoundaryLocation != null) + { + writer.WriteElementString(ConfigurationSchemaIdentifiers.HydraulicBoundaryLocationElement, + input.HydraulicBoundaryLocation.Name); + } + if (input.DikeProfile != null) + { + writer.WriteElementString(GrassCoverErosionInwardsConfigurationSchemaIdentifiers.HydraulicBoundaryLocationElement, + input.DikeProfile.Name); + } + + writer.WriteElementString( + ConfigurationSchemaIdentifiers.Orientation, + XmlConvert.ToString(input.Orientation)); + + WriteWaveReduction(input, writer); + + WriteDistributions(CreateInputDistributions(input), writer); + + writer.WriteEndElement(); + } + + private static IDictionary CreateInputDistributions(GrassCoverErosionInwardsInput calculationInputParameters) + { + return new Dictionary + { + { + GrassCoverErosionInwardsConfigurationSchemaIdentifiers.CriticalFlowRateStochastName, + calculationInputParameters.CriticalFlowRate + } + }; + } + + private static void WriteWaveReduction(GrassCoverErosionInwardsInput input, XmlWriter writer) + { + writer.WriteStartElement(ConfigurationSchemaIdentifiers.WaveReduction); + + writer.WriteElementString( + ConfigurationSchemaIdentifiers.UseBreakWater, + XmlConvert.ToString(input.UseBreakWater)); + + WriteBreakWaterProperties(input.BreakWater, writer); + + writer.WriteElementString( + ConfigurationSchemaIdentifiers.UseForeshore, + XmlConvert.ToString(input.UseForeshore)); + + writer.WriteEndElement(); + } + } +} \ No newline at end of file Index: Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Plugin/GrassCoverErosionInwardsPlugin.cs =================================================================== diff -u -rf9f7e585da06fc8ab1b8ab92ce4dd64bd66d8f04 -r96cd93f1a08294e5af3fec5f5ae0b59cbe914c4b --- Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Plugin/GrassCoverErosionInwardsPlugin.cs (.../GrassCoverErosionInwardsPlugin.cs) (revision f9f7e585da06fc8ab1b8ab92ce4dd64bd66d8f04) +++ Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Plugin/GrassCoverErosionInwardsPlugin.cs (.../GrassCoverErosionInwardsPlugin.cs) (revision 96cd93f1a08294e5af3fec5f5ae0b59cbe914c4b) @@ -44,7 +44,7 @@ using Ringtoets.GrassCoverErosionInwards.Forms.PresentationObjects; using Ringtoets.GrassCoverErosionInwards.Forms.PropertyClasses; using Ringtoets.GrassCoverErosionInwards.Forms.Views; -using Ringtoets.GrassCoverErosionInwards.IO; +using Ringtoets.GrassCoverErosionInwards.IO.Exporters; using Ringtoets.GrassCoverErosionInwards.Service; using Ringtoets.GrassCoverErosionInwards.Utils; using GrassCoverErosionInwardsPluginResources = Ringtoets.GrassCoverErosionInwards.Plugin.Properties.Resources; Index: Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.IO.Test/Exporters/GrassCoverErosionInwardsCalculationConfigurationExporterTest.cs =================================================================== diff -u --- Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.IO.Test/Exporters/GrassCoverErosionInwardsCalculationConfigurationExporterTest.cs (revision 0) +++ Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.IO.Test/Exporters/GrassCoverErosionInwardsCalculationConfigurationExporterTest.cs (revision 96cd93f1a08294e5af3fec5f5ae0b59cbe914c4b) @@ -0,0 +1,141 @@ +// 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.IO; +using System.Linq; +using System.Security.AccessControl; +using Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.Common.Data.Calculation; +using Ringtoets.Common.IO.Exporters; +using Ringtoets.GrassCoverErosionInwards.Data; +using Ringtoets.GrassCoverErosionInwards.IO.Exporters; +using Ringtoets.GrassCoverErosionInwards.IO.Writers; + +namespace Ringtoets.GrassCoverErosionInwards.IO.Test.Exporters +{ + [TestFixture] + public class GrassCoverErosionInwardsCalculationConfigurationExporterTest + { + [Test] + public void Constructor_ExpectedValues() + { + // Call + var exporter = new GrassCoverErosionInwardsCalculationConfigurationExporter(Enumerable.Empty(), "test.xml"); + + // Assert + Assert.IsInstanceOf< + CalculationConfigurationExporter< + GrassCoverErosionInwardsCalculationConfigurationWriter, + GrassCoverErosionInwardsCalculation>>(exporter); + } + + [Test] + public void Export_ValidData_ReturnTrueAndWritesFile() + { + // Setup + string filePath = TestHelper.GetScratchPadPath($"{nameof(Export_ValidData_ReturnTrueAndWritesFile)}.xml"); + + GrassCoverErosionInwardsCalculation calculation = new GrassCoverErosionInwardsCalculation + { + Name = "Berekening 1" + }; + GrassCoverErosionInwardsCalculation calculation2 = new GrassCoverErosionInwardsCalculation + { + Name = "Berekening 2" + }; + + var calculationGroup2 = new CalculationGroup("Nested", false) + { + Children = + { + calculation2 + } + }; + + var calculationGroup = new CalculationGroup("Testmap", false) + { + Children = + { + calculation, + calculationGroup2 + } + }; + + var exporter = new GrassCoverErosionInwardsCalculationConfigurationExporter(new[] + { + calculationGroup + }, filePath); + + try + { + // Call + bool isExported = exporter.Export(); + + // Assert + Assert.IsTrue(isExported); + Assert.IsTrue(File.Exists(filePath)); + + string actualXml = File.ReadAllText(filePath); + string expectedXmlFilePath = TestHelper.GetTestDataPath( + TestDataPath.Ringtoets.GrassCoverErosionInwards.IO, + Path.Combine(nameof(GrassCoverErosionInwardsCalculationConfigurationExporter), "folderWithSubfolderAndCalculation.xml")); + + string expectedXml = File.ReadAllText(expectedXmlFilePath); + + Assert.AreEqual(expectedXml, actualXml); + } + finally + { + File.Delete(filePath); + } + } + + [Test] + public void Export_InvalidDirectoryRights_LogErrorAndReturnFalse() + { + // Setup + string directoryPath = TestHelper.GetScratchPadPath(nameof(Export_InvalidDirectoryRights_LogErrorAndReturnFalse)); + using (var disposeHelper = new DirectoryDisposeHelper(TestHelper.GetScratchPadPath(), nameof(Export_InvalidDirectoryRights_LogErrorAndReturnFalse))) + { + string filePath = Path.Combine(directoryPath, "test.xml"); + + var exporter = new GrassCoverErosionInwardsCalculationConfigurationExporter(new[] + { + new GrassCoverErosionInwardsCalculation() + }, filePath); + + disposeHelper.LockDirectory(FileSystemRights.Write); + + // Call + var isExported = true; + Action call = () => isExported = exporter.Export(); + + // Assert + string expectedMessage = $"Er is een onverwachte fout opgetreden tijdens het schrijven van het bestand '{filePath}'. " + + "Er is geen configuratie geëxporteerd."; + TestHelper.AssertLogMessageIsGenerated(call, expectedMessage); + Assert.IsFalse(isExported); + } + } + } +} \ No newline at end of file Fisheye: Tag 96cd93f1a08294e5af3fec5f5ae0b59cbe914c4b refers to a dead (removed) revision in file `Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.IO.Test/GrassCoverErosionInwardsCalculationConfigurationExporterTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 96cd93f1a08294e5af3fec5f5ae0b59cbe914c4b refers to a dead (removed) revision in file `Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.IO.Test/GrassCoverErosionInwardsCalculationConfigurationWriterTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.IO.Test/Ringtoets.GrassCoverErosionInwards.IO.Test.csproj =================================================================== diff -u -rf9f7e585da06fc8ab1b8ab92ce4dd64bd66d8f04 -r96cd93f1a08294e5af3fec5f5ae0b59cbe914c4b --- Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.IO.Test/Ringtoets.GrassCoverErosionInwards.IO.Test.csproj (.../Ringtoets.GrassCoverErosionInwards.IO.Test.csproj) (revision f9f7e585da06fc8ab1b8ab92ce4dd64bd66d8f04) +++ Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.IO.Test/Ringtoets.GrassCoverErosionInwards.IO.Test.csproj (.../Ringtoets.GrassCoverErosionInwards.IO.Test.csproj) (revision 96cd93f1a08294e5af3fec5f5ae0b59cbe914c4b) @@ -50,8 +50,8 @@ Properties\GlobalAssembly.cs - - + + Index: Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.IO.Test/Writers/GrassCoverErosionInwardsCalculationConfigurationWriterTest.cs =================================================================== diff -u --- Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.IO.Test/Writers/GrassCoverErosionInwardsCalculationConfigurationWriterTest.cs (revision 0) +++ Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.IO.Test/Writers/GrassCoverErosionInwardsCalculationConfigurationWriterTest.cs (revision 96cd93f1a08294e5af3fec5f5ae0b59cbe914c4b) @@ -0,0 +1,285 @@ +// 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.IO; +using System.Linq; +using System.Security.AccessControl; +using Core.Common.Base.Data; +using Core.Common.IO.Exceptions; +using Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.Common.Data.Calculation; +using Ringtoets.Common.Data.DikeProfiles; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.GrassCoverErosionInwards.Data; +using Ringtoets.GrassCoverErosionInwards.IO.Writers; + +namespace Ringtoets.GrassCoverErosionInwards.IO.Test.Writers +{ + [TestFixture] + public class GrassCoverErosionInwardsCalculationConfigurationWriterTest + { + [Test] + public void Write_ConfigurationNull_ThrowArgumentNullException() + { + // Call + TestDelegate test = () => new GrassCoverErosionInwardsCalculationConfigurationWriter().Write(null, string.Empty); + + // Assert + var exception = Assert.Throws(test); + Assert.AreEqual("configuration", exception.ParamName); + } + + [Test] + public void Write_FilePathNull_ThrowArgumentNullException() + { + // Call + TestDelegate test = () => new GrassCoverErosionInwardsCalculationConfigurationWriter().Write(Enumerable.Empty(), null); + + // Assert + var exception = Assert.Throws(test); + Assert.AreEqual("filePath", exception.ParamName); + } + + [Test] + [TestCase("")] + [TestCase(" ")] + [TestCase("c:\\>")] + public void Write_FilePathInvalid_ThrowCriticalFileWriteException(string filePath) + { + // Call + TestDelegate call = () => new GrassCoverErosionInwardsCalculationConfigurationWriter().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); + Assert.IsInstanceOf(exception.InnerException); + } + + [Test] + public void Write_FilePathTooLong_ThrowCriticalFileWriteException() + { + // Setup + var filePath = new string('a', 249); + + // Call + TestDelegate call = () => new GrassCoverErosionInwardsCalculationConfigurationWriter().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); + Assert.IsInstanceOf(exception.InnerException); + } + + [Test] + public void Write_InvalidDirectoryRights_ThrowCriticalFileWriteException() + { + // Setup + string directoryPath = TestHelper.GetScratchPadPath(nameof(Write_InvalidDirectoryRights_ThrowCriticalFileWriteException)); + using (var disposeHelper = new DirectoryDisposeHelper(TestHelper.GetScratchPadPath(), nameof(Write_InvalidDirectoryRights_ThrowCriticalFileWriteException))) + { + string filePath = Path.Combine(directoryPath, "test.xml"); + disposeHelper.LockDirectory(FileSystemRights.Write); + + // Call + TestDelegate call = () => new GrassCoverErosionInwardsCalculationConfigurationWriter().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); + Assert.IsInstanceOf(exception.InnerException); + } + } + + [Test] + public void Write_FileInUse_ThrowCriticalFileWriteException() + { + // Setup + string path = TestHelper.GetScratchPadPath(nameof(Write_FileInUse_ThrowCriticalFileWriteException)); + + using (var fileDisposeHelper = new FileDisposeHelper(path)) + { + fileDisposeHelper.LockFiles(); + + // Call + TestDelegate call = () => new GrassCoverErosionInwardsCalculationConfigurationWriter().Write(Enumerable.Empty(), path); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual($"Er is een onverwachte fout opgetreden tijdens het schrijven van het bestand '{path}'.", exception.Message); + Assert.IsInstanceOf(exception.InnerException); + } + } + + [Test] + public void WriteConfiguration_SparseCalculation_WritesSparseConfigurationToFile() + { + // Setup + string filePath = TestHelper.GetScratchPadPath( + $"{nameof(WriteConfiguration_SparseCalculation_WritesSparseConfigurationToFile)}.xml"); + + string expectedXmlFilePath = TestHelper.GetTestDataPath( + TestDataPath.Ringtoets.GrassCoverErosionInwards.IO, + Path.Combine(nameof(GrassCoverErosionInwardsCalculationConfigurationWriter), "sparseConfiguration.xml")); + + var calculation = new GrassCoverErosionInwardsCalculation() + { + Name = "Berekening 1" + }; + + try + { + var writer = new GrassCoverErosionInwardsCalculationConfigurationWriter(); + + // Call + writer.Write(new[] + { + calculation + }, filePath); + + // Assert + string actualXml = File.ReadAllText(filePath); + string expectedXml = File.ReadAllText(expectedXmlFilePath); + + Assert.AreEqual(expectedXml, actualXml); + } + finally + { + File.Delete(filePath); + } + } + + [Test] + public void WriteConfiguration_CompleteCalculation_WritesCompleteConfigurationToFile() + { + // Setup + string filePath = TestHelper.GetScratchPadPath( + $"{nameof(WriteConfiguration_CompleteCalculation_WritesCompleteConfigurationToFile)}.xml"); + + string expectedXmlFilePath = TestHelper.GetTestDataPath( + TestDataPath.Ringtoets.GrassCoverErosionInwards.IO, + Path.Combine(nameof(GrassCoverErosionInwardsCalculationConfigurationWriter), "completeConfiguration.xml")); + + GrassCoverErosionInwardsCalculation calculation = CreateCompleteCalculation(); + + try + { + var writer = new GrassCoverErosionInwardsCalculationConfigurationWriter(); + + // Call + writer.Write(new[] + { + calculation + }, filePath); + + // Assert + string actualXml = File.ReadAllText(filePath); + string expectedXml = File.ReadAllText(expectedXmlFilePath); + + Assert.AreEqual(expectedXml, actualXml); + } + finally + { + File.Delete(filePath); + } + } + + [Test] + public void Write_NestedConfiguration_ValidFile() + { + // Setup + string filePath = TestHelper.GetScratchPadPath("test.xml"); + + GrassCoverErosionInwardsCalculation calculation = CreateCompleteCalculation(); + GrassCoverErosionInwardsCalculation calculation2 = new GrassCoverErosionInwardsCalculation + { + Name = "Berekening 2" + }; + var calculationGroup2 = new CalculationGroup("Nested", false) + { + Children = + { + calculation2 + } + }; + + var calculationGroup = new CalculationGroup("Testmap", false) + { + Children = + { + calculation, + calculationGroup2 + } + }; + + try + { + // Call + new GrassCoverErosionInwardsCalculationConfigurationWriter().Write(new[] + { + calculationGroup + }, filePath); + + // Assert + Assert.IsTrue(File.Exists(filePath)); + + string actualXml = File.ReadAllText(filePath); + string expectedXmlFilePath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.GrassCoverErosionInwards.IO, + Path.Combine("GrassCoverErosionInwardsCalculationConfigurationWriter", + "folderWithSubfolderAndCalculation.xml")); + string expectedXml = File.ReadAllText(expectedXmlFilePath); + + Assert.AreEqual(expectedXml, actualXml); + } + finally + { + File.Delete(filePath); + } + } + + private static GrassCoverErosionInwardsCalculation CreateCompleteCalculation() + { + return new GrassCoverErosionInwardsCalculation + { + Name = "Berekening 1", + InputParameters = + { + HydraulicBoundaryLocation = new TestHydraulicBoundaryLocation("Locatie1"), + DikeProfile = new TestDikeProfile("dijkProfiel"), + Orientation = (RoundedDouble) 67.1, + UseForeshore = true, + UseBreakWater = true, + BreakWater = + { + Height = (RoundedDouble) 1.23, + Type = BreakWaterType.Caisson + }, + CriticalFlowRate = + { + Mean = (RoundedDouble) 0.1, + StandardDeviation = (RoundedDouble) 0.1 + } + } + }; + } + } +} \ No newline at end of file Index: Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Plugin.Test/ExportInfos/GrassCoverErosionInwardsCalculationContextExportInfoTest.cs =================================================================== diff -u -rf9f7e585da06fc8ab1b8ab92ce4dd64bd66d8f04 -r96cd93f1a08294e5af3fec5f5ae0b59cbe914c4b --- Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Plugin.Test/ExportInfos/GrassCoverErosionInwardsCalculationContextExportInfoTest.cs (.../GrassCoverErosionInwardsCalculationContextExportInfoTest.cs) (revision f9f7e585da06fc8ab1b8ab92ce4dd64bd66d8f04) +++ Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Plugin.Test/ExportInfos/GrassCoverErosionInwardsCalculationContextExportInfoTest.cs (.../GrassCoverErosionInwardsCalculationContextExportInfoTest.cs) (revision 96cd93f1a08294e5af3fec5f5ae0b59cbe914c4b) @@ -28,7 +28,7 @@ using Ringtoets.Common.Data.AssessmentSection; using Ringtoets.GrassCoverErosionInwards.Data; using Ringtoets.GrassCoverErosionInwards.Forms.PresentationObjects; -using Ringtoets.GrassCoverErosionInwards.IO; +using Ringtoets.GrassCoverErosionInwards.IO.Exporters; namespace Ringtoets.GrassCoverErosionInwards.Plugin.Test.ExportInfos { Index: Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Plugin.Test/ExportInfos/GrassCoverErosionInwardsCalculationGroupContextExportInfoTest.cs =================================================================== diff -u -rf9f7e585da06fc8ab1b8ab92ce4dd64bd66d8f04 -r96cd93f1a08294e5af3fec5f5ae0b59cbe914c4b --- Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Plugin.Test/ExportInfos/GrassCoverErosionInwardsCalculationGroupContextExportInfoTest.cs (.../GrassCoverErosionInwardsCalculationGroupContextExportInfoTest.cs) (revision f9f7e585da06fc8ab1b8ab92ce4dd64bd66d8f04) +++ Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Plugin.Test/ExportInfos/GrassCoverErosionInwardsCalculationGroupContextExportInfoTest.cs (.../GrassCoverErosionInwardsCalculationGroupContextExportInfoTest.cs) (revision 96cd93f1a08294e5af3fec5f5ae0b59cbe914c4b) @@ -29,14 +29,13 @@ using Ringtoets.Common.Data.Calculation; using Ringtoets.GrassCoverErosionInwards.Data; using Ringtoets.GrassCoverErosionInwards.Forms.PresentationObjects; -using Ringtoets.GrassCoverErosionInwards.IO; +using Ringtoets.GrassCoverErosionInwards.IO.Exporters; namespace Ringtoets.GrassCoverErosionInwards.Plugin.Test.ExportInfos { [TestFixture] public class GrassCoverErosionInwardsCalculationGroupContextExportInfoTest { - [Test] public void Initialized_Always_ExpectedPropertiesSet() { @@ -65,8 +64,8 @@ mocks.ReplayAll(); var context = new GrassCoverErosionInwardsCalculationGroupContext(new CalculationGroup(), - new GrassCoverErosionInwardsFailureMechanism(), - assessmentSection); + new GrassCoverErosionInwardsFailureMechanism(), + assessmentSection); using (var plugin = new GrassCoverErosionInwardsPlugin()) { @@ -106,8 +105,8 @@ mocks.ReplayAll(); var context = new GrassCoverErosionInwardsCalculationGroupContext(new CalculationGroup(), - new GrassCoverErosionInwardsFailureMechanism(), - assessmentSection); + new GrassCoverErosionInwardsFailureMechanism(), + assessmentSection); using (var plugin = new GrassCoverErosionInwardsPlugin()) { @@ -145,8 +144,8 @@ } var context = new GrassCoverErosionInwardsCalculationGroupContext(calculationGroup, - new GrassCoverErosionInwardsFailureMechanism(), - assessmentSection); + new GrassCoverErosionInwardsFailureMechanism(), + assessmentSection); using (var plugin = new GrassCoverErosionInwardsPlugin()) { Index: Ringtoets/GrassCoverErosionOutwards/src/Ringtoets.GrassCoverErosionOutwards.IO/Exporters/GrassCoverErosionOutwardsCalculationConfigurationExporter.cs =================================================================== diff -u --- Ringtoets/GrassCoverErosionOutwards/src/Ringtoets.GrassCoverErosionOutwards.IO/Exporters/GrassCoverErosionOutwardsCalculationConfigurationExporter.cs (revision 0) +++ Ringtoets/GrassCoverErosionOutwards/src/Ringtoets.GrassCoverErosionOutwards.IO/Exporters/GrassCoverErosionOutwardsCalculationConfigurationExporter.cs (revision 96cd93f1a08294e5af3fec5f5ae0b59cbe914c4b) @@ -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.Collections.Generic; +using Ringtoets.Common.Data.Calculation; +using Ringtoets.Common.IO.Exporters; +using Ringtoets.GrassCoverErosionOutwards.Data; +using Ringtoets.GrassCoverErosionOutwards.IO.Writers; + +namespace Ringtoets.GrassCoverErosionOutwards.IO.Exporters +{ + /// + /// Exports a grass cover erosion outwards configuration and stores it as an XML file. + /// + public class GrassCoverErosionOutwardsCalculationConfigurationExporter + : CalculationConfigurationExporter + { + /// + /// Creates a new instance of . + /// + /// The configuration to export. + /// The path of the XML file to export to. + /// Thrown when is null. + /// Thrown when is invalid. + public GrassCoverErosionOutwardsCalculationConfigurationExporter(IEnumerable configuration, string filePath) + : base(configuration, filePath) {} + } +} \ No newline at end of file Index: Ringtoets/GrassCoverErosionOutwards/src/Ringtoets.GrassCoverErosionOutwards.IO/Exporters/GrassCoverErosionOutwardsWaveConditionsExporter.cs =================================================================== diff -u --- Ringtoets/GrassCoverErosionOutwards/src/Ringtoets.GrassCoverErosionOutwards.IO/Exporters/GrassCoverErosionOutwardsWaveConditionsExporter.cs (revision 0) +++ Ringtoets/GrassCoverErosionOutwards/src/Ringtoets.GrassCoverErosionOutwards.IO/Exporters/GrassCoverErosionOutwardsWaveConditionsExporter.cs (revision 96cd93f1a08294e5af3fec5f5ae0b59cbe914c4b) @@ -0,0 +1,70 @@ +// 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.Linq; +using Core.Common.IO.Exceptions; +using Ringtoets.GrassCoverErosionOutwards.Data; +using Ringtoets.Revetment.IO; +using Ringtoets.Revetment.IO.Exporters; + +namespace Ringtoets.GrassCoverErosionOutwards.IO.Exporters +{ + /// + /// Exports grass cover erosion outwards wave conditions and stores then as a csv file. + /// + public class GrassCoverErosionOutwardsWaveConditionsExporter : WaveConditionsExporterBase + { + /// + /// Creates a new instance of . + /// + /// The objects to export. + /// The file path to export to. + /// Thrown when any parameter is null. + /// Thrown when is invalid. + /// Thrown when the file could not be written. + public GrassCoverErosionOutwardsWaveConditionsExporter(IEnumerable calculations, string filePath) + : base(CreateExportableWaveConditionsCollection(calculations), filePath) {} + + private static IEnumerable CreateExportableWaveConditionsCollection(IEnumerable calculations) + { + if (calculations == null) + { + throw new ArgumentNullException(nameof(calculations)); + } + + var exportableWaveConditions = new List(); + + IEnumerable exportableCalculations = + calculations.Where(c => c.HasOutput && c.InputParameters.HydraulicBoundaryLocation != null); + + foreach (GrassCoverErosionOutwardsWaveConditionsCalculation calculation in exportableCalculations) + { + exportableWaveConditions.AddRange( + ExportableWaveConditionsFactory.CreateExportableWaveConditionsCollection( + calculation.Name, calculation.InputParameters, calculation.Output.Items, CoverType.Grass)); + } + + return exportableWaveConditions; + } + } +} \ No newline at end of file Fisheye: Tag 96cd93f1a08294e5af3fec5f5ae0b59cbe914c4b refers to a dead (removed) revision in file `Ringtoets/GrassCoverErosionOutwards/src/Ringtoets.GrassCoverErosionOutwards.IO/GrassCoverErosionOutwardsCalculationConfigurationExporter.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 96cd93f1a08294e5af3fec5f5ae0b59cbe914c4b refers to a dead (removed) revision in file `Ringtoets/GrassCoverErosionOutwards/src/Ringtoets.GrassCoverErosionOutwards.IO/GrassCoverErosionOutwardsCalculationConfigurationWriter.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 96cd93f1a08294e5af3fec5f5ae0b59cbe914c4b refers to a dead (removed) revision in file `Ringtoets/GrassCoverErosionOutwards/src/Ringtoets.GrassCoverErosionOutwards.IO/GrassCoverErosionOutwardsWaveConditionsExporter.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Ringtoets/GrassCoverErosionOutwards/src/Ringtoets.GrassCoverErosionOutwards.IO/Ringtoets.GrassCoverErosionOutwards.IO.csproj =================================================================== diff -u -rf9f7e585da06fc8ab1b8ab92ce4dd64bd66d8f04 -r96cd93f1a08294e5af3fec5f5ae0b59cbe914c4b --- Ringtoets/GrassCoverErosionOutwards/src/Ringtoets.GrassCoverErosionOutwards.IO/Ringtoets.GrassCoverErosionOutwards.IO.csproj (.../Ringtoets.GrassCoverErosionOutwards.IO.csproj) (revision f9f7e585da06fc8ab1b8ab92ce4dd64bd66d8f04) +++ Ringtoets/GrassCoverErosionOutwards/src/Ringtoets.GrassCoverErosionOutwards.IO/Ringtoets.GrassCoverErosionOutwards.IO.csproj (.../Ringtoets.GrassCoverErosionOutwards.IO.csproj) (revision 96cd93f1a08294e5af3fec5f5ae0b59cbe914c4b) @@ -44,9 +44,9 @@ Properties\GlobalAssembly.cs - - - + + + Index: Ringtoets/GrassCoverErosionOutwards/src/Ringtoets.GrassCoverErosionOutwards.IO/Writers/GrassCoverErosionOutwardsCalculationConfigurationWriter.cs =================================================================== diff -u --- Ringtoets/GrassCoverErosionOutwards/src/Ringtoets.GrassCoverErosionOutwards.IO/Writers/GrassCoverErosionOutwardsCalculationConfigurationWriter.cs (revision 0) +++ Ringtoets/GrassCoverErosionOutwards/src/Ringtoets.GrassCoverErosionOutwards.IO/Writers/GrassCoverErosionOutwardsCalculationConfigurationWriter.cs (revision 96cd93f1a08294e5af3fec5f5ae0b59cbe914c4b) @@ -0,0 +1,40 @@ +// 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.Xml; +using Ringtoets.Common.Data.Calculation; +using Ringtoets.GrassCoverErosionOutwards.Data; +using Ringtoets.Revetment.IO.Writers; + +namespace Ringtoets.GrassCoverErosionOutwards.IO.Writers +{ + /// + /// A writer for writing out configurations of and + /// , to XML format. + /// + public class GrassCoverErosionOutwardsCalculationConfigurationWriter : WaveConditionsCalculationConfigurationWriter + { + protected override void WriteCalculation(GrassCoverErosionOutwardsWaveConditionsCalculation calculation, XmlWriter writer) + { + WriteCalculation(calculation.Name, calculation.InputParameters, writer); + } + } +} \ No newline at end of file Index: Ringtoets/GrassCoverErosionOutwards/src/Ringtoets.GrassCoverErosionOutwards.Plugin/GrassCoverErosionOutwardsPlugin.cs =================================================================== diff -u -rf9f7e585da06fc8ab1b8ab92ce4dd64bd66d8f04 -r96cd93f1a08294e5af3fec5f5ae0b59cbe914c4b --- Ringtoets/GrassCoverErosionOutwards/src/Ringtoets.GrassCoverErosionOutwards.Plugin/GrassCoverErosionOutwardsPlugin.cs (.../GrassCoverErosionOutwardsPlugin.cs) (revision f9f7e585da06fc8ab1b8ab92ce4dd64bd66d8f04) +++ Ringtoets/GrassCoverErosionOutwards/src/Ringtoets.GrassCoverErosionOutwards.Plugin/GrassCoverErosionOutwardsPlugin.cs (.../GrassCoverErosionOutwardsPlugin.cs) (revision 96cd93f1a08294e5af3fec5f5ae0b59cbe914c4b) @@ -48,7 +48,7 @@ using Ringtoets.GrassCoverErosionOutwards.Forms.PresentationObjects; using Ringtoets.GrassCoverErosionOutwards.Forms.PropertyClasses; using Ringtoets.GrassCoverErosionOutwards.Forms.Views; -using Ringtoets.GrassCoverErosionOutwards.IO; +using Ringtoets.GrassCoverErosionOutwards.IO.Exporters; using Ringtoets.GrassCoverErosionOutwards.Plugin.Properties; using Ringtoets.GrassCoverErosionOutwards.Service; using Ringtoets.GrassCoverErosionOutwards.Service.MessageProviders; Index: Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.IO.Test/Exporters/GrassCoverErosionOutwardsCalculationConfigurationExporterTest.cs =================================================================== diff -u --- Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.IO.Test/Exporters/GrassCoverErosionOutwardsCalculationConfigurationExporterTest.cs (revision 0) +++ Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.IO.Test/Exporters/GrassCoverErosionOutwardsCalculationConfigurationExporterTest.cs (revision 96cd93f1a08294e5af3fec5f5ae0b59cbe914c4b) @@ -0,0 +1,122 @@ +// 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.IO; +using System.Linq; +using Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.Common.Data.Calculation; +using Ringtoets.Common.Data.Hydraulics; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.Common.IO.Exporters; +using Ringtoets.GrassCoverErosionOutwards.Data; +using Ringtoets.GrassCoverErosionOutwards.IO.Exporters; +using Ringtoets.GrassCoverErosionOutwards.IO.Writers; + +namespace Ringtoets.GrassCoverErosionOutwards.IO.Test.Exporters +{ + [TestFixture] + public class GrassCoverErosionOutwardsCalculationConfigurationExporterTest + { + [Test] + public void Constructor_ExpectedValues() + { + // Call + var exporter = new GrassCoverErosionOutwardsCalculationConfigurationExporter(Enumerable.Empty(), "test.xml"); + + // Assert + Assert.IsInstanceOf< + CalculationConfigurationExporter< + GrassCoverErosionOutwardsCalculationConfigurationWriter, + GrassCoverErosionOutwardsWaveConditionsCalculation>>(exporter); + } + + [Test] + public void Export_ValidData_ReturnTrueAndWritesFile() + { + // Setup + string filePath = TestHelper.GetScratchPadPath($"{nameof(Export_ValidData_ReturnTrueAndWritesFile)}.xml"); + + var calculation1 = new GrassCoverErosionOutwardsWaveConditionsCalculation + { + Name = "Calculation A", + InputParameters = + { + ForeshoreProfile = new TestForeshoreProfile("ForeshoreA") + } + }; + + var calculation2 = new GrassCoverErosionOutwardsWaveConditionsCalculation + { + Name = "PK001_0002 W1-6_4_1D1", + InputParameters = + { + HydraulicBoundaryLocation = new HydraulicBoundaryLocation(1, "HydraulicLocationA", 0, 0), + UseBreakWater = true + } + }; + + var calculationGroup2 = new CalculationGroup("PK001_0002", false) + { + Children = + { + calculation2 + } + }; + + var calculationGroup = new CalculationGroup("PK001_0001", false) + { + Children = + { + calculation1, + calculationGroup2 + } + }; + + var exporter = new GrassCoverErosionOutwardsCalculationConfigurationExporter(new [] + { + calculationGroup + }, filePath); + + try + { + // Call + bool isExported = exporter.Export(); + + // Assert + Assert.IsTrue(isExported); + Assert.IsTrue(File.Exists(filePath)); + + string actualXml = File.ReadAllText(filePath); + string testDirSubPath = Path.Combine(nameof(GrassCoverErosionOutwardsCalculationConfigurationExporter), "fullValidConfiguration.xml"); + string expectedXmlFilePath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.GrassCoverErosionOutwards.IO, + testDirSubPath); + string expectedXml = File.ReadAllText(expectedXmlFilePath); + + Assert.AreEqual(expectedXml, actualXml); + } + finally + { + File.Delete(filePath); + } + } + } +} \ No newline at end of file Index: Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.IO.Test/Exporters/GrassCoverErosionOutwardsWaveConditionsExporterTest.cs =================================================================== diff -u --- Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.IO.Test/Exporters/GrassCoverErosionOutwardsWaveConditionsExporterTest.cs (revision 0) +++ Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.IO.Test/Exporters/GrassCoverErosionOutwardsWaveConditionsExporterTest.cs (revision 96cd93f1a08294e5af3fec5f5ae0b59cbe914c4b) @@ -0,0 +1,68 @@ +// 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 Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.GrassCoverErosionOutwards.Data; +using Ringtoets.GrassCoverErosionOutwards.IO.Exporters; +using Ringtoets.Revetment.IO.Exporters; + +namespace Ringtoets.GrassCoverErosionOutwards.IO.Test.Exporters +{ + [TestFixture] + public class GrassCoverErosionOutwardsWaveConditionsExporterTest + { + private readonly string testFilePath = TestHelper.GetScratchPadPath($"{nameof(GrassCoverErosionOutwardsWaveConditionsExporterTest)}.csv"); + + [Test] + public void Constructor_ValidParameters_ExpectedValues() + { + // Call + var waveConditionsExporter = new GrassCoverErosionOutwardsWaveConditionsExporter(new GrassCoverErosionOutwardsWaveConditionsCalculation[0], testFilePath); + + // Assert + Assert.IsInstanceOf(waveConditionsExporter); + } + + [Test] + public void Constructor_CalculationNull_ThrowArgumentNullException() + { + // Call + TestDelegate call = () => new GrassCoverErosionOutwardsWaveConditionsExporter(null, testFilePath); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("calculations", exception.ParamName); + } + + [Test] + public void Constructor_FilePathNull_ThrowArgumentNullException() + { + // Call + TestDelegate call = () => new GrassCoverErosionOutwardsWaveConditionsExporter(new GrassCoverErosionOutwardsWaveConditionsCalculation[0], null); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("filePath", exception.ParamName); + } + } +} \ No newline at end of file Fisheye: Tag 96cd93f1a08294e5af3fec5f5ae0b59cbe914c4b refers to a dead (removed) revision in file `Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.IO.Test/GrassCoverErosionOutwardsCalculationConfigurationExporterTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 96cd93f1a08294e5af3fec5f5ae0b59cbe914c4b refers to a dead (removed) revision in file `Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.IO.Test/GrassCoverErosionOutwardsCalculationConfigurationWriterTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 96cd93f1a08294e5af3fec5f5ae0b59cbe914c4b refers to a dead (removed) revision in file `Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.IO.Test/GrassCoverErosionOutwardsWaveConditionsExporterTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.IO.Test/Ringtoets.GrassCoverErosionOutwards.IO.Test.csproj =================================================================== diff -u -rf9f7e585da06fc8ab1b8ab92ce4dd64bd66d8f04 -r96cd93f1a08294e5af3fec5f5ae0b59cbe914c4b --- Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.IO.Test/Ringtoets.GrassCoverErosionOutwards.IO.Test.csproj (.../Ringtoets.GrassCoverErosionOutwards.IO.Test.csproj) (revision f9f7e585da06fc8ab1b8ab92ce4dd64bd66d8f04) +++ Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.IO.Test/Ringtoets.GrassCoverErosionOutwards.IO.Test.csproj (.../Ringtoets.GrassCoverErosionOutwards.IO.Test.csproj) (revision 96cd93f1a08294e5af3fec5f5ae0b59cbe914c4b) @@ -50,9 +50,9 @@ Properties\GlobalAssembly.cs - - - + + + Index: Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.IO.Test/Writers/GrassCoverErosionOutwardsCalculationConfigurationWriterTest.cs =================================================================== diff -u --- Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.IO.Test/Writers/GrassCoverErosionOutwardsCalculationConfigurationWriterTest.cs (revision 0) +++ Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.IO.Test/Writers/GrassCoverErosionOutwardsCalculationConfigurationWriterTest.cs (revision 96cd93f1a08294e5af3fec5f5ae0b59cbe914c4b) @@ -0,0 +1,105 @@ +// 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.IO; +using Core.Common.Base.Data; +using Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.Common.Data.Calculation; +using Ringtoets.Common.Data.DikeProfiles; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.GrassCoverErosionOutwards.Data; +using Ringtoets.GrassCoverErosionOutwards.IO.Writers; +using Ringtoets.Revetment.Data; +using Ringtoets.Revetment.IO.Writers; + +namespace Ringtoets.GrassCoverErosionOutwards.IO.Test.Writers +{ + [TestFixture] + public class GrassCoverErosionOutwardsCalculationConfigurationWriterTest + { + [Test] + public void Constructor_Always_CreateWaveConditionsInputWriter() + { + // Call + var writer = new GrassCoverErosionOutwardsCalculationConfigurationWriter(); + + // Assert + Assert.IsInstanceOf>(writer); + } + + [Test] + public void Write_GroupWithCalculationAndOtherGroup_WritesOutCalculationAndGroupToFile() + { + // Setup + string filePath = TestHelper.GetScratchPadPath("Write_GroupWithCalculationAndOtherGroup.xml"); + string expectedXmlFilePath = TestHelper.GetTestDataPath( + TestDataPath.Ringtoets.GrassCoverErosionOutwards.IO, + Path.Combine(nameof(GrassCoverErosionOutwardsCalculationConfigurationWriter), "calculationAndGroupWithNesting.xml")); + + var calculation = new GrassCoverErosionOutwardsWaveConditionsCalculation + { + Name = "Berekening 1", + InputParameters = + { + HydraulicBoundaryLocation = new TestHydraulicBoundaryLocation("hr_locatie_2"), + UpperBoundaryRevetment = (RoundedDouble) 2.5, + LowerBoundaryRevetment = (RoundedDouble) 1.3, + UpperBoundaryWaterLevels = (RoundedDouble) 2.2, + LowerBoundaryWaterLevels = (RoundedDouble) (-0.2), + StepSize = WaveConditionsInputStepSize.Two, + ForeshoreProfile = new TestForeshoreProfile("profiel2"), + Orientation = (RoundedDouble) 12.3, + UseForeshore = true, + UseBreakWater = true, + BreakWater = + { + Height = (RoundedDouble) 2.11, + Type = BreakWaterType.Wall + } + } + }; + + var calculationGroup = new CalculationGroup("NestedGroup", false); + try + { + var writer = new GrassCoverErosionOutwardsCalculationConfigurationWriter(); + + // Call + writer.Write(new ICalculationBase[] + { + calculation, + calculationGroup + }, filePath); + + // Assert + string actualXml = File.ReadAllText(filePath); + string expectedXml = File.ReadAllText(expectedXmlFilePath); + + Assert.AreEqual(expectedXml, actualXml); + } + finally + { + File.Delete(filePath); + } + } + } +} \ No newline at end of file Index: Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.Plugin.Test/ExportInfos/GrassCoverErosionOutwardsWaveConditionsCalculationContextExportInfoTest.cs =================================================================== diff -u -rf9f7e585da06fc8ab1b8ab92ce4dd64bd66d8f04 -r96cd93f1a08294e5af3fec5f5ae0b59cbe914c4b --- Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.Plugin.Test/ExportInfos/GrassCoverErosionOutwardsWaveConditionsCalculationContextExportInfoTest.cs (.../GrassCoverErosionOutwardsWaveConditionsCalculationContextExportInfoTest.cs) (revision f9f7e585da06fc8ab1b8ab92ce4dd64bd66d8f04) +++ Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.Plugin.Test/ExportInfos/GrassCoverErosionOutwardsWaveConditionsCalculationContextExportInfoTest.cs (.../GrassCoverErosionOutwardsWaveConditionsCalculationContextExportInfoTest.cs) (revision 96cd93f1a08294e5af3fec5f5ae0b59cbe914c4b) @@ -28,8 +28,8 @@ using Ringtoets.Common.Data.AssessmentSection; using Ringtoets.GrassCoverErosionOutwards.Data; using Ringtoets.GrassCoverErosionOutwards.Forms.PresentationObjects; -using Ringtoets.GrassCoverErosionOutwards.IO; -using Ringtoets.Revetment.IO; +using Ringtoets.GrassCoverErosionOutwards.IO.Exporters; +using Ringtoets.Revetment.IO.Exporters; using Ringtoets.Revetment.TestUtil; namespace Ringtoets.GrassCoverErosionOutwards.Plugin.Test.ExportInfos Index: Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.Plugin.Test/ExportInfos/GrassCoverErosionOutwardsWaveConditionsCalculationGroupContextExportInfoTest.cs =================================================================== diff -u -rf9f7e585da06fc8ab1b8ab92ce4dd64bd66d8f04 -r96cd93f1a08294e5af3fec5f5ae0b59cbe914c4b --- Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.Plugin.Test/ExportInfos/GrassCoverErosionOutwardsWaveConditionsCalculationGroupContextExportInfoTest.cs (.../GrassCoverErosionOutwardsWaveConditionsCalculationGroupContextExportInfoTest.cs) (revision f9f7e585da06fc8ab1b8ab92ce4dd64bd66d8f04) +++ Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.Plugin.Test/ExportInfos/GrassCoverErosionOutwardsWaveConditionsCalculationGroupContextExportInfoTest.cs (.../GrassCoverErosionOutwardsWaveConditionsCalculationGroupContextExportInfoTest.cs) (revision 96cd93f1a08294e5af3fec5f5ae0b59cbe914c4b) @@ -29,8 +29,8 @@ using Ringtoets.Common.Data.Calculation; using Ringtoets.GrassCoverErosionOutwards.Data; using Ringtoets.GrassCoverErosionOutwards.Forms.PresentationObjects; -using Ringtoets.GrassCoverErosionOutwards.IO; -using Ringtoets.Revetment.IO; +using Ringtoets.GrassCoverErosionOutwards.IO.Exporters; +using Ringtoets.Revetment.IO.Exporters; using Ringtoets.Revetment.TestUtil; namespace Ringtoets.GrassCoverErosionOutwards.Plugin.Test.ExportInfos Index: Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.Plugin.Test/ExportInfos/HydraulicBoundariesGroupContextExportInfoTest.cs =================================================================== diff -u -r4b68fcd10da185da7eef315c45d80a071c6e1bf5 -r96cd93f1a08294e5af3fec5f5ae0b59cbe914c4b --- Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.Plugin.Test/ExportInfos/HydraulicBoundariesGroupContextExportInfoTest.cs (.../HydraulicBoundariesGroupContextExportInfoTest.cs) (revision 4b68fcd10da185da7eef315c45d80a071c6e1bf5) +++ Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.Plugin.Test/ExportInfos/HydraulicBoundariesGroupContextExportInfoTest.cs (.../HydraulicBoundariesGroupContextExportInfoTest.cs) (revision 96cd93f1a08294e5af3fec5f5ae0b59cbe914c4b) @@ -32,7 +32,7 @@ using Ringtoets.Common.IO.Hydraulics; using Ringtoets.GrassCoverErosionOutwards.Data; using Ringtoets.GrassCoverErosionOutwards.Forms.PresentationObjects; -using Ringtoets.GrassCoverErosionOutwards.IO; +using Ringtoets.GrassCoverErosionOutwards.IO.Exporters; using Ringtoets.Revetment.Data; using RingtoetsCommonFormsResources = Ringtoets.Common.Forms.Properties.Resources; Index: Ringtoets/Revetment/src/Ringtoets.Revetment.IO/Exporters/WaveConditionsExporterBase.cs =================================================================== diff -u --- Ringtoets/Revetment/src/Ringtoets.Revetment.IO/Exporters/WaveConditionsExporterBase.cs (revision 0) +++ Ringtoets/Revetment/src/Ringtoets.Revetment.IO/Exporters/WaveConditionsExporterBase.cs (revision 96cd93f1a08294e5af3fec5f5ae0b59cbe914c4b) @@ -0,0 +1,81 @@ +// 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 Core.Common.Base.IO; +using Core.Common.IO.Exceptions; +using log4net; +using Ringtoets.Revetment.IO.Properties; +using Ringtoets.Revetment.IO.Writers; + +namespace Ringtoets.Revetment.IO.Exporters +{ + /// + /// Abstract class for wave conditions to csv file exporters. + /// + public abstract class WaveConditionsExporterBase : IFileExporter + { + private static readonly ILog log = LogManager.GetLogger(typeof(WaveConditionsExporterBase)); + + private readonly IEnumerable exportableWaveConditionsCollection; + private readonly string filePath; + + /// + /// Creates a new instance of . + /// + /// The objects to export. + /// The file path to export to. + /// Thrown when or + /// is null. + /// Thrown when is invalid. + /// Thrown when the file could not be written. + protected WaveConditionsExporterBase(IEnumerable exportableWaveConditionsCollection, string filePath) + { + if (exportableWaveConditionsCollection == null) + { + throw new ArgumentNullException(nameof(exportableWaveConditionsCollection)); + } + if (filePath == null) + { + throw new ArgumentNullException(nameof(filePath)); + } + + this.exportableWaveConditionsCollection = exportableWaveConditionsCollection; + this.filePath = filePath; + } + + public bool Export() + { + try + { + WaveConditionsWriter.WriteWaveConditions(exportableWaveConditionsCollection, filePath); + } + catch (CriticalFileWriteException e) + { + log.ErrorFormat(Resources.WaveConditionsExporter_Error_Exception_0_no_WaveConditions_exported, e.Message); + return false; + } + + return true; + } + } +} \ No newline at end of file Index: Ringtoets/Revetment/src/Ringtoets.Revetment.IO/Ringtoets.Revetment.IO.csproj =================================================================== diff -u -rf01786afaf51ad02f5be5e2a320461ebfe576bba -r96cd93f1a08294e5af3fec5f5ae0b59cbe914c4b --- Ringtoets/Revetment/src/Ringtoets.Revetment.IO/Ringtoets.Revetment.IO.csproj (.../Ringtoets.Revetment.IO.csproj) (revision f01786afaf51ad02f5be5e2a320461ebfe576bba) +++ Ringtoets/Revetment/src/Ringtoets.Revetment.IO/Ringtoets.Revetment.IO.csproj (.../Ringtoets.Revetment.IO.csproj) (revision 96cd93f1a08294e5af3fec5f5ae0b59cbe914c4b) @@ -58,10 +58,10 @@ - - + + - + Fisheye: Tag 96cd93f1a08294e5af3fec5f5ae0b59cbe914c4b refers to a dead (removed) revision in file `Ringtoets/Revetment/src/Ringtoets.Revetment.IO/WaveConditionsCalculationConfigurationWriter.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 96cd93f1a08294e5af3fec5f5ae0b59cbe914c4b refers to a dead (removed) revision in file `Ringtoets/Revetment/src/Ringtoets.Revetment.IO/WaveConditionsExporterBase.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 96cd93f1a08294e5af3fec5f5ae0b59cbe914c4b refers to a dead (removed) revision in file `Ringtoets/Revetment/src/Ringtoets.Revetment.IO/WaveConditionsWriter.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Ringtoets/Revetment/src/Ringtoets.Revetment.IO/Writers/WaveConditionsCalculationConfigurationWriter.cs =================================================================== diff -u --- Ringtoets/Revetment/src/Ringtoets.Revetment.IO/Writers/WaveConditionsCalculationConfigurationWriter.cs (revision 0) +++ Ringtoets/Revetment/src/Ringtoets.Revetment.IO/Writers/WaveConditionsCalculationConfigurationWriter.cs (revision 96cd93f1a08294e5af3fec5f5ae0b59cbe914c4b) @@ -0,0 +1,123 @@ +// 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.Xml; +using Ringtoets.Common.Data.Calculation; +using Ringtoets.Common.Data.DikeProfiles; +using Ringtoets.Common.Data.Hydraulics; +using Ringtoets.Common.IO.Schema; +using Ringtoets.Common.IO.Writers; +using Ringtoets.Revetment.Data; + +namespace Ringtoets.Revetment.IO.Writers +{ + /// + /// Base implementation of a writer for calculations that contain as input, + /// to XML format. + /// + /// The type of calculations that are written to file. + public abstract class WaveConditionsCalculationConfigurationWriter : CalculationConfigurationWriter where T : class, ICalculation + { + private readonly WaveConditionsInputStepSizeTypeConverter waveConditionsInputStepSizeConverter; + + protected WaveConditionsCalculationConfigurationWriter() + { + waveConditionsInputStepSizeConverter = new WaveConditionsInputStepSizeTypeConverter(); + } + + /// + /// Writes a single calculation with its in XML format to file. + /// + /// The name of the calculation to write. + /// The input of the calculation to write. + /// The writer to use for writing. + protected void WriteCalculation(string name, WaveConditionsInput input, XmlWriter writer) + { + writer.WriteStartElement(ConfigurationSchemaIdentifiers.CalculationElement); + writer.WriteAttributeString(ConfigurationSchemaIdentifiers.NameAttribute, name); + + WriteHydraulicBoundaryLocation(input.HydraulicBoundaryLocation, writer); + + writer.WriteElementString( + WaveConditionsConfigurationSchemaIdentifiers.UpperBoundaryRevetment, + XmlConvert.ToString(input.UpperBoundaryRevetment)); + writer.WriteElementString( + WaveConditionsConfigurationSchemaIdentifiers.LowerBoundaryRevetment, + XmlConvert.ToString(input.LowerBoundaryRevetment)); + writer.WriteElementString( + WaveConditionsConfigurationSchemaIdentifiers.UpperBoundaryWaterLevels, + XmlConvert.ToString(input.UpperBoundaryWaterLevels)); + writer.WriteElementString( + WaveConditionsConfigurationSchemaIdentifiers.LowerBoundaryWaterLevels, + XmlConvert.ToString(input.LowerBoundaryWaterLevels)); + writer.WriteElementString( + WaveConditionsConfigurationSchemaIdentifiers.StepSize, + waveConditionsInputStepSizeConverter.ConvertToInvariantString(input.StepSize)); + + WriteForeshoreProfile(input.ForeshoreProfile, writer); + + writer.WriteElementString( + ConfigurationSchemaIdentifiers.Orientation, + XmlConvert.ToString(input.Orientation)); + + WriteWaveReduction(input, writer); + + writer.WriteEndElement(); + } + + private static void WriteHydraulicBoundaryLocation(HydraulicBoundaryLocation hydraulicBoundaryLocation, XmlWriter writer) + { + if (hydraulicBoundaryLocation != null) + { + writer.WriteElementString( + ConfigurationSchemaIdentifiers.HydraulicBoundaryLocationElement, + hydraulicBoundaryLocation.Name); + } + } + + private static void WriteForeshoreProfile(ForeshoreProfile foreshoreProfile, XmlWriter writer) + { + if (foreshoreProfile != null) + { + writer.WriteElementString( + WaveConditionsConfigurationSchemaIdentifiers.ForeshoreProfile, + foreshoreProfile.Name); + } + } + + private static void WriteWaveReduction(WaveConditionsInput input, XmlWriter writer) + { + writer.WriteStartElement(ConfigurationSchemaIdentifiers.WaveReduction); + + writer.WriteElementString( + ConfigurationSchemaIdentifiers.UseBreakWater, + XmlConvert.ToString(input.UseBreakWater)); + + WriteBreakWaterProperties(input.BreakWater, writer); + + writer.WriteElementString( + ConfigurationSchemaIdentifiers.UseForeshore, + XmlConvert.ToString(input.UseForeshore)); + + writer.WriteEndElement(); + } + } +} \ No newline at end of file Index: Ringtoets/Revetment/src/Ringtoets.Revetment.IO/Writers/WaveConditionsWriter.cs =================================================================== diff -u --- Ringtoets/Revetment/src/Ringtoets.Revetment.IO/Writers/WaveConditionsWriter.cs (revision 0) +++ Ringtoets/Revetment/src/Ringtoets.Revetment.IO/Writers/WaveConditionsWriter.cs (revision 96cd93f1a08294e5af3fec5f5ae0b59cbe914c4b) @@ -0,0 +1,99 @@ +// 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.Globalization; +using System.IO; +using System.Text; +using Core.Common.Base.Data; +using Core.Common.IO.Exceptions; +using Ringtoets.Revetment.IO.Properties; +using CoreCommonUtilsResources = Core.Common.Utils.Properties.Resources; + +namespace Ringtoets.Revetment.IO.Writers +{ + /// + /// Csv file writer for writing objects to file. + /// + public static class WaveConditionsWriter + { + private const string separator = ", "; + + /// + /// Writes wave conditions to a csv file. + /// + /// The to be written to file. + /// The path to the csv file. + /// Thrown when or + /// is null. + /// Thrown when unable to write to . + public static void WriteWaveConditions(IEnumerable exportableWaveConditionsCollection, string filePath) + { + if (exportableWaveConditionsCollection == null) + { + throw new ArgumentNullException(nameof(exportableWaveConditionsCollection)); + } + if (filePath == null) + { + throw new ArgumentNullException(nameof(filePath)); + } + + var stringBuilder = new StringBuilder(Resources.WaveConditionsWriter_HeaderLine + Environment.NewLine); + + try + { + foreach (ExportableWaveConditions exportableWaveConditions in exportableWaveConditionsCollection) + { + stringBuilder.AppendLine(CreateCsvLine(exportableWaveConditions)); + } + + File.WriteAllText(filePath, stringBuilder.ToString()); + } + catch (SystemException e) + { + throw new CriticalFileWriteException(string.Format(CoreCommonUtilsResources.Error_General_output_error_0, filePath), e); + } + } + + private static string CreateCsvLine(ExportableWaveConditions exportableWaveConditions) + { + string[] stringComponents = + { + exportableWaveConditions.CalculationName, + exportableWaveConditions.LocationName, + new RoundedDouble(3, exportableWaveConditions.LocationXCoordinate).ToString(null, CultureInfo.InvariantCulture), + new RoundedDouble(3, exportableWaveConditions.LocationYCoordinate).ToString(null, CultureInfo.InvariantCulture), + exportableWaveConditions.ForeshoreName ?? string.Empty, + exportableWaveConditions.UseBreakWater ? Resources.Yes : Resources.No, + exportableWaveConditions.UseForeshore ? Resources.Yes : Resources.No, + exportableWaveConditions.CoverType.Name, + new RoundedDouble(2, exportableWaveConditions.WaterLevel).ToString(null, CultureInfo.InvariantCulture), + new RoundedDouble(2, exportableWaveConditions.WaveHeight).ToString(null, CultureInfo.InvariantCulture), + new RoundedDouble(2, exportableWaveConditions.WavePeriod).ToString(null, CultureInfo.InvariantCulture), + new RoundedDouble(2, exportableWaveConditions.WaveAngle).ToString(null, CultureInfo.InvariantCulture), + new RoundedDouble(2, exportableWaveConditions.WaveDirection).ToString(null, CultureInfo.InvariantCulture) + }; + + return string.Join(separator, stringComponents); + } + } +} \ No newline at end of file Index: Ringtoets/Revetment/test/Ringtoets.Revetment.IO.Test/Exporters/WaveConditionsExporterBaseTest.cs =================================================================== diff -u --- Ringtoets/Revetment/test/Ringtoets.Revetment.IO.Test/Exporters/WaveConditionsExporterBaseTest.cs (revision 0) +++ Ringtoets/Revetment/test/Ringtoets.Revetment.IO.Test/Exporters/WaveConditionsExporterBaseTest.cs (revision 96cd93f1a08294e5af3fec5f5ae0b59cbe914c4b) @@ -0,0 +1,182 @@ +// 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 Core.Common.Base.Data; +using Core.Common.Base.IO; +using Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.Common.Data.Hydraulics; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.Revetment.Data; +using Ringtoets.Revetment.IO.Exporters; +using Ringtoets.Revetment.IO.Writers; + +namespace Ringtoets.Revetment.IO.Test.Exporters +{ + [TestFixture] + public class WaveConditionsExporterBaseTest + { + [Test] + public void Constructor_ValidParameters_ExpectedValues() + { + // Setup + string filePath = TestHelper.GetScratchPadPath($"{nameof(Constructor_ValidParameters_ExpectedValues)}.csv"); + + // Call + var waveConditionsExporter = new TestWaveConditionsExporter(new ExportableWaveConditions[0], filePath); + + // Assert + Assert.IsInstanceOf(waveConditionsExporter); + } + + [Test] + public void Constructor_ExportableWaveConditionsCollectionNull_ThrowArgumentNullException() + { + // Setup + string filePath = TestHelper.GetScratchPadPath($"{nameof(Constructor_ExportableWaveConditionsCollectionNull_ThrowArgumentNullException)}.csv"); + + // Call + TestDelegate call = () => new TestWaveConditionsExporter(null, filePath); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("exportableWaveConditionsCollection", exception.ParamName); + } + + [Test] + public void Constructor_FilePathNull_ThrowArgumentNullException() + { + // Call + TestDelegate call = () => new TestWaveConditionsExporter(new ExportableWaveConditions[0], null); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("filePath", exception.ParamName); + } + + [Test] + public void Export_InvalidData_LogErrorAndFalse() + { + // Setup + string filePath = TestHelper.GetScratchPadPath("test_.csv"); + string invalidFilePath = filePath.Replace("_", ">"); + var waveConditionsExporter = new TestWaveConditionsExporter(new ExportableWaveConditions[0], invalidFilePath); + + // Call + bool isExported = true; + Action call = () => isExported = waveConditionsExporter.Export(); + + // Assert + string expectedMessage = $"Er is een onverwachte fout opgetreden tijdens het schrijven van het bestand '{invalidFilePath}'. " + + "Er zijn geen golfrandvoorwaarden geëxporteerd."; + TestHelper.AssertLogMessageIsGenerated(call, expectedMessage); + Assert.IsFalse(isExported); + } + + [Test] + public void Export_ValidData_ReturnTrue() + { + // Setup + string directoryPath = TestHelper.GetScratchPadPath(nameof(Export_ValidData_ReturnTrue)); + + using (new DirectoryDisposeHelper(TestHelper.GetScratchPadPath(), nameof(Export_ValidData_ReturnTrue))) + { + string filePath = Path.Combine(directoryPath, "test.csv"); + + var waveConditionsExporter = new TestWaveConditionsExporter(new ExportableWaveConditions[0], filePath); + + // Call + bool isExported = waveConditionsExporter.Export(); + + // Assert + Assert.IsTrue(isExported); + } + } + + [Test] + public void Export_ValidData_ValidFile() + { + // Setup + ExportableWaveConditions[] exportableWaveConditions = + { + new ExportableWaveConditions("blocksName", new WaveConditionsInput + { + HydraulicBoundaryLocation = new HydraulicBoundaryLocation(1, string.Empty, 0, 0) + { + DesignWaterLevelOutput = new TestHydraulicBoundaryLocationOutput(12.34567) + }, + LowerBoundaryRevetment = (RoundedDouble) 5.68, + UpperBoundaryRevetment = (RoundedDouble) 7.214, + StepSize = WaveConditionsInputStepSize.One, + LowerBoundaryWaterLevels = (RoundedDouble) 2.689, + UpperBoundaryWaterLevels = (RoundedDouble) 77.8249863247 + }, CreateWaveConditionsOutputForExport(1.11111, 2.22222, 3.33333, 4.4, 5.5555555), CoverType.StoneCoverBlocks), + new ExportableWaveConditions("columnsName", new WaveConditionsInput + { + HydraulicBoundaryLocation = new HydraulicBoundaryLocation(8, "aLocation", 44, 123.456) + { + DesignWaterLevelOutput = new TestHydraulicBoundaryLocationOutput(28.36844) + }, + LowerBoundaryRevetment = (RoundedDouble) 1.384, + UpperBoundaryRevetment = (RoundedDouble) 11.54898963, + StepSize = WaveConditionsInputStepSize.Half, + LowerBoundaryWaterLevels = (RoundedDouble) 1.98699, + UpperBoundaryWaterLevels = (RoundedDouble) 84.26548 + }, CreateWaveConditionsOutputForExport(3.33333, 1.11111, 4.44444, 2.2, 6.66666), CoverType.StoneCoverColumns) + }; + + string directoryPath = TestHelper.GetScratchPadPath(nameof(Export_ValidData_ValidFile)); + using (new DirectoryDisposeHelper(TestHelper.GetScratchPadPath(), nameof(Export_ValidData_ValidFile))) + { + string filePath = Path.Combine(directoryPath, "test.csv"); + + // Call + WaveConditionsWriter.WriteWaveConditions(exportableWaveConditions, filePath); + + // Assert + Assert.IsTrue(File.Exists(filePath)); + string fileContent = File.ReadAllText(filePath); + Assert.AreEqual("Naam berekening, Naam HR locatie, X HR locatie (RD) [m], Y HR locatie (RD) [m], Naam voorlandprofiel, Dam gebruikt, Voorlandgeometrie gebruikt, Type bekleding, Waterstand [m+NAP], Golfhoogte (Hs) [m], Golfperiode (Tp) [s], Golfrichting t.o.v. dijknormaal [°], Golfrichting t.o.v. Noord [°]\r\n" + + "blocksName, , 0.000, 0.000, , nee, nee, Steen (blokken), 1.11, 2.22, 3.33, 4.40, 5.56\r\n" + + "columnsName, aLocation, 44.000, 123.456, , nee, nee, Steen (zuilen), 3.33, 1.11, 4.44, 2.20, 6.67\r\n", + fileContent); + } + } + + private class TestWaveConditionsExporter : WaveConditionsExporterBase + { + public TestWaveConditionsExporter(IEnumerable exportableWaveConditionsCollection, string filePath) : + base(exportableWaveConditionsCollection, filePath) {} + } + + private static WaveConditionsOutput CreateWaveConditionsOutputForExport(double waterLevel, double waveHeight, + double wavePeakPeriod, double waveAngle, + double waveDirection) + { + return new WaveConditionsOutput(waterLevel, waveHeight, wavePeakPeriod, waveAngle, + waveDirection, double.NaN, double.NaN, double.NaN, + double.NaN, CalculationConvergence.CalculatedConverged); + } + } +} \ No newline at end of file Index: Ringtoets/Revetment/test/Ringtoets.Revetment.IO.Test/Ringtoets.Revetment.IO.Test.csproj =================================================================== diff -u -rf01786afaf51ad02f5be5e2a320461ebfe576bba -r96cd93f1a08294e5af3fec5f5ae0b59cbe914c4b --- Ringtoets/Revetment/test/Ringtoets.Revetment.IO.Test/Ringtoets.Revetment.IO.Test.csproj (.../Ringtoets.Revetment.IO.Test.csproj) (revision f01786afaf51ad02f5be5e2a320461ebfe576bba) +++ Ringtoets/Revetment/test/Ringtoets.Revetment.IO.Test/Ringtoets.Revetment.IO.Test.csproj (.../Ringtoets.Revetment.IO.Test.csproj) (revision 96cd93f1a08294e5af3fec5f5ae0b59cbe914c4b) @@ -56,10 +56,10 @@ - - + + - + Fisheye: Tag 96cd93f1a08294e5af3fec5f5ae0b59cbe914c4b refers to a dead (removed) revision in file `Ringtoets/Revetment/test/Ringtoets.Revetment.IO.Test/WaveConditionsCalculationConfigurationWriterTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 96cd93f1a08294e5af3fec5f5ae0b59cbe914c4b refers to a dead (removed) revision in file `Ringtoets/Revetment/test/Ringtoets.Revetment.IO.Test/WaveConditionsExporterBaseTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 96cd93f1a08294e5af3fec5f5ae0b59cbe914c4b refers to a dead (removed) revision in file `Ringtoets/Revetment/test/Ringtoets.Revetment.IO.Test/WaveConditionsWriterTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Ringtoets/Revetment/test/Ringtoets.Revetment.IO.Test/Writers/WaveConditionsCalculationConfigurationWriterTest.cs =================================================================== diff -u --- Ringtoets/Revetment/test/Ringtoets.Revetment.IO.Test/Writers/WaveConditionsCalculationConfigurationWriterTest.cs (revision 0) +++ Ringtoets/Revetment/test/Ringtoets.Revetment.IO.Test/Writers/WaveConditionsCalculationConfigurationWriterTest.cs (revision 96cd93f1a08294e5af3fec5f5ae0b59cbe914c4b) @@ -0,0 +1,180 @@ +// 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.IO; +using System.Xml; +using Core.Common.Base; +using Core.Common.Base.Data; +using Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.Common.Data; +using Ringtoets.Common.Data.Calculation; +using Ringtoets.Common.Data.DikeProfiles; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.Common.IO.Writers; +using Ringtoets.Revetment.Data; +using Ringtoets.Revetment.IO.Writers; + +namespace Ringtoets.Revetment.IO.Test.Writers +{ + [TestFixture] + public class WaveConditionsCalculationConfigurationWriterTest + { + [Test] + public void Constructor_Always_ReturnsConfigurationWriter() + { + // Call + var writer = new SimpleWaveConditionsCalculationConfigurationWriter(); + + // Assert + Assert.IsInstanceOf>(writer); + } + + [Test] + public void WriteCalculation_SparseCalculation_WritesSparseConfigurationToFile() + { + // Setup + string filePath = TestHelper.GetScratchPadPath( + $"{nameof(WriteCalculation_SparseCalculation_WritesSparseConfigurationToFile)}.xml"); + + string expectedXmlFilePath = TestHelper.GetTestDataPath( + TestDataPath.Ringtoets.Revetment.IO, + Path.Combine(nameof(WaveConditionsCalculationConfigurationWriter), "sparseConfiguration.xml")); + + var calculation = new SimpleWaveConditionsCalculation + { + Name = "Berekening 1" + }; + + try + { + using (XmlWriter xmlWriter = CreateXmlWriter(filePath)) + { + var writer = new SimpleWaveConditionsCalculationConfigurationWriter(); + + // Call + writer.PublicWriteCalculation(calculation, xmlWriter); + } + + // Assert + string actualXml = File.ReadAllText(filePath); + string expectedXml = File.ReadAllText(expectedXmlFilePath); + + Assert.AreEqual(expectedXml, actualXml); + } + finally + { + File.Delete(filePath); + } + } + + [Test] + public void WriteCalculation_CompleteCalculation_WritesCompleteConfigurationToFile() + { + // Setup + string filePath = TestHelper.GetScratchPadPath( + $"{nameof(WriteCalculation_CompleteCalculation_WritesCompleteConfigurationToFile)}.xml"); + + string expectedXmlFilePath = TestHelper.GetTestDataPath( + TestDataPath.Ringtoets.Revetment.IO, + Path.Combine(nameof(WaveConditionsCalculationConfigurationWriter), "completeConfiguration.xml")); + + var calculation = new SimpleWaveConditionsCalculation + { + Name = "Berekening 1", + Input = + { + HydraulicBoundaryLocation = new TestHydraulicBoundaryLocation("Locatie1"), + UpperBoundaryRevetment = (RoundedDouble) 1.5, + LowerBoundaryRevetment = (RoundedDouble) 0.5, + UpperBoundaryWaterLevels = (RoundedDouble) 1.4, + LowerBoundaryWaterLevels = (RoundedDouble) 0.6, + StepSize = WaveConditionsInputStepSize.One, + ForeshoreProfile = new TestForeshoreProfile("profiel1"), + Orientation = (RoundedDouble) 67.1, + UseForeshore = true, + UseBreakWater = true, + BreakWater = + { + Height = (RoundedDouble) 1.23, + Type = BreakWaterType.Dam + } + } + }; + + try + { + using (XmlWriter xmlWriter = CreateXmlWriter(filePath)) + { + var writer = new SimpleWaveConditionsCalculationConfigurationWriter(); + + // Call + writer.PublicWriteCalculation(calculation, xmlWriter); + } + + // Assert + string actualXml = File.ReadAllText(filePath); + string expectedXml = File.ReadAllText(expectedXmlFilePath); + + Assert.AreEqual(expectedXml, actualXml); + } + finally + { + File.Delete(filePath); + } + } + + private static XmlWriter CreateXmlWriter(string filePath) + { + return XmlWriter.Create(filePath, new XmlWriterSettings + { + Indent = true + }); + } + } + + public class SimpleWaveConditionsCalculationConfigurationWriter : WaveConditionsCalculationConfigurationWriter + { + public void PublicWriteCalculation(SimpleWaveConditionsCalculation calculation, XmlWriter writer) + { + WriteCalculation(calculation, writer); + } + + protected override void WriteCalculation(SimpleWaveConditionsCalculation calculation, XmlWriter writer) + { + WriteCalculation(calculation.Name, calculation.Input, writer); + } + } + + public class SimpleWaveConditionsCalculation : Observable, ICalculation + { + public WaveConditionsInput Input { get; } = new WaveConditionsInput(); + public string Name { get; set; } + public bool HasOutput { get; } + public Comment Comments { get; } + + public void ClearOutput() + { + throw new NotImplementedException(); + } + } +} \ No newline at end of file Index: Ringtoets/Revetment/test/Ringtoets.Revetment.IO.Test/Writers/WaveConditionsWriterTest.cs =================================================================== diff -u --- Ringtoets/Revetment/test/Ringtoets.Revetment.IO.Test/Writers/WaveConditionsWriterTest.cs (revision 0) +++ Ringtoets/Revetment/test/Ringtoets.Revetment.IO.Test/Writers/WaveConditionsWriterTest.cs (revision 96cd93f1a08294e5af3fec5f5ae0b59cbe914c4b) @@ -0,0 +1,199 @@ +// 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.IO; +using System.Linq; +using System.Security.AccessControl; +using Core.Common.Base.Data; +using Core.Common.IO.Exceptions; +using Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.Common.Data.Hydraulics; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.Revetment.Data; +using Ringtoets.Revetment.IO.Writers; + +namespace Ringtoets.Revetment.IO.Test.Writers +{ + [TestFixture] + public class WaveConditionsWriterTest + { + [Test] + public void WriteWaveConditions_ExportableWaveConditionsCollectionNull_ThrowArgumentNullException() + { + // Call + TestDelegate call = () => WaveConditionsWriter.WriteWaveConditions(null, "afilePath"); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("exportableWaveConditionsCollection", exception.ParamName); + } + + [Test] + public void WriteWaveConditions_FilePathNull_ThrowArgumentNullException() + { + // Call + TestDelegate call = () => WaveConditionsWriter.WriteWaveConditions(Enumerable.Empty(), null); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("filePath", exception.ParamName); + } + + [Test] + [TestCase("")] + [TestCase(" ")] + [TestCase("c:\\>")] + public void WriteWaveConditions_FilePathInvalid_ThrowCriticalFileWriteException(string filePath) + { + // Call + TestDelegate call = () => WaveConditionsWriter.WriteWaveConditions(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); + Assert.IsInstanceOf(exception.InnerException); + } + + [Test] + public void WriteWaveConditions_FilePathTooLong_ThrowCriticalFileWriteException() + { + // Setup + var filePath = new string('a', 249); + + // Call + TestDelegate call = () => WaveConditionsWriter.WriteWaveConditions(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); + Assert.IsInstanceOf(exception.InnerException); + } + + [Test] + public void WriteWaveConditions_InvalidDirectoryRights_ThrowCriticalFileWriteException() + { + // Setup + string directoryPath = TestHelper.GetScratchPadPath("WriteWaveConditions_InvalidDirectoryRights_ThrowCriticalFileWriteException"); + Directory.CreateDirectory(directoryPath); + string filePath = Path.Combine(directoryPath, "test.csv"); + + // Call + TestDelegate call = () => WaveConditionsWriter.WriteWaveConditions(Enumerable.Empty(), filePath); + + try + { + using (new DirectoryPermissionsRevoker(directoryPath, FileSystemRights.Write)) + { + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual($"Er is een onverwachte fout opgetreden tijdens het schrijven van het bestand '{filePath}'.", exception.Message); + Assert.IsInstanceOf(exception.InnerException); + } + } + finally + { + Directory.Delete(directoryPath, true); + } + } + + [Test] + public void WriteWaveConditions_FileInUse_ThrowCriticalFileWriteException() + { + // Setup + string path = TestHelper.GetScratchPadPath(nameof(WriteWaveConditions_FileInUse_ThrowCriticalFileWriteException)); + + using (var fileDisposeHelper = new FileDisposeHelper(path)) + { + fileDisposeHelper.LockFiles(); + + // Call + TestDelegate call = () => WaveConditionsWriter.WriteWaveConditions(Enumerable.Empty(), path); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual($"Er is een onverwachte fout opgetreden tijdens het schrijven van het bestand '{path}'.", exception.Message); + Assert.IsInstanceOf(exception.InnerException); + } + } + + [Test] + public void WriteWaveConditions_ValidData_ValidFile() + { + // Setup + ExportableWaveConditions[] exportableWaveConditions = + { + new ExportableWaveConditions("blocksName", new WaveConditionsInput + { + HydraulicBoundaryLocation = new HydraulicBoundaryLocation(1, string.Empty, 0, 0) + { + DesignWaterLevelOutput = new TestHydraulicBoundaryLocationOutput(12.34567) + }, + LowerBoundaryRevetment = (RoundedDouble) 5.68, + UpperBoundaryRevetment = (RoundedDouble) 7.214, + StepSize = WaveConditionsInputStepSize.Half, + LowerBoundaryWaterLevels = (RoundedDouble) 2.689, + UpperBoundaryWaterLevels = (RoundedDouble) 77.8249863247, + UseBreakWater = true + }, CreateWaveConditionsOutputForExport(1.11111, 2.22222, 3.33333, 4.4, 5.5555555), CoverType.StoneCoverBlocks), + new ExportableWaveConditions("columnsName", new WaveConditionsInput + { + HydraulicBoundaryLocation = new HydraulicBoundaryLocation(8, "aLocation", 44, 123.456) + { + DesignWaterLevelOutput = new TestHydraulicBoundaryLocationOutput(28.36844) + }, + LowerBoundaryRevetment = (RoundedDouble) 1.384, + UpperBoundaryRevetment = (RoundedDouble) 11.54898963, + StepSize = WaveConditionsInputStepSize.One, + LowerBoundaryWaterLevels = (RoundedDouble) 1.98699, + UpperBoundaryWaterLevels = (RoundedDouble) 84.26548 + }, CreateWaveConditionsOutputForExport(3.33333, 1.11111, 4.44444, 2.2, 6.66666), CoverType.StoneCoverColumns) + }; + + string directoryPath = TestHelper.GetScratchPadPath(nameof(WriteWaveConditions_ValidData_ValidFile)); + using (new DirectoryDisposeHelper(TestHelper.GetScratchPadPath(), nameof(WriteWaveConditions_ValidData_ValidFile))) + { + string filePath = Path.Combine(directoryPath, "test.csv"); + + // Call + WaveConditionsWriter.WriteWaveConditions(exportableWaveConditions, filePath); + + // Assert + Assert.IsTrue(File.Exists(filePath)); + string fileContent = File.ReadAllText(filePath); + Assert.AreEqual("Naam berekening, Naam HR locatie, X HR locatie (RD) [m], Y HR locatie (RD) [m], Naam voorlandprofiel, Dam gebruikt, Voorlandgeometrie gebruikt, Type bekleding, Waterstand [m+NAP], Golfhoogte (Hs) [m], Golfperiode (Tp) [s], Golfrichting t.o.v. dijknormaal [°], Golfrichting t.o.v. Noord [°]\r\n" + + "blocksName, , 0.000, 0.000, , ja, nee, Steen (blokken), 1.11, 2.22, 3.33, 4.40, 5.56\r\n" + + "columnsName, aLocation, 44.000, 123.456, , nee, nee, Steen (zuilen), 3.33, 1.11, 4.44, 2.20, 6.67\r\n", + fileContent); + } + } + + private static WaveConditionsOutput CreateWaveConditionsOutputForExport(double waterLevel, double waveHeight, + double wavePeakPeriod, double waveAngle, + double waveDirection) + { + return new WaveConditionsOutput(waterLevel, waveHeight, wavePeakPeriod, waveAngle, + waveDirection, double.NaN, double.NaN, double.NaN, + double.NaN, CalculationConvergence.CalculatedConverged); + } + } +} \ No newline at end of file Index: Ringtoets/StabilityStoneCover/src/Ringtoets.StabilityStoneCover.IO/Exporters/StabilityStoneCoverCalculationConfigurationExporter.cs =================================================================== diff -u --- Ringtoets/StabilityStoneCover/src/Ringtoets.StabilityStoneCover.IO/Exporters/StabilityStoneCoverCalculationConfigurationExporter.cs (revision 0) +++ Ringtoets/StabilityStoneCover/src/Ringtoets.StabilityStoneCover.IO/Exporters/StabilityStoneCoverCalculationConfigurationExporter.cs (revision 96cd93f1a08294e5af3fec5f5ae0b59cbe914c4b) @@ -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.Collections.Generic; +using Ringtoets.Common.Data.Calculation; +using Ringtoets.Common.IO.Exporters; +using Ringtoets.StabilityStoneCover.Data; +using Ringtoets.StabilityStoneCover.IO.Writers; + +namespace Ringtoets.StabilityStoneCover.IO.Exporters +{ + /// + /// Exports a stability stone cover configuration and stores it as an XML file. + /// + public class StabilityStoneCoverCalculationConfigurationExporter + : CalculationConfigurationExporter + { + /// + /// Creates a new instance of . + /// + /// The configuration to export. + /// The path of the XML file to export to. + /// Thrown when is null. + /// Thrown when is invalid. + public StabilityStoneCoverCalculationConfigurationExporter(IEnumerable configuration, string filePath) + : base(configuration, filePath) {} + } +} \ No newline at end of file Index: Ringtoets/StabilityStoneCover/src/Ringtoets.StabilityStoneCover.IO/Exporters/StabilityStoneCoverWaveConditionsExporter.cs =================================================================== diff -u --- Ringtoets/StabilityStoneCover/src/Ringtoets.StabilityStoneCover.IO/Exporters/StabilityStoneCoverWaveConditionsExporter.cs (revision 0) +++ Ringtoets/StabilityStoneCover/src/Ringtoets.StabilityStoneCover.IO/Exporters/StabilityStoneCoverWaveConditionsExporter.cs (revision 96cd93f1a08294e5af3fec5f5ae0b59cbe914c4b) @@ -0,0 +1,71 @@ +// 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.Linq; +using Core.Common.IO.Exceptions; +using Ringtoets.Revetment.IO; +using Ringtoets.Revetment.IO.Exporters; +using Ringtoets.StabilityStoneCover.Data; + +namespace Ringtoets.StabilityStoneCover.IO.Exporters +{ + /// + /// Exports stability stone cover wave conditions and stores then as a csv file. + /// + public class StabilityStoneCoverWaveConditionsExporter : WaveConditionsExporterBase + { + /// + /// Creates a new instance of . + /// + /// + /// The file path to export to. + /// Thrown when or + /// is null. + /// Thrown when is invalid. + /// Thrown when the file could not be written. + public StabilityStoneCoverWaveConditionsExporter(IEnumerable calculations, string filePath) + : base(CreateExportableWaveConditionsCollection(calculations), filePath) {} + + private static IEnumerable CreateExportableWaveConditionsCollection(IEnumerable calculations) + { + if (calculations == null) + { + throw new ArgumentNullException(nameof(calculations)); + } + + var exportableWaveConditions = new List(); + + IEnumerable exportableCalculations = + calculations.Where(c => c.HasOutput && c.InputParameters.HydraulicBoundaryLocation != null); + + foreach (StabilityStoneCoverWaveConditionsCalculation calculation in exportableCalculations) + { + exportableWaveConditions.AddRange( + ExportableWaveConditionsFactory.CreateExportableWaveConditionsCollection( + calculation.Name, calculation.InputParameters, calculation.Output.ColumnsOutput, calculation.Output.BlocksOutput)); + } + + return exportableWaveConditions; + } + } +} \ No newline at end of file Index: Ringtoets/StabilityStoneCover/src/Ringtoets.StabilityStoneCover.IO/Ringtoets.StabilityStoneCover.IO.csproj =================================================================== diff -u -rf9f7e585da06fc8ab1b8ab92ce4dd64bd66d8f04 -r96cd93f1a08294e5af3fec5f5ae0b59cbe914c4b --- Ringtoets/StabilityStoneCover/src/Ringtoets.StabilityStoneCover.IO/Ringtoets.StabilityStoneCover.IO.csproj (.../Ringtoets.StabilityStoneCover.IO.csproj) (revision f9f7e585da06fc8ab1b8ab92ce4dd64bd66d8f04) +++ Ringtoets/StabilityStoneCover/src/Ringtoets.StabilityStoneCover.IO/Ringtoets.StabilityStoneCover.IO.csproj (.../Ringtoets.StabilityStoneCover.IO.csproj) (revision 96cd93f1a08294e5af3fec5f5ae0b59cbe914c4b) @@ -40,10 +40,10 @@ Properties\GlobalAssembly.cs - - + + - + Fisheye: Tag 96cd93f1a08294e5af3fec5f5ae0b59cbe914c4b refers to a dead (removed) revision in file `Ringtoets/StabilityStoneCover/src/Ringtoets.StabilityStoneCover.IO/StabilityStoneCoverCalculationConfigurationExporter.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 96cd93f1a08294e5af3fec5f5ae0b59cbe914c4b refers to a dead (removed) revision in file `Ringtoets/StabilityStoneCover/src/Ringtoets.StabilityStoneCover.IO/StabilityStoneCoverCalculationConfigurationWriter.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 96cd93f1a08294e5af3fec5f5ae0b59cbe914c4b refers to a dead (removed) revision in file `Ringtoets/StabilityStoneCover/src/Ringtoets.StabilityStoneCover.IO/StabilityStoneCoverWaveConditionsExporter.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Ringtoets/StabilityStoneCover/src/Ringtoets.StabilityStoneCover.IO/Writers/StabilityStoneCoverCalculationConfigurationWriter.cs =================================================================== diff -u --- Ringtoets/StabilityStoneCover/src/Ringtoets.StabilityStoneCover.IO/Writers/StabilityStoneCoverCalculationConfigurationWriter.cs (revision 0) +++ Ringtoets/StabilityStoneCover/src/Ringtoets.StabilityStoneCover.IO/Writers/StabilityStoneCoverCalculationConfigurationWriter.cs (revision 96cd93f1a08294e5af3fec5f5ae0b59cbe914c4b) @@ -0,0 +1,40 @@ +// 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.Xml; +using Ringtoets.Common.Data.Calculation; +using Ringtoets.Revetment.IO.Writers; +using Ringtoets.StabilityStoneCover.Data; + +namespace Ringtoets.StabilityStoneCover.IO.Writers +{ + /// + /// A writer for writing out configurations of and + /// , to XML format. + /// + public class StabilityStoneCoverCalculationConfigurationWriter : WaveConditionsCalculationConfigurationWriter + { + protected override void WriteCalculation(StabilityStoneCoverWaveConditionsCalculation calculation, XmlWriter writer) + { + WriteCalculation(calculation.Name, calculation.InputParameters, writer); + } + } +} \ No newline at end of file Index: Ringtoets/StabilityStoneCover/src/Ringtoets.StabilityStoneCover.Plugin/StabilityStoneCoverPlugin.cs =================================================================== diff -u -rf9f7e585da06fc8ab1b8ab92ce4dd64bd66d8f04 -r96cd93f1a08294e5af3fec5f5ae0b59cbe914c4b --- Ringtoets/StabilityStoneCover/src/Ringtoets.StabilityStoneCover.Plugin/StabilityStoneCoverPlugin.cs (.../StabilityStoneCoverPlugin.cs) (revision f9f7e585da06fc8ab1b8ab92ce4dd64bd66d8f04) +++ Ringtoets/StabilityStoneCover/src/Ringtoets.StabilityStoneCover.Plugin/StabilityStoneCoverPlugin.cs (.../StabilityStoneCoverPlugin.cs) (revision 96cd93f1a08294e5af3fec5f5ae0b59cbe914c4b) @@ -43,7 +43,7 @@ using Ringtoets.StabilityStoneCover.Forms.PresentationObjects; using Ringtoets.StabilityStoneCover.Forms.PropertyClasses; using Ringtoets.StabilityStoneCover.Forms.Views; -using Ringtoets.StabilityStoneCover.IO; +using Ringtoets.StabilityStoneCover.IO.Exporters; using Ringtoets.StabilityStoneCover.Service; using RingtoetsCommonDataResources = Ringtoets.Common.Data.Properties.Resources; using RingtoetsCommonFormsResources = Ringtoets.Common.Forms.Properties.Resources; @@ -68,7 +68,7 @@ yield return new PropertyInfo { CreateInstance = context => new StabilityStoneCoverWaveConditionsInputContextProperties( - context, + context, new ObservablePropertyChangeHandler(context.Calculation, context.WrappedData)) }; } @@ -189,7 +189,10 @@ yield return new ExportInfo { Name = RingtoetsCommonFormsResources.ConfigurationExporter_DisplayName, - CreateFileExporter = (context, filePath) => new StabilityStoneCoverCalculationConfigurationExporter(new [] { context.WrappedData }, filePath), + CreateFileExporter = (context, filePath) => new StabilityStoneCoverCalculationConfigurationExporter(new[] + { + context.WrappedData + }, filePath), FileFilterGenerator = new FileFilterGenerator( RingtoetsCommonFormsResources.DataTypeDisplayName_xml_file_filter_Extension, RingtoetsCommonFormsResources.DataTypeDisplayName_xml_file_filter_Description) Index: Ringtoets/StabilityStoneCover/test/Ringtoets.StabilityStoneCover.IO.Test/Exporters/StabilityStoneCoverCalculationConfigurationExporterTest.cs =================================================================== diff -u --- Ringtoets/StabilityStoneCover/test/Ringtoets.StabilityStoneCover.IO.Test/Exporters/StabilityStoneCoverCalculationConfigurationExporterTest.cs (revision 0) +++ Ringtoets/StabilityStoneCover/test/Ringtoets.StabilityStoneCover.IO.Test/Exporters/StabilityStoneCoverCalculationConfigurationExporterTest.cs (revision 96cd93f1a08294e5af3fec5f5ae0b59cbe914c4b) @@ -0,0 +1,122 @@ +// 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.IO; +using System.Linq; +using Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.Common.Data.Calculation; +using Ringtoets.Common.Data.Hydraulics; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.Common.IO.Exporters; +using Ringtoets.StabilityStoneCover.Data; +using Ringtoets.StabilityStoneCover.IO.Exporters; +using Ringtoets.StabilityStoneCover.IO.Writers; + +namespace Ringtoets.StabilityStoneCover.IO.Test.Exporters +{ + [TestFixture] + public class StabilityStoneCoverCalculationConfigurationExporterTest + { + [Test] + public void Constructor_ExpectedValues() + { + // Call + var exporter = new StabilityStoneCoverCalculationConfigurationExporter(Enumerable.Empty(), "test.xml"); + + // Assert + Assert.IsInstanceOf< + CalculationConfigurationExporter< + StabilityStoneCoverCalculationConfigurationWriter, + StabilityStoneCoverWaveConditionsCalculation>>(exporter); + } + + [Test] + public void Export_ValidData_ReturnTrueAndWritesFile() + { + // Setup + string filePath = TestHelper.GetScratchPadPath($"{nameof(Export_ValidData_ReturnTrueAndWritesFile)}.xml"); + + var calculation1 = new StabilityStoneCoverWaveConditionsCalculation + { + Name = "Calculation A", + InputParameters = + { + ForeshoreProfile = new TestForeshoreProfile("ForeshoreA") + } + }; + + var calculation2 = new StabilityStoneCoverWaveConditionsCalculation + { + Name = "PK001_0002 W1-6_4_1D1", + InputParameters = + { + HydraulicBoundaryLocation = new HydraulicBoundaryLocation(1, "HydraulicLocationA", 0, 0), + UseBreakWater = true + } + }; + + var calculationGroup2 = new CalculationGroup("PK001_0002", false) + { + Children = + { + calculation2 + } + }; + + var calculationGroup = new CalculationGroup("PK001_0001", false) + { + Children = + { + calculation1, + calculationGroup2 + } + }; + + var exporter = new StabilityStoneCoverCalculationConfigurationExporter(new[] + { + calculationGroup + }, filePath); + + try + { + // Call + bool isExported = exporter.Export(); + + // Assert + Assert.IsTrue(isExported); + Assert.IsTrue(File.Exists(filePath)); + + string actualXml = File.ReadAllText(filePath); + string testDirSubPath = Path.Combine(nameof(StabilityStoneCoverCalculationConfigurationExporter), "fullValidConfiguration.xml"); + string expectedXmlFilePath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.StabilityStoneCover.IO, + testDirSubPath); + string expectedXml = File.ReadAllText(expectedXmlFilePath); + + Assert.AreEqual(expectedXml, actualXml); + } + finally + { + File.Delete(filePath); + } + } + } +} \ No newline at end of file Index: Ringtoets/StabilityStoneCover/test/Ringtoets.StabilityStoneCover.IO.Test/Exporters/StabilityStoneCoverWaveConditionsExporterTest.cs =================================================================== diff -u --- Ringtoets/StabilityStoneCover/test/Ringtoets.StabilityStoneCover.IO.Test/Exporters/StabilityStoneCoverWaveConditionsExporterTest.cs (revision 0) +++ Ringtoets/StabilityStoneCover/test/Ringtoets.StabilityStoneCover.IO.Test/Exporters/StabilityStoneCoverWaveConditionsExporterTest.cs (revision 96cd93f1a08294e5af3fec5f5ae0b59cbe914c4b) @@ -0,0 +1,178 @@ +// 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.IO; +using System.Linq; +using Core.Common.Base.Data; +using Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.Common.Data.Hydraulics; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.Revetment.Data; +using Ringtoets.Revetment.IO.Exporters; +using Ringtoets.Revetment.TestUtil; +using Ringtoets.StabilityStoneCover.Data; +using Ringtoets.StabilityStoneCover.IO.Exporters; + +namespace Ringtoets.StabilityStoneCover.IO.Test.Exporters +{ + [TestFixture] + public class StabilityStoneCoverWaveConditionsExporterTest + { + [Test] + public void Constructor_ValidParameters_ExpectedValues() + { + // Setup + string filePath = TestHelper.GetScratchPadPath("test.csv"); + + // Call + var exporter = new StabilityStoneCoverWaveConditionsExporter(new StabilityStoneCoverWaveConditionsCalculation[0], filePath); + + // Assert + Assert.IsInstanceOf(exporter); + } + + [Test] + public void Constructor_CalculationsNull_ExpectedValues() + { + // Setup + string filePath = TestHelper.GetScratchPadPath("test.csv"); + + // Call + TestDelegate call = () => new StabilityStoneCoverWaveConditionsExporter(null, filePath); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("calculations", exception.ParamName); + } + + [Test] + public void Export_CalculationsWithoutOutput_FileWithOnlyHeader() + { + // Setup + string directoryPath = TestHelper.GetScratchPadPath(nameof(Export_CalculationsWithoutOutput_FileWithOnlyHeader)); + using (new DirectoryDisposeHelper(TestHelper.GetScratchPadPath(), nameof(Export_CalculationsWithoutOutput_FileWithOnlyHeader))) + { + string filePath = Path.Combine(directoryPath, "test.csv"); + + var calculationsWithoutOutput = new[] + { + new StabilityStoneCoverWaveConditionsCalculation() + }; + + var exporter = new StabilityStoneCoverWaveConditionsExporter(calculationsWithoutOutput, filePath); + + // Call + bool isExported = exporter.Export(); + + // Assert + Assert.IsTrue(isExported); + Assert.IsTrue(File.Exists(filePath)); + string fileContent = File.ReadAllText(filePath); + Assert.AreEqual("Naam berekening, Naam HR locatie, X HR locatie (RD) [m], Y HR locatie (RD) [m], Naam voorlandprofiel, Dam gebruikt, Voorlandgeometrie gebruikt, Type bekleding, Waterstand [m+NAP], Golfhoogte (Hs) [m], Golfperiode (Tp) [s], Golfrichting t.o.v. dijknormaal [°], Golfrichting t.o.v. Noord [°]\r\n", fileContent); + } + } + + [Test] + public void Export_CalculationsWithoutHydraulicBoundaryLocation_FileWithOnlyHeader() + { + // Setup + string directoryPath = TestHelper.GetScratchPadPath(nameof(Export_CalculationsWithoutHydraulicBoundaryLocation_FileWithOnlyHeader)); + using (new DirectoryDisposeHelper(TestHelper.GetScratchPadPath(), nameof(Export_CalculationsWithoutHydraulicBoundaryLocation_FileWithOnlyHeader))) + { + string filePath = Path.Combine(directoryPath, "test.csv"); + + var calculations = new[] + { + new StabilityStoneCoverWaveConditionsCalculation + { + Output = new StabilityStoneCoverWaveConditionsOutput(Enumerable.Empty(), Enumerable.Empty()), + } + }; + + var exporter = new StabilityStoneCoverWaveConditionsExporter(calculations, filePath); + + // Call + bool isExported = exporter.Export(); + + // Assert + Assert.IsTrue(isExported); + Assert.IsTrue(File.Exists(filePath)); + string fileContent = File.ReadAllText(filePath); + Assert.AreEqual("Naam berekening, Naam HR locatie, X HR locatie (RD) [m], Y HR locatie (RD) [m], Naam voorlandprofiel, Dam gebruikt, Voorlandgeometrie gebruikt, Type bekleding, Waterstand [m+NAP], Golfhoogte (Hs) [m], Golfperiode (Tp) [s], Golfrichting t.o.v. dijknormaal [°], Golfrichting t.o.v. Noord [°]\r\n", fileContent); + } + } + + [Test] + public void Export_ValidData_ValidFile() + { + // Setup + string subFolder = $"{nameof(StabilityStoneCoverWaveConditionsExporterTest)}.{nameof(Export_ValidData_ValidFile)}"; + string directoryPath = TestHelper.GetScratchPadPath(subFolder); + using (new DirectoryDisposeHelper(TestHelper.GetScratchPadPath(), subFolder)) + { + string filePath = Path.Combine(directoryPath, "test.csv"); + + var calculations = new[] + { + new StabilityStoneCoverWaveConditionsCalculation + { + Name = "aCalculation", + InputParameters = + { + HydraulicBoundaryLocation = new HydraulicBoundaryLocation(8, "aLocation", 44, 123.456) + { + DesignWaterLevelOutput = new TestHydraulicBoundaryLocationOutput(28.36844) + }, + LowerBoundaryRevetment = (RoundedDouble) 1.384, + UpperBoundaryRevetment = (RoundedDouble) 11.54898963, + StepSize = WaveConditionsInputStepSize.Half, + LowerBoundaryWaterLevels = (RoundedDouble) 1.98699, + UpperBoundaryWaterLevels = (RoundedDouble) 84.26548 + }, + Output = new StabilityStoneCoverWaveConditionsOutput(new[] + { + new TestWaveConditionsOutput() + }, new[] + { + new TestWaveConditionsOutput() + }) + } + }; + + var exporter = new StabilityStoneCoverWaveConditionsExporter(calculations, filePath); + + // Call + bool isExported = exporter.Export(); + + // Assert + Assert.IsTrue(isExported); + Assert.IsTrue(File.Exists(filePath)); + string fileContent = File.ReadAllText(filePath); + Assert.AreEqual("Naam berekening, Naam HR locatie, X HR locatie (RD) [m], Y HR locatie (RD) [m], Naam voorlandprofiel, Dam gebruikt, Voorlandgeometrie gebruikt, Type bekleding, Waterstand [m+NAP], Golfhoogte (Hs) [m], Golfperiode (Tp) [s], Golfrichting t.o.v. dijknormaal [°], Golfrichting t.o.v. Noord [°]\r\n" + + "aCalculation, aLocation, 44.000, 123.456, , nee, nee, Steen (zuilen), 1.10, 2.20, 3.30, 4.40, 5.50\r\n" + + "aCalculation, aLocation, 44.000, 123.456, , nee, nee, Steen (blokken), 1.10, 2.20, 3.30, 4.40, 5.50\r\n", + fileContent); + } + } + } +} \ No newline at end of file Index: Ringtoets/StabilityStoneCover/test/Ringtoets.StabilityStoneCover.IO.Test/Ringtoets.StabilityStoneCover.IO.Test.csproj =================================================================== diff -u -rf9f7e585da06fc8ab1b8ab92ce4dd64bd66d8f04 -r96cd93f1a08294e5af3fec5f5ae0b59cbe914c4b --- Ringtoets/StabilityStoneCover/test/Ringtoets.StabilityStoneCover.IO.Test/Ringtoets.StabilityStoneCover.IO.Test.csproj (.../Ringtoets.StabilityStoneCover.IO.Test.csproj) (revision f9f7e585da06fc8ab1b8ab92ce4dd64bd66d8f04) +++ Ringtoets/StabilityStoneCover/test/Ringtoets.StabilityStoneCover.IO.Test/Ringtoets.StabilityStoneCover.IO.Test.csproj (.../Ringtoets.StabilityStoneCover.IO.Test.csproj) (revision 96cd93f1a08294e5af3fec5f5ae0b59cbe914c4b) @@ -49,10 +49,10 @@ Properties\GlobalAssembly.cs - - + + - + Fisheye: Tag 96cd93f1a08294e5af3fec5f5ae0b59cbe914c4b refers to a dead (removed) revision in file `Ringtoets/StabilityStoneCover/test/Ringtoets.StabilityStoneCover.IO.Test/StabilityStoneCoverCalculationConfigurationExporterTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 96cd93f1a08294e5af3fec5f5ae0b59cbe914c4b refers to a dead (removed) revision in file `Ringtoets/StabilityStoneCover/test/Ringtoets.StabilityStoneCover.IO.Test/StabilityStoneCoverCalculationConfigurationWriterTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 96cd93f1a08294e5af3fec5f5ae0b59cbe914c4b refers to a dead (removed) revision in file `Ringtoets/StabilityStoneCover/test/Ringtoets.StabilityStoneCover.IO.Test/StabilityStoneCoverWaveConditionsExporterTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Ringtoets/StabilityStoneCover/test/Ringtoets.StabilityStoneCover.IO.Test/Writers/StabilityStoneCoverCalculationConfigurationWriterTest.cs =================================================================== diff -u --- Ringtoets/StabilityStoneCover/test/Ringtoets.StabilityStoneCover.IO.Test/Writers/StabilityStoneCoverCalculationConfigurationWriterTest.cs (revision 0) +++ Ringtoets/StabilityStoneCover/test/Ringtoets.StabilityStoneCover.IO.Test/Writers/StabilityStoneCoverCalculationConfigurationWriterTest.cs (revision 96cd93f1a08294e5af3fec5f5ae0b59cbe914c4b) @@ -0,0 +1,105 @@ +// 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.IO; +using Core.Common.Base.Data; +using Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.Common.Data.Calculation; +using Ringtoets.Common.Data.DikeProfiles; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.Revetment.Data; +using Ringtoets.Revetment.IO.Writers; +using Ringtoets.StabilityStoneCover.Data; +using Ringtoets.StabilityStoneCover.IO.Writers; + +namespace Ringtoets.StabilityStoneCover.IO.Test.Writers +{ + [TestFixture] + public class StabilityStoneCoverCalculationConfigurationWriterTest + { + [Test] + public void Constructor_Always_CreateWaveConditionsInputWriter() + { + // Call + var writer = new StabilityStoneCoverCalculationConfigurationWriter(); + + // Assert + Assert.IsInstanceOf>(writer); + } + + [Test] + public void Write_GroupWithCalculationAndOtherGroup_WritesOutCalculationAndGroupToFile() + { + // Setup + string filePath = TestHelper.GetScratchPadPath("Write_GroupWithCalculationAndOtherGroup.xml"); + string expectedXmlFilePath = TestHelper.GetTestDataPath( + TestDataPath.Ringtoets.StabilityStoneCover.IO, + Path.Combine(nameof(StabilityStoneCoverCalculationConfigurationWriter), "calculationAndGroupWithNesting.xml")); + + var calculation = new StabilityStoneCoverWaveConditionsCalculation + { + Name = "Berekening 1", + InputParameters = + { + HydraulicBoundaryLocation = new TestHydraulicBoundaryLocation("hr_locatie_2"), + UpperBoundaryRevetment = (RoundedDouble) 2.5, + LowerBoundaryRevetment = (RoundedDouble) 1.3, + UpperBoundaryWaterLevels = (RoundedDouble) 2.2, + LowerBoundaryWaterLevels = (RoundedDouble) (-0.2), + StepSize = WaveConditionsInputStepSize.Two, + ForeshoreProfile = new TestForeshoreProfile("profiel2"), + Orientation = (RoundedDouble) 12.3, + UseForeshore = true, + UseBreakWater = true, + BreakWater = + { + Height = (RoundedDouble) 2.11, + Type = BreakWaterType.Wall + } + } + }; + + var calculationGroup = new CalculationGroup("NestedGroup", false); + try + { + var writer = new StabilityStoneCoverCalculationConfigurationWriter(); + + // Call + writer.Write(new ICalculationBase[] + { + calculation, + calculationGroup + }, filePath); + + // Assert + string actualXml = File.ReadAllText(filePath); + string expectedXml = File.ReadAllText(expectedXmlFilePath); + + Assert.AreEqual(expectedXml, actualXml); + } + finally + { + File.Delete(filePath); + } + } + } +} \ No newline at end of file Index: Ringtoets/StabilityStoneCover/test/Ringtoets.StabilityStoneCover.Plugin.Test/ExportInfos/StabilityStoneCoverWaveConditionsCalculationContextExportInfoTest.cs =================================================================== diff -u -rf9f7e585da06fc8ab1b8ab92ce4dd64bd66d8f04 -r96cd93f1a08294e5af3fec5f5ae0b59cbe914c4b --- Ringtoets/StabilityStoneCover/test/Ringtoets.StabilityStoneCover.Plugin.Test/ExportInfos/StabilityStoneCoverWaveConditionsCalculationContextExportInfoTest.cs (.../StabilityStoneCoverWaveConditionsCalculationContextExportInfoTest.cs) (revision f9f7e585da06fc8ab1b8ab92ce4dd64bd66d8f04) +++ Ringtoets/StabilityStoneCover/test/Ringtoets.StabilityStoneCover.Plugin.Test/ExportInfos/StabilityStoneCoverWaveConditionsCalculationContextExportInfoTest.cs (.../StabilityStoneCoverWaveConditionsCalculationContextExportInfoTest.cs) (revision 96cd93f1a08294e5af3fec5f5ae0b59cbe914c4b) @@ -26,11 +26,11 @@ using NUnit.Framework; using Rhino.Mocks; using Ringtoets.Common.Data.AssessmentSection; -using Ringtoets.Revetment.IO; +using Ringtoets.Revetment.IO.Exporters; using Ringtoets.Revetment.TestUtil; using Ringtoets.StabilityStoneCover.Data; using Ringtoets.StabilityStoneCover.Forms.PresentationObjects; -using Ringtoets.StabilityStoneCover.IO; +using Ringtoets.StabilityStoneCover.IO.Exporters; namespace Ringtoets.StabilityStoneCover.Plugin.Test.ExportInfos { Index: Ringtoets/StabilityStoneCover/test/Ringtoets.StabilityStoneCover.Plugin.Test/ExportInfos/StabilityStoneCoverWaveConditionsCalculationGroupContextExportInfoTest.cs =================================================================== diff -u -rf9f7e585da06fc8ab1b8ab92ce4dd64bd66d8f04 -r96cd93f1a08294e5af3fec5f5ae0b59cbe914c4b --- Ringtoets/StabilityStoneCover/test/Ringtoets.StabilityStoneCover.Plugin.Test/ExportInfos/StabilityStoneCoverWaveConditionsCalculationGroupContextExportInfoTest.cs (.../StabilityStoneCoverWaveConditionsCalculationGroupContextExportInfoTest.cs) (revision f9f7e585da06fc8ab1b8ab92ce4dd64bd66d8f04) +++ Ringtoets/StabilityStoneCover/test/Ringtoets.StabilityStoneCover.Plugin.Test/ExportInfos/StabilityStoneCoverWaveConditionsCalculationGroupContextExportInfoTest.cs (.../StabilityStoneCoverWaveConditionsCalculationGroupContextExportInfoTest.cs) (revision 96cd93f1a08294e5af3fec5f5ae0b59cbe914c4b) @@ -27,11 +27,11 @@ using Rhino.Mocks; using Ringtoets.Common.Data.AssessmentSection; using Ringtoets.Common.Data.Calculation; -using Ringtoets.Revetment.IO; +using Ringtoets.Revetment.IO.Exporters; using Ringtoets.Revetment.TestUtil; using Ringtoets.StabilityStoneCover.Data; using Ringtoets.StabilityStoneCover.Forms.PresentationObjects; -using Ringtoets.StabilityStoneCover.IO; +using Ringtoets.StabilityStoneCover.IO.Exporters; namespace Ringtoets.StabilityStoneCover.Plugin.Test.ExportInfos { @@ -248,8 +248,8 @@ mocks.ReplayAll(); var context = new StabilityStoneCoverWaveConditionsCalculationGroupContext(new CalculationGroup(), - new StabilityStoneCoverFailureMechanism(), - assessmentSection); + new StabilityStoneCoverFailureMechanism(), + assessmentSection); // Call IFileExporter fileExporter = configurationExportInfo.CreateFileExporter(context, "test"); @@ -277,8 +277,8 @@ mocks.ReplayAll(); var context = new StabilityStoneCoverWaveConditionsCalculationGroupContext(new CalculationGroup(), - new StabilityStoneCoverFailureMechanism(), - assessmentSection); + new StabilityStoneCoverFailureMechanism(), + assessmentSection); // Call bool isEnabled = configurationExportInfo.IsEnabled(context); @@ -312,8 +312,8 @@ } var context = new StabilityStoneCoverWaveConditionsCalculationGroupContext(calculationGroup, - new StabilityStoneCoverFailureMechanism(), - assessmentSection); + new StabilityStoneCoverFailureMechanism(), + assessmentSection); // Call bool isEnabled = configurationExportInfo.IsEnabled(context); Index: Ringtoets/WaveImpactAsphaltCover/src/Ringtoets.WaveImpactAsphaltCover.IO/Exporters/WaveImpactAsphaltCoverCalculationConfigurationExporter.cs =================================================================== diff -u --- Ringtoets/WaveImpactAsphaltCover/src/Ringtoets.WaveImpactAsphaltCover.IO/Exporters/WaveImpactAsphaltCoverCalculationConfigurationExporter.cs (revision 0) +++ Ringtoets/WaveImpactAsphaltCover/src/Ringtoets.WaveImpactAsphaltCover.IO/Exporters/WaveImpactAsphaltCoverCalculationConfigurationExporter.cs (revision 96cd93f1a08294e5af3fec5f5ae0b59cbe914c4b) @@ -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.Collections.Generic; +using Ringtoets.Common.Data.Calculation; +using Ringtoets.Common.IO.Exporters; +using Ringtoets.WaveImpactAsphaltCover.Data; +using Ringtoets.WaveImpactAsphaltCover.IO.Writers; + +namespace Ringtoets.WaveImpactAsphaltCover.IO.Exporters +{ + /// + /// Exports a wave impact asphalt cover configuration and stores it as an XML file. + /// + public class WaveImpactAsphaltCoverCalculationConfigurationExporter + : CalculationConfigurationExporter + { + /// + /// Creates a new instance of . + /// + /// The configuration to export. + /// The path of the XML file to export to. + /// Thrown when is null. + /// Thrown when is invalid. + public WaveImpactAsphaltCoverCalculationConfigurationExporter(IEnumerable configuration, string filePath) + : base(configuration, filePath) {} + } +} \ No newline at end of file Index: Ringtoets/WaveImpactAsphaltCover/src/Ringtoets.WaveImpactAsphaltCover.IO/Exporters/WaveImpactAsphaltCoverWaveConditionsExporter.cs =================================================================== diff -u --- Ringtoets/WaveImpactAsphaltCover/src/Ringtoets.WaveImpactAsphaltCover.IO/Exporters/WaveImpactAsphaltCoverWaveConditionsExporter.cs (revision 0) +++ Ringtoets/WaveImpactAsphaltCover/src/Ringtoets.WaveImpactAsphaltCover.IO/Exporters/WaveImpactAsphaltCoverWaveConditionsExporter.cs (revision 96cd93f1a08294e5af3fec5f5ae0b59cbe914c4b) @@ -0,0 +1,69 @@ +// 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.Linq; +using Core.Common.IO.Exceptions; +using Ringtoets.Revetment.IO; +using Ringtoets.Revetment.IO.Exporters; +using Ringtoets.WaveImpactAsphaltCover.Data; + +namespace Ringtoets.WaveImpactAsphaltCover.IO.Exporters +{ + /// + /// Exports wave impact asphalt cover wave conditions and stores then as a csv file. + /// + public class WaveImpactAsphaltCoverWaveConditionsExporter : WaveConditionsExporterBase + { + /// + /// Creates a new instance of . + /// + /// The objects to export. + /// The file path to export to. + /// Thrown when any parameter is null. + /// Thrown when the file could not be written. + public WaveImpactAsphaltCoverWaveConditionsExporter(IEnumerable calculations, string filePath) + : base(CreateExportableWaveConditionsCollection(calculations), filePath) {} + + private static IEnumerable CreateExportableWaveConditionsCollection(IEnumerable calculations) + { + if (calculations == null) + { + throw new ArgumentNullException(nameof(calculations)); + } + + var exportableWaveConditions = new List(); + + IEnumerable exportableCalculations = + calculations.Where(c => c.HasOutput && c.InputParameters.HydraulicBoundaryLocation != null); + + foreach (WaveImpactAsphaltCoverWaveConditionsCalculation calculation in exportableCalculations) + { + exportableWaveConditions.AddRange( + ExportableWaveConditionsFactory.CreateExportableWaveConditionsCollection( + calculation.Name, calculation.InputParameters, calculation.Output.Items, CoverType.Asphalt)); + } + + return exportableWaveConditions; + } + } +} \ No newline at end of file Index: Ringtoets/WaveImpactAsphaltCover/src/Ringtoets.WaveImpactAsphaltCover.IO/Ringtoets.WaveImpactAsphaltCover.IO.csproj =================================================================== diff -u -rf9f7e585da06fc8ab1b8ab92ce4dd64bd66d8f04 -r96cd93f1a08294e5af3fec5f5ae0b59cbe914c4b --- Ringtoets/WaveImpactAsphaltCover/src/Ringtoets.WaveImpactAsphaltCover.IO/Ringtoets.WaveImpactAsphaltCover.IO.csproj (.../Ringtoets.WaveImpactAsphaltCover.IO.csproj) (revision f9f7e585da06fc8ab1b8ab92ce4dd64bd66d8f04) +++ Ringtoets/WaveImpactAsphaltCover/src/Ringtoets.WaveImpactAsphaltCover.IO/Ringtoets.WaveImpactAsphaltCover.IO.csproj (.../Ringtoets.WaveImpactAsphaltCover.IO.csproj) (revision 96cd93f1a08294e5af3fec5f5ae0b59cbe914c4b) @@ -40,10 +40,10 @@ Properties\GlobalAssembly.cs - - + + - + Fisheye: Tag 96cd93f1a08294e5af3fec5f5ae0b59cbe914c4b refers to a dead (removed) revision in file `Ringtoets/WaveImpactAsphaltCover/src/Ringtoets.WaveImpactAsphaltCover.IO/WaveImpactAsphaltCoverCalculationConfigurationExporter.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 96cd93f1a08294e5af3fec5f5ae0b59cbe914c4b refers to a dead (removed) revision in file `Ringtoets/WaveImpactAsphaltCover/src/Ringtoets.WaveImpactAsphaltCover.IO/WaveImpactAsphaltCoverCalculationConfigurationWriter.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 96cd93f1a08294e5af3fec5f5ae0b59cbe914c4b refers to a dead (removed) revision in file `Ringtoets/WaveImpactAsphaltCover/src/Ringtoets.WaveImpactAsphaltCover.IO/WaveImpactAsphaltCoverWaveConditionsExporter.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Ringtoets/WaveImpactAsphaltCover/src/Ringtoets.WaveImpactAsphaltCover.IO/Writers/WaveImpactAsphaltCoverCalculationConfigurationWriter.cs =================================================================== diff -u --- Ringtoets/WaveImpactAsphaltCover/src/Ringtoets.WaveImpactAsphaltCover.IO/Writers/WaveImpactAsphaltCoverCalculationConfigurationWriter.cs (revision 0) +++ Ringtoets/WaveImpactAsphaltCover/src/Ringtoets.WaveImpactAsphaltCover.IO/Writers/WaveImpactAsphaltCoverCalculationConfigurationWriter.cs (revision 96cd93f1a08294e5af3fec5f5ae0b59cbe914c4b) @@ -0,0 +1,40 @@ +// 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.Xml; +using Ringtoets.Common.Data.Calculation; +using Ringtoets.Revetment.IO.Writers; +using Ringtoets.WaveImpactAsphaltCover.Data; + +namespace Ringtoets.WaveImpactAsphaltCover.IO.Writers +{ + /// + /// A writer for writing out configurations of and + /// , to XML format. + /// + public class WaveImpactAsphaltCoverCalculationConfigurationWriter : WaveConditionsCalculationConfigurationWriter + { + protected override void WriteCalculation(WaveImpactAsphaltCoverWaveConditionsCalculation calculation, XmlWriter writer) + { + WriteCalculation(calculation.Name, calculation.InputParameters, writer); + } + } +} \ No newline at end of file Index: Ringtoets/WaveImpactAsphaltCover/src/Ringtoets.WaveImpactAsphaltCover.Plugin/WaveImpactAsphaltCoverPlugin.cs =================================================================== diff -u -rf9f7e585da06fc8ab1b8ab92ce4dd64bd66d8f04 -r96cd93f1a08294e5af3fec5f5ae0b59cbe914c4b --- Ringtoets/WaveImpactAsphaltCover/src/Ringtoets.WaveImpactAsphaltCover.Plugin/WaveImpactAsphaltCoverPlugin.cs (.../WaveImpactAsphaltCoverPlugin.cs) (revision f9f7e585da06fc8ab1b8ab92ce4dd64bd66d8f04) +++ Ringtoets/WaveImpactAsphaltCover/src/Ringtoets.WaveImpactAsphaltCover.Plugin/WaveImpactAsphaltCoverPlugin.cs (.../WaveImpactAsphaltCoverPlugin.cs) (revision 96cd93f1a08294e5af3fec5f5ae0b59cbe914c4b) @@ -43,7 +43,7 @@ using Ringtoets.WaveImpactAsphaltCover.Forms.PresentationObjects; using Ringtoets.WaveImpactAsphaltCover.Forms.PropertyClasses; using Ringtoets.WaveImpactAsphaltCover.Forms.Views; -using Ringtoets.WaveImpactAsphaltCover.IO; +using Ringtoets.WaveImpactAsphaltCover.IO.Exporters; using Ringtoets.WaveImpactAsphaltCover.Service; using RingtoetsCommonDataResources = Ringtoets.Common.Data.Properties.Resources; using RingtoetsCommonFormsResources = Ringtoets.Common.Forms.Properties.Resources; @@ -68,7 +68,7 @@ yield return new PropertyInfo { CreateInstance = context => new WaveImpactAsphaltCoverWaveConditionsInputContextProperties( - context, + context, new ObservablePropertyChangeHandler(context.Calculation, context.WrappedData)) }; } @@ -169,10 +169,7 @@ yield return new ExportInfo { Name = RingtoetsCommonFormsResources.ConfigurationExporter_DisplayName, - CreateFileExporter = (context, filePath) => - { - return new WaveImpactAsphaltCoverCalculationConfigurationExporter(context.WrappedData.Children, filePath); - }, + CreateFileExporter = (context, filePath) => { return new WaveImpactAsphaltCoverCalculationConfigurationExporter(context.WrappedData.Children, filePath); }, IsEnabled = context => context.WrappedData.Children.Any(), FileFilterGenerator = new FileFilterGenerator(RingtoetsCommonFormsResources.DataTypeDisplayName_xml_file_filter_Extension, RingtoetsCommonFormsResources.DataTypeDisplayName_xml_file_filter_Description) @@ -195,7 +192,10 @@ Name = RingtoetsCommonFormsResources.ConfigurationExporter_DisplayName, CreateFileExporter = (context, filePath) => { - return new WaveImpactAsphaltCoverCalculationConfigurationExporter(new [] { context.WrappedData }, filePath); + return new WaveImpactAsphaltCoverCalculationConfigurationExporter(new[] + { + context.WrappedData + }, filePath); }, FileFilterGenerator = new FileFilterGenerator(RingtoetsCommonFormsResources.DataTypeDisplayName_xml_file_filter_Extension, RingtoetsCommonFormsResources.DataTypeDisplayName_xml_file_filter_Description) Index: Ringtoets/WaveImpactAsphaltCover/test/Ringtoets.WaveImpactAsphaltCover.IO.Test/Exporters/WaveImpactAsphaltCoverCalculationConfigurationExporterTest.cs =================================================================== diff -u --- Ringtoets/WaveImpactAsphaltCover/test/Ringtoets.WaveImpactAsphaltCover.IO.Test/Exporters/WaveImpactAsphaltCoverCalculationConfigurationExporterTest.cs (revision 0) +++ Ringtoets/WaveImpactAsphaltCover/test/Ringtoets.WaveImpactAsphaltCover.IO.Test/Exporters/WaveImpactAsphaltCoverCalculationConfigurationExporterTest.cs (revision 96cd93f1a08294e5af3fec5f5ae0b59cbe914c4b) @@ -0,0 +1,122 @@ +// 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.IO; +using System.Linq; +using Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.Common.Data.Calculation; +using Ringtoets.Common.Data.Hydraulics; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.Common.IO.Exporters; +using Ringtoets.WaveImpactAsphaltCover.Data; +using Ringtoets.WaveImpactAsphaltCover.IO.Exporters; +using Ringtoets.WaveImpactAsphaltCover.IO.Writers; + +namespace Ringtoets.WaveImpactAsphaltCover.IO.Test.Exporters +{ + [TestFixture] + public class WaveImpactAsphaltCoverCalculationConfigurationExporterTest + { + [Test] + public void Constructor_ExpectedValues() + { + // Call + var exporter = new WaveImpactAsphaltCoverCalculationConfigurationExporter(Enumerable.Empty(), "test.xml"); + + // Assert + Assert.IsInstanceOf< + CalculationConfigurationExporter< + WaveImpactAsphaltCoverCalculationConfigurationWriter, + WaveImpactAsphaltCoverWaveConditionsCalculation>>(exporter); + } + + [Test] + public void Export_ValidData_ReturnTrueAndWritesFile() + { + // Setup + string filePath = TestHelper.GetScratchPadPath($"{nameof(Export_ValidData_ReturnTrueAndWritesFile)}.xml"); + + var calculation1 = new WaveImpactAsphaltCoverWaveConditionsCalculation + { + Name = "Calculation A", + InputParameters = + { + ForeshoreProfile = new TestForeshoreProfile("ForeshoreA") + } + }; + + var calculation2 = new WaveImpactAsphaltCoverWaveConditionsCalculation + { + Name = "PK001_0002 W1-6_4_1D1", + InputParameters = + { + HydraulicBoundaryLocation = new HydraulicBoundaryLocation(1, "HydraulicLocationA", 0, 0), + UseBreakWater = true + } + }; + + var calculationGroup2 = new CalculationGroup("PK001_0002", false) + { + Children = + { + calculation2 + } + }; + + var calculationGroup = new CalculationGroup("PK001_0001", false) + { + Children = + { + calculation1, + calculationGroup2 + } + }; + + var exporter = new WaveImpactAsphaltCoverCalculationConfigurationExporter(new [] + { + calculationGroup + }, filePath); + + try + { + // Call + bool isExported = exporter.Export(); + + // Assert + Assert.IsTrue(isExported); + Assert.IsTrue(File.Exists(filePath)); + + string actualXml = File.ReadAllText(filePath); + string testDirSubPath = Path.Combine(nameof(WaveImpactAsphaltCoverCalculationConfigurationExporter), "fullValidConfiguration.xml"); + string expectedXmlFilePath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.WaveImpactAsphaltCover.IO, + testDirSubPath); + string expectedXml = File.ReadAllText(expectedXmlFilePath); + + Assert.AreEqual(expectedXml, actualXml); + } + finally + { + File.Delete(filePath); + } + } + } +} \ No newline at end of file Index: Ringtoets/WaveImpactAsphaltCover/test/Ringtoets.WaveImpactAsphaltCover.IO.Test/Exporters/WaveImpactAsphaltCoverWaveConditionsExporterTest.cs =================================================================== diff -u --- Ringtoets/WaveImpactAsphaltCover/test/Ringtoets.WaveImpactAsphaltCover.IO.Test/Exporters/WaveImpactAsphaltCoverWaveConditionsExporterTest.cs (revision 0) +++ Ringtoets/WaveImpactAsphaltCover/test/Ringtoets.WaveImpactAsphaltCover.IO.Test/Exporters/WaveImpactAsphaltCoverWaveConditionsExporterTest.cs (revision 96cd93f1a08294e5af3fec5f5ae0b59cbe914c4b) @@ -0,0 +1,72 @@ +// 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 Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.Revetment.IO.Exporters; +using Ringtoets.WaveImpactAsphaltCover.Data; +using Ringtoets.WaveImpactAsphaltCover.IO.Exporters; + +namespace Ringtoets.WaveImpactAsphaltCover.IO.Test.Exporters +{ + [TestFixture] + public class WaveImpactAsphaltCoverWaveConditionsExporterTest + { + [Test] + public void Constructor_ValidParameters_ExpectedValues() + { + // Setup + string filePath = TestHelper.GetScratchPadPath("test.csv"); + + // Call + var waveConditionsExporter = new WaveImpactAsphaltCoverWaveConditionsExporter(new WaveImpactAsphaltCoverWaveConditionsCalculation[0], filePath); + + // Assert + Assert.IsInstanceOf(waveConditionsExporter); + } + + [Test] + public void Constructor_CalculationNull_ThrowArgumentNullException() + { + // Setup + string filePath = TestHelper.GetScratchPadPath("test.csv"); + + // Call + TestDelegate call = () => new WaveImpactAsphaltCoverWaveConditionsExporter(null, filePath); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("calculations", exception.ParamName); + } + + [Test] + public void Constructor_FilePathNull_ThrowArgumentNullException() + { + // Call + TestDelegate call = () => new WaveImpactAsphaltCoverWaveConditionsExporter(new WaveImpactAsphaltCoverWaveConditionsCalculation[0], null); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("filePath", exception.ParamName); + } + } +} \ No newline at end of file Index: Ringtoets/WaveImpactAsphaltCover/test/Ringtoets.WaveImpactAsphaltCover.IO.Test/Ringtoets.WaveImpactAsphaltCover.IO.Test.csproj =================================================================== diff -u -rf9f7e585da06fc8ab1b8ab92ce4dd64bd66d8f04 -r96cd93f1a08294e5af3fec5f5ae0b59cbe914c4b --- Ringtoets/WaveImpactAsphaltCover/test/Ringtoets.WaveImpactAsphaltCover.IO.Test/Ringtoets.WaveImpactAsphaltCover.IO.Test.csproj (.../Ringtoets.WaveImpactAsphaltCover.IO.Test.csproj) (revision f9f7e585da06fc8ab1b8ab92ce4dd64bd66d8f04) +++ Ringtoets/WaveImpactAsphaltCover/test/Ringtoets.WaveImpactAsphaltCover.IO.Test/Ringtoets.WaveImpactAsphaltCover.IO.Test.csproj (.../Ringtoets.WaveImpactAsphaltCover.IO.Test.csproj) (revision 96cd93f1a08294e5af3fec5f5ae0b59cbe914c4b) @@ -49,10 +49,10 @@ Properties\GlobalAssembly.cs - - + + - + Fisheye: Tag 96cd93f1a08294e5af3fec5f5ae0b59cbe914c4b refers to a dead (removed) revision in file `Ringtoets/WaveImpactAsphaltCover/test/Ringtoets.WaveImpactAsphaltCover.IO.Test/WaveImpactAsphaltCoverCalculationConfigurationExporterTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 96cd93f1a08294e5af3fec5f5ae0b59cbe914c4b refers to a dead (removed) revision in file `Ringtoets/WaveImpactAsphaltCover/test/Ringtoets.WaveImpactAsphaltCover.IO.Test/WaveImpactAsphaltCoverCalculationConfigurationWriterTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 96cd93f1a08294e5af3fec5f5ae0b59cbe914c4b refers to a dead (removed) revision in file `Ringtoets/WaveImpactAsphaltCover/test/Ringtoets.WaveImpactAsphaltCover.IO.Test/WaveImpactAsphaltCoverWaveConditionsExporterTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Ringtoets/WaveImpactAsphaltCover/test/Ringtoets.WaveImpactAsphaltCover.IO.Test/Writers/WaveImpactAsphaltCoverCalculationConfigurationWriterTest.cs =================================================================== diff -u --- Ringtoets/WaveImpactAsphaltCover/test/Ringtoets.WaveImpactAsphaltCover.IO.Test/Writers/WaveImpactAsphaltCoverCalculationConfigurationWriterTest.cs (revision 0) +++ Ringtoets/WaveImpactAsphaltCover/test/Ringtoets.WaveImpactAsphaltCover.IO.Test/Writers/WaveImpactAsphaltCoverCalculationConfigurationWriterTest.cs (revision 96cd93f1a08294e5af3fec5f5ae0b59cbe914c4b) @@ -0,0 +1,105 @@ +// 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.IO; +using Core.Common.Base.Data; +using Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.Common.Data.Calculation; +using Ringtoets.Common.Data.DikeProfiles; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.Revetment.Data; +using Ringtoets.Revetment.IO.Writers; +using Ringtoets.WaveImpactAsphaltCover.Data; +using Ringtoets.WaveImpactAsphaltCover.IO.Writers; + +namespace Ringtoets.WaveImpactAsphaltCover.IO.Test.Writers +{ + [TestFixture] + public class WaveImpactAsphaltCoverCalculationConfigurationWriterTest + { + [Test] + public void Constructor_Always_CreateWaveConditionsInputWriter() + { + // Call + var writer = new WaveImpactAsphaltCoverCalculationConfigurationWriter(); + + // Assert + Assert.IsInstanceOf>(writer); + } + + [Test] + public void Write_GroupWithCalculationAndOtherGroup_WritesOutCalculationAndGroupToFile() + { + // Setup + string filePath = TestHelper.GetScratchPadPath("Write_GroupWithCalculationAndOtherGroup.xml"); + string expectedXmlFilePath = TestHelper.GetTestDataPath( + TestDataPath.Ringtoets.WaveImpactAsphaltCover.IO, + Path.Combine(nameof(WaveImpactAsphaltCoverCalculationConfigurationWriter), "calculationAndGroupWithNesting.xml")); + + var calculation = new WaveImpactAsphaltCoverWaveConditionsCalculation + { + Name = "Berekening 1", + InputParameters = + { + HydraulicBoundaryLocation = new TestHydraulicBoundaryLocation("hr_locatie_2"), + UpperBoundaryRevetment = (RoundedDouble) 2.5, + LowerBoundaryRevetment = (RoundedDouble) 1.3, + UpperBoundaryWaterLevels = (RoundedDouble) 2.2, + LowerBoundaryWaterLevels = (RoundedDouble) (-0.2), + StepSize = WaveConditionsInputStepSize.Two, + ForeshoreProfile = new TestForeshoreProfile("profiel2"), + Orientation = (RoundedDouble) 12.3, + UseForeshore = true, + UseBreakWater = true, + BreakWater = + { + Height = (RoundedDouble) 2.11, + Type = BreakWaterType.Wall + } + } + }; + + var calculationGroup = new CalculationGroup("NestedGroup", false); + try + { + var writer = new WaveImpactAsphaltCoverCalculationConfigurationWriter(); + + // Call + writer.Write(new ICalculationBase[] + { + calculation, + calculationGroup + }, filePath); + + // Assert + string actualXml = File.ReadAllText(filePath); + string expectedXml = File.ReadAllText(expectedXmlFilePath); + + Assert.AreEqual(expectedXml, actualXml); + } + finally + { + File.Delete(filePath); + } + } + } +} \ No newline at end of file Index: Ringtoets/WaveImpactAsphaltCover/test/Ringtoets.WaveImpactAsphaltCover.Plugin.Test/ExportInfos/WaveImpactAsphaltCoverWaveConditionsCalculationContextExportInfoTest.cs =================================================================== diff -u -rf9f7e585da06fc8ab1b8ab92ce4dd64bd66d8f04 -r96cd93f1a08294e5af3fec5f5ae0b59cbe914c4b --- Ringtoets/WaveImpactAsphaltCover/test/Ringtoets.WaveImpactAsphaltCover.Plugin.Test/ExportInfos/WaveImpactAsphaltCoverWaveConditionsCalculationContextExportInfoTest.cs (.../WaveImpactAsphaltCoverWaveConditionsCalculationContextExportInfoTest.cs) (revision f9f7e585da06fc8ab1b8ab92ce4dd64bd66d8f04) +++ Ringtoets/WaveImpactAsphaltCover/test/Ringtoets.WaveImpactAsphaltCover.Plugin.Test/ExportInfos/WaveImpactAsphaltCoverWaveConditionsCalculationContextExportInfoTest.cs (.../WaveImpactAsphaltCoverWaveConditionsCalculationContextExportInfoTest.cs) (revision 96cd93f1a08294e5af3fec5f5ae0b59cbe914c4b) @@ -26,11 +26,11 @@ using NUnit.Framework; using Rhino.Mocks; using Ringtoets.Common.Data.AssessmentSection; -using Ringtoets.Revetment.IO; +using Ringtoets.Revetment.IO.Exporters; using Ringtoets.Revetment.TestUtil; using Ringtoets.WaveImpactAsphaltCover.Data; using Ringtoets.WaveImpactAsphaltCover.Forms.PresentationObjects; -using Ringtoets.WaveImpactAsphaltCover.IO; +using Ringtoets.WaveImpactAsphaltCover.IO.Exporters; namespace Ringtoets.WaveImpactAsphaltCover.Plugin.Test.ExportInfos { @@ -74,7 +74,7 @@ var failureMechanism = new WaveImpactAsphaltCoverFailureMechanism(); var context = new WaveImpactAsphaltCoverWaveConditionsCalculationContext(new WaveImpactAsphaltCoverWaveConditionsCalculation(), - failureMechanism, assessmentSection); + failureMechanism, assessmentSection); // Call IFileExporter fileExporter = waveConditionsExportInfo.CreateFileExporter(context, "test"); @@ -105,7 +105,7 @@ var failureMechanism = new WaveImpactAsphaltCoverFailureMechanism(); var context = new WaveImpactAsphaltCoverWaveConditionsCalculationContext(new WaveImpactAsphaltCoverWaveConditionsCalculation(), - failureMechanism, assessmentSection); + failureMechanism, assessmentSection); // Call bool isEnabled = waveConditionsExportInfo.IsEnabled(context); @@ -167,7 +167,7 @@ var failureMechanism = new WaveImpactAsphaltCoverFailureMechanism(); var context = new WaveImpactAsphaltCoverWaveConditionsCalculationContext(new WaveImpactAsphaltCoverWaveConditionsCalculation(), - failureMechanism, assessmentSection); + failureMechanism, assessmentSection); // Call IFileExporter fileExporter = configurationExportInfo.CreateFileExporter(context, "test"); Index: Ringtoets/WaveImpactAsphaltCover/test/Ringtoets.WaveImpactAsphaltCover.Plugin.Test/ExportInfos/WaveImpactAsphaltCoverWaveConditionsCalculationGroupContextExportInfoTest.cs =================================================================== diff -u -rf9f7e585da06fc8ab1b8ab92ce4dd64bd66d8f04 -r96cd93f1a08294e5af3fec5f5ae0b59cbe914c4b --- Ringtoets/WaveImpactAsphaltCover/test/Ringtoets.WaveImpactAsphaltCover.Plugin.Test/ExportInfos/WaveImpactAsphaltCoverWaveConditionsCalculationGroupContextExportInfoTest.cs (.../WaveImpactAsphaltCoverWaveConditionsCalculationGroupContextExportInfoTest.cs) (revision f9f7e585da06fc8ab1b8ab92ce4dd64bd66d8f04) +++ Ringtoets/WaveImpactAsphaltCover/test/Ringtoets.WaveImpactAsphaltCover.Plugin.Test/ExportInfos/WaveImpactAsphaltCoverWaveConditionsCalculationGroupContextExportInfoTest.cs (.../WaveImpactAsphaltCoverWaveConditionsCalculationGroupContextExportInfoTest.cs) (revision 96cd93f1a08294e5af3fec5f5ae0b59cbe914c4b) @@ -27,11 +27,11 @@ using Rhino.Mocks; using Ringtoets.Common.Data.AssessmentSection; using Ringtoets.Common.Data.Calculation; -using Ringtoets.Revetment.IO; +using Ringtoets.Revetment.IO.Exporters; using Ringtoets.Revetment.TestUtil; using Ringtoets.WaveImpactAsphaltCover.Data; using Ringtoets.WaveImpactAsphaltCover.Forms.PresentationObjects; -using Ringtoets.WaveImpactAsphaltCover.IO; +using Ringtoets.WaveImpactAsphaltCover.IO.Exporters; namespace Ringtoets.WaveImpactAsphaltCover.Plugin.Test.ExportInfos { @@ -218,8 +218,8 @@ mocks.ReplayAll(); var context = new WaveImpactAsphaltCoverWaveConditionsCalculationGroupContext(new CalculationGroup(), - new WaveImpactAsphaltCoverFailureMechanism(), - assessmentSection); + new WaveImpactAsphaltCoverFailureMechanism(), + assessmentSection); // Call IFileExporter fileExporter = configurationExportInfo.CreateFileExporter(context, "test"); @@ -247,8 +247,8 @@ mocks.ReplayAll(); var context = new WaveImpactAsphaltCoverWaveConditionsCalculationGroupContext(new CalculationGroup(), - new WaveImpactAsphaltCoverFailureMechanism(), - assessmentSection); + new WaveImpactAsphaltCoverFailureMechanism(), + assessmentSection); // Call bool isEnabled = configurationExportInfo.IsEnabled(context); @@ -280,8 +280,8 @@ } var context = new WaveImpactAsphaltCoverWaveConditionsCalculationGroupContext(calculationGroup, - new WaveImpactAsphaltCoverFailureMechanism(), - assessmentSection); + new WaveImpactAsphaltCoverFailureMechanism(), + assessmentSection); // Call bool isEnabled = configurationExportInfo.IsEnabled(context);