Index: Core/Common/src/Core.Common.Base/Properties/Resources.Designer.cs =================================================================== diff -u -rfae525350cc755ecc783bd4ac3fc13aed2e4ccaa -r683ff9234262d9fa3bea5edc0abe35254f80e49d --- Core/Common/src/Core.Common.Base/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision fae525350cc755ecc783bd4ac3fc13aed2e4ccaa) +++ Core/Common/src/Core.Common.Base/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision 683ff9234262d9fa3bea5edc0abe35254f80e49d) @@ -1,25 +1,4 @@ -// Copyright (C) Stichting Deltares 2017. 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 Lesser 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 Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser 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. - -//------------------------------------------------------------------------------ +//------------------------------------------------------------------------------ // // This code was generated by a tool. // Runtime Version:4.0.30319.42000 Index: Ringtoets/Common/src/Ringtoets.Common.IO/Properties/Resources.Designer.cs =================================================================== diff -u -r8ebf5b222f3b052df95f6164ac488a5e7760cf68 -r683ff9234262d9fa3bea5edc0abe35254f80e49d --- Ringtoets/Common/src/Ringtoets.Common.IO/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision 8ebf5b222f3b052df95f6164ac488a5e7760cf68) +++ Ringtoets/Common/src/Ringtoets.Common.IO/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision 683ff9234262d9fa3bea5edc0abe35254f80e49d) @@ -2099,7 +2099,7 @@ } /// - /// Looks up a localized string similar to Het uittredepunt moet landwaarts van het intredepunt liggen voor locatie {0}.. + /// Looks up a localized string similar to Het uittredepunt moet landwaarts van het intredepunt liggen voor locatie '{0}'.. /// public static string SurfaceLinesCsvImporter_CheckCharacteristicPoints_EntryPointL_greater_or_equal_to_ExitPointL_for_0_ { get { Index: Ringtoets/Common/src/Ringtoets.Common.IO/Properties/Resources.resx =================================================================== diff -u -r8ebf5b222f3b052df95f6164ac488a5e7760cf68 -r683ff9234262d9fa3bea5edc0abe35254f80e49d --- Ringtoets/Common/src/Ringtoets.Common.IO/Properties/Resources.resx (.../Resources.resx) (revision 8ebf5b222f3b052df95f6164ac488a5e7760cf68) +++ Ringtoets/Common/src/Ringtoets.Common.IO/Properties/Resources.resx (.../Resources.resx) (revision 683ff9234262d9fa3bea5edc0abe35254f80e49d) @@ -789,6 +789,6 @@ Klaar met het inlezen van karakteristieke punten uit bestand '{0}'. - Het uittredepunt moet landwaarts van het intredepunt liggen voor locatie {0}. + Het uittredepunt moet landwaarts van het intredepunt liggen voor locatie '{0}'. \ No newline at end of file Index: Ringtoets/Common/src/Ringtoets.Common.IO/Ringtoets.Common.IO.csproj =================================================================== diff -u -rfafb2af7750af9da6d84479074522c8035fccd49 -r683ff9234262d9fa3bea5edc0abe35254f80e49d --- Ringtoets/Common/src/Ringtoets.Common.IO/Ringtoets.Common.IO.csproj (.../Ringtoets.Common.IO.csproj) (revision fafb2af7750af9da6d84479074522c8035fccd49) +++ Ringtoets/Common/src/Ringtoets.Common.IO/Ringtoets.Common.IO.csproj (.../Ringtoets.Common.IO.csproj) (revision 683ff9234262d9fa3bea5edc0abe35254f80e49d) @@ -137,6 +137,7 @@ + Index: Ringtoets/Common/src/Ringtoets.Common.IO/SurfaceLines/ISurfaceLineTransformer.cs =================================================================== diff -u -rb8fa5d6867c945f3f1744fd1455b89cadb357959 -r683ff9234262d9fa3bea5edc0abe35254f80e49d --- Ringtoets/Common/src/Ringtoets.Common.IO/SurfaceLines/ISurfaceLineTransformer.cs (.../ISurfaceLineTransformer.cs) (revision b8fa5d6867c945f3f1744fd1455b89cadb357959) +++ Ringtoets/Common/src/Ringtoets.Common.IO/SurfaceLines/ISurfaceLineTransformer.cs (.../ISurfaceLineTransformer.cs) (revision 683ff9234262d9fa3bea5edc0abe35254f80e49d) @@ -35,8 +35,9 @@ /// /// The surface line to use in the tranformation. /// The characteristic points to use in the transformation. - /// A new based on the given data or null if the transformation - /// failed. + /// A new based on the given data. + /// Thrown when transformation would not result + /// in a valid transformed instance. T Transform(SurfaceLine surfaceLine, CharacteristicPoints characteristicPoints); } } \ No newline at end of file Index: Ringtoets/Common/src/Ringtoets.Common.IO/SurfaceLines/SurfaceLineTransformException.cs =================================================================== diff -u --- Ringtoets/Common/src/Ringtoets.Common.IO/SurfaceLines/SurfaceLineTransformException.cs (revision 0) +++ Ringtoets/Common/src/Ringtoets.Common.IO/SurfaceLines/SurfaceLineTransformException.cs (revision 683ff9234262d9fa3bea5edc0abe35254f80e49d) @@ -0,0 +1,69 @@ +// Copyright (C) Stichting Deltares 2017. 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.Runtime.Serialization; +using Core.Common.IO.Exceptions; + +namespace Ringtoets.Common.IO.SurfaceLines +{ + /// + /// The exception that is thrown when transforming a generic surface line to a mechanism + /// specific surface line fails. + /// + public class SurfaceLineTransformException : Exception + { + /// + /// Initializes a new instance of the class. + /// + public SurfaceLineTransformException() {} + + /// + /// Initializes a new instance of the class + /// with a specified error message. + /// + /// The error message that explains the reason for the exception. + public SurfaceLineTransformException(string message) : base(message) {} + + /// + /// Initializes a new instance of the class + /// with a specified error message and a reference to the inner exception that is + /// the cause of this exception. + /// + /// The error message that explains the reason for the exception. + /// The exception that is the cause of the current exception, + /// or a null reference if no inner exception is specified. + public SurfaceLineTransformException(string message, Exception inner) : base(message, inner) { } + + /// + /// Initializes a new instance of with + /// serialized data. + /// The that holds the serialized + /// object data about the exception being thrown. + /// The that contains contextual + /// information about the source or destination. + /// The parameter is + /// null. + /// The class name is null or + /// is zero (0). + protected SurfaceLineTransformException(SerializationInfo info, StreamingContext context) : base(info, context) { } + } +} \ No newline at end of file Index: Ringtoets/Common/src/Ringtoets.Common.IO/SurfaceLines/SurfaceLinesCsvImporter.cs =================================================================== diff -u -ra940166534b3dd6e778de2e7c8e7e5241f3d3381 -r683ff9234262d9fa3bea5edc0abe35254f80e49d --- Ringtoets/Common/src/Ringtoets.Common.IO/SurfaceLines/SurfaceLinesCsvImporter.cs (.../SurfaceLinesCsvImporter.cs) (revision a940166534b3dd6e778de2e7c8e7e5241f3d3381) +++ Ringtoets/Common/src/Ringtoets.Common.IO/SurfaceLines/SurfaceLinesCsvImporter.cs (.../SurfaceLinesCsvImporter.cs) (revision 683ff9234262d9fa3bea5edc0abe35254f80e49d) @@ -94,8 +94,19 @@ return false; } - T[] transformedSurfaceLines = GetTransformedSurfaceLines(importSurfaceLinesResult.Items, importCharacteristicPointsResult.Items).ToArray(); + T[] transformedSurfaceLines; + try + { + transformedSurfaceLines = GetTransformedSurfaceLines(importSurfaceLinesResult.Items, importCharacteristicPointsResult.Items).ToArray(); + } + catch (SurfaceLineTransformException e) + { + Log.ErrorFormat(RingtoetsCommonIOResources.SurfaceLinesCsvImporter_CriticalErrorMessage_0_File_Skipped, + e.Message); + return false; + } + if (Canceled) { return false; @@ -132,6 +143,16 @@ } } + /// + /// Transforms the surface lines into mechanism specific surface lines with characteristic + /// points set. + /// + /// The surface lines to transform. + /// The characteristic points to use in the + /// transformation. + /// Returns a collection of mechanism specific surface lines. + /// Thrown when transforming a surface + /// line with characteristic points failed. private IEnumerable GetTransformedSurfaceLines(ICollection surfaceLines, ICollection characteristicPointsCollection) { LogMissingSurfaceLinesOrCharacteristicPoints(surfaceLines, characteristicPointsCollection); @@ -154,12 +175,7 @@ SurfaceLine surfaceLine = surfaceLineWithCharacteristicPoints.Item1; CharacteristicPoints characteristicPoints = surfaceLineWithCharacteristicPoints.Item2; - T transformedSurfaceLine = surfaceLineTransformer.Transform(surfaceLine, characteristicPoints); - if (transformedSurfaceLine == null) - { - continue; - } - yield return transformedSurfaceLine; + yield return surfaceLineTransformer.Transform(surfaceLine, characteristicPoints); } } Index: Ringtoets/Common/test/Ringtoets.Common.IO.Test/Ringtoets.Common.IO.Test.csproj =================================================================== diff -u -r3cb43b591851a35a8a3781c934a881d8c3742c9a -r683ff9234262d9fa3bea5edc0abe35254f80e49d --- Ringtoets/Common/test/Ringtoets.Common.IO.Test/Ringtoets.Common.IO.Test.csproj (.../Ringtoets.Common.IO.Test.csproj) (revision 3cb43b591851a35a8a3781c934a881d8c3742c9a) +++ Ringtoets/Common/test/Ringtoets.Common.IO.Test/Ringtoets.Common.IO.Test.csproj (.../Ringtoets.Common.IO.Test.csproj) (revision 683ff9234262d9fa3bea5edc0abe35254f80e49d) @@ -120,6 +120,7 @@ + Index: Ringtoets/Common/test/Ringtoets.Common.IO.Test/SurfaceLines/SurfaceLineTransformExceptionTest.cs =================================================================== diff -u --- Ringtoets/Common/test/Ringtoets.Common.IO.Test/SurfaceLines/SurfaceLineTransformExceptionTest.cs (revision 0) +++ Ringtoets/Common/test/Ringtoets.Common.IO.Test/SurfaceLines/SurfaceLineTransformExceptionTest.cs (revision 683ff9234262d9fa3bea5edc0abe35254f80e49d) @@ -0,0 +1,32 @@ +// Copyright (C) Stichting Deltares 2017. 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.IO.Exceptions; +using Core.Common.TestUtil; +using NUnit.Framework; + +namespace Ringtoets.Common.IO.Test.SurfaceLines +{ + [TestFixture] + public class SurfaceLineTransformExceptionTest : + CustomExceptionDesignGuidelinesTestFixture {} +} \ No newline at end of file Index: Ringtoets/Common/test/Ringtoets.Common.IO.Test/SurfaceLines/SurfaceLinesCsvImporterTest.cs =================================================================== diff -u -ra940166534b3dd6e778de2e7c8e7e5241f3d3381 -r683ff9234262d9fa3bea5edc0abe35254f80e49d --- Ringtoets/Common/test/Ringtoets.Common.IO.Test/SurfaceLines/SurfaceLinesCsvImporterTest.cs (.../SurfaceLinesCsvImporterTest.cs) (revision a940166534b3dd6e778de2e7c8e7e5241f3d3381) +++ Ringtoets/Common/test/Ringtoets.Common.IO.Test/SurfaceLines/SurfaceLinesCsvImporterTest.cs (.../SurfaceLinesCsvImporterTest.cs) (revision 683ff9234262d9fa3bea5edc0abe35254f80e49d) @@ -1091,6 +1091,38 @@ } [Test] + public void Import_TransformerThrowsTransformerException_LogErrorAndReturnFalse() + { + // Setup + var messageProvider = mocks.Stub(); + var exceptionMessage = "This is exceptional"; + transformer.Expect(t => t.Transform(Arg.Is.Anything, Arg.Is.Anything)).Throw(new SurfaceLineTransformException(exceptionMessage)); + mocks.ReplayAll(); + + const string fileName = "TwoValidSurfaceLines_WithCharacteristicPoints"; + string twovalidsurfacelinesCsv = string.Format(surfaceLineFormat, fileName); + string validSurfaceLinesFilePath = Path.Combine(pluginSurfaceLinesTestDataPath, twovalidsurfacelinesCsv); + + var surfaceLines = new TestSurfaceLineCollection(); + var surfaceLineUpdateStrategy = new TestSurfaceLineUpdateStrategy(); + var configuration = new SurfaceLinesCsvImporterConfiguration(transformer, surfaceLineUpdateStrategy); + var importer = new SurfaceLinesCsvImporter(surfaceLines, validSurfaceLinesFilePath, messageProvider, configuration); + + var importResult = true; + + // Call + Action call = () => importResult = importer.Import(); + + // Assert + string expectedMessage = $"{exceptionMessage} \r\nHet bestand wordt overgeslagen."; + TestHelper.AssertLogMessageWithLevelIsGenerated(call, Tuple.Create(expectedMessage, LogLevelConstant.Error), 5); + + Assert.IsFalse(importResult); + Assert.IsFalse(surfaceLineUpdateStrategy.Updated); + Assert.IsNull(surfaceLineUpdateStrategy.FilePath); + } + + [Test] public void Import_FileWithTwoValidLinesAndOneInvalidCharacteristicPointsDefinitionDueToUnparsableNumber_SkipInvalidRowAndLog() { // Setup Index: Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.IO/Importers/MacroStabilityInwardsSurfaceLineTransformer.cs =================================================================== diff -u -r5579d8fdef4f553fb4ba94160825ec960b89bab9 -r683ff9234262d9fa3bea5edc0abe35254f80e49d --- Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.IO/Importers/MacroStabilityInwardsSurfaceLineTransformer.cs (.../MacroStabilityInwardsSurfaceLineTransformer.cs) (revision 5579d8fdef4f553fb4ba94160825ec960b89bab9) +++ Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.IO/Importers/MacroStabilityInwardsSurfaceLineTransformer.cs (.../MacroStabilityInwardsSurfaceLineTransformer.cs) (revision 683ff9234262d9fa3bea5edc0abe35254f80e49d) @@ -66,10 +66,7 @@ }; macroStabilityInwardsSurfaceLine.SetGeometry(surfaceLine.Points); - if (!macroStabilityInwardsSurfaceLine.SetCharacteristicPoints(characteristicPoints)) - { - return null; - } + macroStabilityInwardsSurfaceLine.SetCharacteristicPoints(characteristicPoints); macroStabilityInwardsSurfaceLine.ReferenceLineIntersectionWorldPoint = result.IntersectionPoint; Index: Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.IO/Importers/RingtoetsMacroStabilityInwardsSurfaceLineExtensions.cs =================================================================== diff -u -r5579d8fdef4f553fb4ba94160825ec960b89bab9 -r683ff9234262d9fa3bea5edc0abe35254f80e49d --- Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.IO/Importers/RingtoetsMacroStabilityInwardsSurfaceLineExtensions.cs (.../RingtoetsMacroStabilityInwardsSurfaceLineExtensions.cs) (revision 5579d8fdef4f553fb4ba94160825ec960b89bab9) +++ Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.IO/Importers/RingtoetsMacroStabilityInwardsSurfaceLineExtensions.cs (.../RingtoetsMacroStabilityInwardsSurfaceLineExtensions.cs) (revision 683ff9234262d9fa3bea5edc0abe35254f80e49d) @@ -22,9 +22,11 @@ using System; using Core.Common.Base.Geometry; using log4net; -using Ringtoets.Common.IO.Properties; using Ringtoets.Common.IO.SurfaceLines; using Ringtoets.MacroStabilityInwards.Primitives; +using RingtoetsCommonDataResources = Ringtoets.Common.Data.Properties.Resources; +using RingtoetsCommonIoResources = Ringtoets.Common.IO.Properties.Resources; +using MacroStabilityInwardsIOResources = Ringtoets.MacroStabilityInwards.IO.Properties.Resources; namespace Ringtoets.MacroStabilityInwards.IO.Importers { @@ -36,6 +38,41 @@ private static readonly ILog log = LogManager.GetLogger(typeof(RingtoetsMacroStabilityInwardsSurfaceLineExtensions)); /// + /// Tries to set the relevant characteristic points from the + /// on the . + /// + /// The surface line to set characteristic points for. + /// The characteristic points to set, if the collection is valid. + /// true if the characteristic points could be set; false otherwise. + /// Thrown when is null. + public static void SetCharacteristicPoints(this RingtoetsMacroStabilityInwardsSurfaceLine surfaceLine, CharacteristicPoints characteristicPoints) + { + if (surfaceLine == null) + { + throw new ArgumentNullException(nameof(surfaceLine)); + } + if (characteristicPoints == null) + { + return; + } + + surfaceLine.TrySetSurfaceLevelOutside(characteristicPoints.SurfaceLevelOutside); + surfaceLine.TrySetDikeToeAtRiver(characteristicPoints.DikeToeAtRiver); + surfaceLine.TrySetDikeTopAtPolder(characteristicPoints.DikeTopAtPolder); + surfaceLine.TrySetDikeToeAtPolder(characteristicPoints.DikeToeAtPolder); + surfaceLine.TrySetSurfaceLevelInside(characteristicPoints.SurfaceLevelInside); + + surfaceLine.TrySetTrafficLoadOutside(characteristicPoints.TrafficLoadOutside); + surfaceLine.TrySetTrafficLoadInside(characteristicPoints.TrafficLoadInside); + surfaceLine.TrySetShoulderBaseInside(characteristicPoints.ShoulderBaseInside); + surfaceLine.TrySetShoulderTopInside(characteristicPoints.ShoulderTopInside); + surfaceLine.TrySetDitchDikeSide(characteristicPoints.DitchDikeSide); + surfaceLine.TrySetBottomDitchDikeSide(characteristicPoints.BottomDitchDikeSide); + surfaceLine.TrySetBottomDitchPolderSide(characteristicPoints.BottomDitchPolderSide); + surfaceLine.TrySetDitchPolderSide(characteristicPoints.DitchPolderSide); + } + + /// /// Tries to set the at the location of /// . /// @@ -45,7 +82,7 @@ /// true if the was set, false if /// is null or there is no point in at the location /// of . - public static bool TrySetDitchPolderSide(this RingtoetsMacroStabilityInwardsSurfaceLine surfaceLine, Point3D point) + private static bool TrySetDitchPolderSide(this RingtoetsMacroStabilityInwardsSurfaceLine surfaceLine, Point3D point) { if (point != null) { @@ -56,7 +93,7 @@ } catch (ArgumentException e) { - LogError(surfaceLine, e); + LogOptionalCharacteristicPointError(surfaceLine, e); } } return false; @@ -72,7 +109,7 @@ /// true if the was set, false if /// is null or there is no point in at the location /// of . - public static bool TrySetBottomDitchPolderSide(this RingtoetsMacroStabilityInwardsSurfaceLine surfaceLine, Point3D point) + private static bool TrySetBottomDitchPolderSide(this RingtoetsMacroStabilityInwardsSurfaceLine surfaceLine, Point3D point) { if (point != null) { @@ -83,7 +120,7 @@ } catch (ArgumentException e) { - LogError(surfaceLine, e); + LogOptionalCharacteristicPointError(surfaceLine, e); } } return false; @@ -99,7 +136,7 @@ /// true if the was set, false if /// is null or there is no point in at the location /// of . - public static bool TrySetBottomDitchDikeSide(this RingtoetsMacroStabilityInwardsSurfaceLine surfaceLine, Point3D point) + private static bool TrySetBottomDitchDikeSide(this RingtoetsMacroStabilityInwardsSurfaceLine surfaceLine, Point3D point) { if (point != null) { @@ -110,7 +147,7 @@ } catch (ArgumentException e) { - LogError(surfaceLine, e); + LogOptionalCharacteristicPointError(surfaceLine, e); } } return false; @@ -126,7 +163,7 @@ /// true if the was set, false if /// is null or there is no point in at the location /// of . - public static bool TrySetDitchDikeSide(this RingtoetsMacroStabilityInwardsSurfaceLine surfaceLine, Point3D point) + private static bool TrySetDitchDikeSide(this RingtoetsMacroStabilityInwardsSurfaceLine surfaceLine, Point3D point) { if (point != null) { @@ -137,7 +174,7 @@ } catch (ArgumentException e) { - LogError(surfaceLine, e); + LogOptionalCharacteristicPointError(surfaceLine, e); } } return false; @@ -153,7 +190,7 @@ /// true if the was set, false if /// is null or there is no point in at the location /// of . - public static bool TrySetSurfaceLevelInside(this RingtoetsMacroStabilityInwardsSurfaceLine surfaceLine, Point3D point) + private static bool TrySetSurfaceLevelInside(this RingtoetsMacroStabilityInwardsSurfaceLine surfaceLine, Point3D point) { if (point != null) { @@ -164,10 +201,10 @@ } catch (ArgumentException e) { - LogError(surfaceLine, e); + throw CreateMandatoryCharacteristicPointException(e.Message, surfaceLine.Name); } } - return false; + throw CreateMandatoryCharacteristicPointException(CreateMissingMandatoryPointMessage(RingtoetsCommonDataResources.CharacteristicPoint_SurfaceLevelInside), surfaceLine.Name); } /// @@ -180,7 +217,7 @@ /// true if the was set, false if /// is null or there is no point in at the location /// of . - public static bool TrySetSurfaceLevelOutside(this RingtoetsMacroStabilityInwardsSurfaceLine surfaceLine, Point3D point) + private static bool TrySetSurfaceLevelOutside(this RingtoetsMacroStabilityInwardsSurfaceLine surfaceLine, Point3D point) { if (point != null) { @@ -191,10 +228,10 @@ } catch (ArgumentException e) { - LogError(surfaceLine, e); + throw CreateMandatoryCharacteristicPointException(e.Message, surfaceLine.Name); } } - return false; + throw CreateMandatoryCharacteristicPointException(CreateMissingMandatoryPointMessage(RingtoetsCommonDataResources.CharacteristicPoint_SurfaceLevelOutside), surfaceLine.Name); } /// @@ -207,7 +244,7 @@ /// true if the was set, false if /// is null or there is no point in at the location /// of . - public static bool TrySetDikeTopAtPolder(this RingtoetsMacroStabilityInwardsSurfaceLine surfaceLine, Point3D point) + private static bool TrySetDikeTopAtPolder(this RingtoetsMacroStabilityInwardsSurfaceLine surfaceLine, Point3D point) { if (point != null) { @@ -218,10 +255,10 @@ } catch (ArgumentException e) { - LogError(surfaceLine, e); + throw CreateMandatoryCharacteristicPointException(e.Message, surfaceLine.Name); } } - return false; + throw CreateMandatoryCharacteristicPointException(CreateMissingMandatoryPointMessage(RingtoetsCommonDataResources.CharacteristicPoint_DikeTopAtPolder), surfaceLine.Name); } /// @@ -234,7 +271,7 @@ /// true if the was set, false if /// is null or there is no point in at the location /// of . - public static bool TrySetShoulderBaseInside(this RingtoetsMacroStabilityInwardsSurfaceLine surfaceLine, Point3D point) + private static bool TrySetShoulderBaseInside(this RingtoetsMacroStabilityInwardsSurfaceLine surfaceLine, Point3D point) { if (point != null) { @@ -245,7 +282,7 @@ } catch (ArgumentException e) { - LogError(surfaceLine, e); + LogOptionalCharacteristicPointError(surfaceLine, e); } } return false; @@ -261,7 +298,7 @@ /// true if the was set, false if /// is null or there is no point in at the location /// of . - public static bool TrySetShoulderTopInside(this RingtoetsMacroStabilityInwardsSurfaceLine surfaceLine, Point3D point) + private static bool TrySetShoulderTopInside(this RingtoetsMacroStabilityInwardsSurfaceLine surfaceLine, Point3D point) { if (point != null) { @@ -272,7 +309,7 @@ } catch (ArgumentException e) { - LogError(surfaceLine, e); + LogOptionalCharacteristicPointError(surfaceLine, e); } } return false; @@ -288,7 +325,7 @@ /// true if the was set, false if /// is null or there is no point in at the location /// of . - public static bool TrySetTrafficLoadInside(this RingtoetsMacroStabilityInwardsSurfaceLine surfaceLine, Point3D point) + private static bool TrySetTrafficLoadInside(this RingtoetsMacroStabilityInwardsSurfaceLine surfaceLine, Point3D point) { if (point != null) { @@ -299,7 +336,7 @@ } catch (ArgumentException e) { - LogError(surfaceLine, e); + LogOptionalCharacteristicPointError(surfaceLine, e); } } return false; @@ -315,7 +352,7 @@ /// true if the was set, false if /// is null or there is no point in at the location /// of . - public static bool TrySetTrafficLoadOutside(this RingtoetsMacroStabilityInwardsSurfaceLine surfaceLine, Point3D point) + private static bool TrySetTrafficLoadOutside(this RingtoetsMacroStabilityInwardsSurfaceLine surfaceLine, Point3D point) { if (point != null) { @@ -326,7 +363,7 @@ } catch (ArgumentException e) { - LogError(surfaceLine, e); + LogOptionalCharacteristicPointError(surfaceLine, e); } } return false; @@ -342,7 +379,7 @@ /// true if the was set, false if /// is null or there is no point in at the location /// of . - public static bool TrySetDikeToeAtRiver(this RingtoetsMacroStabilityInwardsSurfaceLine surfaceLine, Point3D point) + private static bool TrySetDikeToeAtRiver(this RingtoetsMacroStabilityInwardsSurfaceLine surfaceLine, Point3D point) { if (point != null) { @@ -353,10 +390,10 @@ } catch (ArgumentException e) { - LogError(surfaceLine, e); + throw CreateMandatoryCharacteristicPointException(e.Message, surfaceLine.Name); } } - return false; + throw CreateMandatoryCharacteristicPointException(CreateMissingMandatoryPointMessage(RingtoetsCommonDataResources.CharacteristicPoint_DikeToeAtRiver), surfaceLine.Name); } /// @@ -369,7 +406,7 @@ /// true if the was set, false if /// is null or there is no point in at the location /// of . - public static bool TrySetDikeToeAtPolder(this RingtoetsMacroStabilityInwardsSurfaceLine surfaceLine, Point3D point) + private static bool TrySetDikeToeAtPolder(this RingtoetsMacroStabilityInwardsSurfaceLine surfaceLine, Point3D point) { if (point != null) { @@ -380,53 +417,28 @@ } catch (ArgumentException e) { - LogError(surfaceLine, e); + throw CreateMandatoryCharacteristicPointException(e.Message, surfaceLine.Name); } } - return false; + throw CreateMandatoryCharacteristicPointException(CreateMissingMandatoryPointMessage(RingtoetsCommonDataResources.CharacteristicPoint_DikeToeAtPolder), surfaceLine.Name); } - /// - /// Tries to set the relevant characteristic points from the - /// on the . - /// - /// The surface line to set characteristic points for. - /// The characteristic points to set, if the collection is valid. - /// true if the characteristic points could be set; false otherwise. - /// Thrown when is null. - public static bool SetCharacteristicPoints(this RingtoetsMacroStabilityInwardsSurfaceLine surfaceLine, CharacteristicPoints characteristicPoints) + private static void LogOptionalCharacteristicPointError(RingtoetsMacroStabilityInwardsSurfaceLine surfaceLine, ArgumentException e) { - if (surfaceLine == null) - { - throw new ArgumentNullException(nameof(surfaceLine)); - } - if (characteristicPoints == null) - { - return false; - } + log.ErrorFormat(RingtoetsCommonIoResources.SurfaceLinesCsvImporter_CharacteristicPoint_of_SurfaceLine_0_skipped_cause_1_, + surfaceLine.Name, + e.Message); + } - surfaceLine.TrySetSurfaceLevelOutside(characteristicPoints.SurfaceLevelOutside); - surfaceLine.TrySetTrafficLoadOutside(characteristicPoints.TrafficLoadOutside); - surfaceLine.TrySetTrafficLoadInside(characteristicPoints.TrafficLoadInside); - surfaceLine.TrySetDikeTopAtPolder(characteristicPoints.DikeTopAtPolder); - surfaceLine.TrySetShoulderBaseInside(characteristicPoints.ShoulderBaseInside); - surfaceLine.TrySetShoulderTopInside(characteristicPoints.ShoulderTopInside); - surfaceLine.TrySetDikeToeAtRiver(characteristicPoints.DikeToeAtRiver); - surfaceLine.TrySetDitchDikeSide(characteristicPoints.DitchDikeSide); - surfaceLine.TrySetBottomDitchDikeSide(characteristicPoints.BottomDitchDikeSide); - surfaceLine.TrySetBottomDitchPolderSide(characteristicPoints.BottomDitchPolderSide); - surfaceLine.TrySetDitchPolderSide(characteristicPoints.DitchPolderSide); - surfaceLine.TrySetDikeToeAtPolder(characteristicPoints.DikeToeAtPolder); - surfaceLine.TrySetSurfaceLevelInside(characteristicPoints.SurfaceLevelInside); - - return true; + private static string CreateMissingMandatoryPointMessage(string surfaceLineName) + { + return string.Format(MacroStabilityInwardsIOResources.MacroStabilityInwardsSurfaceLineTransformer_CharacteristicPoint_0_is_undefined, surfaceLineName); } - private static void LogError(RingtoetsMacroStabilityInwardsSurfaceLine surfaceLine, ArgumentException e) + private static SurfaceLineTransformException CreateMandatoryCharacteristicPointException(string exceptionMessage, string surfaceLineName) { - log.ErrorFormat(Resources.SurfaceLinesCsvImporter_CharacteristicPoint_of_SurfaceLine_0_skipped_cause_1_, - surfaceLine.Name, - e.Message); + string message = string.Format(MacroStabilityInwardsIOResources.SurfaceLinesCsvImporter_SurfaceLine_0_skipped_cause_1_CharacteristicPoint_mandatory, surfaceLineName, exceptionMessage); + return new SurfaceLineTransformException(message); } } } \ No newline at end of file Index: Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.IO/Properties/Resources.Designer.cs =================================================================== diff -u -r650fc7b43cb6729baee51d079f0377df8d7a3de9 -r683ff9234262d9fa3bea5edc0abe35254f80e49d --- Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.IO/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision 650fc7b43cb6729baee51d079f0377df8d7a3de9) +++ Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.IO/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision 683ff9234262d9fa3bea5edc0abe35254f80e49d) @@ -300,6 +300,15 @@ } /// + /// Looks up a localized string similar to Karakteristiek punt '{0}' is niet gedefiniëerd.. + /// + public static string MacroStabilityInwardsSurfaceLineTransformer_CharacteristicPoint_0_is_undefined { + get { + return ResourceManager.GetString("MacroStabilityInwardsSurfaceLineTransformer_CharacteristicPoint_0_is undefined", resourceCulture); + } + } + + /// /// Looks up a localized string similar to Kan geen ondergrondmodellen lezen. Mogelijk bestaat de '{0}' tabel niet.. /// public static string SoilDatabaseConstraintsReader_VerifyConstraints_Can_not_read_StochasticSoilModel_Perhaps_table_missing { @@ -533,6 +542,16 @@ } /// + /// Looks up a localized string similar to Profielschematisatie '{0}' kan niet gebruikt worden. {1} Dit karakteristieke punt is verplicht.. + /// + public static string SurfaceLinesCsvImporter_SurfaceLine_0_skipped_cause_1_CharacteristicPoint_mandatory { + get { + return ResourceManager.GetString("SurfaceLinesCsvImporter_SurfaceLine_0_skipped_cause_1_CharacteristicPoint_mandato" + + "ry", resourceCulture); + } + } + + /// /// Looks up a localized string similar to <?xml version="1.0"?><!-- ///Copyright (C) Stichting Deltares 2017. All rights reserved. /// Index: Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.IO/Properties/Resources.resx =================================================================== diff -u -r650fc7b43cb6729baee51d079f0377df8d7a3de9 -r683ff9234262d9fa3bea5edc0abe35254f80e49d --- Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.IO/Properties/Resources.resx (.../Resources.resx) (revision 650fc7b43cb6729baee51d079f0377df8d7a3de9) +++ Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.IO/Properties/Resources.resx (.../Resources.resx) (revision 683ff9234262d9fa3bea5edc0abe35254f80e49d) @@ -251,6 +251,9 @@ De ondergrondschematisatie '{0}' bestaat niet binnen het stochastische ondergrondmodel '{1}'. + + Profielschematisatie '{0}' kan niet gebruikt worden. {1} Dit karakteristieke punt is verplicht. + ..\Resources\XmlGeometrySchema.xsd;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;Windows-1252 @@ -261,4 +264,7 @@ ..\Resources\MacroStabiliteitBinnenwaartsConfiguratieSchema.xsd;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;Windows-1252 + + Karakteristiek punt '{0}' is niet gedefiniëerd. + \ No newline at end of file Index: Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.IO.Test/Importers/MacrostabilityInwardsSurfaceLineTransformerTest.cs =================================================================== diff -u -r5579d8fdef4f553fb4ba94160825ec960b89bab9 -r683ff9234262d9fa3bea5edc0abe35254f80e49d --- Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.IO.Test/Importers/MacrostabilityInwardsSurfaceLineTransformerTest.cs (.../MacrostabilityInwardsSurfaceLineTransformerTest.cs) (revision 5579d8fdef4f553fb4ba94160825ec960b89bab9) +++ Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.IO.Test/Importers/MacrostabilityInwardsSurfaceLineTransformerTest.cs (.../MacrostabilityInwardsSurfaceLineTransformerTest.cs) (revision 683ff9234262d9fa3bea5edc0abe35254f80e49d) @@ -37,21 +37,11 @@ [TestFixture] public class MacrostabilityInwardsSurfaceLineTransformerTest { - private static IEnumerable MoveCharacteristicPoint + private static IEnumerable MoveOptionalCharacteristicPoint { get { yield return new TestCaseData( - new Action((cp, p) => cp.SurfaceLevelOutside = p), - new Func(sl => sl.SurfaceLevelOutside), - "Maaiveld buitenwaarts") - .SetName("Move SurfaceLevelOutside"); - yield return new TestCaseData( - new Action((cp, p) => cp.DikeToeAtRiver = p), - new Func(sl => sl.DikeToeAtRiver), - "Teen dijk buitenwaarts") - .SetName("Move DikeToeAtRiver"); - yield return new TestCaseData( new Action((cp, p) => cp.TrafficLoadOutside = p), new Func(sl => sl.TrafficLoadOutside), "Verkeersbelasting kant buitenwaarts") @@ -62,11 +52,6 @@ "Verkeersbelasting kant binnenwaarts") .SetName("Move TrafficLoadInside"); yield return new TestCaseData( - new Action((cp, p) => cp.DikeTopAtPolder = p), - new Func(sl => sl.DikeTopAtPolder), - "Kruin binnentalud") - .SetName("Move DikeTopAtPolder"); - yield return new TestCaseData( new Action((cp, p) => cp.ShoulderBaseInside = p), new Func(sl => sl.ShoulderBaseInside), "Insteek binnenberm") @@ -96,7 +81,29 @@ new Func(sl => sl.DitchPolderSide), "Insteek sloot polderzijde") .SetName("Move DitchPolderSide"); + } + } + + private static IEnumerable MoveMandatoryCharacteristicPoint + { + get + { yield return new TestCaseData( + new Action((cp, p) => cp.SurfaceLevelOutside = p), + new Func(sl => sl.SurfaceLevelOutside), + "Maaiveld buitenwaarts") + .SetName("Move SurfaceLevelOutside"); + yield return new TestCaseData( + new Action((cp, p) => cp.DikeToeAtRiver = p), + new Func(sl => sl.DikeToeAtRiver), + "Teen dijk buitenwaarts") + .SetName("Move DikeToeAtRiver"); + yield return new TestCaseData( + new Action((cp, p) => cp.DikeTopAtPolder = p), + new Func(sl => sl.DikeTopAtPolder), + "Kruin binnentalud") + .SetName("Move DikeTopAtPolder"); + yield return new TestCaseData( new Action((cp, p) => cp.DikeToeAtPolder = p), new Func(sl => sl.DikeToeAtPolder), "Teen dijk binnenwaarts") @@ -188,8 +195,8 @@ } [Test] - [TestCaseSource(nameof(MoveCharacteristicPoint))] - public void Transform_CharacteristicPointNotOnSurfaceLine_LogErrorAndReturnNull(Action pointChange, Func pointWhichIsNull, string changedCharacteristicPointName) + [TestCaseSource(nameof(MoveOptionalCharacteristicPoint))] + public void Transform_OptionalCharacteristicPointNotOnSurfaceLine_LogErrorAndReturnSurfaceLineWithoutCharacteristicPointSet(Action pointChange, Func pointWhichIsNull, string changedCharacteristicPointName) { // Setup var referenceLine = new ReferenceLine(); @@ -273,5 +280,71 @@ result.SurfaceLevelInside }.Count(p => p == null)); } + + [Test] + [TestCaseSource(nameof(MoveMandatoryCharacteristicPoint))] + public void Transform_MandatoryCharacteristicPointNotOnSurfaceLine_LogErrorAndReturnNull(Action pointChange, Func pointWhichIsNull, string changedCharacteristicPointName) + { + // Setup + var referenceLine = new ReferenceLine(); + var transformer = new MacroStabilityInwardsSurfaceLineTransformer(referenceLine); + const string locationName = "a location"; + + var random = new Random(21); + double randomZ = random.NextDouble(); + + var surfaceLine = new SurfaceLine + { + Name = locationName + }; + + var point1 = new Point3D(3.5, 4.8, randomZ); + var point2 = new Point3D(7.2, 9.3, randomZ); + var point3 = new Point3D(12.0, 5.6, randomZ); + var notOnSurfaceLinePoint = new Point3D(7.3, 9.3, randomZ); + + surfaceLine.SetGeometry(new[] + { + point1, + point2, + point3 + }); + + var characteristicPoints = new CharacteristicPoints(locationName) + { + SurfaceLevelOutside = point2, + DikeToeAtRiver = point2, + TrafficLoadOutside = point2, + TrafficLoadInside = point2, + DikeTopAtPolder = point2, + ShoulderBaseInside = point3, + ShoulderTopInside = point3, + BottomDitchDikeSide = point3, + BottomDitchPolderSide = point3, + DitchPolderSide = point3, + DitchDikeSide = point3, + DikeToeAtPolder = point3, + SurfaceLevelInside = point3 + }; + + pointChange(characteristicPoints, notOnSurfaceLinePoint); + + referenceLine.SetGeometry(new[] + { + new Point2D(5.6, 2.5), + new Point2D(6.8, 15) + }); + + + // Call + TestDelegate test = () => transformer.Transform(surfaceLine, characteristicPoints); + + // Assert + var exception = Assert.Throws(test); + var message = $"Profielschematisatie '{locationName}' kan niet gebruikt worden. " + + $"De geometrie bevat geen punt op locatie {notOnSurfaceLinePoint} om als \'{changedCharacteristicPointName}\' in te stellen. " + + "Dit karakteristieke punt is verplicht."; + Assert.AreEqual(message, exception.Message); + } } } \ No newline at end of file Index: Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.IO.Test/Importers/RingtoetsMacroStabilityInwardsSurfaceLineExtensionsTest.cs =================================================================== diff -u -r5579d8fdef4f553fb4ba94160825ec960b89bab9 -r683ff9234262d9fa3bea5edc0abe35254f80e49d --- Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.IO.Test/Importers/RingtoetsMacroStabilityInwardsSurfaceLineExtensionsTest.cs (.../RingtoetsMacroStabilityInwardsSurfaceLineExtensionsTest.cs) (revision 5579d8fdef4f553fb4ba94160825ec960b89bab9) +++ Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.IO.Test/Importers/RingtoetsMacroStabilityInwardsSurfaceLineExtensionsTest.cs (.../RingtoetsMacroStabilityInwardsSurfaceLineExtensionsTest.cs) (revision 683ff9234262d9fa3bea5edc0abe35254f80e49d) @@ -23,963 +23,315 @@ using System.Collections.Generic; using System.Linq; using Core.Common.Base.Geometry; -using Core.Common.TestUtil; using NUnit.Framework; using Ringtoets.Common.IO.SurfaceLines; using Ringtoets.MacroStabilityInwards.IO.Importers; using Ringtoets.MacroStabilityInwards.Primitives; +using RingtoetsCommonDataResources = Ringtoets.Common.Data.Properties.Resources; namespace Ringtoets.MacroStabilityInwards.IO.Test.Importers { [TestFixture] public class RingtoetsMacroStabilityInwardsSurfaceLineExtensionsTest { [Test] - public void TrySetDitchDikeSide_Null_ReturnsFalse() + public void SetCharacteristicPoints_SurfaceLineNull_ThrowsArgumentNullException() { // Setup - var surfaceLine = new RingtoetsMacroStabilityInwardsSurfaceLine(); - - // Call - bool result = surfaceLine.TrySetDitchDikeSide(null); - - // Assert - Assert.IsFalse(result); - } - - [Test] - public void TrySetDitchDikeSide_NoPointInGeometry_LogAndReturnFalse() - { - // Setup - var random = new Random(21); - var testPoint = new Point3D(random.NextDouble(), random.NextDouble(), random.NextDouble()); - var surfaceLine = new RingtoetsMacroStabilityInwardsSurfaceLine + var points = new CharacteristicPoints("swapped dike toes") { - Name = "testName" + DikeToeAtPolder = new Point3D(3, 2, 5), + DikeToeAtRiver = new Point3D(3.4, 3, 8), + DitchDikeSide = new Point3D(4.4, 6, 8), + BottomDitchDikeSide = new Point3D(5.1, 6, 6.5), + BottomDitchPolderSide = new Point3D(8.5, 7.2, 4.2), + DitchPolderSide = new Point3D(9.6, 7.5, 3.9) }; - var result = true; - // Call - Action test = () => result = surfaceLine.TrySetDitchDikeSide(testPoint); + TestDelegate test = () => ((RingtoetsMacroStabilityInwardsSurfaceLine) null).SetCharacteristicPoints(points); // Assert - string message = $"Karakteristiek punt van profielschematisatie 'testName' is overgeslagen. De geometrie bevat geen punt op locatie {testPoint} om als 'Insteek sloot dijkzijde' in te stellen."; - TestHelper.AssertLogMessageIsGenerated(test, message, 1); - Assert.IsFalse(result); + var exception = Assert.Throws(test); + Assert.AreEqual("surfaceLine", exception.ParamName); } [Test] - public void TrySetDitchDikeSide_PointInGeometry_PointSetAndReturnTrue() + public void SetCharacteristicPoints_CharacteristicPointsNull_NoCharacteristicPointsSet() { // Setup - var random = new Random(21); - double x = random.NextDouble(); - double y = random.NextDouble(); - double z = random.NextDouble(); var surfaceLine = new RingtoetsMacroStabilityInwardsSurfaceLine(); - - var point = new Point3D(x, y, z); - surfaceLine.SetGeometry(new[] { - point + new Point3D(3, 2, 5), + new Point3D(3.4, 3, 8), + new Point3D(4.4, 6, 8), + new Point3D(5.1, 6, 6.5), + new Point3D(8.5, 7.2, 4.2), + new Point3D(9.6, 7.5, 3.9) }); // Call - bool result = surfaceLine.TrySetDitchDikeSide(point); + surfaceLine.SetCharacteristicPoints(null); // Assert - Assert.IsTrue(result); - Assert.AreEqual(point, surfaceLine.DitchDikeSide); + Assert.IsNull(surfaceLine.DikeToeAtRiver); + Assert.IsNull(surfaceLine.DikeToeAtPolder); + Assert.IsNull(surfaceLine.DitchDikeSide); + Assert.IsNull(surfaceLine.BottomDitchDikeSide); + Assert.IsNull(surfaceLine.BottomDitchPolderSide); + Assert.IsNull(surfaceLine.DitchPolderSide); } [Test] - public void TrySetBottomDitchDikeSide_Null_ReturnsFalse() + [TestCaseSource(nameof(DifferentValidCharacteristicPointConfigurations))] + public void SetCharacteristicPoints_ValidSituations_PointsAreSet(CharacteristicPoints points) { // Setup var surfaceLine = new RingtoetsMacroStabilityInwardsSurfaceLine(); + surfaceLine.SetGeometry(CharacteristicPointsToGeometry(points)); // Call - bool result = surfaceLine.TrySetBottomDitchDikeSide(null); + surfaceLine.SetCharacteristicPoints(points); // Assert - Assert.IsFalse(result); + Assert.AreEqual(points.DikeTopAtPolder, surfaceLine.DikeTopAtPolder); + Assert.AreEqual(points.ShoulderBaseInside, surfaceLine.ShoulderBaseInside); + Assert.AreEqual(points.ShoulderTopInside, surfaceLine.ShoulderTopInside); + Assert.AreEqual(points.TrafficLoadOutside, surfaceLine.TrafficLoadOutside); + Assert.AreEqual(points.TrafficLoadInside, surfaceLine.TrafficLoadInside); + Assert.AreEqual(points.SurfaceLevelOutside, surfaceLine.SurfaceLevelOutside); + Assert.AreEqual(points.SurfaceLevelInside, surfaceLine.SurfaceLevelInside); + Assert.AreEqual(points.DikeToeAtRiver, surfaceLine.DikeToeAtRiver); + Assert.AreEqual(points.DikeToeAtPolder, surfaceLine.DikeToeAtPolder); + Assert.AreEqual(points.DitchDikeSide, surfaceLine.DitchDikeSide); + Assert.AreEqual(points.BottomDitchDikeSide, surfaceLine.BottomDitchDikeSide); + Assert.AreEqual(points.BottomDitchPolderSide, surfaceLine.BottomDitchPolderSide); + Assert.AreEqual(points.DitchPolderSide, surfaceLine.DitchPolderSide); } [Test] - public void TrySetBottomDitchDikeSide_NoPointInGeometry_LogAndReturnFalse() + [TestCaseSource(nameof(DifferentCharacteristicPointWithMissingMandatoryPointConfigurations))] + public void SetCharacteristicPoints_UndefinedMandatoryPoint_ThrowsExceptionWithMessage(CharacteristicPoints points, string pointDescription) { // Setup - var random = new Random(21); - var testPoint = new Point3D(random.NextDouble(), random.NextDouble(), random.NextDouble()); var surfaceLine = new RingtoetsMacroStabilityInwardsSurfaceLine { - Name = "testName" + Name = points.Name }; + surfaceLine.SetGeometry(CharacteristicPointsToGeometry(points)); - var result = true; - // Call - Action test = () => result = surfaceLine.TrySetBottomDitchDikeSide(testPoint); + TestDelegate test = () => surfaceLine.SetCharacteristicPoints(points); // Assert - string message = $"Karakteristiek punt van profielschematisatie 'testName' is overgeslagen. De geometrie bevat geen punt op locatie {testPoint} om als 'Slootbodem dijkzijde' in te stellen."; - TestHelper.AssertLogMessageIsGenerated(test, message, 1); - Assert.IsFalse(result); + var exception = Assert.Throws(test); + var message = $"Profielschematisatie '{points.Name}' kan niet gebruikt worden. Karakteristiek punt \'{pointDescription}\' is niet gedefiniëerd. Dit karakteristieke punt is verplicht."; + Assert.AreEqual(message, exception.Message); } [Test] - public void TrySetBottomDitchDikeSide_PointInGeometry_PointSetAndReturnTrue() + [TestCaseSource(nameof(DifferentCharacteristicPointWithMandatoryPointNotOnSurfaceLineConfigurations))] + public void SetCharacteristicPoints_MandatoryPointNotOnSurfaceLine_ThrowsExceptionWithMessage( + CharacteristicPoints points, + Action setPoint, + string pointDescription) { // Setup - var random = new Random(21); - double x = random.NextDouble(); - double y = random.NextDouble(); - double z = random.NextDouble(); - var surfaceLine = new RingtoetsMacroStabilityInwardsSurfaceLine(); - - var point = new Point3D(x, y, z); - - surfaceLine.SetGeometry(new[] - { - point - }); - - // Call - bool result = surfaceLine.TrySetBottomDitchDikeSide(point); - - // Assert - Assert.IsTrue(result); - Assert.AreEqual(point, surfaceLine.BottomDitchDikeSide); - } - - [Test] - public void TrySetBottomDitchPolderSide_Null_ReturnsFalse() - { - // Setup - var surfaceLine = new RingtoetsMacroStabilityInwardsSurfaceLine(); - - // Call - bool result = surfaceLine.TrySetBottomDitchPolderSide(null); - - // Assert - Assert.IsFalse(result); - } - - [Test] - public void TrySetBottomDitchPolderSide_NoPointInGeometry_LogAndReturnFalse() - { - // Setup - var random = new Random(21); - var testPoint = new Point3D(random.NextDouble(), random.NextDouble(), random.NextDouble()); var surfaceLine = new RingtoetsMacroStabilityInwardsSurfaceLine { - Name = "testName" + Name = points.Name }; + surfaceLine.SetGeometry(CharacteristicPointsToGeometry(points)); - var result = true; + var changedPoint = new Point3D(-1, -1, -1); + setPoint(points, changedPoint); // Call - Action test = () => result = surfaceLine.TrySetBottomDitchPolderSide(testPoint); + TestDelegate test = () => surfaceLine.SetCharacteristicPoints(points); // Assert - string message = $"Karakteristiek punt van profielschematisatie 'testName' is overgeslagen. De geometrie bevat geen punt op locatie {testPoint} om als 'Slootbodem polderzijde' in te stellen."; - TestHelper.AssertLogMessageIsGenerated(test, message, 1); - Assert.IsFalse(result); + var exception = Assert.Throws(test); + var message = $"Profielschematisatie '{points.Name}' kan niet gebruikt worden. " + + $"De geometrie bevat geen punt op locatie {changedPoint} om als \'{pointDescription}\' in te stellen. " + + "Dit karakteristieke punt is verplicht."; + Assert.AreEqual(message, exception.Message); } - [Test] - public void TrySetBottomDitchPolderSide_PointInGeometry_PointSetAndReturnTrue() + private static IEnumerable CharacteristicPointsToGeometry(CharacteristicPoints points) { - // Setup - var random = new Random(21); - double x = random.NextDouble(); - double y = random.NextDouble(); - double z = random.NextDouble(); - var surfaceLine = new RingtoetsMacroStabilityInwardsSurfaceLine(); - - var point = new Point3D(x, y, z); - - surfaceLine.SetGeometry(new[] + return new[] { - point - }); - - // Call - bool result = surfaceLine.TrySetBottomDitchPolderSide(point); - - // Assert - Assert.IsTrue(result); - Assert.AreEqual(point, surfaceLine.BottomDitchPolderSide); + points.DikeTopAtPolder, + points.ShoulderBaseInside, + points.ShoulderTopInside, + points.TrafficLoadOutside, + points.TrafficLoadInside, + points.SurfaceLevelOutside, + points.SurfaceLevelInside, + points.DikeToeAtRiver, + points.DikeToeAtPolder, + points.DitchDikeSide, + points.BottomDitchDikeSide, + points.BottomDitchPolderSide, + points.DitchPolderSide + }.Where(p => p != null); } - [Test] - public void TrySetDitchPolderSide_Null_ReturnsFalse() + private static IEnumerable DifferentCharacteristicPointWithMissingMandatoryPointConfigurations { - // Setup - var surfaceLine = new RingtoetsMacroStabilityInwardsSurfaceLine(); - - // Call - bool result = surfaceLine.TrySetDitchPolderSide(null); - - // Assert - Assert.IsFalse(result); - } - - [Test] - public void TrySetDitchPolderSide_NoPointInGeometry_LogAndReturnFalse() - { - // Setup - var random = new Random(21); - var testPoint = new Point3D(random.NextDouble(), random.NextDouble(), random.NextDouble()); - var surfaceLine = new RingtoetsMacroStabilityInwardsSurfaceLine + get { - Name = "testName" - }; + var name = "Missing SurfaceLevelOutside"; + CharacteristicPoints set = CreateCompleteCharacteristicPointSet(name); + set.SurfaceLevelOutside = null; + yield return new TestCaseData(set, RingtoetsCommonDataResources.CharacteristicPoint_SurfaceLevelOutside).SetName(name); - var result = true; + name = "Missing DikeToeAtRiver"; + set = CreateCompleteCharacteristicPointSet(name); + set.DikeToeAtRiver = null; + yield return new TestCaseData(set, RingtoetsCommonDataResources.CharacteristicPoint_DikeToeAtRiver).SetName(name); - // Call - Action test = () => result = surfaceLine.TrySetDitchPolderSide(testPoint); + name = "Missing DikeTopAtPolder"; + set = CreateCompleteCharacteristicPointSet(name); + set.DikeTopAtPolder = null; + yield return new TestCaseData(set, RingtoetsCommonDataResources.CharacteristicPoint_DikeTopAtPolder).SetName(name); - // Assert - string message = $"Karakteristiek punt van profielschematisatie 'testName' is overgeslagen. De geometrie bevat geen punt op locatie {testPoint} om als 'Insteek sloot polderzijde' in te stellen."; - TestHelper.AssertLogMessageIsGenerated(test, message, 1); - Assert.IsFalse(result); - } + name = "Missing DikeToeAtPolder"; + set = CreateCompleteCharacteristicPointSet(name); + set.DikeToeAtPolder = null; + yield return new TestCaseData(set, RingtoetsCommonDataResources.CharacteristicPoint_DikeToeAtPolder).SetName(name); - [Test] - public void TrySetDitchPolderSide_PointInGeometry_PointSetAndReturnTrue() - { - // Setup - var random = new Random(21); - double x = random.NextDouble(); - double y = random.NextDouble(); - double z = random.NextDouble(); - var surfaceLine = new RingtoetsMacroStabilityInwardsSurfaceLine(); - - var point = new Point3D(x, y, z); - - surfaceLine.SetGeometry(new[] - { - point - }); - - // Call - bool result = surfaceLine.TrySetDitchPolderSide(point); - - // Assert - Assert.IsTrue(result); - Assert.AreEqual(point, surfaceLine.DitchPolderSide); + name = "Missing SurfaceLevelInside"; + set = CreateCompleteCharacteristicPointSet(name); + set.SurfaceLevelInside = null; + yield return new TestCaseData(set, RingtoetsCommonDataResources.CharacteristicPoint_SurfaceLevelInside).SetName(name); + } } - [Test] - public void TrySetTrafficLoadInside_Null_ReturnsFalse() + private static IEnumerable DifferentCharacteristicPointWithMandatoryPointNotOnSurfaceLineConfigurations { - // Setup - var surfaceLine = new RingtoetsMacroStabilityInwardsSurfaceLine(); - - // Call - bool result = surfaceLine.TrySetTrafficLoadInside(null); - - // Assert - Assert.IsFalse(result); - } - - [Test] - public void TrySetTrafficLoadInside_NoPointInGeometry_LogAndReturnFalse() - { - // Setup - var random = new Random(21); - var testPoint = new Point3D(random.NextDouble(), random.NextDouble(), random.NextDouble()); - var surfaceLine = new RingtoetsMacroStabilityInwardsSurfaceLine + get { - Name = "testName" - }; + var name = "Moved SurfaceLevelOutside"; + CharacteristicPoints set = CreateCompleteCharacteristicPointSet(name); + yield return new TestCaseData( + set, + new Action((points, p) => points.SurfaceLevelOutside = p), + RingtoetsCommonDataResources.CharacteristicPoint_SurfaceLevelOutside).SetName(name); - var result = true; + name = "Moved DikeToeAtRiver"; + set = CreateCompleteCharacteristicPointSet(name); + yield return new TestCaseData( + set, + new Action((points, p) => points.DikeToeAtRiver = p), + RingtoetsCommonDataResources.CharacteristicPoint_DikeToeAtRiver).SetName(name); - // Call - Action test = () => result = surfaceLine.TrySetTrafficLoadInside(testPoint); + name = "Moved DikeTopAtPolder"; + set = CreateCompleteCharacteristicPointSet(name); + yield return new TestCaseData( + set, + new Action((points, p) => points.DikeTopAtPolder = p), + RingtoetsCommonDataResources.CharacteristicPoint_DikeTopAtPolder).SetName(name); - // Assert - string message = $"Karakteristiek punt van profielschematisatie 'testName' is overgeslagen. De geometrie bevat geen punt op locatie {testPoint} om als 'Verkeersbelasting kant binnenwaarts' in te stellen."; - TestHelper.AssertLogMessageIsGenerated(test, message, 1); - Assert.IsFalse(result); - } + name = "Moved DikeToeAtPolder"; + set = CreateCompleteCharacteristicPointSet(name); + yield return new TestCaseData( + set, + new Action((points, p) => points.DikeToeAtPolder = p), + RingtoetsCommonDataResources.CharacteristicPoint_DikeToeAtPolder).SetName(name); - [Test] - public void TrySetTrafficLoadInside_PointInGeometry_PointSetAndReturnTrue() - { - // Setup - var random = new Random(21); - double x = random.NextDouble(); - double y = random.NextDouble(); - double z = random.NextDouble(); - var surfaceLine = new RingtoetsMacroStabilityInwardsSurfaceLine(); - - var point = new Point3D(x, y, z); - - surfaceLine.SetGeometry(new[] - { - point - }); - - // Call - bool result = surfaceLine.TrySetTrafficLoadInside(point); - - // Assert - Assert.IsTrue(result); - Assert.AreEqual(point, surfaceLine.TrafficLoadInside); + name = "Moved SurfaceLevelInside"; + set = CreateCompleteCharacteristicPointSet(name); + yield return new TestCaseData( + set, + new Action((points, p) => points.SurfaceLevelInside = p), + RingtoetsCommonDataResources.CharacteristicPoint_SurfaceLevelInside).SetName(name); + } } - [Test] - public void TrySetTrafficLoadOutside_Null_ReturnsFalse() - { - // Setup - var surfaceLine = new RingtoetsMacroStabilityInwardsSurfaceLine(); - - // Call - bool result = surfaceLine.TrySetTrafficLoadOutside(null); - - // Assert - Assert.IsFalse(result); - } - - [Test] - public void TrySetTrafficLoadOutside_NoPointInGeometry_LogAndReturnFalse() - { - // Setup - var random = new Random(21); - var testPoint = new Point3D(random.NextDouble(), random.NextDouble(), random.NextDouble()); - var surfaceLine = new RingtoetsMacroStabilityInwardsSurfaceLine - { - Name = "testName" - }; - - var result = true; - - // Call - Action test = () => result = surfaceLine.TrySetTrafficLoadOutside(testPoint); - - // Assert - string message = $"Karakteristiek punt van profielschematisatie 'testName' is overgeslagen. De geometrie bevat geen punt op locatie {testPoint} om als 'Verkeersbelasting kant buitenwaarts' in te stellen."; - TestHelper.AssertLogMessageIsGenerated(test, message, 1); - Assert.IsFalse(result); - } - - [Test] - public void TrySetTrafficLoadOutside_PointInGeometry_PointSetAndReturnTrue() - { - // Setup - var random = new Random(21); - double x = random.NextDouble(); - double y = random.NextDouble(); - double z = random.NextDouble(); - var surfaceLine = new RingtoetsMacroStabilityInwardsSurfaceLine(); - - var point = new Point3D(x, y, z); - - surfaceLine.SetGeometry(new[] - { - point - }); - - // Call - bool result = surfaceLine.TrySetTrafficLoadOutside(point); - - // Assert - Assert.IsTrue(result); - Assert.AreEqual(point, surfaceLine.TrafficLoadOutside); - } - - [Test] - public void TrySetDikeTopAtPolder_Null_ReturnsFalse() - { - // Setup - var surfaceLine = new RingtoetsMacroStabilityInwardsSurfaceLine(); - - // Call - bool result = surfaceLine.TrySetDikeTopAtPolder(null); - - // Assert - Assert.IsFalse(result); - } - - [Test] - public void TrySetDikeTopAtPolder_NoPointInGeometry_LogAndReturnFalse() - { - // Setup - var random = new Random(21); - var testPoint = new Point3D(random.NextDouble(), random.NextDouble(), random.NextDouble()); - var surfaceLine = new RingtoetsMacroStabilityInwardsSurfaceLine - { - Name = "testName" - }; - - var result = true; - - // Call - Action test = () => result = surfaceLine.TrySetDikeTopAtPolder(testPoint); - - // Assert - string message = $"Karakteristiek punt van profielschematisatie 'testName' is overgeslagen. De geometrie bevat geen punt op locatie {testPoint} om als 'Kruin binnentalud' in te stellen."; - TestHelper.AssertLogMessageIsGenerated(test, message, 1); - Assert.IsFalse(result); - } - - [Test] - public void TrySetDikeTopAtPolder_PointInGeometry_PointSetAndReturnTrue() - { - // Setup - var random = new Random(21); - double x = random.NextDouble(); - double y = random.NextDouble(); - double z = random.NextDouble(); - var surfaceLine = new RingtoetsMacroStabilityInwardsSurfaceLine(); - - var point = new Point3D(x, y, z); - - surfaceLine.SetGeometry(new[] - { - point - }); - - // Call - bool result = surfaceLine.TrySetDikeTopAtPolder(point); - - // Assert - Assert.IsTrue(result); - Assert.AreEqual(point, surfaceLine.DikeTopAtPolder); - } - - [Test] - public void TrySetShoulderBaseInside_Null_ReturnsFalse() - { - // Setup - var surfaceLine = new RingtoetsMacroStabilityInwardsSurfaceLine(); - - // Call - bool result = surfaceLine.TrySetShoulderBaseInside(null); - - // Assert - Assert.IsFalse(result); - } - - [Test] - public void TrySetShoulderBaseInside_NoPointInGeometry_LogAndReturnFalse() - { - // Setup - var random = new Random(21); - var testPoint = new Point3D(random.NextDouble(), random.NextDouble(), random.NextDouble()); - var surfaceLine = new RingtoetsMacroStabilityInwardsSurfaceLine - { - Name = "testName" - }; - - var result = true; - - // Call - Action test = () => result = surfaceLine.TrySetShoulderBaseInside(testPoint); - - // Assert - string message = $"Karakteristiek punt van profielschematisatie 'testName' is overgeslagen. De geometrie bevat geen punt op locatie {testPoint} om als 'Insteek binnenberm' in te stellen."; - TestHelper.AssertLogMessageIsGenerated(test, message, 1); - Assert.IsFalse(result); - } - - [Test] - public void TrySetShoulderBaseInside_PointInGeometry_PointSetAndReturnTrue() - { - // Setup - var random = new Random(21); - double x = random.NextDouble(); - double y = random.NextDouble(); - double z = random.NextDouble(); - var surfaceLine = new RingtoetsMacroStabilityInwardsSurfaceLine(); - - var point = new Point3D(x, y, z); - - surfaceLine.SetGeometry(new[] - { - point - }); - - // Call - bool result = surfaceLine.TrySetShoulderBaseInside(point); - - // Assert - Assert.IsTrue(result); - Assert.AreEqual(point, surfaceLine.ShoulderBaseInside); - } - - [Test] - public void TrySetShoulderTopInside_Null_ReturnsFalse() - { - // Setup - var surfaceLine = new RingtoetsMacroStabilityInwardsSurfaceLine(); - - // Call - bool result = surfaceLine.TrySetShoulderTopInside(null); - - // Assert - Assert.IsFalse(result); - } - - [Test] - public void TrySetShoulderTopInside_NoPointInGeometry_LogAndReturnFalse() - { - // Setup - var random = new Random(21); - var testPoint = new Point3D(random.NextDouble(), random.NextDouble(), random.NextDouble()); - var surfaceLine = new RingtoetsMacroStabilityInwardsSurfaceLine - { - Name = "testName" - }; - - var result = true; - - // Call - Action test = () => result = surfaceLine.TrySetShoulderTopInside(testPoint); - - // Assert - string message = $"Karakteristiek punt van profielschematisatie 'testName' is overgeslagen. De geometrie bevat geen punt op locatie {testPoint} om als 'Kruin binnenberm' in te stellen."; - TestHelper.AssertLogMessageIsGenerated(test, message, 1); - Assert.IsFalse(result); - } - - [Test] - public void TrySetShoulderTopInside_PointInGeometry_PointSetAndReturnTrue() - { - // Setup - var random = new Random(21); - double x = random.NextDouble(); - double y = random.NextDouble(); - double z = random.NextDouble(); - var surfaceLine = new RingtoetsMacroStabilityInwardsSurfaceLine(); - - var point = new Point3D(x, y, z); - - surfaceLine.SetGeometry(new[] - { - point - }); - - // Call - bool result = surfaceLine.TrySetShoulderTopInside(point); - - // Assert - Assert.IsTrue(result); - Assert.AreEqual(point, surfaceLine.ShoulderTopInside); - } - - [Test] - public void TrySetDikeToeAtPolder_Null_ReturnsFalse() - { - // Setup - var surfaceLine = new RingtoetsMacroStabilityInwardsSurfaceLine(); - - // Call - bool result = surfaceLine.TrySetDikeToeAtPolder(null); - - // Assert - Assert.IsFalse(result); - } - - [Test] - public void TrySetDikeToeAtPolder_NoPointInGeometry_LogAndReturnFalse() - { - // Setup - var random = new Random(21); - var testPoint = new Point3D(random.NextDouble(), random.NextDouble(), random.NextDouble()); - var surfaceLine = new RingtoetsMacroStabilityInwardsSurfaceLine - { - Name = "testName" - }; - - var result = true; - - // Call - Action test = () => result = surfaceLine.TrySetDikeToeAtPolder(testPoint); - - // Assert - string message = $"Karakteristiek punt van profielschematisatie 'testName' is overgeslagen. De geometrie bevat geen punt op locatie {testPoint} om als 'Teen dijk binnenwaarts' in te stellen."; - TestHelper.AssertLogMessageIsGenerated(test, message, 1); - Assert.IsFalse(result); - } - - [Test] - public void TrySetDikeToeAtPolder_PointInGeometry_PointSetAndReturnTrue() - { - // Setup - var random = new Random(21); - double x = random.NextDouble(); - double y = random.NextDouble(); - double z = random.NextDouble(); - var surfaceLine = new RingtoetsMacroStabilityInwardsSurfaceLine(); - - var point = new Point3D(x, y, z); - - surfaceLine.SetGeometry(new[] - { - point - }); - - // Call - bool result = surfaceLine.TrySetDikeToeAtPolder(point); - - // Assert - Assert.IsTrue(result); - Assert.AreEqual(point, surfaceLine.DikeToeAtPolder); - } - - [Test] - public void TrySetDikeToeAtRiver_Null_ReturnsFalse() - { - // Setup - var surfaceLine = new RingtoetsMacroStabilityInwardsSurfaceLine(); - - // Call - bool result = surfaceLine.TrySetDikeToeAtRiver(null); - - // Assert - Assert.IsFalse(result); - } - - [Test] - public void TrySetDikeToeAtRiver_NoPointInGeometry_LogAndReturnFalse() - { - // Setup - var random = new Random(21); - var testPoint = new Point3D(random.NextDouble(), random.NextDouble(), random.NextDouble()); - var surfaceLine = new RingtoetsMacroStabilityInwardsSurfaceLine - { - Name = "testName" - }; - - var result = true; - - // Call - Action test = () => result = surfaceLine.TrySetDikeToeAtRiver(testPoint); - - // Assert - string message = $"Karakteristiek punt van profielschematisatie 'testName' is overgeslagen. De geometrie bevat geen punt op locatie {testPoint} om als 'Teen dijk buitenwaarts' in te stellen."; - TestHelper.AssertLogMessageIsGenerated(test, message, 1); - Assert.IsFalse(result); - } - - [Test] - public void TrySetDikeToeAtRiver_PointInGeometry_PointSetAndReturnTrue() - { - // Setup - var random = new Random(21); - double x = random.NextDouble(); - double y = random.NextDouble(); - double z = random.NextDouble(); - var surfaceLine = new RingtoetsMacroStabilityInwardsSurfaceLine(); - - var point = new Point3D(x, y, z); - - surfaceLine.SetGeometry(new[] - { - point - }); - - // Call - bool result = surfaceLine.TrySetDikeToeAtRiver(point); - - // Assert - Assert.IsTrue(result); - Assert.AreEqual(point, surfaceLine.DikeToeAtRiver); - } - - [Test] - public void TrySetSurfaceLevelInside_Null_ReturnsFalse() - { - // Setup - var surfaceLine = new RingtoetsMacroStabilityInwardsSurfaceLine(); - - // Call - bool result = surfaceLine.TrySetSurfaceLevelInside(null); - - // Assert - Assert.IsFalse(result); - } - - [Test] - public void TrySetSurfaceLevelInside_NoPointInGeometry_LogAndReturnFalse() - { - // Setup - var random = new Random(21); - var testPoint = new Point3D(random.NextDouble(), random.NextDouble(), random.NextDouble()); - var surfaceLine = new RingtoetsMacroStabilityInwardsSurfaceLine - { - Name = "testName" - }; - - var result = true; - - // Call - Action test = () => result = surfaceLine.TrySetSurfaceLevelInside(testPoint); - - // Assert - string message = $"Karakteristiek punt van profielschematisatie 'testName' is overgeslagen. De geometrie bevat geen punt op locatie {testPoint} om als 'Maaiveld binnenwaarts' in te stellen."; - TestHelper.AssertLogMessageIsGenerated(test, message, 1); - Assert.IsFalse(result); - } - - [Test] - public void TrySetSurfaceLevelInside_PointInGeometry_PointSetAndReturnTrue() - { - // Setup - var random = new Random(21); - double x = random.NextDouble(); - double y = random.NextDouble(); - double z = random.NextDouble(); - var surfaceLine = new RingtoetsMacroStabilityInwardsSurfaceLine(); - - var point = new Point3D(x, y, z); - - surfaceLine.SetGeometry(new[] - { - point - }); - - // Call - bool result = surfaceLine.TrySetSurfaceLevelInside(point); - - // Assert - Assert.IsTrue(result); - Assert.AreEqual(point, surfaceLine.SurfaceLevelInside); - } - - [Test] - public void TrySetSurfaceLevelOutside_Null_ReturnsFalse() - { - // Setup - var surfaceLine = new RingtoetsMacroStabilityInwardsSurfaceLine(); - - // Call - bool result = surfaceLine.TrySetSurfaceLevelOutside(null); - - // Assert - Assert.IsFalse(result); - } - - [Test] - public void TrySetSurfaceLevelOutside_NoPointInGeometry_LogAndReturnFalse() - { - // Setup - var random = new Random(21); - var testPoint = new Point3D(random.NextDouble(), random.NextDouble(), random.NextDouble()); - var surfaceLine = new RingtoetsMacroStabilityInwardsSurfaceLine - { - Name = "testName" - }; - - var result = true; - - // Call - Action test = () => result = surfaceLine.TrySetSurfaceLevelOutside(testPoint); - - // Assert - string message = $"Karakteristiek punt van profielschematisatie 'testName' is overgeslagen. De geometrie bevat geen punt op locatie {testPoint} om als 'Maaiveld buitenwaarts' in te stellen."; - TestHelper.AssertLogMessageIsGenerated(test, message, 1); - Assert.IsFalse(result); - } - - [Test] - public void TrySetSurfaceLevelOutside_PointInGeometry_PointSetAndReturnTrue() - { - // Setup - var random = new Random(21); - double x = random.NextDouble(); - double y = random.NextDouble(); - double z = random.NextDouble(); - var surfaceLine = new RingtoetsMacroStabilityInwardsSurfaceLine(); - - var point = new Point3D(x, y, z); - - surfaceLine.SetGeometry(new[] - { - point - }); - - // Call - bool result = surfaceLine.TrySetSurfaceLevelOutside(point); - - // Assert - Assert.IsTrue(result); - Assert.AreEqual(point, surfaceLine.SurfaceLevelOutside); - } - - [Test] - public void SetCharacteristicPoints_SurfaceLineNull_ThrowsArgumentNullException() - { - // Setup - var points = new CharacteristicPoints("swapped dike toes") - { - DikeToeAtPolder = new Point3D(3, 2, 5), - DikeToeAtRiver = new Point3D(3.4, 3, 8), - DitchDikeSide = new Point3D(4.4, 6, 8), - BottomDitchDikeSide = new Point3D(5.1, 6, 6.5), - BottomDitchPolderSide = new Point3D(8.5, 7.2, 4.2), - DitchPolderSide = new Point3D(9.6, 7.5, 3.9) - }; - - // Call - TestDelegate test = () => ((RingtoetsMacroStabilityInwardsSurfaceLine) null).SetCharacteristicPoints(points); - - // Assert - var exception = Assert.Throws(test); - Assert.AreEqual("surfaceLine", exception.ParamName); - } - - [Test] - public void SetCharacteristicPoints_CharacteristicPointsNull_ReturnsFalseNoCharacteristicPointsSet() - { - // Setup - var surfaceLine = new RingtoetsMacroStabilityInwardsSurfaceLine(); - surfaceLine.SetGeometry(new[] - { - new Point3D(3, 2, 5), - new Point3D(3.4, 3, 8), - new Point3D(4.4, 6, 8), - new Point3D(5.1, 6, 6.5), - new Point3D(8.5, 7.2, 4.2), - new Point3D(9.6, 7.5, 3.9) - }); - - // Call - bool result = surfaceLine.SetCharacteristicPoints(null); - - // Assert - Assert.IsFalse(result); - Assert.IsNull(surfaceLine.DikeToeAtRiver); - Assert.IsNull(surfaceLine.DikeToeAtPolder); - Assert.IsNull(surfaceLine.DitchDikeSide); - Assert.IsNull(surfaceLine.BottomDitchDikeSide); - Assert.IsNull(surfaceLine.BottomDitchPolderSide); - Assert.IsNull(surfaceLine.DitchPolderSide); - } - - [Test] - [TestCaseSource(nameof(DifferentValidCharacteristicPointConfigurations))] - public void SetCharacteristicPoints_ValidSituations_ReturnsTruePointsAreSet(CharacteristicPoints points) - { - // Setup - var surfaceLine = new RingtoetsMacroStabilityInwardsSurfaceLine(); - surfaceLine.SetGeometry(CharacteristicPointsToGeometry(points)); - - // Call - bool result = surfaceLine.SetCharacteristicPoints(points); - - // Assert - Assert.IsTrue(result); - Assert.AreEqual(points.DikeToeAtRiver, surfaceLine.DikeToeAtRiver); - Assert.AreEqual(points.DikeToeAtPolder, surfaceLine.DikeToeAtPolder); - Assert.AreEqual(points.DitchDikeSide, surfaceLine.DitchDikeSide); - Assert.AreEqual(points.BottomDitchDikeSide, surfaceLine.BottomDitchDikeSide); - Assert.AreEqual(points.BottomDitchPolderSide, surfaceLine.BottomDitchPolderSide); - Assert.AreEqual(points.DitchPolderSide, surfaceLine.DitchPolderSide); - } - - private static IEnumerable CharacteristicPointsToGeometry(CharacteristicPoints points) - { - return new[] - { - points.DikeToeAtRiver, - points.DikeToeAtPolder, - points.DitchDikeSide, - points.BottomDitchDikeSide, - points.BottomDitchPolderSide, - points.DitchPolderSide - }.Where(p => p != null); - } - private static IEnumerable DifferentValidCharacteristicPointConfigurations { get { - var dikeToeAtRiver = new Point3D(3, 2, 5); - var dikeToeAtPolder = new Point3D(3.4, 3, 8); - var ditchDikeSide = new Point3D(4.4, 6, 8); - var bottomDitchDikeSide = new Point3D(5.1, 6, 6.5); - var bottomDitchPolderSide = new Point3D(8.5, 7.2, 4.2); - var ditchPolderSide = new Point3D(9.6, 7.5, 3.9); - var name = "All present"; - yield return new TestCaseData(new CharacteristicPoints(name) - { - DikeToeAtRiver = dikeToeAtRiver, - DikeToeAtPolder = dikeToeAtPolder, - DitchDikeSide = ditchDikeSide, - BottomDitchDikeSide = bottomDitchDikeSide, - BottomDitchPolderSide = bottomDitchPolderSide, - DitchPolderSide = ditchPolderSide - }).SetName(name); + CharacteristicPoints set = CreateCompleteCharacteristicPointSet(name); + yield return new TestCaseData(set).SetName(name); - name = "Missing DikeToeAtRiver"; - yield return new TestCaseData(new CharacteristicPoints(name) - { - DikeToeAtPolder = dikeToeAtPolder, - DitchDikeSide = ditchDikeSide, - BottomDitchDikeSide = bottomDitchDikeSide, - BottomDitchPolderSide = bottomDitchPolderSide, - DitchPolderSide = ditchPolderSide - }).SetName(name); + name = "Missing ShoulderBaseInside"; + set = CreateCompleteCharacteristicPointSet(name); + set.ShoulderBaseInside = null; + yield return new TestCaseData(set).SetName(name); - name = "Missing DikeToeAtPolder"; - yield return new TestCaseData(new CharacteristicPoints(name) - { - DikeToeAtRiver = dikeToeAtRiver, - DitchDikeSide = ditchDikeSide, - BottomDitchDikeSide = bottomDitchDikeSide, - BottomDitchPolderSide = bottomDitchPolderSide, - DitchPolderSide = ditchPolderSide - }).SetName(name); + name = "Missing ShoulderTopInside"; + set = CreateCompleteCharacteristicPointSet(name); + set.ShoulderTopInside = null; + yield return new TestCaseData(set).SetName(name); + name = "Missing TrafficLoadOutside"; + set = CreateCompleteCharacteristicPointSet(name); + set.TrafficLoadOutside = null; + yield return new TestCaseData(set).SetName(name); + + name = "Missing TrafficLoadInside"; + set = CreateCompleteCharacteristicPointSet(name); + set.TrafficLoadInside = null; + yield return new TestCaseData(set).SetName(name); + name = "Missing DitchDikeSide"; - yield return new TestCaseData(new CharacteristicPoints(name) - { - DikeToeAtRiver = dikeToeAtRiver, - DikeToeAtPolder = dikeToeAtPolder, - BottomDitchDikeSide = bottomDitchDikeSide, - BottomDitchPolderSide = bottomDitchPolderSide, - DitchPolderSide = ditchPolderSide - }).SetName(name); + set = CreateCompleteCharacteristicPointSet(name); + set.DitchDikeSide = null; + yield return new TestCaseData(set).SetName(name); name = "Missing BottomDitchDikeSide"; - yield return new TestCaseData(new CharacteristicPoints(name) - { - DikeToeAtRiver = dikeToeAtRiver, - DikeToeAtPolder = dikeToeAtPolder, - DitchDikeSide = ditchDikeSide, - BottomDitchPolderSide = bottomDitchPolderSide, - DitchPolderSide = ditchPolderSide - }).SetName(name); + set = CreateCompleteCharacteristicPointSet(name); + set.BottomDitchDikeSide = null; + yield return new TestCaseData(set).SetName(name); name = "Missing BottomDitchPolderSide"; - yield return new TestCaseData(new CharacteristicPoints(name) - { - DikeToeAtRiver = dikeToeAtRiver, - DikeToeAtPolder = dikeToeAtPolder, - DitchDikeSide = ditchDikeSide, - BottomDitchDikeSide = bottomDitchDikeSide, - DitchPolderSide = ditchPolderSide - }).SetName(name); + set = CreateCompleteCharacteristicPointSet(name); + set.BottomDitchPolderSide = null; + yield return new TestCaseData(set).SetName(name); name = "Missing DitchPolderSide"; - yield return new TestCaseData(new CharacteristicPoints(name) - { - DikeToeAtRiver = dikeToeAtRiver, - DikeToeAtPolder = dikeToeAtPolder, - DitchDikeSide = ditchDikeSide, - BottomDitchDikeSide = bottomDitchDikeSide, - BottomDitchPolderSide = bottomDitchPolderSide - }).SetName(name); + set = CreateCompleteCharacteristicPointSet(name); + set.DitchPolderSide = null; + yield return new TestCaseData(set).SetName(name); } } + + private static CharacteristicPoints CreateCompleteCharacteristicPointSet(string name) + { + var surfaceLevelOutside = new Point3D(2, 2, 5); + var dikeToeAtRiver = new Point3D(2.1, 2, 5); + var trafficLoadOutside = new Point3D(2.25, 2, 5); + var trafficLoadInside = new Point3D(2.45, 2, 5); + var dikeTopAtPolder = new Point3D(2.7, 2, 5); + var shoulderBaseInside = new Point3D(3.2, 2, 5); + var shoulderTopInside = new Point3D(3.5, 2, 5); + var dikeToeAtPolder = new Point3D(4.4, 3, 8); + var ditchDikeSide = new Point3D(6.3, 6, 8); + var bottomDitchDikeSide = new Point3D(5.1, 6, 6.5); + var bottomDitchPolderSide = new Point3D(8.5, 7.2, 4.2); + var ditchPolderSide = new Point3D(9.6, 7.5, 3.9); + var surfaceLevelInside = new Point3D(10.1, 2, 5); + + return new CharacteristicPoints(name) + { + DikeTopAtPolder = dikeTopAtPolder, + ShoulderBaseInside = shoulderBaseInside, + ShoulderTopInside = shoulderTopInside, + TrafficLoadOutside = trafficLoadOutside, + TrafficLoadInside = trafficLoadInside, + SurfaceLevelOutside = surfaceLevelOutside, + SurfaceLevelInside = surfaceLevelInside, + DikeToeAtRiver = dikeToeAtRiver, + DikeToeAtPolder = dikeToeAtPolder, + DitchDikeSide = ditchDikeSide, + BottomDitchDikeSide = bottomDitchDikeSide, + BottomDitchPolderSide = bottomDitchPolderSide, + DitchPolderSide = ditchPolderSide + }; + } } } \ No newline at end of file Index: Ringtoets/Piping/src/Ringtoets.Piping.IO/Importers/PipingSurfaceLineTransformer.cs =================================================================== diff -u -r5579d8fdef4f553fb4ba94160825ec960b89bab9 -r683ff9234262d9fa3bea5edc0abe35254f80e49d --- Ringtoets/Piping/src/Ringtoets.Piping.IO/Importers/PipingSurfaceLineTransformer.cs (.../PipingSurfaceLineTransformer.cs) (revision 5579d8fdef4f553fb4ba94160825ec960b89bab9) +++ Ringtoets/Piping/src/Ringtoets.Piping.IO/Importers/PipingSurfaceLineTransformer.cs (.../PipingSurfaceLineTransformer.cs) (revision 683ff9234262d9fa3bea5edc0abe35254f80e49d) @@ -67,10 +67,7 @@ }; pipingSurfaceLine.SetGeometry(surfaceLine.Points); - if (!pipingSurfaceLine.SetCharacteristicPoints(characteristicPoints)) - { - return null; - } + pipingSurfaceLine.SetCharacteristicPoints(characteristicPoints); pipingSurfaceLine.ReferenceLineIntersectionWorldPoint = result.IntersectionPoint; Index: Ringtoets/Piping/src/Ringtoets.Piping.IO/Importers/RingtoetsPipingSurfaceLineExtensions.cs =================================================================== diff -u -r5579d8fdef4f553fb4ba94160825ec960b89bab9 -r683ff9234262d9fa3bea5edc0abe35254f80e49d --- Ringtoets/Piping/src/Ringtoets.Piping.IO/Importers/RingtoetsPipingSurfaceLineExtensions.cs (.../RingtoetsPipingSurfaceLineExtensions.cs) (revision 5579d8fdef4f553fb4ba94160825ec960b89bab9) +++ Ringtoets/Piping/src/Ringtoets.Piping.IO/Importers/RingtoetsPipingSurfaceLineExtensions.cs (.../RingtoetsPipingSurfaceLineExtensions.cs) (revision 683ff9234262d9fa3bea5edc0abe35254f80e49d) @@ -203,27 +203,28 @@ /// /// The surface line to set characteristic points for. /// The characteristic points to set, if the collection is valid. - /// true if the characteristic points could be set; false otherwise. /// Thrown when is null. - public static bool SetCharacteristicPoints(this RingtoetsPipingSurfaceLine surfaceLine, CharacteristicPoints characteristicPoints) + /// Thrown when were + /// invalid to use for piping. + public static void SetCharacteristicPoints(this RingtoetsPipingSurfaceLine surfaceLine, CharacteristicPoints characteristicPoints) { if (surfaceLine == null) { throw new ArgumentNullException(nameof(surfaceLine)); } - if (characteristicPoints == null || !surfaceLine.ValidateDikeToesInOrder(characteristicPoints)) + if (characteristicPoints == null) { - return false; + return; } + surfaceLine.ValidateDikeToesInOrder(characteristicPoints); + surfaceLine.TrySetDikeToeAtRiver(characteristicPoints.DikeToeAtRiver); surfaceLine.TrySetDitchDikeSide(characteristicPoints.DitchDikeSide); surfaceLine.TrySetBottomDitchDikeSide(characteristicPoints.BottomDitchDikeSide); surfaceLine.TrySetBottomDitchPolderSide(characteristicPoints.BottomDitchPolderSide); surfaceLine.TrySetDitchPolderSide(characteristicPoints.DitchPolderSide); surfaceLine.TrySetDikeToeAtPolder(characteristicPoints.DikeToeAtPolder); - - return true; } private static void LogError(RingtoetsPipingSurfaceLine surfaceLine, ArgumentException e) @@ -233,7 +234,7 @@ e.Message); } - private static bool ValidateDikeToesInOrder(this RingtoetsPipingSurfaceLine readSurfaceLine, CharacteristicPoints characteristicPoints) + private static void ValidateDikeToesInOrder(this RingtoetsPipingSurfaceLine readSurfaceLine, CharacteristicPoints characteristicPoints) { if (characteristicPoints != null && characteristicPoints.DikeToeAtRiver != null && characteristicPoints.DikeToeAtPolder != null) { @@ -242,11 +243,10 @@ if (localDikeToeAtPolder.X <= localDikeToeAtRiver.X) { - log.WarnFormat(Resources.SurfaceLinesCsvImporter_CheckCharacteristicPoints_EntryPointL_greater_or_equal_to_ExitPointL_for_0_, characteristicPoints.Name); - return false; + string message = string.Format(Resources.SurfaceLinesCsvImporter_CheckCharacteristicPoints_EntryPointL_greater_or_equal_to_ExitPointL_for_0_, characteristicPoints.Name); + throw new SurfaceLineTransformException(message); } } - return true; } } } \ No newline at end of file Index: Ringtoets/Piping/test/Ringtoets.Piping.IO.Test/Importers/PipingSurfaceLineTransformerTest.cs =================================================================== diff -u -rb8fa5d6867c945f3f1744fd1455b89cadb357959 -r683ff9234262d9fa3bea5edc0abe35254f80e49d --- Ringtoets/Piping/test/Ringtoets.Piping.IO.Test/Importers/PipingSurfaceLineTransformerTest.cs (.../PipingSurfaceLineTransformerTest.cs) (revision b8fa5d6867c945f3f1744fd1455b89cadb357959) +++ Ringtoets/Piping/test/Ringtoets.Piping.IO.Test/Importers/PipingSurfaceLineTransformerTest.cs (.../PipingSurfaceLineTransformerTest.cs) (revision 683ff9234262d9fa3bea5edc0abe35254f80e49d) @@ -153,10 +153,45 @@ } [Test] + public void Transform_WithoutCharacteristicPoints_ReturnsSurfaceLineWithoutCharacteristicPointsSet() + { + // Setup + var referenceLine = new ReferenceLine(); + var transformer = new PipingSurfaceLineTransformer(referenceLine); + + const string surfaceLineName = "somewhere"; + var surfaceLine = new SurfaceLine + { + Name = surfaceLineName + }; + surfaceLine.SetGeometry(new[] + { + new Point3D(1.0, 5.0, 2.1), + new Point3D(1.0, 3.0, 2.1) + }); + referenceLine.SetGeometry(new[] + { + new Point2D(0.0, 4.0), + new Point2D(2.0, 4.0) + }); + + // Call + RingtoetsPipingSurfaceLine result = transformer.Transform(surfaceLine, null); + + // Assert + Assert.IsNull(result.DitchDikeSide); + Assert.IsNull(result.BottomDitchDikeSide); + Assert.IsNull(result.BottomDitchPolderSide); + Assert.IsNull(result.DitchPolderSide); + Assert.IsNull(result.DikeToeAtPolder); + Assert.IsNull(result.DikeToeAtRiver); + } + + [Test] [TestCase(2.0)] [TestCase(3.0)] [TestCase(3.5)] - public void Transform_DikeToePolderOnOrBeforeDikeToeRiver_LogErrorAndReturnNull(double xDikeToePolder) + public void Transform_DikeToePolderOnOrBeforeDikeToeRiver_ThrowsException(double xDikeToePolder) { // Setup var referenceLine = new ReferenceLine(); @@ -187,20 +222,18 @@ new Point2D(3.2, randomY + 1) }); - IMechanismSurfaceLine result = null; - // Call - Action call = () => result = transformer.Transform(surfaceLine, characteristicPoints); + TestDelegate test = () => transformer.Transform(surfaceLine, characteristicPoints); // Assert - string message = $"Het uittredepunt moet landwaarts van het intredepunt liggen voor locatie {locationName}."; - TestHelper.AssertLogMessageWithLevelIsGenerated(call, Tuple.Create(message, LogLevelConstant.Warn)); - Assert.IsNull(result); + string message = $"Het uittredepunt moet landwaarts van het intredepunt liggen voor locatie '{locationName}'."; + var exception = Assert.Throws(test); + Assert.AreEqual(message, exception.Message); } [Test] [TestCaseSource(nameof(MoveCharacteristicPoint))] - public void Transform_CharacteristicPointNotOnSurfaceLine_LogErrorAndReturnNull(Action pointChange, Func pointWhichIsNull, string changedCharacteristicPointName) + public void Transform_CharacteristicPointNotOnSurfaceLine_LogErrorAndReturnSurfaceLineWithoutCharacteristicPointSet(Action pointChange, Func pointWhichIsNull, string changedCharacteristicPointName) { // Setup var referenceLine = new ReferenceLine(); Index: Ringtoets/Piping/test/Ringtoets.Piping.IO.Test/Importers/RingtoetsPipingSurfaceLineExtensionsTest.cs =================================================================== diff -u -r5579d8fdef4f553fb4ba94160825ec960b89bab9 -r683ff9234262d9fa3bea5edc0abe35254f80e49d --- Ringtoets/Piping/test/Ringtoets.Piping.IO.Test/Importers/RingtoetsPipingSurfaceLineExtensionsTest.cs (.../RingtoetsPipingSurfaceLineExtensionsTest.cs) (revision 5579d8fdef4f553fb4ba94160825ec960b89bab9) +++ Ringtoets/Piping/test/Ringtoets.Piping.IO.Test/Importers/RingtoetsPipingSurfaceLineExtensionsTest.cs (.../RingtoetsPipingSurfaceLineExtensionsTest.cs) (revision 683ff9234262d9fa3bea5edc0abe35254f80e49d) @@ -417,7 +417,7 @@ } [Test] - public void SetCharacteristicPoints_CharacteristicPointsNull_ReturnsFalseNoCharacteristicPointsSet() + public void SetCharacteristicPoints_CharacteristicPointsNull_NoCharacteristicPointsSet() { // Setup var surfaceLine = new RingtoetsPipingSurfaceLine(); @@ -432,10 +432,9 @@ }); // Call - bool result = surfaceLine.SetCharacteristicPoints(null); + surfaceLine.SetCharacteristicPoints(null); // Assert - Assert.IsFalse(result); Assert.IsNull(surfaceLine.DikeToeAtRiver); Assert.IsNull(surfaceLine.DikeToeAtPolder); Assert.IsNull(surfaceLine.DitchDikeSide); @@ -445,10 +444,11 @@ } [Test] - public void SetCharacteristicPoints_DikeToesReversed_ReturnsFalseNoCharacteristicPointsSet() + public void SetCharacteristicPoints_DikeToesReversed_ThrowsTransformException() { // Setup - var points = new CharacteristicPoints("swapped dike toes") + var name = "swapped dike toes"; + var points = new CharacteristicPoints(name) { DikeToeAtPolder = new Point3D(3, 2, 5), DikeToeAtRiver = new Point3D(3.4, 3, 8), @@ -461,31 +461,25 @@ surfaceLine.SetGeometry(CharacteristicPointsToGeometry(points)); // Call - bool result = surfaceLine.SetCharacteristicPoints(points); + TestDelegate test = () => surfaceLine.SetCharacteristicPoints(points); // Assert - Assert.IsFalse(result); - Assert.IsNull(surfaceLine.DikeToeAtRiver); - Assert.IsNull(surfaceLine.DikeToeAtPolder); - Assert.IsNull(surfaceLine.DitchDikeSide); - Assert.IsNull(surfaceLine.BottomDitchDikeSide); - Assert.IsNull(surfaceLine.BottomDitchPolderSide); - Assert.IsNull(surfaceLine.DitchPolderSide); + var exception = Assert.Throws(test); + Assert.AreEqual($"Het uittredepunt moet landwaarts van het intredepunt liggen voor locatie '{name}'.", exception.Message); } [Test] [TestCaseSource(nameof(DifferentValidCharacteristicPointConfigurations))] - public void SetCharacteristicPoints_ValidSituations_ReturnsTruePointsAreSet(CharacteristicPoints points) + public void SetCharacteristicPoints_ValidSituations_PointsAreSet(CharacteristicPoints points) { // Setup var surfaceLine = new RingtoetsPipingSurfaceLine(); surfaceLine.SetGeometry(CharacteristicPointsToGeometry(points)); // Call - bool result = surfaceLine.SetCharacteristicPoints(points); + surfaceLine.SetCharacteristicPoints(points); // Assert - Assert.IsTrue(result); Assert.AreEqual(points.DikeToeAtRiver, surfaceLine.DikeToeAtRiver); Assert.AreEqual(points.DikeToeAtPolder, surfaceLine.DikeToeAtPolder); Assert.AreEqual(points.DitchDikeSide, surfaceLine.DitchDikeSide);