Index: Ringtoets/Common/src/Ringtoets.Common.Service/CalculationServiceHelper.cs
===================================================================
diff -u -r92210258706d0f57e05552037b676bd941a6fe19 -re2786bbbad5456a4b42b68e1d0b0f85f732393d7
--- Ringtoets/Common/src/Ringtoets.Common.Service/CalculationServiceHelper.cs (.../CalculationServiceHelper.cs) (revision 92210258706d0f57e05552037b676bd941a6fe19)
+++ Ringtoets/Common/src/Ringtoets.Common.Service/CalculationServiceHelper.cs (.../CalculationServiceHelper.cs) (revision e2786bbbad5456a4b42b68e1d0b0f85f732393d7)
@@ -117,5 +117,25 @@
{
return !canceled && !exceptionThrown && !string.IsNullOrEmpty(lastErrorFileContent);
}
+
+ ///
+ /// Logs message and exception as error.
+ ///
+ /// The message to log.
+ /// The exception to log.
+ /// Thrown when any parameter
+ /// is null.
+ public static void LogExceptionAsError(string message, Exception exception)
+ {
+ if (message == null)
+ {
+ throw new ArgumentNullException(nameof(message));
+ }
+ if (exception == null)
+ {
+ throw new ArgumentNullException(nameof(exception));
+ }
+ log.Error(message, exception);
+ }
}
}
\ No newline at end of file
Index: Ringtoets/Common/test/Ringtoets.Common.Service.Test/CalculationServiceHelperTest.cs
===================================================================
diff -u -r92210258706d0f57e05552037b676bd941a6fe19 -re2786bbbad5456a4b42b68e1d0b0f85f732393d7
--- Ringtoets/Common/test/Ringtoets.Common.Service.Test/CalculationServiceHelperTest.cs (.../CalculationServiceHelperTest.cs) (revision 92210258706d0f57e05552037b676bd941a6fe19)
+++ Ringtoets/Common/test/Ringtoets.Common.Service.Test/CalculationServiceHelperTest.cs (.../CalculationServiceHelperTest.cs) (revision e2786bbbad5456a4b42b68e1d0b0f85f732393d7)
@@ -22,6 +22,7 @@
using System;
using System.Linq;
using Core.Common.TestUtil;
+using log4net.Core;
using NUnit.Framework;
using Ringtoets.Common.Service.TestUtil;
@@ -203,5 +204,46 @@
// Assert
Assert.IsFalse(errorOccurred);
}
+
+ [Test]
+ public void LogExceptionAsError_MessageNull_ThrowsArgumentNullException()
+ {
+ // Call
+ TestDelegate call = () => CalculationServiceHelper.LogExceptionAsError(null, new Exception());
+
+ // Assert
+ var exception = Assert.Throws(call);
+ Assert.AreEqual("message", exception.ParamName);
+ }
+
+ [Test]
+ public void LogExceptionAsError_ExceptionNull_ThrowsArgumentNullException()
+ {
+ // Call
+ TestDelegate call = () => CalculationServiceHelper.LogExceptionAsError("message", null);
+
+ // Assert
+ var exception = Assert.Throws(call);
+ Assert.AreEqual("exception", exception.ParamName);
+ }
+
+ [Test]
+ public void LogExceptionAsError_WithParameters_LogMessageAndException()
+ {
+ // Setup
+ const string message = "Message";
+
+ // Call
+ Action call = () => CalculationServiceHelper.LogExceptionAsError(message, new Exception());
+
+ // Assert
+ TestHelper.AssertLogMessagesWithLevelAndLoggedExceptions(call, tuples =>
+ {
+ Tuple tuple = tuples.Single();
+ Assert.AreEqual(message, tuple.Item1);
+ Assert.AreEqual(Level.Error, tuple.Item2);
+ Assert.IsInstanceOf(tuple.Item3);
+ });
+ }
}
}
\ No newline at end of file
Index: Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.Service/MacroStabilityInwardsCalculationService.cs
===================================================================
diff -u -r3c4b16fb41ff6fdb7600b77292513e023382b79e -re2786bbbad5456a4b42b68e1d0b0f85f732393d7
--- Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.Service/MacroStabilityInwardsCalculationService.cs (.../MacroStabilityInwardsCalculationService.cs) (revision 3c4b16fb41ff6fdb7600b77292513e023382b79e)
+++ Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.Service/MacroStabilityInwardsCalculationService.cs (.../MacroStabilityInwardsCalculationService.cs) (revision e2786bbbad5456a4b42b68e1d0b0f85f732393d7)
@@ -21,6 +21,7 @@
using System;
using System.Collections.Generic;
+using System.Linq;
using Ringtoets.Common.Service;
using Ringtoets.Common.Service.ValidationRules;
using Ringtoets.MacroStabilityInwards.Data;
@@ -110,6 +111,11 @@
ForbiddenZonesXEntryMax = macroStabilityInwardsResult.ForbiddenZonesXEntryMax
});
}
+ catch (UpliftVanCalculatorException e)
+ {
+ CalculationServiceHelper.LogExceptionAsError(Resources.MacroStabilityInwardsCalculationService_Calculate_Error_in_MacroStabilityInwards_calculation, e);
+ throw;
+ }
finally
{
CalculationServiceHelper.LogCalculationEnd();
Index: Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.Service/Properties/Resources.Designer.cs
===================================================================
diff -u -r650fc7b43cb6729baee51d079f0377df8d7a3de9 -re2786bbbad5456a4b42b68e1d0b0f85f732393d7
--- Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.Service/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision 650fc7b43cb6729baee51d079f0377df8d7a3de9)
+++ Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.Service/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision e2786bbbad5456a4b42b68e1d0b0f85f732393d7)
@@ -82,6 +82,16 @@
}
///
+ /// Looks up a localized string similar to Macrostabiliteit berekening mislukt..
+ ///
+ internal static string MacroStabilityInwardsCalculationService_Calculate_Error_in_MacroStabilityInwards_calculation {
+ get {
+ return ResourceManager.GetString("MacroStabilityInwardsCalculationService_Calculate_Error_in_MacroStabilityInwards_" +
+ "calculation", resourceCulture);
+ }
+ }
+
+ ///
/// Looks up a localized string similar to Kan het toetspeil niet afleiden op basis van de invoer..
///
internal static string MacroStabilityInwardsCalculationService_ValidateInput_Cannot_determine_AssessmentLevel {
Index: Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.Service/Properties/Resources.resx
===================================================================
diff -u -r650fc7b43cb6729baee51d079f0377df8d7a3de9 -re2786bbbad5456a4b42b68e1d0b0f85f732393d7
--- Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.Service/Properties/Resources.resx (.../Resources.resx) (revision 650fc7b43cb6729baee51d079f0377df8d7a3de9)
+++ Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.Service/Properties/Resources.resx (.../Resources.resx) (revision e2786bbbad5456a4b42b68e1d0b0f85f732393d7)
@@ -129,4 +129,7 @@
Kan het toetspeil niet afleiden op basis van de invoer.
+
+ Macrostabiliteit berekening mislukt.
+
\ No newline at end of file
Index: Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.KernelWrapper.TestUtil.Test/Calculators/UpliftVan/UpliftVanCalculatorStubTest.cs
===================================================================
diff -u -r8cf507b4db04c91cd5bc5ed243616f093a3016da -re2786bbbad5456a4b42b68e1d0b0f85f732393d7
--- Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.KernelWrapper.TestUtil.Test/Calculators/UpliftVan/UpliftVanCalculatorStubTest.cs (.../UpliftVanCalculatorStubTest.cs) (revision 8cf507b4db04c91cd5bc5ed243616f093a3016da)
+++ Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.KernelWrapper.TestUtil.Test/Calculators/UpliftVan/UpliftVanCalculatorStubTest.cs (.../UpliftVanCalculatorStubTest.cs) (revision e2786bbbad5456a4b42b68e1d0b0f85f732393d7)
@@ -19,6 +19,7 @@
// Stichting Deltares and remain full property of Stichting Deltares at all times.
// All rights reserved.
+using System;
using System.Collections.Generic;
using NUnit.Framework;
using Ringtoets.MacroStabilityInwards.KernelWrapper.Calculators.UpliftVan;
@@ -56,7 +57,7 @@
}
[Test]
- public void Calculate_Always_ReturnResult()
+ public void Calculate_ThrowExceptionOnCalculateFalse_ReturnResult()
{
// Setup
var calculator = new UpliftVanCalculatorStub();
@@ -72,5 +73,24 @@
Assert.IsNotNull(result.SlidingCurveResult);
Assert.IsNotNull(result.CalculationGridResult);
}
+
+ [Test]
+ public void Calculate_ThrowExceptionOnCalculateTrue_ThrowUpliftVanCalculatorException()
+ {
+ // Setup
+ var calculator = new UpliftVanCalculatorStub
+ {
+ ThrowExceptionOnCalculate = true
+ };
+
+ // Call
+ TestDelegate test = () => calculator.Calculate();
+
+ // Assert
+ var exception = Assert.Throws(test);
+ Assert.IsNull(exception.InnerException);
+ Assert.AreEqual($"Message 1{Environment.NewLine}Message 2", exception.Message);
+ Assert.IsNull(calculator.Output);
+ }
}
}
\ No newline at end of file
Index: Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.KernelWrapper.TestUtil/Calculators/UpliftVan/UpliftVanCalculatorStub.cs
===================================================================
diff -u -rbcb7ee1318355c19145c87d641d31c97307d59dd -re2786bbbad5456a4b42b68e1d0b0f85f732393d7
--- Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.KernelWrapper.TestUtil/Calculators/UpliftVan/UpliftVanCalculatorStub.cs (.../UpliftVanCalculatorStub.cs) (revision bcb7ee1318355c19145c87d641d31c97307d59dd)
+++ Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.KernelWrapper.TestUtil/Calculators/UpliftVan/UpliftVanCalculatorStub.cs (.../UpliftVanCalculatorStub.cs) (revision e2786bbbad5456a4b42b68e1d0b0f85f732393d7)
@@ -19,6 +19,7 @@
// Stichting Deltares and remain full property of Stichting Deltares at all times.
// All rights reserved.
+using System;
using System.Collections.Generic;
using Ringtoets.MacroStabilityInwards.KernelWrapper.Calculators.UpliftVan;
using Ringtoets.MacroStabilityInwards.KernelWrapper.Calculators.UpliftVan.Input;
@@ -35,9 +36,14 @@
public UpliftVanCalculatorInput Input { get; set; }
public UpliftVanCalculatorResult Output { get; private set; }
+ public bool ThrowExceptionOnCalculate { get; set; }
public UpliftVanCalculatorResult Calculate()
{
+ if (ThrowExceptionOnCalculate)
+ {
+ throw new UpliftVanCalculatorException($"Message 1{Environment.NewLine}Message 2");
+ }
return Output ?? (Output = CreateUpliftVanCalculatorResult());
}
Index: Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Service.Test/MacroStabilityInwardsCalculationServiceTest.cs
===================================================================
diff -u -r3c4b16fb41ff6fdb7600b77292513e023382b79e -re2786bbbad5456a4b42b68e1d0b0f85f732393d7
--- Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Service.Test/MacroStabilityInwardsCalculationServiceTest.cs (.../MacroStabilityInwardsCalculationServiceTest.cs) (revision 3c4b16fb41ff6fdb7600b77292513e023382b79e)
+++ Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Service.Test/MacroStabilityInwardsCalculationServiceTest.cs (.../MacroStabilityInwardsCalculationServiceTest.cs) (revision e2786bbbad5456a4b42b68e1d0b0f85f732393d7)
@@ -24,12 +24,14 @@
using System.Linq;
using Core.Common.Base.Data;
using Core.Common.TestUtil;
+using log4net.Core;
using NUnit.Framework;
using Ringtoets.Common.Data.TestUtil;
using Ringtoets.Common.Service.TestUtil;
using Ringtoets.MacroStabilityInwards.Data;
using Ringtoets.MacroStabilityInwards.Data.TestUtil;
using Ringtoets.MacroStabilityInwards.KernelWrapper.Calculators;
+using Ringtoets.MacroStabilityInwards.KernelWrapper.Calculators.UpliftVan;
using Ringtoets.MacroStabilityInwards.KernelWrapper.Calculators.UpliftVan.Input;
using Ringtoets.MacroStabilityInwards.KernelWrapper.Calculators.UpliftVan.Output;
using Ringtoets.MacroStabilityInwards.KernelWrapper.TestUtil.Calculators;
@@ -345,6 +347,45 @@
}
}
+ [Test]
+ public void Calculate_ErrorWhileCalculating_LogErrorMessageAndThrowException()
+ {
+ // Setup
+ using (new MacroStabilityInwardsCalculatorFactoryConfig())
+ {
+ var calculatorFactory = (TestMacroStabilityInwardsCalculatorFactory) MacroStabilityInwardsCalculatorFactory.Instance;
+ calculatorFactory.LastCreatedUpliftVanCalculator.ThrowExceptionOnCalculate = true;
+
+ // Precondition
+ Assert.IsTrue(MacroStabilityInwardsCalculationService.Validate(testCalculation));
+
+ var exceptionThrown = false;
+
+ // Call
+ Action call = () =>
+ {
+ try
+ {
+ MacroStabilityInwardsCalculationService.Calculate(testCalculation);
+ }
+ catch (UpliftVanCalculatorException)
+ {
+ exceptionThrown = true;
+ }
+ };
+
+ // Assert
+ TestHelper.AssertLogMessagesWithLevelAndLoggedExceptions(call, tuples =>
+ {
+ Tuple tuple = tuples.ElementAt(1);
+ Assert.AreEqual("Macrostabiliteit berekening mislukt.", tuple.Item1);
+ Assert.AreEqual(Level.Error, tuple.Item2);
+ Assert.IsInstanceOf(tuple.Item3);
+ });
+ Assert.IsTrue(exceptionThrown);
+ }
+ }
+
private static void AssertInput(MacroStabilityInwardsInput originalInput, TestMacroStabilityInwardsCalculatorFactory factory)
{
UpliftVanCalculatorInput actualInput = factory.LastCreatedUpliftVanCalculator.Input;
Index: Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Service.Test/Ringtoets.MacroStabilityInwards.Service.Test.csproj
===================================================================
diff -u -rde60841b8ffece957b147fc7a35a93d2c1918f5f -re2786bbbad5456a4b42b68e1d0b0f85f732393d7
--- Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Service.Test/Ringtoets.MacroStabilityInwards.Service.Test.csproj (.../Ringtoets.MacroStabilityInwards.Service.Test.csproj) (revision de60841b8ffece957b147fc7a35a93d2c1918f5f)
+++ Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Service.Test/Ringtoets.MacroStabilityInwards.Service.Test.csproj (.../Ringtoets.MacroStabilityInwards.Service.Test.csproj) (revision e2786bbbad5456a4b42b68e1d0b0f85f732393d7)
@@ -41,6 +41,10 @@
MinimumRecommendedRules.ruleset
+
+ ..\..\..\..\packages\log4net.2.0.4\lib\net40-full\log4net.dll
+ True
+
..\..\..\..\packages\NUnit.3.8.1\lib\net40\nunit.framework.dll
True
Index: Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Service.Test/packages.config
===================================================================
diff -u -ra1fa1538918813373bcc864f0bce092bf28fd0ce -re2786bbbad5456a4b42b68e1d0b0f85f732393d7
--- Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Service.Test/packages.config (.../packages.config) (revision a1fa1538918813373bcc864f0bce092bf28fd0ce)
+++ Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Service.Test/packages.config (.../packages.config) (revision e2786bbbad5456a4b42b68e1d0b0f85f732393d7)
@@ -22,6 +22,7 @@
All rights reserved.
-->
+
\ No newline at end of file