Index: Ringtoets/Common/src/Ringtoets.Common.Data/Exceptions/AssemblyCategoryConversionException.cs
===================================================================
diff -u
--- Ringtoets/Common/src/Ringtoets.Common.Data/Exceptions/AssemblyCategoryConversionException.cs (revision 0)
+++ Ringtoets/Common/src/Ringtoets.Common.Data/Exceptions/AssemblyCategoryConversionException.cs (revision c664a015d5ebcd9e4154f6a9bb48c8a09c2d0127)
@@ -0,0 +1,70 @@
+// 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.Common.Data.Exceptions
+{
+ ///
+ /// The exception that is thrown when converting assembly categories from the Assembly tool data was unsuccessful.
+ ///
+ [Serializable]
+ public class AssemblyCategoryConversionException : Exception
+ {
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ public AssemblyCategoryConversionException() {}
+
+ ///
+ /// Initializes a new instance of the class
+ /// with a specified error message.
+ ///
+ /// The error message that explains the reason for the exception.
+ public AssemblyCategoryConversionException(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 AssemblyCategoryConversionException(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 AssemblyCategoryConversionException(SerializationInfo info, StreamingContext context) : base(info, context) {}
+
+
+ }
+}
\ No newline at end of file
Index: Ringtoets/Common/src/Ringtoets.Common.Data/Ringtoets.Common.Data.csproj
===================================================================
diff -u -r4160a30705d657946461b76a5c443119cb78d437 -rc664a015d5ebcd9e4154f6a9bb48c8a09c2d0127
--- Ringtoets/Common/src/Ringtoets.Common.Data/Ringtoets.Common.Data.csproj (.../Ringtoets.Common.Data.csproj) (revision 4160a30705d657946461b76a5c443119cb78d437)
+++ Ringtoets/Common/src/Ringtoets.Common.Data/Ringtoets.Common.Data.csproj (.../Ringtoets.Common.Data.csproj) (revision c664a015d5ebcd9e4154f6a9bb48c8a09c2d0127)
@@ -42,6 +42,7 @@
+
Index: Ringtoets/Common/src/Ringtoets.Common.Service/AssemblyTool/AssemblyCategoryConverter.cs
===================================================================
diff -u -r8c111accea72ca8a9205a8615102e16168f62ce7 -rc664a015d5ebcd9e4154f6a9bb48c8a09c2d0127
--- Ringtoets/Common/src/Ringtoets.Common.Service/AssemblyTool/AssemblyCategoryConverter.cs (.../AssemblyCategoryConverter.cs) (revision 8c111accea72ca8a9205a8615102e16168f62ce7)
+++ Ringtoets/Common/src/Ringtoets.Common.Service/AssemblyTool/AssemblyCategoryConverter.cs (.../AssemblyCategoryConverter.cs) (revision c664a015d5ebcd9e4154f6a9bb48c8a09c2d0127)
@@ -25,6 +25,7 @@
using System.Linq;
using Ringtoets.AssemblyTool.Data.Output;
using Ringtoets.Common.Data.AssemblyTool;
+using Ringtoets.Common.Data.Exceptions;
namespace Ringtoets.Common.Service.AssemblyTool
{
@@ -39,10 +40,9 @@
/// The result to convert.
/// The converted categories.
/// Thrown when is null.
- /// Thrown when
- /// is an invalid value.
- /// Thrown when
- /// is a valid value but unsupported.
+ /// Thrown when
+ /// is an invalid value
+ /// or a valid value but unsupported.
public static IEnumerable ConvertAssessmentSectionAssemblyCategories(
IEnumerable result)
{
@@ -59,14 +59,20 @@
///
/// The result to convert.
/// The converted category.
- /// Thrown when
- /// is an invalid value.
- /// Thrown when
- /// is a valid value but unsupported.
+ /// Thrown when
+ /// is an invalid value
+ /// or a valid value but unsupported.
private static AssessmentSectionAssemblyCategory ConvertAssessmentSectionAssemblyCategory(AssessmentSectionAssemblyCategoryResult result)
{
- return new AssessmentSectionAssemblyCategory(result.LowerBoundary, result.UpperBoundary,
- ConvertAssessmentSectionAssemblyCategoryType(result.Category));
+ try
+ {
+ return new AssessmentSectionAssemblyCategory(result.LowerBoundary, result.UpperBoundary,
+ ConvertAssessmentSectionAssemblyCategoryType(result.Category));
+ }
+ catch (Exception e) when (e is InvalidEnumArgumentException || e is NotSupportedException)
+ {
+ throw new AssemblyCategoryConversionException(e.Message, e);
+ }
}
///
Index: Ringtoets/Common/test/Ringtoets.Common.Data.Test/Exceptions/AssemblyCategoryConversionExceptionTest.cs
===================================================================
diff -u
--- Ringtoets/Common/test/Ringtoets.Common.Data.Test/Exceptions/AssemblyCategoryConversionExceptionTest.cs (revision 0)
+++ Ringtoets/Common/test/Ringtoets.Common.Data.Test/Exceptions/AssemblyCategoryConversionExceptionTest.cs (revision c664a015d5ebcd9e4154f6a9bb48c8a09c2d0127)
@@ -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.Common.Data.Exceptions;
+
+namespace Ringtoets.Common.Data.Test.Exceptions
+{
+ [TestFixture]
+ public class AssemblyCategoryConversionExceptionTest : CustomExceptionDesignGuidelinesTestFixture {}
+}
\ No newline at end of file
Index: Ringtoets/Common/test/Ringtoets.Common.Data.Test/Ringtoets.Common.Data.Test.csproj
===================================================================
diff -u -r4160a30705d657946461b76a5c443119cb78d437 -rc664a015d5ebcd9e4154f6a9bb48c8a09c2d0127
--- Ringtoets/Common/test/Ringtoets.Common.Data.Test/Ringtoets.Common.Data.Test.csproj (.../Ringtoets.Common.Data.Test.csproj) (revision 4160a30705d657946461b76a5c443119cb78d437)
+++ Ringtoets/Common/test/Ringtoets.Common.Data.Test/Ringtoets.Common.Data.Test.csproj (.../Ringtoets.Common.Data.Test.csproj) (revision c664a015d5ebcd9e4154f6a9bb48c8a09c2d0127)
@@ -41,6 +41,7 @@
+
Index: Ringtoets/Common/test/Ringtoets.Common.Service.Test/AssemblyTool/AssemblyCategoryConverterTest.cs
===================================================================
diff -u -r8c111accea72ca8a9205a8615102e16168f62ce7 -rc664a015d5ebcd9e4154f6a9bb48c8a09c2d0127
--- Ringtoets/Common/test/Ringtoets.Common.Service.Test/AssemblyTool/AssemblyCategoryConverterTest.cs (.../AssemblyCategoryConverterTest.cs) (revision 8c111accea72ca8a9205a8615102e16168f62ce7)
+++ Ringtoets/Common/test/Ringtoets.Common.Service.Test/AssemblyTool/AssemblyCategoryConverterTest.cs (.../AssemblyCategoryConverterTest.cs) (revision c664a015d5ebcd9e4154f6a9bb48c8a09c2d0127)
@@ -27,6 +27,7 @@
using NUnit.Framework;
using Ringtoets.AssemblyTool.Data.Output;
using Ringtoets.Common.Data.AssemblyTool;
+using Ringtoets.Common.Data.Exceptions;
using Ringtoets.Common.Service.AssemblyTool;
namespace Ringtoets.Common.Service.Test.AssemblyTool
@@ -79,8 +80,10 @@
TestDelegate test = () => AssemblyCategoryConverter.ConvertAssessmentSectionAssemblyCategories(result);
// Assert
- const string expectedMessage = "The value of argument 'categoryType' (99) is invalid for Enum type 'AssessmentSectionAssemblyCategoryResultType'.";
- TestHelper.AssertThrowsArgumentExceptionAndTestMessage(test, expectedMessage);
+ const string expectedMessage = "The value of argument 'categoryType' (99) is invalid for Enum type 'AssessmentSectionAssemblyCategoryResultType'.\r\nParameter name: categoryType";
+ var exception = Assert.Throws(test);
+ Assert.AreEqual(expectedMessage, exception.Message);
+ Assert.IsInstanceOf(exception.InnerException);
}
[Test]