Index: Ringtoets/Common/src/Ringtoets.Common.IO/Writers/CalculationConfigurationWriter.cs =================================================================== diff -u -r97c94a903e0fd98edd8cd4120340f91f06d3955c -r0e700dc5121b8f56c96d1d552056bbe6ebe29300 --- Ringtoets/Common/src/Ringtoets.Common.IO/Writers/CalculationConfigurationWriter.cs (.../CalculationConfigurationWriter.cs) (revision 97c94a903e0fd98edd8cd4120340f91f06d3955c) +++ Ringtoets/Common/src/Ringtoets.Common.IO/Writers/CalculationConfigurationWriter.cs (.../CalculationConfigurationWriter.cs) (revision 0e700dc5121b8f56c96d1d552056bbe6ebe29300) @@ -41,13 +41,15 @@ /// /// The calculation to write. /// The writer to use for writing. + /// Thrown when the is closed. protected abstract void WriteCalculation(T calculation, XmlWriter writer); /// /// Writes the in XML format to file. /// /// The distributions, as tuples of name and distribution, to write. /// The writer to use for writing. + /// Thrown when the is closed. protected static void WriteDistributions(IEnumerable> distributions, XmlWriter writer) { writer.WriteStartElement(ConfigurationSchemaIdentifiers.StochastsElement); Index: Ringtoets/Common/test/Ringtoets.Common.Data.TestUtil.Test/TestHydraulicBoundaryLocationTest.cs =================================================================== diff -u -rcfca0be21e050ae7ed7626ef4e3b1472eecc69a1 -r0e700dc5121b8f56c96d1d552056bbe6ebe29300 --- Ringtoets/Common/test/Ringtoets.Common.Data.TestUtil.Test/TestHydraulicBoundaryLocationTest.cs (.../TestHydraulicBoundaryLocationTest.cs) (revision cfca0be21e050ae7ed7626ef4e3b1472eecc69a1) +++ Ringtoets/Common/test/Ringtoets.Common.Data.TestUtil.Test/TestHydraulicBoundaryLocationTest.cs (.../TestHydraulicBoundaryLocationTest.cs) (revision 0e700dc5121b8f56c96d1d552056bbe6ebe29300) @@ -49,6 +49,29 @@ } [Test] + public void Constructor_WithName_ExpectedValues() + { + // Setup + const string name = "some name"; + + // Call + var testLocation = new TestHydraulicBoundaryLocation(name); + + // Assert + Assert.IsInstanceOf(testLocation); + Assert.AreEqual(0, testLocation.Id); + Assert.AreEqual(name, testLocation.Name); + Assert.AreEqual(new Point2D(0, 0), testLocation.Location); + + Assert.IsNull(testLocation.DesignWaterLevelOutput); + Assert.IsNull(testLocation.WaveHeightOutput); + Assert.IsNaN(testLocation.DesignWaterLevel); + Assert.IsNaN(testLocation.WaveHeight); + Assert.AreEqual(CalculationConvergence.NotCalculated, testLocation.DesignWaterLevelCalculationConvergence); + Assert.AreEqual(CalculationConvergence.NotCalculated, testLocation.WaveHeightCalculationConvergence); + } + + [Test] public void CreateDesignWaterLevelCalculated_DesignWaterLevel_ExpectedValues() { // Setup Index: Ringtoets/Common/test/Ringtoets.Common.Data.TestUtil/TestHydraulicBoundaryLocation.cs =================================================================== diff -u -r20a3e0fe462e2afb58034a32ac56c063c7d9b5e2 -r0e700dc5121b8f56c96d1d552056bbe6ebe29300 --- Ringtoets/Common/test/Ringtoets.Common.Data.TestUtil/TestHydraulicBoundaryLocation.cs (.../TestHydraulicBoundaryLocation.cs) (revision 20a3e0fe462e2afb58034a32ac56c063c7d9b5e2) +++ Ringtoets/Common/test/Ringtoets.Common.Data.TestUtil/TestHydraulicBoundaryLocation.cs (.../TestHydraulicBoundaryLocation.cs) (revision 0e700dc5121b8f56c96d1d552056bbe6ebe29300) @@ -30,6 +30,13 @@ public class TestHydraulicBoundaryLocation : HydraulicBoundaryLocation { /// + /// Creates a new instance of + /// with the given name. + /// + /// The name for the . + public TestHydraulicBoundaryLocation(string name) : base(0, name, 0, 0) {} + + /// /// Creates a new instance of . /// public TestHydraulicBoundaryLocation() : this(null, null) {} @@ -41,7 +48,7 @@ /// The design water level result to set in the output. /// The wave height result to set in the output. private TestHydraulicBoundaryLocation(double? designWaterLevel, double? waveHeight) - : base(0, string.Empty, 0, 0) + : this(string.Empty) { if (designWaterLevel.HasValue) { Index: Ringtoets/Common/test/Ringtoets.Common.IO.Test/Writers/CalculationConfigurationWriterTest.cs =================================================================== diff -u -r97c94a903e0fd98edd8cd4120340f91f06d3955c -r0e700dc5121b8f56c96d1d552056bbe6ebe29300 --- Ringtoets/Common/test/Ringtoets.Common.IO.Test/Writers/CalculationConfigurationWriterTest.cs (.../CalculationConfigurationWriterTest.cs) (revision 97c94a903e0fd98edd8cd4120340f91f06d3955c) +++ Ringtoets/Common/test/Ringtoets.Common.IO.Test/Writers/CalculationConfigurationWriterTest.cs (.../CalculationConfigurationWriterTest.cs) (revision 0e700dc5121b8f56c96d1d552056bbe6ebe29300) @@ -138,7 +138,7 @@ string filePath = TestHelper.GetScratchPadPath("test_distributions_write.xml"); string expectedXmlFilePath = TestHelper.GetTestDataPath( TestDataPath.Ringtoets.Common.IO, - Path.Combine("CalculationConfigurationWriter", "distributions.xml")); + Path.Combine(nameof(CalculationConfigurationWriter), "distributions.xml")); var distributions = new List> { Fisheye: Tag 0e700dc5121b8f56c96d1d552056bbe6ebe29300 refers to a dead (removed) revision in file `Ringtoets/Common/test/Ringtoets.Common.IO.Test/test-data/CalculationConfigurationWriter/folderWithSubfolder.xml'. Fisheye: No comparison available. Pass `N' to diff? Index: Ringtoets/Revetment/src/Ringtoets.Revetment.IO/Ringtoets.Revetment.IO.csproj =================================================================== diff -u -r23d1e296e2da4364fbfe346e68d582dfcf966bb0 -r0e700dc5121b8f56c96d1d552056bbe6ebe29300 --- Ringtoets/Revetment/src/Ringtoets.Revetment.IO/Ringtoets.Revetment.IO.csproj (.../Ringtoets.Revetment.IO.csproj) (revision 23d1e296e2da4364fbfe346e68d582dfcf966bb0) +++ Ringtoets/Revetment/src/Ringtoets.Revetment.IO/Ringtoets.Revetment.IO.csproj (.../Ringtoets.Revetment.IO.csproj) (revision 0e700dc5121b8f56c96d1d552056bbe6ebe29300) @@ -38,6 +38,7 @@ + @@ -52,6 +53,8 @@ True Resources.resx + + @@ -82,6 +85,10 @@ Ringtoets.Common.Data False + + {52BA7627-CBAB-4209-BE77-3B5F31378277} + Ringtoets.Common.IO + {87C2C553-C0BC-40BF-B1EA-B83BFF357F27} Ringtoets.Revetment.Data Index: Ringtoets/Revetment/src/Ringtoets.Revetment.IO/WaveConditionsInputConfigurationSchemaIdentifiers.cs =================================================================== diff -u --- Ringtoets/Revetment/src/Ringtoets.Revetment.IO/WaveConditionsInputConfigurationSchemaIdentifiers.cs (revision 0) +++ Ringtoets/Revetment/src/Ringtoets.Revetment.IO/WaveConditionsInputConfigurationSchemaIdentifiers.cs (revision 0e700dc5121b8f56c96d1d552056bbe6ebe29300) @@ -0,0 +1,94 @@ +// 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. + +namespace Ringtoets.Revetment.IO +{ + /// + /// Container of identifiers related to the piping configuration schema definition. + /// + internal static class WaveConditionsInputConfigurationSchemaIdentifiers + { + /// + /// The tag of elements containing the name of the hydraulic boundary location. + /// + internal const string HydraulicBoundaryLocationElement = "hrlocatie"; + + /// + /// The tag of elements containing the upper boundary of revetment. + /// + internal const string UpperBoundaryRevetment = "bovengrensbekleding"; + + /// + /// The tag of elements containing the lower boundary of revetment. + /// + internal const string LowerBoundaryRevetment = "ondergrensbekleding"; + + /// + /// The tag of elements containing the upper boundary of water level. + /// + internal const string UpperBoundaryWaterLevels = "bovengrenswaterstanden"; + + /// + /// The tag of elements containing the lower boundary of water level. + /// + internal const string LowerBoundaryWaterLevels = "ondergrenswaterstanden"; + + /// + /// The tag of elements containing the step size of the water levels. + /// + internal const string StepSize = "stapgrootte"; + + /// + /// The tag of elements containing the name of the foreshore profile. + /// + internal const string ForeshoreProfile = "voorlandprofiel"; + + /// + /// The tag of elements containing the orientation of the foreshore profile. + /// + internal const string Orientation = "orientatie"; + + /// + /// The tag of elements containing parameters that define wave reduction. + /// + internal const string WaveReduction = "golfreductie"; + + /// + /// The tag of elements containing the value indicating whether to use break water. + /// + internal const string UseBreakWater = "damgebruiken"; + + /// + /// The tag of elements containing the type of the break water. + /// + internal const string BreakWaterType = "damtype"; + + /// + /// The tag of elements containing the height of the break water. + /// + internal const string BreakWaterHeight = "damhoogte"; + + /// + /// The tag of elements containing the value indicating whether to use break water. + /// + internal const string UseForeshore = "voorlandgebruiken"; + } +} \ No newline at end of file Index: Ringtoets/Revetment/src/Ringtoets.Revetment.IO/WaveConditionsInputConfigurationWriter.cs =================================================================== diff -u --- Ringtoets/Revetment/src/Ringtoets.Revetment.IO/WaveConditionsInputConfigurationWriter.cs (revision 0) +++ Ringtoets/Revetment/src/Ringtoets.Revetment.IO/WaveConditionsInputConfigurationWriter.cs (revision 0e700dc5121b8f56c96d1d552056bbe6ebe29300) @@ -0,0 +1,116 @@ +// 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.ComponentModel; +using System.Globalization; +using System.Xml; +using Ringtoets.Common.Data.Calculation; +using Ringtoets.Common.Data.DikeProfiles; +using Ringtoets.Common.IO.Schema; +using Ringtoets.Common.IO.Writers; +using Ringtoets.Revetment.Data; + +namespace Ringtoets.Revetment.IO +{ + /// + /// 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 WaveConditionsInputConfigurationWriter : CalculationConfigurationWriter where T : class, ICalculation + { + /// + /// 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); + + writer.WriteElementString( + WaveConditionsInputConfigurationSchemaIdentifiers.HydraulicBoundaryLocationElement, + input.HydraulicBoundaryLocation.Name); + writer.WriteElementString( + WaveConditionsInputConfigurationSchemaIdentifiers.UpperBoundaryRevetment, + XmlConvert.ToString(input.UpperBoundaryRevetment)); + writer.WriteElementString( + WaveConditionsInputConfigurationSchemaIdentifiers.LowerBoundaryRevetment, + XmlConvert.ToString(input.LowerBoundaryRevetment)); + writer.WriteElementString( + WaveConditionsInputConfigurationSchemaIdentifiers.UpperBoundaryWaterLevels, + XmlConvert.ToString(input.UpperBoundaryWaterLevels)); + writer.WriteElementString( + WaveConditionsInputConfigurationSchemaIdentifiers.LowerBoundaryWaterLevels, + XmlConvert.ToString(input.LowerBoundaryWaterLevels)); + writer.WriteElementString( + WaveConditionsInputConfigurationSchemaIdentifiers.StepSize, + string.Format(CultureInfo.InvariantCulture, "{0:0.0}", input.StepSize.AsValue())); + writer.WriteElementString( + WaveConditionsInputConfigurationSchemaIdentifiers.ForeshoreProfile, + input.ForeshoreProfile.Name); + writer.WriteElementString( + WaveConditionsInputConfigurationSchemaIdentifiers.Orientation, + XmlConvert.ToString(input.Orientation)); + + WriteWaveReduction(input, writer); + + writer.WriteEndElement(); + } + + private static void WriteWaveReduction(WaveConditionsInput input, XmlWriter writer) + { + writer.WriteStartElement(WaveConditionsInputConfigurationSchemaIdentifiers.WaveReduction); + + writer.WriteElementString( + WaveConditionsInputConfigurationSchemaIdentifiers.UseBreakWater, + XmlConvert.ToString(input.UseBreakWater)); + writer.WriteElementString( + WaveConditionsInputConfigurationSchemaIdentifiers.BreakWaterType, + BreakWaterTypeAsXmlString(input.BreakWater.Type)); + writer.WriteElementString( + WaveConditionsInputConfigurationSchemaIdentifiers.BreakWaterHeight, + XmlConvert.ToString(input.BreakWater.Height)); + writer.WriteElementString( + WaveConditionsInputConfigurationSchemaIdentifiers.UseForeshore, + XmlConvert.ToString(input.UseForeshore)); + + writer.WriteEndElement(); + } + + private static string BreakWaterTypeAsXmlString(BreakWaterType type) + { + switch (type) + { + case BreakWaterType.Caisson: + return "caisson"; + case BreakWaterType.Dam: + return "havendam"; + case BreakWaterType.Wall: + return "verticalewand"; + default: + throw new InvalidEnumArgumentException(nameof(type), (int) type, typeof(BreakWaterType)); + } + } + } +} \ No newline at end of file Index: Ringtoets/Revetment/test/Ringtoets.Revetment.IO.Test/Ringtoets.Revetment.IO.Test.csproj =================================================================== diff -u -r6a5d7b40b7ba4dcb73e393075338352d194e97c2 -r0e700dc5121b8f56c96d1d552056bbe6ebe29300 --- Ringtoets/Revetment/test/Ringtoets.Revetment.IO.Test/Ringtoets.Revetment.IO.Test.csproj (.../Ringtoets.Revetment.IO.Test.csproj) (revision 6a5d7b40b7ba4dcb73e393075338352d194e97c2) +++ Ringtoets/Revetment/test/Ringtoets.Revetment.IO.Test/Ringtoets.Revetment.IO.Test.csproj (.../Ringtoets.Revetment.IO.Test.csproj) (revision 0e700dc5121b8f56c96d1d552056bbe6ebe29300) @@ -44,6 +44,7 @@ + @@ -53,6 +54,7 @@ + @@ -81,6 +83,10 @@ Ringtoets.Common.Data True + + {52BA7627-CBAB-4209-BE77-3B5F31378277} + Ringtoets.Common.IO + {4843D6E5-066F-4795-94F5-1D53932DD03C} Ringtoets.Common.Data.TestUtil Index: Ringtoets/Revetment/test/Ringtoets.Revetment.IO.Test/WaveConditionsInputConfigurationWriterTest.cs =================================================================== diff -u --- Ringtoets/Revetment/test/Ringtoets.Revetment.IO.Test/WaveConditionsInputConfigurationWriterTest.cs (revision 0) +++ Ringtoets/Revetment/test/Ringtoets.Revetment.IO.Test/WaveConditionsInputConfigurationWriterTest.cs (revision 0e700dc5121b8f56c96d1d552056bbe6ebe29300) @@ -0,0 +1,136 @@ +// 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.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.Hydraulics; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.Common.IO.Writers; +using Ringtoets.Revetment.Data; + +namespace Ringtoets.Revetment.IO.Test +{ + [TestFixture] + public class WaveConditionsInputConfigurationWriterTest + { + [Test] + public void Constructor_Always_ReturnsConfigurationWriter() + { + // Call + var writer = new SimpleWaveConditionsInputConfigurationWriter(); + + // Assert + Assert.IsInstanceOf>(writer); + } + + [Test] + public void WriteConfiguration_SingleCalculation_WritesCompleteConfigurationToFile() + { + // Setup + string filePath = TestHelper.GetScratchPadPath("WriteConfiguration_SingleCalculation.xml"); + string expectedXmlFilePath = TestHelper.GetTestDataPath( + TestDataPath.Ringtoets.Revetment.IO, + Path.Combine(nameof(WaveConditionsInputConfigurationWriter), "completeConfiguration.xml")); + + var calculation = new SimpleWaveConditionsCalculation + { + Name = "Berekening 1", + Input = new WaveConditionsInput + { + 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.234, + Type = BreakWaterType.Dam + } + } + }; + + // Call + try + { + using (XmlWriter writer = XmlWriter.Create(filePath, new XmlWriterSettings + { + Indent = true + })) + { + // Call + new SimpleWaveConditionsInputConfigurationWriter().PublicWriteCalculation(calculation, writer); + } + + // Assert + string actualXml = File.ReadAllText(filePath); + string expectedXml = File.ReadAllText(expectedXmlFilePath); + + Assert.AreEqual(expectedXml, actualXml); + } + finally + { + File.Delete(filePath); + } + + // Assert + } + } + + public class SimpleWaveConditionsInputConfigurationWriter : WaveConditionsInputConfigurationWriter + { + protected override void WriteCalculation(SimpleWaveConditionsCalculation calculation, XmlWriter writer) + { + WriteCalculation(calculation.Name, calculation.Input, writer); + } + + public void PublicWriteCalculation(SimpleWaveConditionsCalculation calculation, XmlWriter writer) + { + WriteCalculation(calculation, writer); + } + } + + public class SimpleWaveConditionsCalculation : Observable, ICalculation + { + public string Name { get; set; } + public bool HasOutput { get; } + public Comment Comments { get; } + + public void ClearOutput() + { + throw new System.NotImplementedException(); + } + + public WaveConditionsInput Input { get; set; } + } +} \ No newline at end of file Index: Ringtoets/Revetment/test/Ringtoets.Revetment.IO.Test/test-data/WaveConditionsInputConfigurationWriter/completeConfiguration.xml =================================================================== diff -u --- Ringtoets/Revetment/test/Ringtoets.Revetment.IO.Test/test-data/WaveConditionsInputConfigurationWriter/completeConfiguration.xml (revision 0) +++ Ringtoets/Revetment/test/Ringtoets.Revetment.IO.Test/test-data/WaveConditionsInputConfigurationWriter/completeConfiguration.xml (revision 0e700dc5121b8f56c96d1d552056bbe6ebe29300) @@ -0,0 +1,17 @@ + + + Locatie1 + 1.5 + 0.5 + 1.4 + 0.6 + 1.0 + profiel1 + 67.1 + + true + havendam + 1.23 + true + + \ No newline at end of file