Index: Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.KernelWrapper/Calculators/UpliftVan/IUpliftVanCalculator.cs =================================================================== diff -u -rf2821a4b299043f78c93fb0acf5851081f96961b -r98893373912f751309ca68fa432e3b9abd9ec2ce --- Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.KernelWrapper/Calculators/UpliftVan/IUpliftVanCalculator.cs (.../IUpliftVanCalculator.cs) (revision f2821a4b299043f78c93fb0acf5851081f96961b) +++ Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.KernelWrapper/Calculators/UpliftVan/IUpliftVanCalculator.cs (.../IUpliftVanCalculator.cs) (revision 98893373912f751309ca68fa432e3b9abd9ec2ce) @@ -40,6 +40,8 @@ /// Performs the calculation. /// /// A . + /// Thrown when an error + /// occurs during the calculation. UpliftVanCalculatorResult Calculate(); /// Index: Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.KernelWrapper/Calculators/UpliftVan/UpliftVanCalculator.cs =================================================================== diff -u -r9f936b0b29f490a024df02345df182133b1c041a -r98893373912f751309ca68fa432e3b9abd9ec2ce --- Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.KernelWrapper/Calculators/UpliftVan/UpliftVanCalculator.cs (.../UpliftVanCalculator.cs) (revision 9f936b0b29f490a024df02345df182133b1c041a) +++ Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.KernelWrapper/Calculators/UpliftVan/UpliftVanCalculator.cs (.../UpliftVanCalculator.cs) (revision 98893373912f751309ca68fa432e3b9abd9ec2ce) @@ -90,9 +90,9 @@ { upliftVanKernel.Calculate(); } - catch (Exception e) + catch (UpliftVanKernelWrapperException e) { - // Temporary do nothing + throw new UpliftVanCalculatorException(e.Message, e); } return upliftVanKernel; Index: Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.KernelWrapper/Calculators/UpliftVan/UpliftVanCalculatorException.cs =================================================================== diff -u --- Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.KernelWrapper/Calculators/UpliftVan/UpliftVanCalculatorException.cs (revision 0) +++ Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.KernelWrapper/Calculators/UpliftVan/UpliftVanCalculatorException.cs (revision 98893373912f751309ca68fa432e3b9abd9ec2ce) @@ -0,0 +1,69 @@ +// 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.Calculators.UpliftVan +{ + /// + /// The exception that is thrown when an error occurs while performing a calculation. + /// + [Serializable] + public class UpliftVanCalculatorException : Exception + { + /// + /// Initializes a new instance of the class. + /// + public UpliftVanCalculatorException() {} + + /// + /// Initializes a new instance of the class + /// with a specified error message. + /// + /// The error message that explains the reason for the exception. + public UpliftVanCalculatorException(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 UpliftVanCalculatorException(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 UpliftVanCalculatorException(SerializationInfo info, StreamingContext context) : base(info, context) {} + } +} \ No newline at end of file Index: Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.KernelWrapper/Kernels/UpliftVan/UpliftVanKernelWrapper.cs =================================================================== diff -u -r01f2f9421fd1bc8dcef928a2d86da8840da24ef5 -r98893373912f751309ca68fa432e3b9abd9ec2ce --- Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.KernelWrapper/Kernels/UpliftVan/UpliftVanKernelWrapper.cs (.../UpliftVanKernelWrapper.cs) (revision 01f2f9421fd1bc8dcef928a2d86da8840da24ef5) +++ Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.KernelWrapper/Kernels/UpliftVan/UpliftVanKernelWrapper.cs (.../UpliftVanKernelWrapper.cs) (revision 98893373912f751309ca68fa432e3b9abd9ec2ce) @@ -193,11 +193,11 @@ } catch (XmlSchemaValidationException e) { - throw new UpliftVanKernelWrapperException(e); + throw new UpliftVanKernelWrapperException(e.Message, e); } catch (Exception e) when (!(e is UpliftVanKernelWrapperException)) { - throw new UpliftVanKernelWrapperException(e); + throw new UpliftVanKernelWrapperException(e.Message, e); } } @@ -207,7 +207,8 @@ if (convertedResult.Messages.Any()) { - throw new UpliftVanKernelWrapperException(convertedResult.Messages.Select(m => m.Message)); + string message = convertedResult.Messages.Aggregate(string.Empty, (current, logMessage) => current + $"{logMessage}{Environment.NewLine}").Trim(); + throw new UpliftVanKernelWrapperException(message); } FactorOfStability = convertedResult.FactorOfSafety; Index: Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.KernelWrapper/Kernels/UpliftVan/UpliftVanKernelWrapperException.cs =================================================================== diff -u -r5b4fdd217b573664d8ee5b2d3b571159833d4ed5 -r98893373912f751309ca68fa432e3b9abd9ec2ce --- Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.KernelWrapper/Kernels/UpliftVan/UpliftVanKernelWrapperException.cs (.../UpliftVanKernelWrapperException.cs) (revision 5b4fdd217b573664d8ee5b2d3b571159833d4ed5) +++ Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.KernelWrapper/Kernels/UpliftVan/UpliftVanKernelWrapperException.cs (.../UpliftVanKernelWrapperException.cs) (revision 98893373912f751309ca68fa432e3b9abd9ec2ce) @@ -54,24 +54,6 @@ 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 @@ -83,7 +65,5 @@ /// 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 -r5b4fdd217b573664d8ee5b2d3b571159833d4ed5 -r98893373912f751309ca68fa432e3b9abd9ec2ce --- Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.KernelWrapper/Ringtoets.MacroStabilityInwards.KernelWrapper.csproj (.../Ringtoets.MacroStabilityInwards.KernelWrapper.csproj) (revision 5b4fdd217b573664d8ee5b2d3b571159833d4ed5) +++ Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.KernelWrapper/Ringtoets.MacroStabilityInwards.KernelWrapper.csproj (.../Ringtoets.MacroStabilityInwards.KernelWrapper.csproj) (revision 98893373912f751309ca68fa432e3b9abd9ec2ce) @@ -48,6 +48,7 @@ + Index: Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.KernelWrapper.Test/Calculators/UpliftVan/UpliftVanCalculatorExceptionTest.cs =================================================================== diff -u --- Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.KernelWrapper.Test/Calculators/UpliftVan/UpliftVanCalculatorExceptionTest.cs (revision 0) +++ Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.KernelWrapper.Test/Calculators/UpliftVan/UpliftVanCalculatorExceptionTest.cs (revision 98893373912f751309ca68fa432e3b9abd9ec2ce) @@ -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.Calculators.UpliftVan; + +namespace Ringtoets.MacroStabilityInwards.KernelWrapper.Test.Calculators.UpliftVan +{ + [TestFixture] + public class UpliftVanCalculatorExceptionTest : CustomExceptionDesignGuidelinesTestFixture {} +} \ No newline at end of file Index: Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.KernelWrapper.Test/Calculators/UpliftVan/UpliftVanCalculatorTest.cs =================================================================== diff -u -r3096dd0aeecf478a662cae38533233949c76e103 -r98893373912f751309ca68fa432e3b9abd9ec2ce --- Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.KernelWrapper.Test/Calculators/UpliftVan/UpliftVanCalculatorTest.cs (.../UpliftVanCalculatorTest.cs) (revision 3096dd0aeecf478a662cae38533233949c76e103) +++ Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.KernelWrapper.Test/Calculators/UpliftVan/UpliftVanCalculatorTest.cs (.../UpliftVanCalculatorTest.cs) (revision 98893373912f751309ca68fa432e3b9abd9ec2ce) @@ -34,6 +34,7 @@ using Ringtoets.MacroStabilityInwards.KernelWrapper.Creators.Input; using Ringtoets.MacroStabilityInwards.KernelWrapper.Creators.Output; using Ringtoets.MacroStabilityInwards.KernelWrapper.Kernels; +using Ringtoets.MacroStabilityInwards.KernelWrapper.Kernels.UpliftVan; using Ringtoets.MacroStabilityInwards.KernelWrapper.TestUtil.Calculators.UpliftVan.Output; using Ringtoets.MacroStabilityInwards.KernelWrapper.TestUtil.Kernels; using Ringtoets.MacroStabilityInwards.KernelWrapper.TestUtil.Kernels.UpliftVan; @@ -175,6 +176,26 @@ } [Test] + public void Calculate_KernelThrowsUpliftVanKernelWrapperException_ThrowUpliftVanCalculatorException() + { + // Setup + UpliftVanCalculatorInput input = CreateValidCalculatorInput(); + var testMacroStabilityInwardsKernelFactory = new TestMacroStabilityInwardsKernelFactory(); + + UpliftVanKernelStub upliftVanKernel = testMacroStabilityInwardsKernelFactory.LastCreatedUpliftVanKernel; + SetCompleteKernelOutput(upliftVanKernel); + upliftVanKernel.ThrowExceptionOnCalculate = true; + + // Call + TestDelegate test = () => new UpliftVanCalculator(input, testMacroStabilityInwardsKernelFactory).Calculate(); + + // Assert + var exception = Assert.Throws(test); + Assert.IsInstanceOf(exception.InnerException); + Assert.AreEqual(exception.InnerException.Message, exception.Message); + } + + [Test] public void Validate_Always_ReturnEmptyList() { // Setup Index: Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.KernelWrapper.Test/Kernels/UpliftVan/UpliftVanKernelWrapperExceptionTest.cs =================================================================== diff -u -r5b4fdd217b573664d8ee5b2d3b571159833d4ed5 -r98893373912f751309ca68fa432e3b9abd9ec2ce --- Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.KernelWrapper.Test/Kernels/UpliftVan/UpliftVanKernelWrapperExceptionTest.cs (.../UpliftVanKernelWrapperExceptionTest.cs) (revision 5b4fdd217b573664d8ee5b2d3b571159833d4ed5) +++ Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.KernelWrapper.Test/Kernels/UpliftVan/UpliftVanKernelWrapperExceptionTest.cs (.../UpliftVanKernelWrapperExceptionTest.cs) (revision 98893373912f751309ca68fa432e3b9abd9ec2ce) @@ -20,7 +20,6 @@ // All rights reserved. using System; -using System.Collections.Generic; using Core.Common.TestUtil; using NUnit.Framework; using Ringtoets.MacroStabilityInwards.KernelWrapper.Kernels.UpliftVan; @@ -29,43 +28,5 @@ { [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); - } - } + : CustomExceptionDesignGuidelinesTestFixture {} } \ No newline at end of file Index: Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.KernelWrapper.Test/Kernels/UpliftVan/UpliftVanKernelWrapperTest.cs =================================================================== diff -u -r01f2f9421fd1bc8dcef928a2d86da8840da24ef5 -r98893373912f751309ca68fa432e3b9abd9ec2ce --- Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.KernelWrapper.Test/Kernels/UpliftVan/UpliftVanKernelWrapperTest.cs (.../UpliftVanKernelWrapperTest.cs) (revision 01f2f9421fd1bc8dcef928a2d86da8840da24ef5) +++ Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.KernelWrapper.Test/Kernels/UpliftVan/UpliftVanKernelWrapperTest.cs (.../UpliftVanKernelWrapperTest.cs) (revision 98893373912f751309ca68fa432e3b9abd9ec2ce) @@ -59,6 +59,7 @@ // Assert var exception = Assert.Throws(test); Assert.IsInstanceOf(exception.InnerException); + Assert.AreEqual(exception.InnerException.Message, exception.Message); } [Test] @@ -134,6 +135,7 @@ // Assert var exception = Assert.Throws(test); Assert.IsInstanceOf(exception.InnerException); + Assert.AreEqual(exception.InnerException.Message, exception.Message); } [Test] @@ -215,11 +217,9 @@ // 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); + CollectionAssert.AreEqual($"Index was out of range. Must be non-negative and less than the size of the collection.{Environment.NewLine}" + + $"Parameter name: index{Environment.NewLine}" + + $"Fatale fout in Uplift-Van berekening", exception.Message); } } } \ No newline at end of file Index: Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.KernelWrapper.Test/Ringtoets.MacroStabilityInwards.KernelWrapper.Test.csproj =================================================================== diff -u -r5b4fdd217b573664d8ee5b2d3b571159833d4ed5 -r98893373912f751309ca68fa432e3b9abd9ec2ce --- Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.KernelWrapper.Test/Ringtoets.MacroStabilityInwards.KernelWrapper.Test.csproj (.../Ringtoets.MacroStabilityInwards.KernelWrapper.Test.csproj) (revision 5b4fdd217b573664d8ee5b2d3b571159833d4ed5) +++ Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.KernelWrapper.Test/Ringtoets.MacroStabilityInwards.KernelWrapper.Test.csproj (.../Ringtoets.MacroStabilityInwards.KernelWrapper.Test.csproj) (revision 98893373912f751309ca68fa432e3b9abd9ec2ce) @@ -66,6 +66,7 @@ + Index: Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.KernelWrapper.TestUtil.Test/Kernels/UpliftVan/UpliftVanKernelStubTest.cs =================================================================== diff -u -r8cf507b4db04c91cd5bc5ed243616f093a3016da -r98893373912f751309ca68fa432e3b9abd9ec2ce --- Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.KernelWrapper.TestUtil.Test/Kernels/UpliftVan/UpliftVanKernelStubTest.cs (.../UpliftVanKernelStubTest.cs) (revision 8cf507b4db04c91cd5bc5ed243616f093a3016da) +++ Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.KernelWrapper.TestUtil.Test/Kernels/UpliftVan/UpliftVanKernelStubTest.cs (.../UpliftVanKernelStubTest.cs) (revision 98893373912f751309ca68fa432e3b9abd9ec2ce) @@ -19,7 +19,9 @@ // 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.UpliftVan; using Ringtoets.MacroStabilityInwards.KernelWrapper.TestUtil.Kernels.UpliftVan; namespace Ringtoets.MacroStabilityInwards.KernelWrapper.TestUtil.Test.Kernels.UpliftVan @@ -38,7 +40,7 @@ } [Test] - public void Calculate_Always_SetCalculatedTrue() + public void Calculate_ThrowExceptionOnCalculateFalse_SetCalculatedTrue() { // Setup var kernel = new UpliftVanKernelStub(); @@ -52,5 +54,27 @@ // Assert Assert.IsTrue(kernel.Calculated); } + + [Test] + public void Calculate_ThrowExceptionOnCalculateTrue_ThrowsUpliftVanKernelWrapperException() + { + // Setup + var kernel = new UpliftVanKernelStub + { + 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/UpliftVan/UpliftVanKernelStub.cs =================================================================== diff -u -rbcb7ee1318355c19145c87d641d31c97307d59dd -r98893373912f751309ca68fa432e3b9abd9ec2ce --- Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.KernelWrapper.TestUtil/Kernels/UpliftVan/UpliftVanKernelStub.cs (.../UpliftVanKernelStub.cs) (revision bcb7ee1318355c19145c87d641d31c97307d59dd) +++ Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.KernelWrapper.TestUtil/Kernels/UpliftVan/UpliftVanKernelStub.cs (.../UpliftVanKernelStub.cs) (revision 98893373912f751309ca68fa432e3b9abd9ec2ce) @@ -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.UpliftVan; @@ -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 SoilModel SoilModel { get; set; } public SoilProfile2D SoilProfile { get; set; } @@ -73,6 +79,11 @@ public void Calculate() { + if (ThrowExceptionOnCalculate) + { + throw new UpliftVanKernelWrapperException($"Message 1{Environment.NewLine}Message 2", new Exception()); + } + Calculated = true; } }