Index: Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.KernelWrapper/Kernels/Waternet/IWaternetKernel.cs
===================================================================
diff -u -rbb00f605b488366c45f303a78a7194a2f60ff453 -r5859430bf93fa658cdceb8c2731de08f0a1c1ab7
--- Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.KernelWrapper/Kernels/Waternet/IWaternetKernel.cs (.../IWaternetKernel.cs) (revision bb00f605b488366c45f303a78a7194a2f60ff453)
+++ Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.KernelWrapper/Kernels/Waternet/IWaternetKernel.cs (.../IWaternetKernel.cs) (revision 5859430bf93fa658cdceb8c2731de08f0a1c1ab7)
@@ -60,6 +60,8 @@
///
/// Performs the Waternet calculation.
///
+ /// Thrown when
+ /// an error occurs when performing the calculation.
void Calculate();
}
}
\ No newline at end of file
Index: Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.KernelWrapper/Kernels/Waternet/WaternetKernelWrapper.cs
===================================================================
diff -u -rbb00f605b488366c45f303a78a7194a2f60ff453 -r5859430bf93fa658cdceb8c2731de08f0a1c1ab7
--- Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.KernelWrapper/Kernels/Waternet/WaternetKernelWrapper.cs (.../WaternetKernelWrapper.cs) (revision bb00f605b488366c45f303a78a7194a2f60ff453)
+++ Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.KernelWrapper/Kernels/Waternet/WaternetKernelWrapper.cs (.../WaternetKernelWrapper.cs) (revision 5859430bf93fa658cdceb8c2731de08f0a1c1ab7)
@@ -73,12 +73,19 @@
public void Calculate()
{
- var waternetCalculation = new WTIStabilityCalculation();
- waternetCalculation.InitializeForDeterministic(WTISerializer.Serialize(stabilityModel));
+ try
+ {
+ var waternetCalculation = new WTIStabilityCalculation();
+ waternetCalculation.InitializeForDeterministic(WTISerializer.Serialize(stabilityModel));
- string s = waternetCalculation.CreateWaternet(false);
+ string s = waternetCalculation.CreateWaternet(false);
- Console.WriteLine(s);
+ Console.WriteLine(s);
+ }
+ catch (Exception e)
+ {
+ throw new WaternetKernelWrapperException(e.Message, e);
+ }
}
}
}
\ No newline at end of file
Index: Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.KernelWrapper/Kernels/Waternet/WaternetKernelWrapperException.cs
===================================================================
diff -u
--- Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.KernelWrapper/Kernels/Waternet/WaternetKernelWrapperException.cs (revision 0)
+++ Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.KernelWrapper/Kernels/Waternet/WaternetKernelWrapperException.cs (revision 5859430bf93fa658cdceb8c2731de08f0a1c1ab7)
@@ -0,0 +1,68 @@
+// 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;
+
+namespace Ringtoets.MacroStabilityInwards.KernelWrapper.Kernels.Waternet
+{
+ ///
+ /// The exception that is thrown when an error occurs while performing the Waternet kernel calculation
+ ///
+ [Serializable]
+ public class WaternetKernelWrapperException : Exception
+ {
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ public WaternetKernelWrapperException() {}
+
+ ///
+ /// Initializes a new instance of the class
+ /// with a specified error message.
+ ///
+ /// The error message that explains the reason for the exception.
+ public WaternetKernelWrapperException(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 WaternetKernelWrapperException(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 WaternetKernelWrapperException(SerializationInfo info, StreamingContext context) : base(info, context) {}
+ }
+}
\ No newline at end of file
Index: Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.KernelWrapper/Ringtoets.MacroStabilityInwards.KernelWrapper.csproj
===================================================================
diff -u -r136fec781013393636cee5f7375a88013d8c5ba6 -r5859430bf93fa658cdceb8c2731de08f0a1c1ab7
--- Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.KernelWrapper/Ringtoets.MacroStabilityInwards.KernelWrapper.csproj (.../Ringtoets.MacroStabilityInwards.KernelWrapper.csproj) (revision 136fec781013393636cee5f7375a88013d8c5ba6)
+++ Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.KernelWrapper/Ringtoets.MacroStabilityInwards.KernelWrapper.csproj (.../Ringtoets.MacroStabilityInwards.KernelWrapper.csproj) (revision 5859430bf93fa658cdceb8c2731de08f0a1c1ab7)
@@ -77,6 +77,7 @@
+
Index: Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.KernelWrapper.Test/Kernels/UpliftVan/UpliftVanKernelWrapperTest.cs
===================================================================
diff -u -r5b7130dfd83f2b30773c045b0e28f5dead055c78 -r5859430bf93fa658cdceb8c2731de08f0a1c1ab7
--- Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.KernelWrapper.Test/Kernels/UpliftVan/UpliftVanKernelWrapperTest.cs (.../UpliftVanKernelWrapperTest.cs) (revision 5b7130dfd83f2b30773c045b0e28f5dead055c78)
+++ Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.KernelWrapper.Test/Kernels/UpliftVan/UpliftVanKernelWrapperTest.cs (.../UpliftVanKernelWrapperTest.cs) (revision 5859430bf93fa658cdceb8c2731de08f0a1c1ab7)
@@ -123,7 +123,7 @@
// Assert
var exception = Assert.Throws(test);
- Assert.IsInstanceOf(exception.InnerException);
+ Assert.IsNotNull(exception.InnerException);
Assert.AreEqual(exception.InnerException.Message, exception.Message);
}
Index: Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.KernelWrapper.Test/Kernels/Waternet/WaternetKernelWrapperExceptionTest.cs
===================================================================
diff -u
--- Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.KernelWrapper.Test/Kernels/Waternet/WaternetKernelWrapperExceptionTest.cs (revision 0)
+++ Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.KernelWrapper.Test/Kernels/Waternet/WaternetKernelWrapperExceptionTest.cs (revision 5859430bf93fa658cdceb8c2731de08f0a1c1ab7)
@@ -0,0 +1,31 @@
+// 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.TestUtil;
+using NUnit.Framework;
+using Ringtoets.MacroStabilityInwards.KernelWrapper.Kernels.Waternet;
+
+namespace Ringtoets.MacroStabilityInwards.KernelWrapper.Test.Kernels.Waternet
+{
+ [TestFixture]
+ public class WaternetKernelWrapperExceptionTest : CustomExceptionDesignGuidelinesTestFixture {}
+}
\ No newline at end of file
Index: Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.KernelWrapper.Test/Kernels/Waternet/WaternetKernelWrapperTest.cs
===================================================================
diff -u -rbb00f605b488366c45f303a78a7194a2f60ff453 -r5859430bf93fa658cdceb8c2731de08f0a1c1ab7
--- Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.KernelWrapper.Test/Kernels/Waternet/WaternetKernelWrapperTest.cs (.../WaternetKernelWrapperTest.cs) (revision bb00f605b488366c45f303a78a7194a2f60ff453)
+++ Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.KernelWrapper.Test/Kernels/Waternet/WaternetKernelWrapperTest.cs (.../WaternetKernelWrapperTest.cs) (revision 5859430bf93fa658cdceb8c2731de08f0a1c1ab7)
@@ -70,10 +70,25 @@
AssertAutomaticallySyncedValues(stabilityModel, soilProfile2D, surfaceLine);
}
+ [Test]
+ public void Calculate_ExceptionInWrappedKernel_ThrowsWaternetKernelWrapperException()
+ {
+ // Setup
+ var kernel = new WaternetKernelWrapper();
+
+ // Call
+ TestDelegate test = () => kernel.Calculate();
+
+ // Assert
+ var exception = Assert.Throws(test);
+ Assert.IsNotNull(exception.InnerException);
+ Assert.AreEqual(exception.InnerException.Message, exception.Message);
+ }
+
private static void AssertIrrelevantValues(StabilityModel stabilityModel)
{
- Assert.IsNaN(stabilityModel.SlipPlaneConstraints.XEntryMin); // Set during calculation
- Assert.IsNaN(stabilityModel.SlipPlaneConstraints.XEntryMax); // Set during calculation
+ Assert.IsNaN(stabilityModel.SlipPlaneConstraints.XEntryMin); // Not applicable for Waternet calculation
+ Assert.IsNaN(stabilityModel.SlipPlaneConstraints.XEntryMax); // Not applicable for Waternet calculation
Assert.IsEmpty(stabilityModel.MultiplicationFactorsCPhiForUpliftList); // No multiplication factors CPhi for WBI
Assert.IsEmpty(stabilityModel.UniformLoads); // No traffic load for WBI
Assert.AreEqual(0.0, stabilityModel.FileVersionAsRead); // Set by XML serialization
Index: Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.KernelWrapper.Test/Ringtoets.MacroStabilityInwards.KernelWrapper.Test.csproj
===================================================================
diff -u -r136fec781013393636cee5f7375a88013d8c5ba6 -r5859430bf93fa658cdceb8c2731de08f0a1c1ab7
--- Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.KernelWrapper.Test/Ringtoets.MacroStabilityInwards.KernelWrapper.Test.csproj (.../Ringtoets.MacroStabilityInwards.KernelWrapper.Test.csproj) (revision 136fec781013393636cee5f7375a88013d8c5ba6)
+++ Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.KernelWrapper.Test/Ringtoets.MacroStabilityInwards.KernelWrapper.Test.csproj (.../Ringtoets.MacroStabilityInwards.KernelWrapper.Test.csproj) (revision 5859430bf93fa658cdceb8c2731de08f0a1c1ab7)
@@ -94,6 +94,7 @@
+
Index: Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.KernelWrapper.TestUtil.Test/Kernels/Waternet/WaternetKernelStubTest.cs
===================================================================
diff -u -rbb00f605b488366c45f303a78a7194a2f60ff453 -r5859430bf93fa658cdceb8c2731de08f0a1c1ab7
--- Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.KernelWrapper.TestUtil.Test/Kernels/Waternet/WaternetKernelStubTest.cs (.../WaternetKernelStubTest.cs) (revision bb00f605b488366c45f303a78a7194a2f60ff453)
+++ Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.KernelWrapper.TestUtil.Test/Kernels/Waternet/WaternetKernelStubTest.cs (.../WaternetKernelStubTest.cs) (revision 5859430bf93fa658cdceb8c2731de08f0a1c1ab7)
@@ -19,6 +19,7 @@
// Stichting Deltares and remain full property of Stichting Deltares at all times.
// All rights reserved.
+using System;
using NUnit.Framework;
using Ringtoets.MacroStabilityInwards.KernelWrapper.Kernels.Waternet;
using Ringtoets.MacroStabilityInwards.KernelWrapper.TestUtil.Kernels.Waternet;
@@ -40,7 +41,7 @@
}
[Test]
- public void Calculate_Always_SetCalculatedTrue()
+ public void Calculate_ThrowExceptionOnCalculateFalse_SetCalculatedTrue()
{
// Setup
var kernel = new WaternetKernelStub();
@@ -54,5 +55,28 @@
// Assert
Assert.IsTrue(kernel.Calculated);
}
+
+
+ [Test]
+ public void Calculate_ThrowExceptionOnCalculateTrue_ThrowsUpliftVanKernelWrapperException()
+ {
+ // Setup
+ var kernel = new WaternetKernelStub
+ {
+ ThrowExceptionOnCalculate = true
+ };
+
+ // Precondition
+ Assert.IsFalse(kernel.Calculated);
+
+ // Call
+ TestDelegate test = () => kernel.Calculate();
+
+ // Assert
+ var exception = Assert.Throws(test);
+ Assert.AreEqual($"Message 1{Environment.NewLine}Message 2", exception.Message);
+ Assert.IsNotNull(exception.InnerException);
+ Assert.IsFalse(kernel.Calculated);
+ }
}
}
\ No newline at end of file
Index: Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.KernelWrapper.TestUtil/Kernels/Waternet/WaternetKernelStub.cs
===================================================================
diff -u -rbb00f605b488366c45f303a78a7194a2f60ff453 -r5859430bf93fa658cdceb8c2731de08f0a1c1ab7
--- Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.KernelWrapper.TestUtil/Kernels/Waternet/WaternetKernelStub.cs (.../WaternetKernelStub.cs) (revision bb00f605b488366c45f303a78a7194a2f60ff453)
+++ Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.KernelWrapper.TestUtil/Kernels/Waternet/WaternetKernelStub.cs (.../WaternetKernelStub.cs) (revision 5859430bf93fa658cdceb8c2731de08f0a1c1ab7)
@@ -19,6 +19,7 @@
// Stichting Deltares and remain full property of Stichting Deltares at all times.
// All rights reserved.
+using System;
using Deltares.WTIStability;
using Deltares.WTIStability.Data.Geo;
using Ringtoets.MacroStabilityInwards.KernelWrapper.Kernels.Waternet;
@@ -35,6 +36,11 @@
///
public bool Calculated { get; private set; }
+ ///
+ /// Indicator whether an exception must be thrown when performing the calculation.
+ ///
+ public bool ThrowExceptionOnCalculate { get; set; }
+
public StabilityLocation Location { get; set; }
public SoilModel SoilModel { get; set; }
@@ -45,6 +51,11 @@
public void Calculate()
{
+ if (ThrowExceptionOnCalculate)
+ {
+ throw new WaternetKernelWrapperException($"Message 1{Environment.NewLine}Message 2", new Exception());
+ }
+
Calculated = true;
}
}