Index: Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.KernelWrapper/Calculators/UpliftVan/UpliftVanCalculator.cs =================================================================== diff -u -r6139d8deb7b8f83cd06a4534f04ed18ecbada3b6 -r0b21aa321e05e40b31eb5ace3adc8bb9cebea68d --- Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.KernelWrapper/Calculators/UpliftVan/UpliftVanCalculator.cs (.../UpliftVanCalculator.cs) (revision 6139d8deb7b8f83cd06a4534f04ed18ecbada3b6) +++ Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.KernelWrapper/Calculators/UpliftVan/UpliftVanCalculator.cs (.../UpliftVanCalculator.cs) (revision 0b21aa321e05e40b31eb5ace3adc8bb9cebea68d) @@ -79,6 +79,17 @@ public List Validate() { + IUpliftVanKernel upliftVanKernel = CreateUpliftVanKernel(); + + try + { + upliftVanKernel.Validate(); + } + catch (UpliftVanKernelWrapperException e) + { + throw new UpliftVanCalculatorException(e.Message, e); + } + return new List(); } Index: Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.KernelWrapper/Kernels/UpliftVan/IUpliftVanKernel.cs =================================================================== diff -u -r5b4fdd217b573664d8ee5b2d3b571159833d4ed5 -r0b21aa321e05e40b31eb5ace3adc8bb9cebea68d --- Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.KernelWrapper/Kernels/UpliftVan/IUpliftVanKernel.cs (.../IUpliftVanKernel.cs) (revision 5b4fdd217b573664d8ee5b2d3b571159833d4ed5) +++ Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.KernelWrapper/Kernels/UpliftVan/IUpliftVanKernel.cs (.../IUpliftVanKernel.cs) (revision 0b21aa321e05e40b31eb5ace3adc8bb9cebea68d) @@ -19,6 +19,7 @@ // Stichting Deltares and remain full property of Stichting Deltares at all times. // All rights reserved. +using System.Collections.Generic; using Deltares.WTIStability; using Deltares.WTIStability.Data.Geo; using Ringtoets.MacroStabilityInwards.KernelWrapper.Calculators.UpliftVan; @@ -136,5 +137,11 @@ /// Thrown when /// an unexpected error occurs when performing the calculation. void Calculate(); + + /// + /// Validates the input for the Uplift Van calculation. + /// + /// A list of validation strings, or an empty list if there are no validation errors. + List Validate(); } } \ No newline at end of file Index: Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.KernelWrapper/Kernels/UpliftVan/UpliftVanKernelWrapper.cs =================================================================== diff -u -rcdc86218b530bf9cc5cd579955cf4be77c305d0a -r0b21aa321e05e40b31eb5ace3adc8bb9cebea68d --- Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.KernelWrapper/Kernels/UpliftVan/UpliftVanKernelWrapper.cs (.../UpliftVanKernelWrapper.cs) (revision cdc86218b530bf9cc5cd579955cf4be77c305d0a) +++ Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.KernelWrapper/Kernels/UpliftVan/UpliftVanKernelWrapper.cs (.../UpliftVanKernelWrapper.cs) (revision 0b21aa321e05e40b31eb5ace3adc8bb9cebea68d) @@ -20,10 +20,12 @@ // All rights reserved. using System; +using System.Collections.Generic; using System.Linq; using Deltares.WTIStability; using Deltares.WTIStability.Calculation.Wrapper; using Deltares.WTIStability.Data.Geo; +using Deltares.WTIStability.Data.Standard; using Deltares.WTIStability.IO; namespace Ringtoets.MacroStabilityInwards.KernelWrapper.Kernels.UpliftVan @@ -181,6 +183,24 @@ } } + public List Validate() + { + try + { + var wtiStabilityCalculation = new WTIStabilityCalculation(); + wtiStabilityCalculation.InitializeForDeterministic(WTISerializer.Serialize(stabilityModel)); + + string result = wtiStabilityCalculation.Validate(); + ValidationResult[] deserializedResult = WTIDeserializer.DeserializeValidation(result); + return deserializedResult.Select(r => r.Text).ToList(); + + } + catch (Exception e) when (!(e is UpliftVanKernelWrapperException)) + { + throw new UpliftVanKernelWrapperException(e.Message, e); + } + } + private void ReadResult(string result) { StabilityAssessmentCalculationResult convertedResult = WTIDeserializer.DeserializeResult(result); Index: Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.KernelWrapper.Test/Calculators/UpliftVan/UpliftVanCalculatorTest.cs =================================================================== diff -u -r6139d8deb7b8f83cd06a4534f04ed18ecbada3b6 -r0b21aa321e05e40b31eb5ace3adc8bb9cebea68d --- Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.KernelWrapper.Test/Calculators/UpliftVan/UpliftVanCalculatorTest.cs (.../UpliftVanCalculatorTest.cs) (revision 6139d8deb7b8f83cd06a4534f04ed18ecbada3b6) +++ Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.KernelWrapper.Test/Calculators/UpliftVan/UpliftVanCalculatorTest.cs (.../UpliftVanCalculatorTest.cs) (revision 0b21aa321e05e40b31eb5ace3adc8bb9cebea68d) @@ -196,7 +196,7 @@ } [Test] - public void Validate_Always_ReturnEmptyList() + public void Validate_CalculatorWithValidInput_ReturnEmptyList() { // Setup UpliftVanCalculatorInput input = CreateValidCalculatorInput(); @@ -209,6 +209,23 @@ CollectionAssert.IsEmpty(validationResult); } + [Test] + public void Validate_KernelThrowsUpliftVanKernelWrapperException_ThrowUpliftVanCalculatorException() + { + // Setup + var testMacroStabilityInwardsKernelFactory = new TestMacroStabilityInwardsKernelFactory(); + UpliftVanKernelStub upliftVanKernel = testMacroStabilityInwardsKernelFactory.LastCreatedUpliftVanKernel; + upliftVanKernel.ThrowExceptionOnValidate = true; + + // Call + TestDelegate test = () => new UpliftVanCalculator(CreateValidCalculatorInput(), testMacroStabilityInwardsKernelFactory).Validate(); + + // Assert + var exception = Assert.Throws(test); + Assert.IsInstanceOf(exception.InnerException); + Assert.AreEqual(exception.InnerException.Message, exception.Message); + } + private static UpliftVanCalculatorInput CreateValidCalculatorInput() { var random = new Random(21); Index: Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.KernelWrapper.Test/Kernels/UpliftVan/UpliftVanKernelWrapperTest.cs =================================================================== diff -u -rf81e440cf9c89825947cb632f34b6c21dec6a0df -r0b21aa321e05e40b31eb5ace3adc8bb9cebea68d --- Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.KernelWrapper.Test/Kernels/UpliftVan/UpliftVanKernelWrapperTest.cs (.../UpliftVanKernelWrapperTest.cs) (revision f81e440cf9c89825947cb632f34b6c21dec6a0df) +++ Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.KernelWrapper.Test/Kernels/UpliftVan/UpliftVanKernelWrapperTest.cs (.../UpliftVanKernelWrapperTest.cs) (revision 0b21aa321e05e40b31eb5ace3adc8bb9cebea68d) @@ -218,6 +218,106 @@ AssertAutomaticallySyncedValues(stabilityModel, soilProfile2D, surfaceLine); } + [Test] + public void Validate_InputNotComplete_ThrowsUpliftVanKernelWrapperException() + { + // Setup + var kernel = new UpliftVanKernelWrapper(); + + // Call + TestDelegate test = () => kernel.Validate(); + + // Assert + var exception = Assert.Throws(test); + Assert.IsInstanceOf(exception.InnerException); + Assert.AreEqual(exception.InnerException.Message, exception.Message); + } + + [Test] + public void Validate_InvalidInput_ThrowsUpliftVanKernelWrapperException() + { + // Setup + var point1 = new Point2D(0, 0); + var point2 = new Point2D(1, 1); + var point3 = new Point2D(2, 2); + var point4 = new Point2D(3, 3); + var curve1 = new GeometryCurve(point1, point2); + var curve2 = new GeometryCurve(point2, point3); + var curve3 = new GeometryCurve(point3, point4); + var curve4 = new GeometryCurve(point4, point1); + var loop = new GeometryLoop + { + CurveList = + { + curve1, + curve2, + curve3, + curve4 + } + }; + var kernel = new UpliftVanKernelWrapper + { + SurfaceLine = new SurfaceLine2(), + Location = new StabilityLocation(), + SoilProfile = new SoilProfile2D + { + Geometry = new GeometryData + { + Points = + { + point1, + point2, + point3, + point4 + }, + Curves = + { + curve1, + curve2, + curve3, + curve4 + }, + Loops = + { + loop + } + }, + Surfaces = + { + new SoilLayer2D + { + GeometrySurface = new GeometrySurface + { + OuterLoop = loop + } + } + } + }, + SoilModel = new SoilModel + { + Soils = + { + new Soil() + } + }, + SlipPlaneUpliftVan = new SlipPlaneUpliftVan(), + MoveGrid = true, + AutomaticForbiddenZones = true, + CreateZones = true, + SlipPlaneMinimumDepth = 0, + MaximumSliceWidth = 0, + SlipPlaneMinimumLength = 0 + }; + + // Call + TestDelegate test = () => kernel.Validate(); + + // Assert + var exception = Assert.Throws(test); + Assert.IsInstanceOf(exception.InnerException); + Assert.AreEqual(exception.InnerException.Message, exception.Message); + } + private static void AssertIrrelevantValues(StabilityModel stabilityModel) { Assert.IsNaN(stabilityModel.SlipPlaneConstraints.XEntryMin); // Set during calculation Index: Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.KernelWrapper.TestUtil.Test/Kernels/UpliftVan/UpliftVanKernelStubTest.cs =================================================================== diff -u -r98893373912f751309ca68fa432e3b9abd9ec2ce -r0b21aa321e05e40b31eb5ace3adc8bb9cebea68d --- Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.KernelWrapper.TestUtil.Test/Kernels/UpliftVan/UpliftVanKernelStubTest.cs (.../UpliftVanKernelStubTest.cs) (revision 98893373912f751309ca68fa432e3b9abd9ec2ce) +++ Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.KernelWrapper.TestUtil.Test/Kernels/UpliftVan/UpliftVanKernelStubTest.cs (.../UpliftVanKernelStubTest.cs) (revision 0b21aa321e05e40b31eb5ace3adc8bb9cebea68d) @@ -76,5 +76,43 @@ Assert.IsNotNull(exception.InnerException); Assert.IsFalse(kernel.Calculated); } + + [Test] + public void Validate_ThrowExceptionOnValidateFalse_SetValidatedTrue() + { + // Setup + var kernel = new UpliftVanKernelStub(); + + // Precondition + Assert.IsFalse(kernel.Validated); + + // Call + kernel.Validate(); + + // Assert + Assert.IsTrue(kernel.Validated); + } + + [Test] + public void Validate_ThrowExceptionOnValidateTrue_ThrowsUpliftVanKernelWrapperException() + { + // Setup + var kernel = new UpliftVanKernelStub + { + ThrowExceptionOnValidate = true + }; + + // Precondition + Assert.IsFalse(kernel.Validated); + + // Call + TestDelegate test = () => kernel.Validate(); + + // Assert + var exception = Assert.Throws(test); + Assert.AreEqual($"Message 1{Environment.NewLine}Message 2", exception.Message); + Assert.IsNotNull(exception.InnerException); + Assert.IsFalse(kernel.Validated); + } } } \ No newline at end of file Index: Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.KernelWrapper.TestUtil/Kernels/UpliftVan/UpliftVanKernelStub.cs =================================================================== diff -u -r98893373912f751309ca68fa432e3b9abd9ec2ce -r0b21aa321e05e40b31eb5ace3adc8bb9cebea68d --- Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.KernelWrapper.TestUtil/Kernels/UpliftVan/UpliftVanKernelStub.cs (.../UpliftVanKernelStub.cs) (revision 98893373912f751309ca68fa432e3b9abd9ec2ce) +++ Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.KernelWrapper.TestUtil/Kernels/UpliftVan/UpliftVanKernelStub.cs (.../UpliftVanKernelStub.cs) (revision 0b21aa321e05e40b31eb5ace3adc8bb9cebea68d) @@ -20,6 +20,7 @@ // All rights reserved. using System; +using System.Collections.Generic; using Deltares.WTIStability; using Deltares.WTIStability.Data.Geo; using Ringtoets.MacroStabilityInwards.KernelWrapper.Kernels.UpliftVan; @@ -37,10 +38,20 @@ public bool Calculated { get; private set; } /// + /// Gets a value indicating whether was called or not. + /// + public bool Validated { get; private set; } + + /// /// Indicator whether an exception must be thrown when performing the calculation. /// public bool ThrowExceptionOnCalculate { get; set; } + /// + /// Indicator whether an exception must be thrown when performing the validation. + /// + public bool ThrowExceptionOnValidate { get; set; } + public SoilModel SoilModel { get; set; } public SoilProfile2D SoilProfile { get; set; } @@ -86,5 +97,16 @@ Calculated = true; } + + public List Validate() + { + if (ThrowExceptionOnValidate) + { + throw new UpliftVanKernelWrapperException($"Message 1{Environment.NewLine}Message 2", new Exception()); + } + + Validated = true; + return new List(); + } } } \ No newline at end of file