Index: Ringtoets/Piping/src/Ringtoets.Piping.Forms/Extensions/PipingInputExtensions.cs =================================================================== diff -u -r2a7be595bf1251849a3c5f3be000f0e40f8fa874 -r98a291d574281a04a9e0a243d8a4429a1ffb9379 --- Ringtoets/Piping/src/Ringtoets.Piping.Forms/Extensions/PipingInputExtensions.cs (.../PipingInputExtensions.cs) (revision 2a7be595bf1251849a3c5f3be000f0e40f8fa874) +++ Ringtoets/Piping/src/Ringtoets.Piping.Forms/Extensions/PipingInputExtensions.cs (.../PipingInputExtensions.cs) (revision 98a291d574281a04a9e0a243d8a4429a1ffb9379) @@ -1,6 +1,7 @@ using System; using System.Linq; using Ringtoets.Piping.Data; +using Ringtoets.Piping.Forms.Properties; namespace Ringtoets.Piping.Forms.Extensions { @@ -57,5 +58,43 @@ input.SeepageLength.Mean = mean; input.SeepageLength.StandardDeviation = mean * PipingInput.SeepageLengthStandardDeviationFraction; } + + /// + /// Sets the L-coordinate of the entry point. + /// + /// The to update the entry point for. + /// The L-coordinate of the entry point to set. + public static void SetEntryPointL(this PipingInput input, double entryPointL) + { + try + { + input.SetSeepageLengthMean(input.ExitPointL - entryPointL); + } + catch (ArgumentOutOfRangeException) + { + var message = string.Format(Resources.PipingInputContextProperties_EntryPointL_Value_0_results_in_invalid_seepage_length, entryPointL); + throw new ArgumentException(message); + } + } + + /// + /// Sets the L-coordinate of the exit point. + /// + /// The to update the entry point for. + /// The L-coordinate of the entry point to set. + public static void SetExitPointL(this PipingInput input, double exitPointL) + { + var exitPointLChange = exitPointL - input.ExitPointL; + try + { + input.SetSeepageLengthMean(input.SeepageLength.Mean + exitPointLChange); + } + catch (ArgumentOutOfRangeException) + { + var message = string.Format(Resources.PipingInputContextProperties_ExitPointL_Value_0_results_in_invalid_seepage_length, exitPointL); + throw new ArgumentException(message); + } + input.ExitPointL = exitPointL; + } } } \ No newline at end of file Index: Ringtoets/Piping/src/Ringtoets.Piping.Forms/PropertyClasses/PipingInputContextProperties.cs =================================================================== diff -u -r2a7be595bf1251849a3c5f3be000f0e40f8fa874 -r98a291d574281a04a9e0a243d8a4429a1ffb9379 --- Ringtoets/Piping/src/Ringtoets.Piping.Forms/PropertyClasses/PipingInputContextProperties.cs (.../PipingInputContextProperties.cs) (revision 2a7be595bf1251849a3c5f3be000f0e40f8fa874) +++ Ringtoets/Piping/src/Ringtoets.Piping.Forms/PropertyClasses/PipingInputContextProperties.cs (.../PipingInputContextProperties.cs) (revision 98a291d574281a04a9e0a243d8a4429a1ffb9379) @@ -362,16 +362,7 @@ } set { - try - { - data.WrappedData.SetSeepageLengthMean(data.WrappedData.ExitPointL - value); - } - catch (ArgumentOutOfRangeException) - { - var message = string.Format(Resources.PipingInputContextProperties_EntryPointL_Value_0_results_in_invalid_seepage_length, value); - throw new ArgumentException(message); - } - + data.WrappedData.SetEntryPointL(value); data.WrappedData.NotifyObservers(); } } @@ -387,18 +378,7 @@ } set { - try - { - var exitPointLChange = value - data.WrappedData.ExitPointL; - data.WrappedData.SetSeepageLengthMean(data.WrappedData.SeepageLength.Mean + exitPointLChange); - } - catch (ArgumentOutOfRangeException) - { - var message = string.Format(Resources.PipingInputContextProperties_ExitPointL_Value_0_results_in_invalid_seepage_length, value); - throw new ArgumentException(message); - } - - data.WrappedData.ExitPointL = value; + data.WrappedData.SetExitPointL(value); data.WrappedData.NotifyObservers(); } } Index: Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/Extensions/PipingInputExtensionsTest.cs =================================================================== diff -u -r2a7be595bf1251849a3c5f3be000f0e40f8fa874 -r98a291d574281a04a9e0a243d8a4429a1ffb9379 --- Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/Extensions/PipingInputExtensionsTest.cs (.../PipingInputExtensionsTest.cs) (revision 2a7be595bf1251849a3c5f3be000f0e40f8fa874) +++ Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/Extensions/PipingInputExtensionsTest.cs (.../PipingInputExtensionsTest.cs) (revision 98a291d574281a04a9e0a243d8a4429a1ffb9379) @@ -1,7 +1,10 @@ -using Core.Common.Base.Geometry; +using System; +using Core.Common.Base.Geometry; +using Core.Common.TestUtil; using NUnit.Framework; using Ringtoets.Piping.Data; using Ringtoets.Piping.Forms.Extensions; +using Ringtoets.Piping.Forms.Properties; namespace Ringtoets.Piping.Forms.Test.Extensions { @@ -115,5 +118,153 @@ Assert.AreEqual(0.2, inputParameters.SeepageLength.StandardDeviation); Assert.AreEqual(thirdPointX - firstPointX, inputParameters.ExitPointL); } + + [Test] + [TestCase(2, 0, 2)] + [TestCase(2, -2, 4)] + [TestCase(0.5, -3.5, 4)] + [TestCase(1e-6, -(4 - 1e-6), 4)] + [TestCase(3 + 1e-6, 3, 1e-6)] + [TestCase(0.5, 0.5 - 1e-6, 1e-6)] + public void SetEntryPointL_ExitPointAndSeepageLengthSet_UpdatesSeepageLength(double exitPoint, double entryPoint, double seepageLength) + { + // Setup + var random = new Random(22); + + var surfaceLine = ValidSurfaceLine(0.0, 4.0); + var soilProfile = new PipingSoilProfile(String.Empty, random.NextDouble(), new[] + { + new PipingSoilLayer(random.NextDouble()) + { + IsAquifer = true + } + }); + var input = new PipingInput + { + SurfaceLine = surfaceLine, + SoilProfile = soilProfile, + ExitPointL = exitPoint + }; + + input.SetEntryPointL(entryPoint); + + // Call & Assert + Assert.AreEqual(exitPoint, input.ExitPointL); + Assert.AreEqual(seepageLength, input.SeepageLength.Mean, 1e-6); + } + + [Test] + [TestCase(2, 2, 4)] + [TestCase(4, 2, 6)] + [TestCase(4, 0.5, 4.5)] + [TestCase(1e-6, 4, 4 + 1e-6)] + [TestCase(3, -1e-6, 3 - 1e-6)] + [TestCase(0.5, 1e-6, 0.5 + 1e-6)] + public void SetExitPointL_ExitPointAndSeepageLengthSet_UpdatesSeepageLength(double seepageLength, double exitPoint, double newSeepageLength) + { + // Setup + var random = new Random(22); + + var surfaceLine = ValidSurfaceLine(0.0, 4.0); + var soilProfile = new PipingSoilProfile(String.Empty, random.NextDouble(), new[] + { + new PipingSoilLayer(random.NextDouble()) + { + IsAquifer = true + } + }); + var input = new PipingInput + { + SurfaceLine = surfaceLine, + SoilProfile = soilProfile, + SeepageLength = + { + Mean = seepageLength + } + }; + + input.SetExitPointL(exitPoint); + + // Call & Assert + Assert.AreEqual(exitPoint, input.ExitPointL); + Assert.AreEqual(newSeepageLength, input.SeepageLength.Mean); + } + + [Test] + public void SetEntryPointL_SetResultInInvalidSeePage_ThrowsArgumentException() + { + // Setup + var random = new Random(22); + + var surfaceLine = ValidSurfaceLine(0.0, 4.0); + var soilProfile = new PipingSoilProfile(String.Empty, random.NextDouble(), new[] + { + new PipingSoilLayer(random.NextDouble()) + { + IsAquifer = true + } + }); + + var l = 2.0; + var input = new PipingInput + { + SurfaceLine = surfaceLine, + SoilProfile = soilProfile, + ExitPointL = l + }; + + + // Call + TestDelegate test = () => input.SetEntryPointL(l); + + // Assert + var message = string.Format(Resources.PipingInputContextProperties_EntryPointL_Value_0_results_in_invalid_seepage_length, l); + TestHelper.AssertThrowsArgumentExceptionAndTestMessage(test, message); + } + + [Test] + public void SetExitPointL_SetResultInInvalidSeePage_ThrowsArgumentException() + { + // Setup + var random = new Random(22); + + var surfaceLine = ValidSurfaceLine(0.0, 4.0); + var soilProfile = new PipingSoilProfile(String.Empty, random.NextDouble(), new[] + { + new PipingSoilLayer(random.NextDouble()) + { + IsAquifer = true + } + }); + var l = -2.0; + var input = new PipingInput + { + SurfaceLine = surfaceLine, + SoilProfile = soilProfile, + SeepageLength = + { + Mean = -l + } + }; + + + // Call + TestDelegate test = () => input.SetExitPointL(l); + + // Assert + var message = string.Format(Resources.PipingInputContextProperties_ExitPointL_Value_0_results_in_invalid_seepage_length, l); + TestHelper.AssertThrowsArgumentExceptionAndTestMessage(test, message); + } + + private static RingtoetsPipingSurfaceLine ValidSurfaceLine(double xMin, double xMax) + { + var surfaceLine = new RingtoetsPipingSurfaceLine(); + surfaceLine.SetGeometry(new[] + { + new Point3D(xMin, 0.0, 0.0), + new Point3D(xMax, 0.0, 1.0) + }); + return surfaceLine; + } } } \ No newline at end of file