Index: Ringtoets/Common/src/Ringtoets.Common.IO/FileImporters/CalculationConfigurationImporter.cs =================================================================== diff -u -r3f8a98df037e5ab1623b4d786a37bf3797b85f78 -rcc8b9d8e93577a236afec4dd16a25f89996241fa --- Ringtoets/Common/src/Ringtoets.Common.IO/FileImporters/CalculationConfigurationImporter.cs (.../CalculationConfigurationImporter.cs) (revision 3f8a98df037e5ab1623b4d786a37bf3797b85f78) +++ Ringtoets/Common/src/Ringtoets.Common.IO/FileImporters/CalculationConfigurationImporter.cs (.../CalculationConfigurationImporter.cs) (revision cc8b9d8e93577a236afec4dd16a25f89996241fa) @@ -117,6 +117,24 @@ /// Thrown when something goes wrong while parsing. protected abstract ICalculation ParseReadCalculation(TReadCalculation readCalculation); + /// + /// Performs the provided and handles any thrown . + /// + /// The action to perform. + /// The error message to provide when rethrowing any thrown . + /// Thrown when throws an . + protected static void PerformActionHandlingAnyArgumentOutOfRangeException(Action action, string errorMessage) + { + try + { + action(); + } + catch (ArgumentOutOfRangeException e) + { + throw new CriticalFileValidationException($"{errorMessage} {e.Message}"); + } + } + private ReadResult ReadConfiguration() { try Index: Ringtoets/Piping/src/Ringtoets.Piping.IO/Importers/PipingCalculationConfigurationImporter.cs =================================================================== diff -u -r24c6381ad343979eeeabaf26e1ab9a85b482f607 -rcc8b9d8e93577a236afec4dd16a25f89996241fa --- Ringtoets/Piping/src/Ringtoets.Piping.IO/Importers/PipingCalculationConfigurationImporter.cs (.../PipingCalculationConfigurationImporter.cs) (revision 24c6381ad343979eeeabaf26e1ab9a85b482f607) +++ Ringtoets/Piping/src/Ringtoets.Piping.IO/Importers/PipingCalculationConfigurationImporter.cs (.../PipingCalculationConfigurationImporter.cs) (revision cc8b9d8e93577a236afec4dd16a25f89996241fa) @@ -303,23 +303,5 @@ pipingCalculation.InputParameters.DampingFactorExit = logNormalDistribution; } } - - /// - /// Performs the provided and handles any thrown . - /// - /// The action to perform. - /// The error message to provide when rethrowing any thrown . - /// Thrown when throws an . - private static void PerformActionHandlingAnyArgumentOutOfRangeException(Action action, string errorMessage) - { - try - { - action(); - } - catch (ArgumentOutOfRangeException e) - { - throw new CriticalFileValidationException($"{errorMessage} {e.Message}"); - } - } } } \ No newline at end of file Index: Ringtoets/Revetment/src/Ringtoets.Revetment.Data/WaveConditionsInput.cs =================================================================== diff -u -r974fb1eadbd8a630c7a992648ad42ac85ec205b1 -rcc8b9d8e93577a236afec4dd16a25f89996241fa --- Ringtoets/Revetment/src/Ringtoets.Revetment.Data/WaveConditionsInput.cs (.../WaveConditionsInput.cs) (revision 974fb1eadbd8a630c7a992648ad42ac85ec205b1) +++ Ringtoets/Revetment/src/Ringtoets.Revetment.Data/WaveConditionsInput.cs (.../WaveConditionsInput.cs) (revision cc8b9d8e93577a236afec4dd16a25f89996241fa) @@ -80,7 +80,7 @@ { get { - return HydraulicBoundaryLocation != null ? HydraulicBoundaryLocation.DesignWaterLevel : new RoundedDouble(2, double.NaN); + return HydraulicBoundaryLocation?.DesignWaterLevel ?? new RoundedDouble(2, double.NaN); } } Index: Ringtoets/Revetment/src/Ringtoets.Revetment.IO/Importers/WaveConditionsCalculationConfigurationImporter.cs =================================================================== diff -u -r24c6381ad343979eeeabaf26e1ab9a85b482f607 -rcc8b9d8e93577a236afec4dd16a25f89996241fa --- Ringtoets/Revetment/src/Ringtoets.Revetment.IO/Importers/WaveConditionsCalculationConfigurationImporter.cs (.../WaveConditionsCalculationConfigurationImporter.cs) (revision 24c6381ad343979eeeabaf26e1ab9a85b482f607) +++ Ringtoets/Revetment/src/Ringtoets.Revetment.IO/Importers/WaveConditionsCalculationConfigurationImporter.cs (.../WaveConditionsCalculationConfigurationImporter.cs) (revision cc8b9d8e93577a236afec4dd16a25f89996241fa) @@ -22,11 +22,13 @@ using System; using System.Collections.Generic; using System.Linq; +using Core.Common.Base.Data; using Ringtoets.Common.Data.Calculation; using Ringtoets.Common.Data.Hydraulics; using Ringtoets.Common.IO.Exceptions; using Ringtoets.Common.IO.FileImporters; using Ringtoets.Revetment.Data; +using Ringtoets.Revetment.IO.Properties; using Ringtoets.Revetment.IO.Readers; using RingtoetsCommonIOResources = Ringtoets.Common.IO.Properties.Resources; @@ -77,6 +79,7 @@ }; ReadHydraulicBoundaryLocation(readCalculation, waveConditionsCalculation); + ReadBoundaries(readCalculation, waveConditionsCalculation); return waveConditionsCalculation; } @@ -88,7 +91,7 @@ /// The calculation to configure. /// Thrown when the /// has a set which is not available in . - private void ReadHydraulicBoundaryLocation(ReadWaveConditionsCalculation readCalculation, T calculation) + private void ReadHydraulicBoundaryLocation(ReadWaveConditionsCalculation readCalculation, IWaveConditionsCalculation calculation) { if (readCalculation.HydraulicBoundaryLocation != null) { @@ -104,5 +107,55 @@ calculation.InputParameters.HydraulicBoundaryLocation = location; } } + + /// + /// Reads the entry point and exit point. + /// + /// The calculation read from the imported file. + /// The calculation to configure. + /// Thrown when one of the boundaries is invalid. + private static void ReadBoundaries(ReadWaveConditionsCalculation readCalculation, IWaveConditionsCalculation calculation) + { + bool hasUpperBoundaryRevetment = readCalculation.UpperBoundaryRevetment.HasValue; + bool hasLowerBoundaryRevetment = readCalculation.LowerBoundaryRevetment.HasValue; + bool hasUpperBoundaryWaterLevels = readCalculation.UpperBoundaryWaterLevels.HasValue; + bool hasLowerBoundaryWaterLevels = readCalculation.LowerBoundaryWaterLevels.HasValue; + + if (hasUpperBoundaryRevetment) + { + var upperBoundaryRevetment = (double) readCalculation.UpperBoundaryRevetment; + + PerformActionHandlingAnyArgumentOutOfRangeException( + () => calculation.InputParameters.UpperBoundaryRevetment = (RoundedDouble) upperBoundaryRevetment, + string.Format(Resources.WaveConditionsCalculationConfigurationImporter_ReadBoundaries_Upper_boundary_revetment_0_invalid, upperBoundaryRevetment)); + } + + if (hasLowerBoundaryRevetment) + { + var lowerBoundaryRevetment = (double) readCalculation.LowerBoundaryRevetment; + + PerformActionHandlingAnyArgumentOutOfRangeException( + () => calculation.InputParameters.LowerBoundaryRevetment = (RoundedDouble) lowerBoundaryRevetment, + string.Format(Resources.WaveConditionsCalculationConfigurationImporter_ReadBoundaries_Lower_boundary_revetment_0_invalid, lowerBoundaryRevetment)); + } + + if (hasUpperBoundaryWaterLevels) + { + var upperBoundaryWaterLevels = (double) readCalculation.UpperBoundaryWaterLevels; + + PerformActionHandlingAnyArgumentOutOfRangeException( + () => calculation.InputParameters.UpperBoundaryWaterLevels = (RoundedDouble) upperBoundaryWaterLevels, + string.Format(Resources.WaveConditionsCalculationConfigurationImporter_ReadBoundaries_Upper_boundary_waterlevels_0_invalid, upperBoundaryWaterLevels)); + } + + if (hasLowerBoundaryWaterLevels) + { + var lowerBoundaryWaterLevels = (double) readCalculation.LowerBoundaryWaterLevels; + + PerformActionHandlingAnyArgumentOutOfRangeException( + () => calculation.InputParameters.LowerBoundaryWaterLevels = (RoundedDouble) lowerBoundaryWaterLevels, + string.Format(Resources.WaveConditionsCalculationConfigurationImporter_ReadBoundaries_Lower_boundary_waterlevels_0_invalid, lowerBoundaryWaterLevels)); + } + } } } \ No newline at end of file Index: Ringtoets/Revetment/src/Ringtoets.Revetment.IO/Properties/Resources.Designer.cs =================================================================== diff -u -rb84f4b9c37b5ce0bd49b65269c4984c0bc1543e8 -rcc8b9d8e93577a236afec4dd16a25f89996241fa --- Ringtoets/Revetment/src/Ringtoets.Revetment.IO/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision b84f4b9c37b5ce0bd49b65269c4984c0bc1543e8) +++ Ringtoets/Revetment/src/Ringtoets.Revetment.IO/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision cc8b9d8e93577a236afec4dd16a25f89996241fa) @@ -82,9 +82,7 @@ } /// - /// Looks up a localized string similar to <?xml version="1.0" encoding="UTF-8"?> - /// - ///<!-- + /// Looks up a localized string similar to <?xml version="1.0" encoding="UTF-8"?><!-- ///Copyright (C) Stichting Deltares 2016. All rights reserved. /// ///This file is part of Ringtoets. @@ -95,7 +93,7 @@ ///(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 warrant [rest of string was truncated]";. + ///but WITHOUT ANY WARRANTY; without even the implied warranty of [rest of string was truncated]";. /// internal static string BekledingenHrConfiguratieSchema { get { @@ -149,6 +147,46 @@ } /// + /// Looks up a localized string similar to Een waarde van '{0}' als ondergrens bekledingen is ongeldig.. + /// + internal static string WaveConditionsCalculationConfigurationImporter_ReadBoundaries_Lower_boundary_revetment_0_invalid { + get { + return ResourceManager.GetString("WaveConditionsCalculationConfigurationImporter_ReadBoundaries_Lower_boundary_reve" + + "tment_0_invalid", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Een waarde van '{0}' als ondergrens van de rekenreeks is ongeldig.. + /// + internal static string WaveConditionsCalculationConfigurationImporter_ReadBoundaries_Lower_boundary_waterlevels_0_invalid { + get { + return ResourceManager.GetString("WaveConditionsCalculationConfigurationImporter_ReadBoundaries_Lower_boundary_wate" + + "rlevels_0_invalid", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Een waarde van '{0}' als bovengrens bekledingen is ongeldig.. + /// + internal static string WaveConditionsCalculationConfigurationImporter_ReadBoundaries_Upper_boundary_revetment_0_invalid { + get { + return ResourceManager.GetString("WaveConditionsCalculationConfigurationImporter_ReadBoundaries_Upper_boundary_reve" + + "tment_0_invalid", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Een waarde van '{0}' als bovengrens van de rekenreeks is ongeldig.. + /// + internal static string WaveConditionsCalculationConfigurationImporter_ReadBoundaries_Upper_boundary_waterlevels_0_invalid { + get { + return ResourceManager.GetString("WaveConditionsCalculationConfigurationImporter_ReadBoundaries_Upper_boundary_wate" + + "rlevels_0_invalid", resourceCulture); + } + } + + /// /// Looks up a localized string similar to {0} Er zijn geen golfrandvoorwaarden geƫxporteerd.. /// internal static string WaveConditionsExporter_Error_Exception_0_no_WaveConditions_exported { Index: Ringtoets/Revetment/src/Ringtoets.Revetment.IO/Properties/Resources.resx =================================================================== diff -u -rb84f4b9c37b5ce0bd49b65269c4984c0bc1543e8 -rcc8b9d8e93577a236afec4dd16a25f89996241fa --- Ringtoets/Revetment/src/Ringtoets.Revetment.IO/Properties/Resources.resx (.../Resources.resx) (revision b84f4b9c37b5ce0bd49b65269c4984c0bc1543e8) +++ Ringtoets/Revetment/src/Ringtoets.Revetment.IO/Properties/Resources.resx (.../Resources.resx) (revision cc8b9d8e93577a236afec4dd16a25f89996241fa) @@ -145,4 +145,16 @@ ..\Resources\BekledingenHrConfiguratieSchema.xsd;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;Windows-1252 + + Een waarde van '{0}' als bovengrens bekledingen is ongeldig. + + + Een waarde van '{0}' als ondergrens bekledingen is ongeldig. + + + Een waarde van '{0}' als bovengrens van de rekenreeks is ongeldig. + + + Een waarde van '{0}' als ondergrens van de rekenreeks is ongeldig. + \ No newline at end of file Index: Ringtoets/Revetment/test/Ringtoets.Revetment.IO.Test/Importers/WaveConditionsCalculationConfigurationImporterTest.cs =================================================================== diff -u -r24c6381ad343979eeeabaf26e1ab9a85b482f607 -rcc8b9d8e93577a236afec4dd16a25f89996241fa --- Ringtoets/Revetment/test/Ringtoets.Revetment.IO.Test/Importers/WaveConditionsCalculationConfigurationImporterTest.cs (.../WaveConditionsCalculationConfigurationImporterTest.cs) (revision 24c6381ad343979eeeabaf26e1ab9a85b482f607) +++ Ringtoets/Revetment/test/Ringtoets.Revetment.IO.Test/Importers/WaveConditionsCalculationConfigurationImporterTest.cs (.../WaveConditionsCalculationConfigurationImporterTest.cs) (revision cc8b9d8e93577a236afec4dd16a25f89996241fa) @@ -23,6 +23,7 @@ using System.IO; using System.Linq; using Core.Common.Base; +using Core.Common.Base.Data; using Core.Common.TestUtil; using NUnit.Framework; using Ringtoets.Common.Data; @@ -68,6 +69,34 @@ } [Test] + [SetCulture("nl-NL")] + [TestCase("validConfigurationInvalidRevetmentBoundaries.xml", + "Een waarde van '2,2' als ondergrens bekledingen is ongeldig. De bovengrens van de bekleding moet boven de ondergrens liggen.")] + [TestCase("validConfigurationInvalidWaterLevelBoundaries.xml", + "Een waarde van '2,2' als ondergrens van de rekenreeks is ongeldig. De bovengrens van de rekenreeks moet boven de ondergrens liggen.")] + public void Import_ValidConfigurationInvalidData_LogMessageAndContinueImport(string file, string expectedErrorMessage) + { + // Setup + string filePath = Path.Combine(path, file); + + var calculationGroup = new CalculationGroup(); + var importer = new WaveConditionsCalculationConfigurationImporter( + filePath, + calculationGroup, + Enumerable.Empty()); + + // Call + var successful = false; + Action call = () => successful = importer.Import(); + + // Assert + string expectedMessage = $"{expectedErrorMessage} Berekening 'Berekening 1' is overgeslagen."; + TestHelper.AssertLogMessageIsGenerated(call, expectedMessage, 1); + Assert.IsTrue(successful); + CollectionAssert.IsEmpty(calculationGroup.Children); + } + + [Test] public void Import_HydraulicBoundaryLocationUnknown_LogMessageAndContinueImport() { // Setup @@ -117,7 +146,11 @@ Name = "Berekening 1", InputParameters = { - HydraulicBoundaryLocation = hydraulicBoundaryLocation + HydraulicBoundaryLocation = hydraulicBoundaryLocation, + UpperBoundaryRevetment = (RoundedDouble) 10, + LowerBoundaryRevetment = (RoundedDouble) 2, + UpperBoundaryWaterLevels = (RoundedDouble) 9, + LowerBoundaryWaterLevels = (RoundedDouble) 4 } }; @@ -129,6 +162,10 @@ { Assert.AreEqual(expectedCalculation.Name, actualCalculation.Name); Assert.AreSame(expectedCalculation.InputParameters.HydraulicBoundaryLocation, actualCalculation.InputParameters.HydraulicBoundaryLocation); + Assert.AreEqual(expectedCalculation.InputParameters.UpperBoundaryRevetment, actualCalculation.InputParameters.UpperBoundaryRevetment); + Assert.AreEqual(expectedCalculation.InputParameters.LowerBoundaryRevetment, actualCalculation.InputParameters.LowerBoundaryRevetment); + Assert.AreEqual(expectedCalculation.InputParameters.UpperBoundaryWaterLevels, actualCalculation.InputParameters.UpperBoundaryWaterLevels); + Assert.AreEqual(expectedCalculation.InputParameters.LowerBoundaryWaterLevels, actualCalculation.InputParameters.LowerBoundaryWaterLevels); } private class SimpleWaveConditionsCalculation : Observable, IWaveConditionsCalculation Index: Ringtoets/Revetment/test/Ringtoets.Revetment.IO.Test/test-data/WaveConditionsCalculationConfigurationImporter/validConfigurationFullCalculation.xml =================================================================== diff -u -r038eb94cddc025675fb784caca7acd7f4ec39b89 -rcc8b9d8e93577a236afec4dd16a25f89996241fa --- Ringtoets/Revetment/test/Ringtoets.Revetment.IO.Test/test-data/WaveConditionsCalculationConfigurationImporter/validConfigurationFullCalculation.xml (.../validConfigurationFullCalculation.xml) (revision 038eb94cddc025675fb784caca7acd7f4ec39b89) +++ Ringtoets/Revetment/test/Ringtoets.Revetment.IO.Test/test-data/WaveConditionsCalculationConfigurationImporter/validConfigurationFullCalculation.xml (.../validConfigurationFullCalculation.xml) (revision cc8b9d8e93577a236afec4dd16a25f89996241fa) @@ -2,10 +2,10 @@ HRlocatie - 1.1 - 2.2 - 3.3 - 4.4 + 10 + 2 + 9 + 4 0.5 Voorlandprofiel 5.5 Index: Ringtoets/Revetment/test/Ringtoets.Revetment.IO.Test/test-data/WaveConditionsCalculationConfigurationImporter/validConfigurationInvalidRevetmentBoundaries.xml =================================================================== diff -u --- Ringtoets/Revetment/test/Ringtoets.Revetment.IO.Test/test-data/WaveConditionsCalculationConfigurationImporter/validConfigurationInvalidRevetmentBoundaries.xml (revision 0) +++ Ringtoets/Revetment/test/Ringtoets.Revetment.IO.Test/test-data/WaveConditionsCalculationConfigurationImporter/validConfigurationInvalidRevetmentBoundaries.xml (revision cc8b9d8e93577a236afec4dd16a25f89996241fa) @@ -0,0 +1,7 @@ + + + + 1.1 + 2.2 + + Index: Ringtoets/Revetment/test/Ringtoets.Revetment.IO.Test/test-data/WaveConditionsCalculationConfigurationImporter/validConfigurationInvalidWaterLevelBoundaries.xml =================================================================== diff -u --- Ringtoets/Revetment/test/Ringtoets.Revetment.IO.Test/test-data/WaveConditionsCalculationConfigurationImporter/validConfigurationInvalidWaterLevelBoundaries.xml (revision 0) +++ Ringtoets/Revetment/test/Ringtoets.Revetment.IO.Test/test-data/WaveConditionsCalculationConfigurationImporter/validConfigurationInvalidWaterLevelBoundaries.xml (revision cc8b9d8e93577a236afec4dd16a25f89996241fa) @@ -0,0 +1,7 @@ + + + + 1.1 + 2.2 + +