Index: Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.KernelWrapper/Kernels/UpliftVan/IUpliftVanKernel.cs
===================================================================
diff -u -r0e809897e28ca8673b98ec8abb68b42939a3a647 -r5b4fdd217b573664d8ee5b2d3b571159833d4ed5
--- Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.KernelWrapper/Kernels/UpliftVan/IUpliftVanKernel.cs (.../IUpliftVanKernel.cs) (revision 0e809897e28ca8673b98ec8abb68b42939a3a647)
+++ Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.KernelWrapper/Kernels/UpliftVan/IUpliftVanKernel.cs (.../IUpliftVanKernel.cs) (revision 5b4fdd217b573664d8ee5b2d3b571159833d4ed5)
@@ -133,6 +133,8 @@
///
/// Performs the Uplift Van calculation.
///
+ /// Thrown when
+ /// an unexpected error occurs when performing the calculation.
void Calculate();
}
}
\ No newline at end of file
Index: Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.KernelWrapper/Kernels/UpliftVan/UpliftVanKernelWrapper.cs
===================================================================
diff -u -r08435352faa218dc7a27da54a255c497353dff24 -r5b4fdd217b573664d8ee5b2d3b571159833d4ed5
--- Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.KernelWrapper/Kernels/UpliftVan/UpliftVanKernelWrapper.cs (.../UpliftVanKernelWrapper.cs) (revision 08435352faa218dc7a27da54a255c497353dff24)
+++ Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.KernelWrapper/Kernels/UpliftVan/UpliftVanKernelWrapper.cs (.../UpliftVanKernelWrapper.cs) (revision 5b4fdd217b573664d8ee5b2d3b571159833d4ed5)
@@ -20,10 +20,14 @@
// All rights reserved.
using System;
+using System.Collections.Generic;
using System.Linq;
+using System.Text;
+using System.Xml.Schema;
using Deltares.WTIStability;
using Deltares.WTIStability.Calculation.Wrapper;
using Deltares.WTIStability.Data.Geo;
+using Deltares.WTIStability.Data.Standard;
using Deltares.WTIStability.IO;
using Deltares.WTIStability.Levenberg;
@@ -34,15 +38,13 @@
///
public class UpliftVanKernelWrapper : IUpliftVanKernel
{
- private readonly WTIStabilityCalculation wtiStabilityCalculation;
private readonly StabilityModel stabilityModel;
///
/// Creates a new instance of .
///
public UpliftVanKernelWrapper()
{
- wtiStabilityCalculation = new WTIStabilityCalculation();
stabilityModel = new StabilityModel
{
ModelOption = ModelOptions.UpliftVan,
@@ -183,12 +185,23 @@
public void Calculate()
{
- wtiStabilityCalculation.InitializeForDeterministic(WTISerializer.Serialize(stabilityModel));
+ try
+ {
+ var wtiStabilityCalculation = new WTIStabilityCalculation();
+ wtiStabilityCalculation.InitializeForDeterministic(WTISerializer.Serialize(stabilityModel));
- string messages = wtiStabilityCalculation.Validate();
- string result = wtiStabilityCalculation.Run();
+ string result = wtiStabilityCalculation.Run();
- ReadResult(result);
+ ReadResult(result);
+ }
+ catch (XmlSchemaValidationException e)
+ {
+ throw new UpliftVanKernelWrapperException(e);
+ }
+ catch (Exception e) when (!(e is UpliftVanKernelWrapperException))
+ {
+ throw new UpliftVanKernelWrapperException(e);
+ }
}
private void ReadResult(string result)
@@ -197,7 +210,7 @@
if (convertedResult.Messages.Any())
{
- throw new Exception();
+ throw new UpliftVanKernelWrapperException(convertedResult.Messages.Select(m => m.Message));
}
FactorOfStability = convertedResult.FactorOfSafety;
Index: Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.KernelWrapper/Kernels/UpliftVan/UpliftVanKernelWrapperException.cs
===================================================================
diff -u
--- Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.KernelWrapper/Kernels/UpliftVan/UpliftVanKernelWrapperException.cs (revision 0)
+++ Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.KernelWrapper/Kernels/UpliftVan/UpliftVanKernelWrapperException.cs (revision 5b4fdd217b573664d8ee5b2d3b571159833d4ed5)
@@ -0,0 +1,89 @@
+// 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.Collections.Generic;
+using System.Runtime.Serialization;
+
+namespace Ringtoets.MacroStabilityInwards.KernelWrapper.Kernels.UpliftVan
+{
+ ///
+ /// The exception that is thrown when an error occurs while performing the kernel calculation.
+ ///
+ [Serializable]
+ public class UpliftVanKernelWrapperException : Exception
+ {
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ public UpliftVanKernelWrapperException() {}
+
+ ///
+ /// Initializes a new instance of the class
+ /// with a specified error message.
+ ///
+ /// The error message that explains the reason for the exception.
+ public UpliftVanKernelWrapperException(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 UpliftVanKernelWrapperException(string message, Exception inner) : base(message, inner) {}
+
+ ///
+ /// Initializes a new instance of the class
+ /// with a reference to the inner exception that is the cause of this exception.
+ ///
+ /// The exception that is the cause of the current exception,
+ /// or a null reference if no inner exception is specified.
+ public UpliftVanKernelWrapperException(Exception inner) : base(null, inner) { }
+
+ ///
+ /// Initializes a new instance of the class
+ /// with specified error messages.
+ ///
+ /// The error messages that explains the reason for the exception.
+ public UpliftVanKernelWrapperException(IEnumerable messages)
+ {
+ Messages = messages;
+ }
+
+ ///
+ /// 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 UpliftVanKernelWrapperException(SerializationInfo info, StreamingContext context) : base(info, context) {}
+
+ public IEnumerable Messages { get; }
+ }
+}
\ No newline at end of file
Index: Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.KernelWrapper/Ringtoets.MacroStabilityInwards.KernelWrapper.csproj
===================================================================
diff -u -r1563658643a853839ec2b7b9002a3dff75919ef2 -r5b4fdd217b573664d8ee5b2d3b571159833d4ed5
--- Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.KernelWrapper/Ringtoets.MacroStabilityInwards.KernelWrapper.csproj (.../Ringtoets.MacroStabilityInwards.KernelWrapper.csproj) (revision 1563658643a853839ec2b7b9002a3dff75919ef2)
+++ Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.KernelWrapper/Ringtoets.MacroStabilityInwards.KernelWrapper.csproj (.../Ringtoets.MacroStabilityInwards.KernelWrapper.csproj) (revision 5b4fdd217b573664d8ee5b2d3b571159833d4ed5)
@@ -34,6 +34,7 @@
+
False
..\..\..\..\lib\Plugins\Wti\WTIStability.dll
@@ -63,6 +64,7 @@
+
Index: Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.KernelWrapper.Test/Kernels/UpliftVan/UpliftVanKernelWrapperExceptionTest.cs
===================================================================
diff -u
--- Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.KernelWrapper.Test/Kernels/UpliftVan/UpliftVanKernelWrapperExceptionTest.cs (revision 0)
+++ Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.KernelWrapper.Test/Kernels/UpliftVan/UpliftVanKernelWrapperExceptionTest.cs (revision 5b4fdd217b573664d8ee5b2d3b571159833d4ed5)
@@ -0,0 +1,71 @@
+// 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.Collections.Generic;
+using Core.Common.TestUtil;
+using NUnit.Framework;
+using Ringtoets.MacroStabilityInwards.KernelWrapper.Kernels.UpliftVan;
+
+namespace Ringtoets.MacroStabilityInwards.KernelWrapper.Test.Kernels.UpliftVan
+{
+ [TestFixture]
+ public class UpliftVanKernelWrapperExceptionTest
+ : CustomExceptionDesignGuidelinesTestFixture
+ {
+ [Test]
+ public void MessagesListConstructor_ExpectedValues()
+ {
+ // Setup
+ var messages = new List
+ {
+ "Message 1",
+ "Message 2"
+ };
+
+ // Call
+ var exception = new UpliftVanKernelWrapperException(messages);
+
+ // Assert
+ Assert.IsInstanceOf(exception);
+ CollectionAssert.AreEqual(messages, exception.Messages);
+ Assert.IsNull(exception.HelpLink);
+ Assert.IsNull(exception.InnerException);
+ Assert.IsNull(exception.Source);
+ Assert.IsNull(exception.StackTrace);
+ Assert.IsNull(exception.TargetSite);
+ CollectionAssert.IsEmpty(exception.Data);
+ }
+
+ [Test]
+ public void InnerExceptionConstructor_ExpectedValues()
+ {
+ // Setup
+ var innerException = new Exception();
+
+ // Call
+ var exception = new UpliftVanKernelWrapperException(innerException);
+
+ // Assert
+ AssertMessageAndInnerExceptionConstructedInstance(exception, $"Exception of type '{typeof(UpliftVanKernelWrapperException).FullName}' was thrown.", innerException);
+ }
+ }
+}
\ No newline at end of file
Index: Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.KernelWrapper.Test/Kernels/UpliftVan/UpliftVanKernelWrapperTest.cs
===================================================================
diff -u -r08435352faa218dc7a27da54a255c497353dff24 -r5b4fdd217b573664d8ee5b2d3b571159833d4ed5
--- Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.KernelWrapper.Test/Kernels/UpliftVan/UpliftVanKernelWrapperTest.cs (.../UpliftVanKernelWrapperTest.cs) (revision 08435352faa218dc7a27da54a255c497353dff24)
+++ Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.KernelWrapper.Test/Kernels/UpliftVan/UpliftVanKernelWrapperTest.cs (.../UpliftVanKernelWrapperTest.cs) (revision 5b4fdd217b573664d8ee5b2d3b571159833d4ed5)
@@ -19,6 +19,10 @@
// Stichting Deltares and remain full property of Stichting Deltares at all times.
// All rights reserved.
+using System;
+using System.Xml.Schema;
+using Deltares.WTIStability;
+using Deltares.WTIStability.Data.Geo;
using NUnit.Framework;
using Ringtoets.MacroStabilityInwards.KernelWrapper.Kernels.UpliftVan;
@@ -42,5 +46,180 @@
Assert.IsNull(kernel.SlidingCurveResult);
Assert.IsNull(kernel.SlipPlaneResult);
}
+
+ [Test]
+ public void Calculate_InputNotComplete_ThrowsUpliftVanKernelWrapperException()
+ {
+ // Setup
+ var kernel = new UpliftVanKernelWrapper();
+
+ // Call
+ TestDelegate test = () => kernel.Calculate();
+
+ // Assert
+ var exception = Assert.Throws(test);
+ Assert.IsInstanceOf(exception.InnerException);
+ }
+
+ [Test]
+ public void Calculate_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.Calculate();
+
+ // Assert
+ var exception = Assert.Throws(test);
+ Assert.IsInstanceOf(exception.InnerException);
+ }
+
+ [Test]
+ public void Calculate_ErrorInCalculation_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 geometrySurface = new GeometrySurface
+ {
+ OuterLoop = loop
+ };
+ var soil = new Soil();
+ 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 =
+ {
+ geometrySurface
+ }
+ },
+ Surfaces =
+ {
+ new SoilLayer2D
+ {
+ GeometrySurface = geometrySurface,
+ Soil = soil
+ }
+ }
+ },
+ SoilModel = new SoilModel
+ {
+ Soils =
+ {
+ soil
+ }
+ },
+ SlipPlaneUpliftVan = new SlipPlaneUpliftVan(),
+ MoveGrid = true,
+ AutomaticForbiddenZones = true,
+ CreateZones = true,
+ SlipPlaneMinimumDepth = 0,
+ MaximumSliceWidth = 0,
+ SlipPlaneMinimumLength = 0
+ };
+
+ // Call
+ TestDelegate test = () => kernel.Calculate();
+
+ // Assert
+ var exception = Assert.Throws(test);
+ CollectionAssert.AreEqual(new []
+ {
+ $"Index was out of range. Must be non-negative and less than the size of the collection.{Environment.NewLine}Parameter name: index",
+ "Fatale fout in Uplift-Van berekening"
+ }, exception.Messages);
+ }
}
}
\ No newline at end of file
Index: Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.KernelWrapper.Test/Ringtoets.MacroStabilityInwards.KernelWrapper.Test.csproj
===================================================================
diff -u -rebb8e3bcd23386f645d0ef35dd3741b1e7893377 -r5b4fdd217b573664d8ee5b2d3b571159833d4ed5
--- Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.KernelWrapper.Test/Ringtoets.MacroStabilityInwards.KernelWrapper.Test.csproj (.../Ringtoets.MacroStabilityInwards.KernelWrapper.Test.csproj) (revision ebb8e3bcd23386f645d0ef35dd3741b1e7893377)
+++ Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.KernelWrapper.Test/Ringtoets.MacroStabilityInwards.KernelWrapper.Test.csproj (.../Ringtoets.MacroStabilityInwards.KernelWrapper.Test.csproj) (revision 5b4fdd217b573664d8ee5b2d3b571159833d4ed5)
@@ -51,6 +51,7 @@
+
False
..\..\..\..\lib\Plugins\Wti\WTIStability.dll
@@ -82,6 +83,7 @@
+