Index: Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.IO/GrassCoverErosionInwardsCalculationConfigurationWriter.cs =================================================================== diff -u --- Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.IO/GrassCoverErosionInwardsCalculationConfigurationWriter.cs (revision 0) +++ Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.IO/GrassCoverErosionInwardsCalculationConfigurationWriter.cs (revision 9eb8e313e0f401980ca0a4b8015d23e8a12735f7) @@ -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 +{ + /// + /// 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.IO/GrassCoverErosionInwardsConfigurationExporter.cs =================================================================== diff -u -r00a4b6318d0d1ae57df5ef362ba1e8908aa330be -r9eb8e313e0f401980ca0a4b8015d23e8a12735f7 --- Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.IO/GrassCoverErosionInwardsConfigurationExporter.cs (.../GrassCoverErosionInwardsConfigurationExporter.cs) (revision 00a4b6318d0d1ae57df5ef362ba1e8908aa330be) +++ Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.IO/GrassCoverErosionInwardsConfigurationExporter.cs (.../GrassCoverErosionInwardsConfigurationExporter.cs) (revision 9eb8e313e0f401980ca0a4b8015d23e8a12735f7) @@ -31,7 +31,7 @@ /// Exports a grass cover erosion inwards configuration and stores it as an XML file. /// public class GrassCoverErosionInwardsConfigurationExporter - : ConfigurationExporter + : ConfigurationExporter { /// Fisheye: Tag 9eb8e313e0f401980ca0a4b8015d23e8a12735f7 refers to a dead (removed) revision in file `Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.IO/GrassCoverErosionInwardsConfigurationWriter.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.IO/Ringtoets.GrassCoverErosionInwards.IO.csproj =================================================================== diff -u -r2923096aeb41e1fb5d4ba0ad43ccb9f95ca7407a -r9eb8e313e0f401980ca0a4b8015d23e8a12735f7 --- Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.IO/Ringtoets.GrassCoverErosionInwards.IO.csproj (.../Ringtoets.GrassCoverErosionInwards.IO.csproj) (revision 2923096aeb41e1fb5d4ba0ad43ccb9f95ca7407a) +++ Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.IO/Ringtoets.GrassCoverErosionInwards.IO.csproj (.../Ringtoets.GrassCoverErosionInwards.IO.csproj) (revision 9eb8e313e0f401980ca0a4b8015d23e8a12735f7) @@ -42,7 +42,7 @@ - + Index: Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.IO.Test/GrassCoverErosionInwardsCalculationConfigurationWriterTest.cs =================================================================== diff -u --- Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.IO.Test/GrassCoverErosionInwardsCalculationConfigurationWriterTest.cs (revision 0) +++ Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.IO.Test/GrassCoverErosionInwardsCalculationConfigurationWriterTest.cs (revision 9eb8e313e0f401980ca0a4b8015d23e8a12735f7) @@ -0,0 +1,284 @@ +// 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; + +namespace Ringtoets.GrassCoverErosionInwards.IO.Test +{ + [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.IO.Test/GrassCoverErosionInwardsConfigurationExporterTest.cs =================================================================== diff -u -r00a4b6318d0d1ae57df5ef362ba1e8908aa330be -r9eb8e313e0f401980ca0a4b8015d23e8a12735f7 --- Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.IO.Test/GrassCoverErosionInwardsConfigurationExporterTest.cs (.../GrassCoverErosionInwardsConfigurationExporterTest.cs) (revision 00a4b6318d0d1ae57df5ef362ba1e8908aa330be) +++ Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.IO.Test/GrassCoverErosionInwardsConfigurationExporterTest.cs (.../GrassCoverErosionInwardsConfigurationExporterTest.cs) (revision 9eb8e313e0f401980ca0a4b8015d23e8a12735f7) @@ -44,7 +44,7 @@ // Assert Assert.IsInstanceOf< ConfigurationExporter< - GrassCoverErosionInwardsConfigurationWriter, + GrassCoverErosionInwardsCalculationConfigurationWriter, GrassCoverErosionInwardsCalculation>>(exporter); } Fisheye: Tag 9eb8e313e0f401980ca0a4b8015d23e8a12735f7 refers to a dead (removed) revision in file `Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.IO.Test/GrassCoverErosionInwardsConfigurationWriterTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.IO.Test/Ringtoets.GrassCoverErosionInwards.IO.Test.csproj =================================================================== diff -u -r2923096aeb41e1fb5d4ba0ad43ccb9f95ca7407a -r9eb8e313e0f401980ca0a4b8015d23e8a12735f7 --- Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.IO.Test/Ringtoets.GrassCoverErosionInwards.IO.Test.csproj (.../Ringtoets.GrassCoverErosionInwards.IO.Test.csproj) (revision 2923096aeb41e1fb5d4ba0ad43ccb9f95ca7407a) +++ Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.IO.Test/Ringtoets.GrassCoverErosionInwards.IO.Test.csproj (.../Ringtoets.GrassCoverErosionInwards.IO.Test.csproj) (revision 9eb8e313e0f401980ca0a4b8015d23e8a12735f7) @@ -51,7 +51,7 @@ Properties\GlobalAssembly.cs - + Index: Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.IO.Test/test-data/GrassCoverErosionInwardsCalculationConfigurationWriter/completeConfiguration.xml =================================================================== diff -u --- Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.IO.Test/test-data/GrassCoverErosionInwardsCalculationConfigurationWriter/completeConfiguration.xml (revision 0) +++ Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.IO.Test/test-data/GrassCoverErosionInwardsCalculationConfigurationWriter/completeConfiguration.xml (revision 9eb8e313e0f401980ca0a4b8015d23e8a12735f7) @@ -0,0 +1,20 @@ + + + + Locatie1 + dijkProfiel + 67.1 + + true + caisson + 1.23 + true + + + + 0.1 + 0.1 + + + + \ No newline at end of file Index: Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.IO.Test/test-data/GrassCoverErosionInwardsCalculationConfigurationWriter/folderWithSubfolderAndCalculation.xml =================================================================== diff -u --- Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.IO.Test/test-data/GrassCoverErosionInwardsCalculationConfigurationWriter/folderWithSubfolderAndCalculation.xml (revision 0) +++ Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.IO.Test/test-data/GrassCoverErosionInwardsCalculationConfigurationWriter/folderWithSubfolderAndCalculation.xml (revision 9eb8e313e0f401980ca0a4b8015d23e8a12735f7) @@ -0,0 +1,39 @@ + + + + + Locatie1 + dijkProfiel + 67.1 + + true + caisson + 1.23 + true + + + + 0.1 + 0.1 + + + + + + NaN + + false + havendam + 0 + false + + + + 0.004 + 0.0006 + + + + + + \ No newline at end of file Index: Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.IO.Test/test-data/GrassCoverErosionInwardsCalculationConfigurationWriter/sparseConfiguration.xml =================================================================== diff -u --- Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.IO.Test/test-data/GrassCoverErosionInwardsCalculationConfigurationWriter/sparseConfiguration.xml (revision 0) +++ Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.IO.Test/test-data/GrassCoverErosionInwardsCalculationConfigurationWriter/sparseConfiguration.xml (revision 9eb8e313e0f401980ca0a4b8015d23e8a12735f7) @@ -0,0 +1,18 @@ + + + + NaN + + false + havendam + 0 + false + + + + 0.004 + 0.0006 + + + + \ No newline at end of file Fisheye: Tag 9eb8e313e0f401980ca0a4b8015d23e8a12735f7 refers to a dead (removed) revision in file `Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.IO.Test/test-data/GrassCoverErosionInwardsConfigurationWriter/completeConfiguration.xml'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 9eb8e313e0f401980ca0a4b8015d23e8a12735f7 refers to a dead (removed) revision in file `Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.IO.Test/test-data/GrassCoverErosionInwardsConfigurationWriter/folderWithSubfolderAndCalculation.xml'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 9eb8e313e0f401980ca0a4b8015d23e8a12735f7 refers to a dead (removed) revision in file `Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.IO.Test/test-data/GrassCoverErosionInwardsConfigurationWriter/sparseConfiguration.xml'. Fisheye: No comparison available. Pass `N' to diff?