Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Exceptions/CannotDeleteBackupFileExceptionTest.cs =================================================================== diff -u -r49c5da81f49a23dd6e66526d264a08bf510e6963 -rfa3b352bc1b1c01fc73a9a45268c5573807a6381 --- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Exceptions/CannotDeleteBackupFileExceptionTest.cs (.../CannotDeleteBackupFileExceptionTest.cs) (revision 49c5da81f49a23dd6e66526d264a08bf510e6963) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Exceptions/CannotDeleteBackupFileExceptionTest.cs (.../CannotDeleteBackupFileExceptionTest.cs) (revision fa3b352bc1b1c01fc73a9a45268c5573807a6381) @@ -27,74 +27,6 @@ namespace Application.Ringtoets.Storage.Test.Exceptions { [TestFixture] - public class CannotDeleteBackupFileExceptionTest - { - [Test] - public void DefaultConstructor_InnerExceptionNullAndMessageDefault() - { - // Setup - string expectedMessage = string.Format("Exception of type '{0}' was thrown.", typeof(CannotDeleteBackupFileException).FullName); - - // Call - var exception = new CannotDeleteBackupFileException(); - - // Assert - Assert.IsInstanceOf(exception); - Assert.IsNull(exception.InnerException); - Assert.AreEqual(expectedMessage, exception.Message); - } - - [Test] - public void Constructor_WithCustomMessage_InnerExceptionNullAndMessageSetToCustom() - { - // Setup - const string expectedMessage = "Some exception message"; - - // Call - var exception = new CannotDeleteBackupFileException(expectedMessage); - - // Assert - Assert.IsInstanceOf(exception); - Assert.IsNull(exception.InnerException); - Assert.AreEqual(expectedMessage, exception.Message); - } - - [Test] - public void Constructor_WithCustomMessageAndInnerException_InnerExceptionSetAndMessageSetToCustom() - { - // Setup - const string expectedMessage = "Some exception message"; - Exception expectedInnerException = new Exception(); - - // Call - var exception = new CannotDeleteBackupFileException(expectedMessage, expectedInnerException); - - // Assert - Assert.IsInstanceOf(exception); - Assert.AreSame(expectedInnerException, exception.InnerException); - Assert.AreEqual(expectedMessage, exception.Message); - } - - [Test] - public void Constructor_SerializationRoundTrip_ExceptionProperlyInitialized() - { - // Setup - var originalInnerException = new Exception("inner"); - var originalException = new CannotDeleteBackupFileException("outer", originalInnerException); - - // Precondition - Assert.IsNotNull(originalException.InnerException); - Assert.IsNull(originalException.InnerException.InnerException); - - // Call - CannotDeleteBackupFileException persistedException = SerializationTestHelper.SerializeAndDeserializeException(originalException); - - // Assert - Assert.AreEqual(originalException.Message, persistedException.Message); - Assert.IsNotNull(persistedException.InnerException); - Assert.AreEqual(originalException.InnerException.GetType(), persistedException.InnerException.GetType()); - Assert.AreEqual(originalException.InnerException.Message, persistedException.InnerException.Message); - Assert.IsNull(persistedException.InnerException.InnerException); - } - } + public class CannotDeleteBackupFileExceptionTest : + CustomExceptionDesignGuidelinesTestFixture {} } \ No newline at end of file Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Exceptions/EntityNotFoundExceptionTest.cs =================================================================== diff -u -r49c5da81f49a23dd6e66526d264a08bf510e6963 -rfa3b352bc1b1c01fc73a9a45268c5573807a6381 --- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Exceptions/EntityNotFoundExceptionTest.cs (.../EntityNotFoundExceptionTest.cs) (revision 49c5da81f49a23dd6e66526d264a08bf510e6963) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Exceptions/EntityNotFoundExceptionTest.cs (.../EntityNotFoundExceptionTest.cs) (revision fa3b352bc1b1c01fc73a9a45268c5573807a6381) @@ -27,74 +27,6 @@ namespace Application.Ringtoets.Storage.Test.Exceptions { [TestFixture] - public class EntityNotFoundExceptionTest - { - [Test] - public void DefaultConstructor_InnerExceptionNullAndMessageDefault() - { - // Setup - string expectedMessage = string.Format("Exception of type '{0}' was thrown.", typeof(EntityNotFoundException).FullName); - - // Call - EntityNotFoundException exception = new EntityNotFoundException(); - - // Assert - Assert.IsInstanceOf(exception); - Assert.IsNull(exception.InnerException); - Assert.AreEqual(expectedMessage, exception.Message); - } - - [Test] - public void Constructor_WithCustomMessage_InnerExceptionNullAndMessageSetToCustom() - { - // Setup - const string expectedMessage = "Some exception message"; - - // Call - EntityNotFoundException exception = new EntityNotFoundException(expectedMessage); - - // Assert - Assert.IsInstanceOf(exception); - Assert.IsNull(exception.InnerException); - Assert.AreEqual(expectedMessage, exception.Message); - } - - [Test] - public void Constructor_WithCustomMessageAndInnerException_InnerExceptionSetAndMessageSetToCustom() - { - // Setup - const string expectedMessage = "Some exception message"; - Exception expectedInnerException = new Exception(); - - // Call - EntityNotFoundException exception = new EntityNotFoundException(expectedMessage, expectedInnerException); - - // Assert - Assert.IsInstanceOf(exception); - Assert.AreSame(expectedInnerException, exception.InnerException); - Assert.AreEqual(expectedMessage, exception.Message); - } - - [Test] - public void Constructor_SerializationRoundTrip_ExceptionProperlyInitialized() - { - // Setup - var originalInnerException = new Exception("inner"); - var originalException = new EntityNotFoundException("outer", originalInnerException); - - // Precondition - Assert.IsNotNull(originalException.InnerException); - Assert.IsNull(originalException.InnerException.InnerException); - - // Call - EntityNotFoundException persistedException = SerializationTestHelper.SerializeAndDeserializeException(originalException); - - // Assert - Assert.AreEqual(originalException.Message, persistedException.Message); - Assert.IsNotNull(persistedException.InnerException); - Assert.AreEqual(originalException.InnerException.GetType(), persistedException.InnerException.GetType()); - Assert.AreEqual(originalException.InnerException.Message, persistedException.InnerException.Message); - Assert.IsNull(persistedException.InnerException.InnerException); - } - } + public class EntityNotFoundExceptionTest : + CustomExceptionDesignGuidelinesTestFixture {} } \ No newline at end of file Index: Core/Common/src/Core.Common.Base/Storage/UpdateStorageException.cs =================================================================== diff -u -r49c5da81f49a23dd6e66526d264a08bf510e6963 -rfa3b352bc1b1c01fc73a9a45268c5573807a6381 --- Core/Common/src/Core.Common.Base/Storage/UpdateStorageException.cs (.../UpdateStorageException.cs) (revision 49c5da81f49a23dd6e66526d264a08bf510e6963) +++ Core/Common/src/Core.Common.Base/Storage/UpdateStorageException.cs (.../UpdateStorageException.cs) (revision fa3b352bc1b1c01fc73a9a45268c5573807a6381) @@ -29,7 +29,7 @@ /// parsing a row/line during the read. /// [Serializable] - public class UpdateStorageException : Exception + public class UpdateStorageException : StorageException { /// /// Initializes a new instance of the class. Index: Core/Common/src/Core.Common.Geometry/InvalidPolygonException.cs =================================================================== diff -u -r24da3aa72ccc0776599628c9f971081694048d9a -rfa3b352bc1b1c01fc73a9a45268c5573807a6381 --- Core/Common/src/Core.Common.Geometry/InvalidPolygonException.cs (.../InvalidPolygonException.cs) (revision 24da3aa72ccc0776599628c9f971081694048d9a) +++ Core/Common/src/Core.Common.Geometry/InvalidPolygonException.cs (.../InvalidPolygonException.cs) (revision fa3b352bc1b1c01fc73a9a45268c5573807a6381) @@ -20,6 +20,7 @@ // All rights reserved. using System; +using System.Runtime.Serialization; namespace Core.Common.Geometry { @@ -50,5 +51,7 @@ /// The exception that is the cause of the current exception, /// or a null reference if no inner exception is specified. public InvalidPolygonException(string message, Exception inner) : base(message, inner) {} + + protected InvalidPolygonException(SerializationInfo info, StreamingContext context) : base(info, context) { } } } \ No newline at end of file Index: Core/Common/src/Core.Common.Utils/EnumDisplayWrapper.cs =================================================================== diff -u -rb2b9fdf365e70928a05c57966eeed30d9050e528 -rfa3b352bc1b1c01fc73a9a45268c5573807a6381 --- Core/Common/src/Core.Common.Utils/EnumDisplayWrapper.cs (.../EnumDisplayWrapper.cs) (revision b2b9fdf365e70928a05c57966eeed30d9050e528) +++ Core/Common/src/Core.Common.Utils/EnumDisplayWrapper.cs (.../EnumDisplayWrapper.cs) (revision fa3b352bc1b1c01fc73a9a45268c5573807a6381) @@ -48,7 +48,7 @@ } if (!(typeof(Enum).IsAssignableFrom(typeof(T)))) { - throw new InvalidTypeParameterException("T", @"The type parameter has to be an Enum type."); + throw new InvalidTypeParameterException(@"The type parameter has to be an Enum type.", "T"); } Value = value; SetDisplayName(value); Index: Core/Common/src/Core.Common.Utils/Exceptions/InvalidTypeParameterException.cs =================================================================== diff -u -r4c580b17f584bdfcaae96992b11f90025647ca20 -rfa3b352bc1b1c01fc73a9a45268c5573807a6381 --- Core/Common/src/Core.Common.Utils/Exceptions/InvalidTypeParameterException.cs (.../InvalidTypeParameterException.cs) (revision 4c580b17f584bdfcaae96992b11f90025647ca20) +++ Core/Common/src/Core.Common.Utils/Exceptions/InvalidTypeParameterException.cs (.../InvalidTypeParameterException.cs) (revision fa3b352bc1b1c01fc73a9a45268c5573807a6381) @@ -31,7 +31,7 @@ [Serializable] public class InvalidTypeParameterException : Exception { - private const string typeParamNameKey = "TypeParamName"; + private const string typeParamNameKey = nameof(TypeParamName); /// /// Initializes a new instance of the class. @@ -42,19 +42,16 @@ /// Initializes a new instance of the class /// with a specified error message. /// - /// The name of the type parameter that caused the exception. - public InvalidTypeParameterException(string typeParamName) - { - TypeParamName = typeParamName; - } + /// The error message that explains the reason for the exception. + public InvalidTypeParameterException(string message) : base(message) { } /// /// Initializes a new instance of the class - /// with a specified error message. + /// with a specified error message and type rapameter name. /// - /// The name of the type parameter that caused the exception. /// The error message that explains the reason for the exception. - public InvalidTypeParameterException(string typeParamName, string message) + /// The name of the type parameter that caused the exception. + public InvalidTypeParameterException(string message, string typeParamName) : base(message) { TypeParamName = typeParamName; @@ -75,11 +72,11 @@ /// with a specified error message and a reference to the inner exception that is /// the cause of this exception. /// - /// The name of the type parameter that caused the exception. /// The error message that explains the reason for the exception. + /// The name of the type parameter that caused the exception. /// The exception that is the cause of the current exception, - /// or a null reference if no inner exception is specified. - public InvalidTypeParameterException(string typeParamName, string message, Exception inner) : base(message, inner) + /// or a null reference if no inner exception is specified. + public InvalidTypeParameterException(string message, string typeParamName, Exception inner) : base(message, inner) { TypeParamName = typeParamName; } Index: Core/Common/test/Core.Common.Base.Test/Storage/CouldNotConnectExceptionTest.cs =================================================================== diff -u -r49c5da81f49a23dd6e66526d264a08bf510e6963 -rfa3b352bc1b1c01fc73a9a45268c5573807a6381 --- Core/Common/test/Core.Common.Base.Test/Storage/CouldNotConnectExceptionTest.cs (.../CouldNotConnectExceptionTest.cs) (revision 49c5da81f49a23dd6e66526d264a08bf510e6963) +++ Core/Common/test/Core.Common.Base.Test/Storage/CouldNotConnectExceptionTest.cs (.../CouldNotConnectExceptionTest.cs) (revision fa3b352bc1b1c01fc73a9a45268c5573807a6381) @@ -19,80 +19,13 @@ // Stichting Deltares and remain full property of Stichting Deltares at all times. // All rights reserved. -using System; using Core.Common.Base.Storage; using Core.Common.TestUtil; using NUnit.Framework; namespace Core.Common.Base.Test.Storage { [TestFixture] - public class CouldNotConnectExceptionTest - { - [Test] - public void DefaultConstructor_InnerExceptionNullAndMessageDefault() - { - // Setup - string expectedMessage = string.Format("Exception of type '{0}' was thrown.", typeof(CouldNotConnectException).FullName); - - // Call - CouldNotConnectException exception = new CouldNotConnectException(); - - // Assert - Assert.IsInstanceOf(exception); - Assert.IsNull(exception.InnerException); - Assert.AreEqual(expectedMessage, exception.Message); - } - - [Test] - public void Constructor_WithCustomMessage_InnerExceptionNullAndMessageSetToCustom() - { - // Setup - const string expectedMessage = "Some exception message"; - - // Call - CouldNotConnectException exception = new CouldNotConnectException(expectedMessage); - - // Assert - Assert.IsNull(exception.InnerException); - Assert.AreEqual(expectedMessage, exception.Message); - } - - [Test] - public void Constructor_WithCustomMessageAndInnerException_InnerExceptionSetAndMessageSetToCustom() - { - // Setup - const string expectedMessage = "Some exception message"; - Exception expectedInnerException = new Exception(); - - // Call - CouldNotConnectException exception = new CouldNotConnectException(expectedMessage, expectedInnerException); - - // Assert - Assert.AreSame(expectedInnerException, exception.InnerException); - Assert.AreEqual(expectedMessage, exception.Message); - } - - [Test] - public void Constructor_SerializationRoundTrip_ExceptionProperlyInitialized() - { - // Setup - var originalInnerException = new Exception("inner"); - var originalException = new CouldNotConnectException("outer", originalInnerException); - - // Precondition - Assert.IsNotNull(originalException.InnerException); - Assert.IsNull(originalException.InnerException.InnerException); - - // Call - CouldNotConnectException persistedException = SerializationTestHelper.SerializeAndDeserializeException(originalException); - - // Assert - Assert.AreEqual(originalException.Message, persistedException.Message); - Assert.IsNotNull(persistedException.InnerException); - Assert.AreEqual(originalException.InnerException.GetType(), persistedException.InnerException.GetType()); - Assert.AreEqual(originalException.InnerException.Message, persistedException.InnerException.Message); - Assert.IsNull(persistedException.InnerException.InnerException); - } - } + public class CouldNotConnectExceptionTest : + CustomExceptionDesignGuidelinesTestFixture {} } \ No newline at end of file Index: Core/Common/test/Core.Common.Base.Test/Storage/StorageExceptionTest.cs =================================================================== diff -u -r49c5da81f49a23dd6e66526d264a08bf510e6963 -rfa3b352bc1b1c01fc73a9a45268c5573807a6381 --- Core/Common/test/Core.Common.Base.Test/Storage/StorageExceptionTest.cs (.../StorageExceptionTest.cs) (revision 49c5da81f49a23dd6e66526d264a08bf510e6963) +++ Core/Common/test/Core.Common.Base.Test/Storage/StorageExceptionTest.cs (.../StorageExceptionTest.cs) (revision fa3b352bc1b1c01fc73a9a45268c5573807a6381) @@ -27,72 +27,6 @@ namespace Core.Common.Base.Test.Storage { [TestFixture] - public class StorageExceptionTest - { - [Test] - public void DefaultConstructor_InnerExceptionNullAndMessageDefault() - { - // Setup - string expectedMessage = string.Format("Exception of type '{0}' was thrown.", typeof(StorageException).FullName); - - // Call - StorageException exception = new StorageException(); - - // Assert - Assert.IsInstanceOf(exception); - Assert.IsNull(exception.InnerException); - Assert.AreEqual(expectedMessage, exception.Message); - } - - [Test] - public void Constructor_WithCustomMessage_InnerExceptionNullAndMessageSetToCustom() - { - // Setup - const string expectedMessage = "Some exception message"; - - // Call - StorageException exception = new StorageException(expectedMessage); - - // Assert - Assert.IsNull(exception.InnerException); - Assert.AreEqual(expectedMessage, exception.Message); - } - - [Test] - public void Constructor_WithCustomMessageAndInnerException_InnerExceptionSetAndMessageSetToCustom() - { - // Setup - const string expectedMessage = "Some exception message"; - Exception expectedInnerException = new Exception(); - - // Call - StorageException exception = new StorageException(expectedMessage, expectedInnerException); - - // Assert - Assert.AreSame(expectedInnerException, exception.InnerException); - Assert.AreEqual(expectedMessage, exception.Message); - } - - [Test] - public void Constructor_SerializationRoundTrip_ExceptionProperlyInitialized() - { - // Setup - var originalInnerException = new Exception("inner"); - var originalException = new StorageException("outer", originalInnerException); - - // Precondition - Assert.IsNotNull(originalException.InnerException); - Assert.IsNull(originalException.InnerException.InnerException); - - // Call - StorageException persistedException = SerializationTestHelper.SerializeAndDeserializeException(originalException); - - // Assert - Assert.AreEqual(originalException.Message, persistedException.Message); - Assert.IsNotNull(persistedException.InnerException); - Assert.AreEqual(originalException.InnerException.GetType(), persistedException.InnerException.GetType()); - Assert.AreEqual(originalException.InnerException.Message, persistedException.InnerException.Message); - Assert.IsNull(persistedException.InnerException.InnerException); - } - } + public class StorageExceptionTest : + CustomExceptionDesignGuidelinesTestFixture {} } \ No newline at end of file Index: Core/Common/test/Core.Common.Base.Test/Storage/StorageValidationExceptionTest.cs =================================================================== diff -u -r49c5da81f49a23dd6e66526d264a08bf510e6963 -rfa3b352bc1b1c01fc73a9a45268c5573807a6381 --- Core/Common/test/Core.Common.Base.Test/Storage/StorageValidationExceptionTest.cs (.../StorageValidationExceptionTest.cs) (revision 49c5da81f49a23dd6e66526d264a08bf510e6963) +++ Core/Common/test/Core.Common.Base.Test/Storage/StorageValidationExceptionTest.cs (.../StorageValidationExceptionTest.cs) (revision fa3b352bc1b1c01fc73a9a45268c5573807a6381) @@ -19,80 +19,13 @@ // Stichting Deltares and remain full property of Stichting Deltares at all times. // All rights reserved. -using System; using Core.Common.Base.Storage; using Core.Common.TestUtil; using NUnit.Framework; namespace Core.Common.Base.Test.Storage { [TestFixture] - public class StorageValidationExceptionTest - { - [Test] - public void DefaultConstructor_InnerExceptionNullAndMessageDefault() - { - // Setup - string expectedMessage = string.Format("Exception of type '{0}' was thrown.", typeof(StorageValidationException).FullName); - - // Call - StorageValidationException exception = new StorageValidationException(); - - // Assert - Assert.IsInstanceOf(exception); - Assert.IsNull(exception.InnerException); - Assert.AreEqual(expectedMessage, exception.Message); - } - - [Test] - public void Constructor_WithCustomMessage_InnerExceptionNullAndMessageSetToCustom() - { - // Setup - const string expectedMessage = "Some exception message"; - - // Call - StorageValidationException exception = new StorageValidationException(expectedMessage); - - // Assert - Assert.IsNull(exception.InnerException); - Assert.AreEqual(expectedMessage, exception.Message); - } - - [Test] - public void Constructor_WithCustomMessageAndInnerException_InnerExceptionSetAndMessageSetToCustom() - { - // Setup - const string expectedMessage = "Some exception message"; - Exception expectedInnerException = new Exception(); - - // Call - StorageValidationException exception = new StorageValidationException(expectedMessage, expectedInnerException); - - // Assert - Assert.AreSame(expectedInnerException, exception.InnerException); - Assert.AreEqual(expectedMessage, exception.Message); - } - - [Test] - public void Constructor_SerializationRoundTrip_ExceptionProperlyInitialized() - { - // Setup - var originalInnerException = new Exception("inner"); - var originalException = new StorageValidationException("outer", originalInnerException); - - // Precondition - Assert.IsNotNull(originalException.InnerException); - Assert.IsNull(originalException.InnerException.InnerException); - - // Call - StorageValidationException persistedException = SerializationTestHelper.SerializeAndDeserializeException(originalException); - - // Assert - Assert.AreEqual(originalException.Message, persistedException.Message); - Assert.IsNotNull(persistedException.InnerException); - Assert.AreEqual(originalException.InnerException.GetType(), persistedException.InnerException.GetType()); - Assert.AreEqual(originalException.InnerException.Message, persistedException.InnerException.Message); - Assert.IsNull(persistedException.InnerException.InnerException); - } - } + public class StorageValidationExceptionTest : + CustomExceptionDesignGuidelinesTestFixture {} } \ No newline at end of file Index: Core/Common/test/Core.Common.Base.Test/Storage/UpdateStorageExceptionTest.cs =================================================================== diff -u -r49c5da81f49a23dd6e66526d264a08bf510e6963 -rfa3b352bc1b1c01fc73a9a45268c5573807a6381 --- Core/Common/test/Core.Common.Base.Test/Storage/UpdateStorageExceptionTest.cs (.../UpdateStorageExceptionTest.cs) (revision 49c5da81f49a23dd6e66526d264a08bf510e6963) +++ Core/Common/test/Core.Common.Base.Test/Storage/UpdateStorageExceptionTest.cs (.../UpdateStorageExceptionTest.cs) (revision fa3b352bc1b1c01fc73a9a45268c5573807a6381) @@ -19,80 +19,13 @@ // Stichting Deltares and remain full property of Stichting Deltares at all times. // All rights reserved. -using System; using Core.Common.Base.Storage; using Core.Common.TestUtil; using NUnit.Framework; namespace Core.Common.Base.Test.Storage { [TestFixture] - public class UpdateStorageExceptionTest - { - [Test] - public void DefaultConstructor_InnerExceptionNullAndMessageDefault() - { - // Setup - string expectedMessage = string.Format("Exception of type '{0}' was thrown.", typeof(UpdateStorageException).FullName); - - // Call - UpdateStorageException exception = new UpdateStorageException(); - - // Assert - Assert.IsInstanceOf(exception); - Assert.IsNull(exception.InnerException); - Assert.AreEqual(expectedMessage, exception.Message); - } - - [Test] - public void Constructor_WithCustomMessage_InnerExceptionNullAndMessageSetToCustom() - { - // Setup - const string expectedMessage = "Some exception message"; - - // Call - UpdateStorageException exception = new UpdateStorageException(expectedMessage); - - // Assert - Assert.IsNull(exception.InnerException); - Assert.AreEqual(expectedMessage, exception.Message); - } - - [Test] - public void Constructor_WithCustomMessageAndInnerException_InnerExceptionSetAndMessageSetToCustom() - { - // Setup - const string expectedMessage = "Some exception message"; - Exception expectedInnerException = new Exception(); - - // Call - UpdateStorageException exception = new UpdateStorageException(expectedMessage, expectedInnerException); - - // Assert - Assert.AreSame(expectedInnerException, exception.InnerException); - Assert.AreEqual(expectedMessage, exception.Message); - } - - [Test] - public void Constructor_SerializationRoundTrip_ExceptionProperlyInitialized() - { - // Setup - var originalInnerException = new Exception("inner"); - var originalException = new UpdateStorageException("outer", originalInnerException); - - // Precondition - Assert.IsNotNull(originalException.InnerException); - Assert.IsNull(originalException.InnerException.InnerException); - - // Call - UpdateStorageException persistedException = SerializationTestHelper.SerializeAndDeserializeException(originalException); - - // Assert - Assert.AreEqual(originalException.Message, persistedException.Message); - Assert.IsNotNull(persistedException.InnerException); - Assert.AreEqual(originalException.InnerException.GetType(), persistedException.InnerException.GetType()); - Assert.AreEqual(originalException.InnerException.Message, persistedException.InnerException.Message); - Assert.IsNull(persistedException.InnerException.InnerException); - } - } + public class UpdateStorageExceptionTest : + CustomExceptionDesignGuidelinesTestFixture {} } \ No newline at end of file Index: Core/Common/test/Core.Common.Geometry.Test/InvalidPolygonExceptionTest.cs =================================================================== diff -u -rce31448a066c084f755439f3e7d453bfb042b291 -rfa3b352bc1b1c01fc73a9a45268c5573807a6381 --- Core/Common/test/Core.Common.Geometry.Test/InvalidPolygonExceptionTest.cs (.../InvalidPolygonExceptionTest.cs) (revision ce31448a066c084f755439f3e7d453bfb042b291) +++ Core/Common/test/Core.Common.Geometry.Test/InvalidPolygonExceptionTest.cs (.../InvalidPolygonExceptionTest.cs) (revision fa3b352bc1b1c01fc73a9a45268c5573807a6381) @@ -20,57 +20,12 @@ // All rights reserved. using System; +using Core.Common.TestUtil; using NUnit.Framework; namespace Core.Common.Geometry.Test { [TestFixture] - public class InvalidPolygonExceptionTest - { - [Test] - public void DefaultConstructor_InnerExceptionNullAndMessageDefault() - { - // Setup - string expectedMessage = string.Format("Exception of type '{0}' was thrown.", typeof(InvalidPolygonException).FullName); - - // Call - InvalidPolygonException exception = new InvalidPolygonException(); - - // Assert - Assert.IsInstanceOf(exception); - Assert.IsNull(exception.InnerException); - Assert.AreEqual(expectedMessage, exception.Message); - } - - [Test] - public void Constructor_WithCustomMessage_InnerExceptionNullAndMessageSetToCustom() - { - // Setup - const string expectedMessage = "Some exception message"; - - // Call - InvalidPolygonException exception = new InvalidPolygonException(expectedMessage); - - // Assert - Assert.IsInstanceOf(exception); - Assert.IsNull(exception.InnerException); - Assert.AreEqual(expectedMessage, exception.Message); - } - - [Test] - public void Constructor_WithCustomMessageAndInnerException_InnerExceptionSetAndMessageSetToCustom() - { - // Setup - const string expectedMessage = "Some exception message"; - Exception expectedInnerException = new Exception(); - - // Call - InvalidPolygonException exception = new InvalidPolygonException(expectedMessage, expectedInnerException); - - // Assert - Assert.IsInstanceOf(exception); - Assert.AreSame(expectedInnerException, exception.InnerException); - Assert.AreEqual(expectedMessage, exception.Message); - } - } + public class InvalidPolygonExceptionTest : + CustomExceptionDesignGuidelinesTestFixture {} } \ No newline at end of file Index: Core/Common/test/Core.Common.Gui.Test/ContextMenu/ContextMenuBuilderExceptionTest.cs =================================================================== diff -u -r49c5da81f49a23dd6e66526d264a08bf510e6963 -rfa3b352bc1b1c01fc73a9a45268c5573807a6381 --- Core/Common/test/Core.Common.Gui.Test/ContextMenu/ContextMenuBuilderExceptionTest.cs (.../ContextMenuBuilderExceptionTest.cs) (revision 49c5da81f49a23dd6e66526d264a08bf510e6963) +++ Core/Common/test/Core.Common.Gui.Test/ContextMenu/ContextMenuBuilderExceptionTest.cs (.../ContextMenuBuilderExceptionTest.cs) (revision fa3b352bc1b1c01fc73a9a45268c5573807a6381) @@ -27,71 +27,6 @@ namespace Core.Common.Gui.Test.ContextMenu { [TestFixture] - public class ContextMenuBuilderExceptionTest - { - [Test] - public void DefaultConstructor_InnerExceptionNullAndMessageDefault() - { - // Setup - var expectedMessage = string.Format("Exception of type '{0}' was thrown.", typeof(ContextMenuBuilderException).FullName); - - // Call - var exception = new ContextMenuBuilderException(); - - // Assert - Assert.IsNull(exception.InnerException); - Assert.AreEqual(expectedMessage, exception.Message); - } - - [Test] - public void Constructor_WithCustomMessage_InnerExceptionNullAndMessageSetToCustom() - { - // Setup - var expectedMessage = "Some exception message"; - - // Call - var exception = new ContextMenuBuilderException(expectedMessage); - - // Assert - Assert.IsNull(exception.InnerException); - Assert.AreEqual(expectedMessage, exception.Message); - } - - [Test] - public void Constructor_WithCustomMessageAndInnerException_InnerExceptionSetAndMessageSetToCustom() - { - // Setup - var expectedMessage = "Some exception message"; - var expectedInnerException = new Exception(); - - // Call - var exception = new ContextMenuBuilderException(expectedMessage, expectedInnerException); - - // Assert - Assert.AreSame(expectedInnerException, exception.InnerException); - Assert.AreEqual(expectedMessage, exception.Message); - } - - [Test] - public void Constructor_SerializationRoundTrip_ExceptionProperlyInitialized() - { - // Setup - var originalInnerException = new Exception("inner"); - var originalException = new ContextMenuBuilderException("outer", originalInnerException); - - // Precondition - Assert.IsNotNull(originalException.InnerException); - Assert.IsNull(originalException.InnerException.InnerException); - - // Call - ContextMenuBuilderException persistedException = SerializationTestHelper.SerializeAndDeserializeException(originalException); - - // Assert - Assert.AreEqual(originalException.Message, persistedException.Message); - Assert.IsNotNull(persistedException.InnerException); - Assert.AreEqual(originalException.InnerException.GetType(), persistedException.InnerException.GetType()); - Assert.AreEqual(originalException.InnerException.Message, persistedException.InnerException.Message); - Assert.IsNull(persistedException.InnerException.InnerException); - } - } + public class ContextMenuBuilderExceptionTest : + CustomExceptionDesignGuidelinesTestFixture {} } \ No newline at end of file Index: Core/Common/test/Core.Common.IO.Test/Exceptions/ConversionExceptionTest.cs =================================================================== diff -u -rd73c509c93f18a87da76086c871eca2a2c903e12 -rfa3b352bc1b1c01fc73a9a45268c5573807a6381 --- Core/Common/test/Core.Common.IO.Test/Exceptions/ConversionExceptionTest.cs (.../ConversionExceptionTest.cs) (revision d73c509c93f18a87da76086c871eca2a2c903e12) +++ Core/Common/test/Core.Common.IO.Test/Exceptions/ConversionExceptionTest.cs (.../ConversionExceptionTest.cs) (revision fa3b352bc1b1c01fc73a9a45268c5573807a6381) @@ -27,88 +27,6 @@ namespace Core.Common.IO.Test.Exceptions { [TestFixture] - public class ConversionExceptionTest - { - [Test] - [SetCulture("en-US")] - public void DefaultConstructor_ExpectedValues() - { - // Call - var exception = new ConversionException(); - - // Assert - Assert.IsInstanceOf(exception); - var expectedMessage = string.Format("Exception of type '{0}' was thrown.", exception.GetType()); - Assert.AreEqual(expectedMessage, exception.Message); - CollectionAssert.IsEmpty(exception.Data); - Assert.IsNull(exception.HelpLink); - Assert.IsNull(exception.InnerException); - Assert.IsNull(exception.Source); - Assert.IsNull(exception.StackTrace); - Assert.IsNull(exception.TargetSite); - } - - [Test] - public void MessageConstructor_ExpectedValues() - { - // Setup - const string messageText = ""; - - // Call - var exception = new ConversionException(messageText); - - // Assert - Assert.IsInstanceOf(exception); - Assert.AreEqual(messageText, exception.Message); - CollectionAssert.IsEmpty(exception.Data); - Assert.IsNull(exception.HelpLink); - Assert.IsNull(exception.InnerException); - Assert.IsNull(exception.Source); - Assert.IsNull(exception.StackTrace); - Assert.IsNull(exception.TargetSite); - } - - [Test] - public void MessageAndInnerExceptionConstructor_ExpectedValues() - { - // Setup - var innerException = new Exception(); - const string messageText = ""; - - // Call - var exception = new ConversionException(messageText, innerException); - - // Assert - Assert.IsInstanceOf(exception); - Assert.AreEqual(messageText, exception.Message); - CollectionAssert.IsEmpty(exception.Data); - Assert.IsNull(exception.HelpLink); - Assert.AreSame(innerException, exception.InnerException); - Assert.IsNull(exception.Source); - Assert.IsNull(exception.StackTrace); - Assert.IsNull(exception.TargetSite); - } - - [Test] - public void Constructor_SerializationRoundTrip_ExceptionProperlyInitialized() - { - // Setup - var originalInnerException = new Exception("inner"); - var originalException = new ConversionException("outer", originalInnerException); - - // Precondition - Assert.IsNotNull(originalException.InnerException); - Assert.IsNull(originalException.InnerException.InnerException); - - // Call - ConversionException persistedException = SerializationTestHelper.SerializeAndDeserializeException(originalException); - - // Assert - Assert.AreEqual(originalException.Message, persistedException.Message); - Assert.IsNotNull(persistedException.InnerException); - Assert.AreEqual(originalException.InnerException.GetType(), persistedException.InnerException.GetType()); - Assert.AreEqual(originalException.InnerException.Message, persistedException.InnerException.Message); - Assert.IsNull(persistedException.InnerException.InnerException); - } - } + public class ConversionExceptionTest : + CustomExceptionDesignGuidelinesTestFixture {} } \ No newline at end of file Index: Core/Common/test/Core.Common.IO.Test/Exceptions/CriticalFileReadExceptionTest.cs =================================================================== diff -u -r49c5da81f49a23dd6e66526d264a08bf510e6963 -rfa3b352bc1b1c01fc73a9a45268c5573807a6381 --- Core/Common/test/Core.Common.IO.Test/Exceptions/CriticalFileReadExceptionTest.cs (.../CriticalFileReadExceptionTest.cs) (revision 49c5da81f49a23dd6e66526d264a08bf510e6963) +++ Core/Common/test/Core.Common.IO.Test/Exceptions/CriticalFileReadExceptionTest.cs (.../CriticalFileReadExceptionTest.cs) (revision fa3b352bc1b1c01fc73a9a45268c5573807a6381) @@ -27,88 +27,6 @@ namespace Core.Common.IO.Test.Exceptions { [TestFixture] - public class CriticalFileReadExceptionTest - { - [Test] - [SetCulture("en-US")] - public void DefaultConstructor_ExpectedValues() - { - // Call - var exception = new CriticalFileReadException(); - - // Assert - Assert.IsInstanceOf(exception); - var expectedMessage = string.Format("Exception of type '{0}' was thrown.", exception.GetType()); - Assert.AreEqual(expectedMessage, exception.Message); - CollectionAssert.IsEmpty(exception.Data); - Assert.IsNull(exception.HelpLink); - Assert.IsNull(exception.InnerException); - Assert.IsNull(exception.Source); - Assert.IsNull(exception.StackTrace); - Assert.IsNull(exception.TargetSite); - } - - [Test] - public void MessageConstructor_ExpectedValues() - { - // Setup - const string messageText = ""; - - // Call - var exception = new CriticalFileReadException(messageText); - - // Assert - Assert.IsInstanceOf(exception); - Assert.AreEqual(messageText, exception.Message); - CollectionAssert.IsEmpty(exception.Data); - Assert.IsNull(exception.HelpLink); - Assert.IsNull(exception.InnerException); - Assert.IsNull(exception.Source); - Assert.IsNull(exception.StackTrace); - Assert.IsNull(exception.TargetSite); - } - - [Test] - public void MessageAndInnerExceptionConstructor_ExpectedValues() - { - // Setup - var innerException = new Exception(); - const string messageText = ""; - - // Call - var exception = new CriticalFileReadException(messageText, innerException); - - // Assert - Assert.IsInstanceOf(exception); - Assert.AreEqual(messageText, exception.Message); - CollectionAssert.IsEmpty(exception.Data); - Assert.IsNull(exception.HelpLink); - Assert.AreSame(innerException, exception.InnerException); - Assert.IsNull(exception.Source); - Assert.IsNull(exception.StackTrace); - Assert.IsNull(exception.TargetSite); - } - - [Test] - public void Constructor_SerializationRoundTrip_ExceptionProperlyInitialized() - { - // Setup - var originalInnerException = new Exception("inner"); - var originalException = new CriticalFileReadException("outer", originalInnerException); - - // Precondition - Assert.IsNotNull(originalException.InnerException); - Assert.IsNull(originalException.InnerException.InnerException); - - // Call - CriticalFileReadException persistedException = SerializationTestHelper.SerializeAndDeserializeException(originalException); - - // Assert - Assert.AreEqual(originalException.Message, persistedException.Message); - Assert.IsNotNull(persistedException.InnerException); - Assert.AreEqual(originalException.InnerException.GetType(), persistedException.InnerException.GetType()); - Assert.AreEqual(originalException.InnerException.Message, persistedException.InnerException.Message); - Assert.IsNull(persistedException.InnerException.InnerException); - } - } + public class CriticalFileReadExceptionTest : + CustomExceptionDesignGuidelinesTestFixture {} } \ No newline at end of file Index: Core/Common/test/Core.Common.IO.Test/Exceptions/CriticalFileWriteExceptionTest.cs =================================================================== diff -u -r49c5da81f49a23dd6e66526d264a08bf510e6963 -rfa3b352bc1b1c01fc73a9a45268c5573807a6381 --- Core/Common/test/Core.Common.IO.Test/Exceptions/CriticalFileWriteExceptionTest.cs (.../CriticalFileWriteExceptionTest.cs) (revision 49c5da81f49a23dd6e66526d264a08bf510e6963) +++ Core/Common/test/Core.Common.IO.Test/Exceptions/CriticalFileWriteExceptionTest.cs (.../CriticalFileWriteExceptionTest.cs) (revision fa3b352bc1b1c01fc73a9a45268c5573807a6381) @@ -27,88 +27,6 @@ namespace Core.Common.IO.Test.Exceptions { [TestFixture] - public class CriticalFileWriteExceptionTest - { - [Test] - [SetCulture("en-US")] - public void DefaultConstructor_ExpectedValues() - { - // Call - var exception = new CriticalFileWriteException(); - - // Assert - Assert.IsInstanceOf(exception); - var expectedMessage = string.Format("Exception of type '{0}' was thrown.", exception.GetType()); - Assert.AreEqual(expectedMessage, exception.Message); - CollectionAssert.IsEmpty(exception.Data); - Assert.IsNull(exception.HelpLink); - Assert.IsNull(exception.InnerException); - Assert.IsNull(exception.Source); - Assert.IsNull(exception.StackTrace); - Assert.IsNull(exception.TargetSite); - } - - [Test] - public void MessageConstructor_ExpectedValues() - { - // Setup - const string messageText = ""; - - // Call - var exception = new CriticalFileWriteException(messageText); - - // Assert - Assert.IsInstanceOf(exception); - Assert.AreEqual(messageText, exception.Message); - CollectionAssert.IsEmpty(exception.Data); - Assert.IsNull(exception.HelpLink); - Assert.IsNull(exception.InnerException); - Assert.IsNull(exception.Source); - Assert.IsNull(exception.StackTrace); - Assert.IsNull(exception.TargetSite); - } - - [Test] - public void MessageAndInnerExceptionConstructor_ExpectedValues() - { - // Setup - var innerException = new Exception(); - const string messageText = ""; - - // Call - var exception = new CriticalFileWriteException(messageText, innerException); - - // Assert - Assert.IsInstanceOf(exception); - Assert.AreEqual(messageText, exception.Message); - CollectionAssert.IsEmpty(exception.Data); - Assert.IsNull(exception.HelpLink); - Assert.AreSame(innerException, exception.InnerException); - Assert.IsNull(exception.Source); - Assert.IsNull(exception.StackTrace); - Assert.IsNull(exception.TargetSite); - } - - [Test] - public void Constructor_SerializationRoundTrip_ExceptionProperlyInitialized() - { - // Setup - var originalInnerException = new Exception("inner"); - var originalException = new CriticalFileWriteException("outer", originalInnerException); - - // Precondition - Assert.IsNotNull(originalException.InnerException); - Assert.IsNull(originalException.InnerException.InnerException); - - // Call - CriticalFileWriteException persistedException = SerializationTestHelper.SerializeAndDeserializeException(originalException); - - // Assert - Assert.AreEqual(originalException.Message, persistedException.Message); - Assert.IsNotNull(persistedException.InnerException); - Assert.AreEqual(originalException.InnerException.GetType(), persistedException.InnerException.GetType()); - Assert.AreEqual(originalException.InnerException.Message, persistedException.InnerException.Message); - Assert.IsNull(persistedException.InnerException.InnerException); - } - } + public class CriticalFileWriteExceptionTest : + CustomExceptionDesignGuidelinesTestFixture {} } \ No newline at end of file Index: Core/Common/test/Core.Common.IO.Test/Exceptions/LineParseExceptionTest.cs =================================================================== diff -u -r49c5da81f49a23dd6e66526d264a08bf510e6963 -rfa3b352bc1b1c01fc73a9a45268c5573807a6381 --- Core/Common/test/Core.Common.IO.Test/Exceptions/LineParseExceptionTest.cs (.../LineParseExceptionTest.cs) (revision 49c5da81f49a23dd6e66526d264a08bf510e6963) +++ Core/Common/test/Core.Common.IO.Test/Exceptions/LineParseExceptionTest.cs (.../LineParseExceptionTest.cs) (revision fa3b352bc1b1c01fc73a9a45268c5573807a6381) @@ -27,88 +27,6 @@ namespace Core.Common.IO.Test.Exceptions { [TestFixture] - public class LineParseExceptionTest - { - [Test] - [SetCulture("en-US")] - public void DefaultConstructor_ExpectedValues() - { - // Call - var exception = new LineParseException(); - - // Assert - Assert.IsInstanceOf(exception); - var expectedMessage = string.Format("Exception of type '{0}' was thrown.", exception.GetType()); - Assert.AreEqual(expectedMessage, exception.Message); - CollectionAssert.IsEmpty(exception.Data); - Assert.IsNull(exception.HelpLink); - Assert.IsNull(exception.InnerException); - Assert.IsNull(exception.Source); - Assert.IsNull(exception.StackTrace); - Assert.IsNull(exception.TargetSite); - } - - [Test] - public void MessageConstructor_ExpectedValues() - { - // Setup - const string messageText = ""; - - // Call - var exception = new LineParseException(messageText); - - // Assert - Assert.IsInstanceOf(exception); - Assert.AreEqual(messageText, exception.Message); - CollectionAssert.IsEmpty(exception.Data); - Assert.IsNull(exception.HelpLink); - Assert.IsNull(exception.InnerException); - Assert.IsNull(exception.Source); - Assert.IsNull(exception.StackTrace); - Assert.IsNull(exception.TargetSite); - } - - [Test] - public void MessageAndInnerExceptionConstructor_ExpectedValues() - { - // Setup - var innerException = new Exception(); - const string messageText = ""; - - // Call - var exception = new LineParseException(messageText, innerException); - - // Assert - Assert.IsInstanceOf(exception); - Assert.AreEqual(messageText, exception.Message); - CollectionAssert.IsEmpty(exception.Data); - Assert.IsNull(exception.HelpLink); - Assert.AreEqual(innerException, exception.InnerException); - Assert.IsNull(exception.Source); - Assert.IsNull(exception.StackTrace); - Assert.IsNull(exception.TargetSite); - } - - [Test] - public void Constructor_SerializationRoundTrip_ExceptionProperlyInitialized() - { - // Setup - var originalInnerException = new Exception("inner"); - var originalException = new LineParseException("outer", originalInnerException); - - // Precondition - Assert.IsNotNull(originalException.InnerException); - Assert.IsNull(originalException.InnerException.InnerException); - - // Call - LineParseException persistedException = SerializationTestHelper.SerializeAndDeserializeException(originalException); - - // Assert - Assert.AreEqual(originalException.Message, persistedException.Message); - Assert.IsNotNull(persistedException.InnerException); - Assert.AreEqual(originalException.InnerException.GetType(), persistedException.InnerException.GetType()); - Assert.AreEqual(originalException.InnerException.Message, persistedException.InnerException.Message); - Assert.IsNull(persistedException.InnerException.InnerException); - } - } + public class LineParseExceptionTest : + CustomExceptionDesignGuidelinesTestFixture {} } \ No newline at end of file Index: Core/Common/test/Core.Common.TestUtil/Core.Common.TestUtil.csproj =================================================================== diff -u -r888f6cdc81e8fb6d6a5b9baadf6395f209008836 -rfa3b352bc1b1c01fc73a9a45268c5573807a6381 --- Core/Common/test/Core.Common.TestUtil/Core.Common.TestUtil.csproj (.../Core.Common.TestUtil.csproj) (revision 888f6cdc81e8fb6d6a5b9baadf6395f209008836) +++ Core/Common/test/Core.Common.TestUtil/Core.Common.TestUtil.csproj (.../Core.Common.TestUtil.csproj) (revision fa3b352bc1b1c01fc73a9a45268c5573807a6381) @@ -92,6 +92,7 @@ Properties\GlobalAssembly.cs + Index: Core/Common/test/Core.Common.TestUtil/CustomExceptionDesignGuidelinesTestFixture.cs =================================================================== diff -u --- Core/Common/test/Core.Common.TestUtil/CustomExceptionDesignGuidelinesTestFixture.cs (revision 0) +++ Core/Common/test/Core.Common.TestUtil/CustomExceptionDesignGuidelinesTestFixture.cs (revision fa3b352bc1b1c01fc73a9a45268c5573807a6381) @@ -0,0 +1,146 @@ +using System; +using NUnit.Framework; + +namespace Core.Common.TestUtil +{ + /// + /// Test fixture that asserts that a custom exception follows the design guidelines + /// specified at https://msdn.microsoft.com/en-us/library/ms229064(v=vs.100).aspx. + /// + [TestFixture] + public abstract class CustomExceptionDesignGuidelinesTestFixture where TCustomExceptionType : Exception + where TBaseExceptionType : Exception + { + [Test] + [SetCulture("en-US")] + public void DefaultConstructor_ExpectedValues() + { + // Call + TCustomExceptionType exception = CallDefaultConstructor(); + + // Assert + AssertDefaultConstructedInstance(exception); + } + + [Test] + public void MessageConstructor_ExpectedValues() + { + // Setup + const string messageText = ""; + + // Call + TCustomExceptionType exception = CallMessageConstructor(messageText); + + // Assert + AssertMessageConstructedInstance(exception, messageText); + } + + [Test] + public void MessageAndInnerExceptionConstructor_ExpectedValues() + { + // Setup + var innerException = new Exception(); + const string messageText = ""; + + // Call + TCustomExceptionType exception = CallMessageAndInnerExceptionConstructor(messageText, innerException); + + // Assert + AssertMessageAndInnerExceptionConstructedInstance(exception, messageText, innerException); + } + + [Test] + public void Constructor_SerializationRoundTrip_ExceptionProperlyInitialized() + { + // Setup + TCustomExceptionType originalException = CreateFullyConfiguredException(); + + // Precondition + Assert.IsNotNull(originalException.InnerException); + Assert.IsNull(originalException.InnerException.InnerException); + + // Call + TCustomExceptionType persistedException = SerializationTestHelper.SerializeAndDeserializeException(originalException); + + // Assert + AssertRoundTripResult(originalException, persistedException); + } + + protected virtual void AssertDefaultConstructedInstance(TCustomExceptionType exception) + { + Assert.IsInstanceOf(exception); + var expectedMessage = $"Exception of type '{typeof(TCustomExceptionType)}' was thrown."; + Assert.AreEqual(expectedMessage, exception.Message); + CollectionAssert.IsEmpty(exception.Data); + Assert.IsNull(exception.HelpLink); + Assert.IsNull(exception.InnerException); + Assert.IsNull(exception.Source); + Assert.IsNull(exception.StackTrace); + Assert.IsNull(exception.TargetSite); + } + + protected virtual void AssertMessageConstructedInstance(TCustomExceptionType exception, string messageText, + bool assertData = true) + { + Assert.IsInstanceOf(exception); + Assert.AreEqual(messageText, exception.Message); + Assert.IsNull(exception.HelpLink); + Assert.IsNull(exception.InnerException); + Assert.IsNull(exception.Source); + Assert.IsNull(exception.StackTrace); + Assert.IsNull(exception.TargetSite); + + if (assertData) + { + CollectionAssert.IsEmpty(exception.Data); + } + } + + protected virtual void AssertMessageAndInnerExceptionConstructedInstance(TCustomExceptionType exception, string messageText, + Exception innerException, bool assertData = true) + { + Assert.IsInstanceOf(exception); + Assert.AreEqual(messageText, exception.Message); + Assert.IsNull(exception.HelpLink); + Assert.AreEqual(innerException, exception.InnerException); + Assert.IsNull(exception.Source); + Assert.IsNull(exception.StackTrace); + Assert.IsNull(exception.TargetSite); + + if (assertData) + { + CollectionAssert.IsEmpty(exception.Data); + } + } + + protected virtual void AssertRoundTripResult(TCustomExceptionType originalException, TCustomExceptionType persistedException) + { + Assert.AreEqual(originalException.Message, persistedException.Message); + Assert.IsNotNull(persistedException.InnerException); + Assert.AreEqual(originalException.InnerException.GetType(), persistedException.InnerException.GetType()); + Assert.AreEqual(originalException.InnerException.Message, persistedException.InnerException.Message); + Assert.IsNull(persistedException.InnerException.InnerException); + } + + protected virtual TCustomExceptionType CreateFullyConfiguredException() + { + var originalInnerException = new Exception("inner"); + return CallMessageAndInnerExceptionConstructor("outer", originalInnerException); + } + + private static TCustomExceptionType CallDefaultConstructor() + { + return (TCustomExceptionType) Activator.CreateInstance(typeof(TCustomExceptionType)); + } + + private static TCustomExceptionType CallMessageConstructor(string message) + { + return (TCustomExceptionType) Activator.CreateInstance(typeof(TCustomExceptionType), message); + } + + private static TCustomExceptionType CallMessageAndInnerExceptionConstructor(string message, Exception innerException) + { + return (TCustomExceptionType) Activator.CreateInstance(typeof(TCustomExceptionType), message, innerException); + } + } +} \ No newline at end of file Index: Core/Common/test/Core.Common.Utils.Test/Exceptions/InvalidTypeParameterExceptionTest.cs =================================================================== diff -u -r4c580b17f584bdfcaae96992b11f90025647ca20 -rfa3b352bc1b1c01fc73a9a45268c5573807a6381 --- Core/Common/test/Core.Common.Utils.Test/Exceptions/InvalidTypeParameterExceptionTest.cs (.../InvalidTypeParameterExceptionTest.cs) (revision 4c580b17f584bdfcaae96992b11f90025647ca20) +++ Core/Common/test/Core.Common.Utils.Test/Exceptions/InvalidTypeParameterExceptionTest.cs (.../InvalidTypeParameterExceptionTest.cs) (revision fa3b352bc1b1c01fc73a9a45268c5573807a6381) @@ -27,141 +27,81 @@ namespace Core.Common.Utils.Test.Exceptions { [TestFixture] - public class InvalidTypeParameterExceptionTest + public class InvalidTypeParameterExceptionTest : + CustomExceptionDesignGuidelinesTestFixture { [Test] - public void DefaultConstructor_ExpectedValues() + public void TypeParameterAndMessageConstructor_ExpectedValues() { - // Call - var exception = new InvalidTypeParameterException(); - - // Assert - Assert.IsInstanceOf(exception); - var expectedMessage = string.Format("Exception of type '{0}' was thrown.", typeof(InvalidTypeParameterException).FullName); - Assert.AreEqual(expectedMessage, exception.Message); - CollectionAssert.IsEmpty(exception.Data); - Assert.IsNull(exception.TypeParamName); - Assert.IsNull(exception.HelpLink); - Assert.IsNull(exception.InnerException); - Assert.IsNull(exception.Source); - Assert.IsNull(exception.StackTrace); - Assert.IsNull(exception.TargetSite); - } - - [Test] - public void TypeParameterConstructor_ExpectedValues() - { // Setup string typeParamName = "T"; + const string messageText = ""; // Call - var exception = new InvalidTypeParameterException(typeParamName); + var exception = new InvalidTypeParameterException(messageText, typeParamName); // Assert - Assert.IsInstanceOf(exception); - var expectedMessage = string.Format("Exception of type '{0}' was thrown.", exception.GetType()); - Assert.AreEqual(expectedMessage, exception.Message); + base.AssertMessageConstructedInstance(exception, messageText, false); Assert.AreEqual(typeParamName, exception.TypeParamName); Assert.AreEqual(1, exception.Data.Count); - Assert.AreEqual(exception.TypeParamName, exception.Data["TypeParamName"]); - Assert.IsNull(exception.HelpLink); - Assert.IsNull(exception.InnerException); - Assert.IsNull(exception.Source); - Assert.IsNull(exception.StackTrace); - Assert.IsNull(exception.TargetSite); + Assert.AreEqual(exception.TypeParamName, exception.Data[nameof(exception.TypeParamName)]); } [Test] - public void TypeParameterAndMessageConstructor_ExpectedValues() + public void TypeParameterAndMessageAndInnerExceptionConstructor_ExpectedValues() { // Setup + var innerException = new Exception(); string typeParamName = "T"; const string messageText = ""; // Call - var exception = new InvalidTypeParameterException(typeParamName, messageText); + var exception = new InvalidTypeParameterException(messageText, typeParamName, innerException); // Assert - Assert.IsInstanceOf(exception); - Assert.AreEqual(messageText, exception.Message); + AssertMessageAndInnerExceptionConstructedInstance(exception, messageText, innerException, false); Assert.AreEqual(typeParamName, exception.TypeParamName); Assert.AreEqual(1, exception.Data.Count); - Assert.AreEqual(exception.TypeParamName, exception.Data["TypeParamName"]); - Assert.IsNull(exception.HelpLink); - Assert.IsNull(exception.InnerException); - Assert.IsNull(exception.Source); - Assert.IsNull(exception.StackTrace); - Assert.IsNull(exception.TargetSite); + Assert.AreEqual(exception.TypeParamName, exception.Data[nameof(exception.TypeParamName)]); } - [Test] - public void MessageAndInnerExceptionConstructor_ExpectedValues() + protected override void AssertDefaultConstructedInstance(InvalidTypeParameterException exception) { - // Setup - var innerException = new Exception(); - const string messageText = ""; - - // Call - var exception = new InvalidTypeParameterException(messageText, innerException); - - // Assert - Assert.IsInstanceOf(exception); - Assert.AreEqual(messageText, exception.Message); + base.AssertDefaultConstructedInstance(exception); + CollectionAssert.IsEmpty(exception.Data); Assert.IsNull(exception.TypeParamName); - Assert.AreEqual(0, exception.Data.Count); - Assert.AreEqual(exception.TypeParamName, exception.Data["TypeParamName"]); - Assert.IsNull(exception.HelpLink); - Assert.AreEqual(innerException, exception.InnerException); - Assert.IsNull(exception.Source); - Assert.IsNull(exception.StackTrace); - Assert.IsNull(exception.TargetSite); } - [Test] - public void TypeParameterAndMessageAndInnerExceptionConstructor_ExpectedValues() + protected override void AssertMessageConstructedInstance(InvalidTypeParameterException exception, string messageText, + bool assertData = true) { - // Setup - var innerException = new Exception(); - string typeParamName = "T"; - const string messageText = ""; + base.AssertMessageConstructedInstance(exception, messageText, assertData); + if (assertData) + { + Assert.IsNull(exception.TypeParamName); + } + } - // Call - var exception = new InvalidTypeParameterException(typeParamName, messageText, innerException); - - // Assert - Assert.IsInstanceOf(exception); - Assert.AreEqual(messageText, exception.Message); - Assert.AreEqual(typeParamName, exception.TypeParamName); - Assert.AreEqual(1, exception.Data.Count); - Assert.AreEqual(exception.TypeParamName, exception.Data["TypeParamName"]); - Assert.IsNull(exception.HelpLink); - Assert.AreEqual(innerException, exception.InnerException); - Assert.IsNull(exception.Source); - Assert.IsNull(exception.StackTrace); - Assert.IsNull(exception.TargetSite); + protected override void AssertMessageAndInnerExceptionConstructedInstance(InvalidTypeParameterException exception, string messageText, + Exception innerException, bool assertData = true) + { + base.AssertMessageAndInnerExceptionConstructedInstance(exception, messageText, innerException, assertData); + if (assertData) + { + Assert.IsNull(exception.TypeParamName); + } } - [Test] - public void Constructor_SerializationRoundTrip_ExceptionProperlyInitialized() + protected override InvalidTypeParameterException CreateFullyConfiguredException() { - // Setup var originalInnerException = new Exception("inner"); - var originalException = new InvalidTypeParameterException("", "", originalInnerException); + return new InvalidTypeParameterException("", "", originalInnerException); + } - // Precondition - Assert.IsNotNull(originalException.InnerException); - Assert.IsNull(originalException.InnerException.InnerException); - - // Call - InvalidTypeParameterException persistedException = SerializationTestHelper.SerializeAndDeserializeException(originalException); - - // Assert - Assert.AreEqual(originalException.Message, persistedException.Message); + protected override void AssertRoundTripResult(InvalidTypeParameterException originalException, InvalidTypeParameterException persistedException) + { + base.AssertRoundTripResult(originalException, persistedException); Assert.AreEqual(originalException.TypeParamName, persistedException.TypeParamName); - Assert.IsNotNull(persistedException.InnerException); - Assert.AreEqual(originalException.InnerException.GetType(), persistedException.InnerException.GetType()); - Assert.AreEqual(originalException.InnerException.Message, persistedException.InnerException.Message); - Assert.IsNull(persistedException.InnerException.InnerException); } } } \ No newline at end of file Index: Core/Components/src/Core.Components.DotSpatial/Core.Components.DotSpatial.csproj =================================================================== diff -u -rc0ec9f5dc0c96437c4088eea1284fe2cc33bfddd -rfa3b352bc1b1c01fc73a9a45268c5573807a6381 --- Core/Components/src/Core.Components.DotSpatial/Core.Components.DotSpatial.csproj (.../Core.Components.DotSpatial.csproj) (revision c0ec9f5dc0c96437c4088eea1284fe2cc33bfddd) +++ Core/Components/src/Core.Components.DotSpatial/Core.Components.DotSpatial.csproj (.../Core.Components.DotSpatial.csproj) (revision fa3b352bc1b1c01fc73a9a45268c5573807a6381) @@ -94,10 +94,10 @@ + - Index: Core/Components/src/Core.Components.DotSpatial/Layer/BruTile/BruTileLayer.cs =================================================================== diff -u -rc0ec9f5dc0c96437c4088eea1284fe2cc33bfddd -rfa3b352bc1b1c01fc73a9a45268c5573807a6381 --- Core/Components/src/Core.Components.DotSpatial/Layer/BruTile/BruTileLayer.cs (.../BruTileLayer.cs) (revision c0ec9f5dc0c96437c4088eea1284fe2cc33bfddd) +++ Core/Components/src/Core.Components.DotSpatial/Layer/BruTile/BruTileLayer.cs (.../BruTileLayer.cs) (revision fa3b352bc1b1c01fc73a9a45268c5573807a6381) @@ -114,15 +114,23 @@ /// The tile source configuration. /// Thrown when /// is null. + /// Thrown when no tile source + /// can be found based on . + /// Thrown when a critical error + /// prevents the creation of the persistent tile cache. + /// Thrown when it no tiles can be + /// received from the tile source. public BruTileLayer(IConfiguration configuration) { if (configuration == null) { throw new ArgumentNullException(nameof(configuration)); } - // Initialize the configuration prior to usage - configuration.Initialize(); + if (!configuration.Initialized) + { + configuration.Initialize(); + } this.configuration = configuration; ITileSchema tileSchema = configuration.TileSource.Schema; Index: Core/Components/src/Core.Components.DotSpatial/Layer/BruTile/BruTileSettings.cs =================================================================== diff -u -rc0ec9f5dc0c96437c4088eea1284fe2cc33bfddd -rfa3b352bc1b1c01fc73a9a45268c5573807a6381 --- Core/Components/src/Core.Components.DotSpatial/Layer/BruTile/BruTileSettings.cs (.../BruTileSettings.cs) (revision c0ec9f5dc0c96437c4088eea1284fe2cc33bfddd) +++ Core/Components/src/Core.Components.DotSpatial/Layer/BruTile/BruTileSettings.cs (.../BruTileSettings.cs) (revision fa3b352bc1b1c01fc73a9a45268c5573807a6381) @@ -52,11 +52,6 @@ public static int PersistentCacheExpireInDays { get; } = 14; /// - /// Gets the type of the perma cache. - /// - public static PersistentCacheStrategy DefaultPersistentCacheType { get; } = PersistentCacheStrategy.Default; - - /// /// Gets the value /// public static int MemoryCacheMinimum { get; } = 100; Index: Core/Components/src/Core.Components.DotSpatial/Layer/BruTile/Configurations/BruTileReflectionHelper.cs =================================================================== diff -u -rc0ec9f5dc0c96437c4088eea1284fe2cc33bfddd -rfa3b352bc1b1c01fc73a9a45268c5573807a6381 --- Core/Components/src/Core.Components.DotSpatial/Layer/BruTile/Configurations/BruTileReflectionHelper.cs (.../BruTileReflectionHelper.cs) (revision c0ec9f5dc0c96437c4088eea1284fe2cc33bfddd) +++ Core/Components/src/Core.Components.DotSpatial/Layer/BruTile/Configurations/BruTileReflectionHelper.cs (.../BruTileReflectionHelper.cs) (revision fa3b352bc1b1c01fc73a9a45268c5573807a6381) @@ -40,10 +40,19 @@ /// /// The tile source. /// The tile provider. - /// Thrown when does + /// Thrown when + /// is null. + /// Thrown when does /// not have the expected field to get the from. + /// Thrown when caller does not have permission + /// to access the expected field that holds the instance. internal static ITileProvider GetProviderFromTileSource(ITileSource source) { + if (source == null) + { + throw new ArgumentNullException(nameof(source)); + } + FieldInfo fi = null; // Note: This implementation respects inheritance. Cannot use 'source.GetType()' // as that only grant access to fields declared in that type. Therefore the _provider @@ -59,7 +68,7 @@ if (fi == null) { - throw new ArgumentException("Tile source does not have a private field '_provider'", nameof(source)); + throw new NotSupportedException($"Unable to find a {typeof(ITileProvider).Name} field for type {source.GetType().Name}."); } return (ITileProvider) fi.GetValue(source); Index: Core/Components/src/Core.Components.DotSpatial/Layer/BruTile/Configurations/CannotCreateTileCacheException.cs =================================================================== diff -u -r43a1410b8cf0b1ff0fe8c689ff49028bf93f65ad -rfa3b352bc1b1c01fc73a9a45268c5573807a6381 --- Core/Components/src/Core.Components.DotSpatial/Layer/BruTile/Configurations/CannotCreateTileCacheException.cs (.../CannotCreateTileCacheException.cs) (revision 43a1410b8cf0b1ff0fe8c689ff49028bf93f65ad) +++ Core/Components/src/Core.Components.DotSpatial/Layer/BruTile/Configurations/CannotCreateTileCacheException.cs (.../CannotCreateTileCacheException.cs) (revision fa3b352bc1b1c01fc73a9a45268c5573807a6381) @@ -27,7 +27,8 @@ /// /// The exception that is thrown when the creation of a tile cache failed. /// - public class CannotCreateTileCacheException : SystemException + [Serializable] + public class CannotCreateTileCacheException : Exception { /// /// Initializes a new instance of the class. Index: Core/Components/src/Core.Components.DotSpatial/Layer/BruTile/Configurations/CannotFindTileSourceException.cs =================================================================== diff -u -r7cc1fd960a912443ccc3c6995eccb5673d1d8d22 -rfa3b352bc1b1c01fc73a9a45268c5573807a6381 --- Core/Components/src/Core.Components.DotSpatial/Layer/BruTile/Configurations/CannotFindTileSourceException.cs (.../CannotFindTileSourceException.cs) (revision 7cc1fd960a912443ccc3c6995eccb5673d1d8d22) +++ Core/Components/src/Core.Components.DotSpatial/Layer/BruTile/Configurations/CannotFindTileSourceException.cs (.../CannotFindTileSourceException.cs) (revision fa3b352bc1b1c01fc73a9a45268c5573807a6381) @@ -30,7 +30,7 @@ /// the specified . /// [Serializable] - public class CannotFindTileSourceException : SystemException + public class CannotFindTileSourceException : Exception { /// /// Initializes a new instance of the class. Index: Core/Components/src/Core.Components.DotSpatial/Layer/BruTile/Configurations/CannotReceiveTilesException.cs =================================================================== diff -u --- Core/Components/src/Core.Components.DotSpatial/Layer/BruTile/Configurations/CannotReceiveTilesException.cs (revision 0) +++ Core/Components/src/Core.Components.DotSpatial/Layer/BruTile/Configurations/CannotReceiveTilesException.cs (revision fa3b352bc1b1c01fc73a9a45268c5573807a6381) @@ -0,0 +1,57 @@ +// Copyright (C) Stichting Deltares 2016. 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 Lesser 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 Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser 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 Core.Components.DotSpatial.Layer.BruTile.Configurations +{ + /// + /// The exception that is thrown when receiving tiles has become impossible or fails. + /// + [Serializable] + public class CannotReceiveTilesException : Exception + { + /// + /// Initializes a new instance of the class. + /// + public CannotReceiveTilesException() { } + + /// + /// Initializes a new instance of the class + /// with a specified error message. + /// + /// The error message that explains the reason for the exception. + public CannotReceiveTilesException(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 CannotReceiveTilesException(string message, Exception inner) : base(message, inner) { } + + protected CannotReceiveTilesException(SerializationInfo info, StreamingContext context) : base(info, context) { } + } +} \ No newline at end of file Index: Core/Components/src/Core.Components.DotSpatial/Layer/BruTile/Configurations/IConfiguration.cs =================================================================== diff -u -rc0ec9f5dc0c96437c4088eea1284fe2cc33bfddd -rfa3b352bc1b1c01fc73a9a45268c5573807a6381 --- Core/Components/src/Core.Components.DotSpatial/Layer/BruTile/Configurations/IConfiguration.cs (.../IConfiguration.cs) (revision c0ec9f5dc0c96437c4088eea1284fe2cc33bfddd) +++ Core/Components/src/Core.Components.DotSpatial/Layer/BruTile/Configurations/IConfiguration.cs (.../IConfiguration.cs) (revision fa3b352bc1b1c01fc73a9a45268c5573807a6381) @@ -49,6 +49,14 @@ AsyncTileFetcher TileFetcher { get; } /// + /// Gets a value indicating whether the configuration has been fully initialized + /// or not. + /// + /// can be used to initialize the configuration + /// if needed. + bool Initialized { get; } + + /// /// Gets a deep copy of the configuration. /// /// The cloned configuration. @@ -61,6 +69,8 @@ /// cannot be found. /// Thrown when the configured /// tile cache cannot be created. + /// Thrown when + /// doesn't allow for tiles to be received. void Initialize(); } } \ No newline at end of file Index: Core/Components/src/Core.Components.DotSpatial/Layer/BruTile/Configurations/ITileSourceFactory.cs =================================================================== diff -u -r16bd8076863c03907abeee60b16704aba1bdb1a0 -rfa3b352bc1b1c01fc73a9a45268c5573807a6381 --- Core/Components/src/Core.Components.DotSpatial/Layer/BruTile/Configurations/ITileSourceFactory.cs (.../ITileSourceFactory.cs) (revision 16bd8076863c03907abeee60b16704aba1bdb1a0) +++ Core/Components/src/Core.Components.DotSpatial/Layer/BruTile/Configurations/ITileSourceFactory.cs (.../ITileSourceFactory.cs) (revision fa3b352bc1b1c01fc73a9a45268c5573807a6381) @@ -35,7 +35,8 @@ /// Returns all tile sources based on the capabilities of a Web Map Tile Service. /// /// The URL to the 'GetCapabilities' part of the service. - /// The tile sources. + /// The tile sources with initialized + /// with an instance of . /// Thrown when unable to retrieve /// tile sources from the given service. IEnumerable GetWmtsTileSources(string capabilitiesUrl); Index: Core/Components/src/Core.Components.DotSpatial/Layer/BruTile/Configurations/PersistentCacheConfiguration.cs =================================================================== diff -u -rc0ec9f5dc0c96437c4088eea1284fe2cc33bfddd -rfa3b352bc1b1c01fc73a9a45268c5573807a6381 --- Core/Components/src/Core.Components.DotSpatial/Layer/BruTile/Configurations/PersistentCacheConfiguration.cs (.../PersistentCacheConfiguration.cs) (revision c0ec9f5dc0c96437c4088eea1284fe2cc33bfddd) +++ Core/Components/src/Core.Components.DotSpatial/Layer/BruTile/Configurations/PersistentCacheConfiguration.cs (.../PersistentCacheConfiguration.cs) (revision fa3b352bc1b1c01fc73a9a45268c5573807a6381) @@ -20,11 +20,10 @@ // All rights reserved. using System; -using System.ComponentModel; -using System.Data.SQLite; using System.IO; using BruTile.Cache; using Core.Common.Utils; +using Core.Components.DotSpatial.Properties; namespace Core.Components.DotSpatial.Layer.BruTile.Configurations { @@ -50,7 +49,9 @@ { if (!IOUtils.IsValidFolderPath(persistentCacheDirectoryPath)) { - throw new ArgumentException("Invalid folder path", nameof(persistentCacheDirectoryPath)); + throw new ArgumentException(string.Format(Resources.PersistentCacheConfiguration_Invalid_path_for_persistent_cache, + persistentCacheDirectoryPath), + nameof(persistentCacheDirectoryPath)); } this.persistentCacheDirectoryPath = persistentCacheDirectoryPath; } @@ -71,37 +72,21 @@ } catch (Exception e) when (SupportedCreateDirectoryExceptions(e)) { - string message = "Een kritieke fout is opgetreden bij het aanmaken van de cache."; + string message = Resources.PersistentCacheConfiguration_CreateTileCache_Critical_error_while_creating_tile_cache; throw new CannotCreateTileCacheException(message, e); } } - switch (BruTileSettings.DefaultPersistentCacheType) - { - case PersistentCacheStrategy.FileCache: - return new FileCache(persistentCacheDirectoryPath, BruTileSettings.PersistentCacheFormat, - TimeSpan.FromDays(BruTileSettings.PersistentCacheExpireInDays)); - case PersistentCacheStrategy.DbCache: - return CreateDbCache(persistentCacheDirectoryPath); - default: - throw new InvalidEnumArgumentException(nameof(BruTileSettings.DefaultPersistentCacheType), - (int) BruTileSettings.DefaultPersistentCacheType, - typeof(PersistentCacheStrategy)); - } + return new FileCache(persistentCacheDirectoryPath, BruTileSettings.PersistentCacheFormat, + TimeSpan.FromDays(BruTileSettings.PersistentCacheExpireInDays)); } - private bool SupportedCreateDirectoryExceptions(Exception exception) + private static bool SupportedCreateDirectoryExceptions(Exception exception) { return exception is IOException || exception is UnauthorizedAccessException || exception is ArgumentException || exception is NotSupportedException; } - - private static DbCache CreateDbCache(string path) - { - var conn = new SQLiteConnection($"Data Source={path};"); - return new DbCache(conn); - } } } \ No newline at end of file Fisheye: Tag fa3b352bc1b1c01fc73a9a45268c5573807a6381 refers to a dead (removed) revision in file `Core/Components/src/Core.Components.DotSpatial/Layer/BruTile/Configurations/PersistentCacheStrategy.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Core/Components/src/Core.Components.DotSpatial/Layer/BruTile/Configurations/TileSourceFactory.cs =================================================================== diff -u -r16bd8076863c03907abeee60b16704aba1bdb1a0 -rfa3b352bc1b1c01fc73a9a45268c5573807a6381 --- Core/Components/src/Core.Components.DotSpatial/Layer/BruTile/Configurations/TileSourceFactory.cs (.../TileSourceFactory.cs) (revision 16bd8076863c03907abeee60b16704aba1bdb1a0) +++ Core/Components/src/Core.Components.DotSpatial/Layer/BruTile/Configurations/TileSourceFactory.cs (.../TileSourceFactory.cs) (revision fa3b352bc1b1c01fc73a9a45268c5573807a6381) @@ -22,16 +22,25 @@ using System; using System.Collections.Generic; using System.IO; +using System.Linq; using System.Net; using BruTile; using BruTile.Wmts; +using Core.Components.DotSpatial.Properties; namespace Core.Components.DotSpatial.Layer.BruTile.Configurations { + /// + /// Class responsible for creating instances for a given + /// source. + /// public class TileSourceFactory : ITileSourceFactory { private static ITileSourceFactory instance; + /// + /// The singleton instance. + /// public static ITileSourceFactory Instance { get @@ -46,6 +55,16 @@ public IEnumerable GetWmtsTileSources(string capabilitiesUrl) { + ITileSource[] wmtsTileSources = ParseWmtsTileSources(capabilitiesUrl).ToArray(); + if(wmtsTileSources.Any(ts => !(ts.Schema is WmtsTileSchema))) + { + throw new CannotFindTileSourceException(Resources.TileSourceFactory_GetWmtsTileSources_TileSource_without_WmtsTileSchema_error); + } + return wmtsTileSources; + } + + private static IEnumerable ParseWmtsTileSources(string capabilitiesUrl) + { try { WebRequest req = WebRequest.Create(capabilitiesUrl); @@ -59,7 +78,8 @@ } catch (Exception e) { - string message = string.Format("Niet in staat om de databronnen op te halen bij de WTMS url '{0}'.", capabilitiesUrl); + string message = string.Format(Resources.TileSourceFactory_ParseWmtsTileSources_Cannot_connect_to_WMTS_0_, + capabilitiesUrl); throw new CannotFindTileSourceException(message, e); } } Index: Core/Components/src/Core.Components.DotSpatial/Layer/BruTile/Configurations/WmtsLayerConfiguration.cs =================================================================== diff -u -rc0ec9f5dc0c96437c4088eea1284fe2cc33bfddd -rfa3b352bc1b1c01fc73a9a45268c5573807a6381 --- Core/Components/src/Core.Components.DotSpatial/Layer/BruTile/Configurations/WmtsLayerConfiguration.cs (.../WmtsLayerConfiguration.cs) (revision c0ec9f5dc0c96437c4088eea1284fe2cc33bfddd) +++ Core/Components/src/Core.Components.DotSpatial/Layer/BruTile/Configurations/WmtsLayerConfiguration.cs (.../WmtsLayerConfiguration.cs) (revision fa3b352bc1b1c01fc73a9a45268c5573807a6381) @@ -23,11 +23,11 @@ using System.Collections.Generic; using System.IO; using System.Linq; -using System.Net; using BruTile; using BruTile.Cache; using BruTile.Wmts; using Core.Components.DotSpatial.Layer.BruTile.TileFetching; +using Core.Components.DotSpatial.Properties; namespace Core.Components.DotSpatial.Layer.BruTile.Configurations { @@ -53,8 +53,9 @@ /// The directory path to the persistent tile cache. /// Thrown when /// is an invalid folder path - public WmtsLayerConfiguration(string wmtsCapabilitiesUrl, string capabilityIdentifier, string preferredFormat, - string persistentCacheDirectoryPath) : base(persistentCacheDirectoryPath) + /// Thrown when any input argument is null. + private WmtsLayerConfiguration(string wmtsCapabilitiesUrl, string capabilityIdentifier, string preferredFormat, + string persistentCacheDirectoryPath) : base(persistentCacheDirectoryPath) { ValidateConfigurationParameters(wmtsCapabilitiesUrl, capabilityIdentifier, preferredFormat); @@ -71,27 +72,20 @@ /// /// The capabilities url of the WMTS. /// The tile source. - /// Thrown when - /// is null. /// Thrown when creating the file /// cache failed. + /// Thrown when + /// doesn't allow for tiles to be received. private WmtsLayerConfiguration(string wmtsCapabilitiesUrl, ITileSource tileSource) - : base(SuggestTileCachePath(tileSource)) + : base(SuggestTileCachePath(ValidateTileSource(tileSource))) { - if (tileSource == null) - { - throw new ArgumentNullException(nameof(tileSource)); - } - capabilitiesUri = wmtsCapabilitiesUrl; capabilityIdentifier = ((WmtsTileSchema) tileSource.Schema).Identifier; preferredFormat = tileSource.Schema.Format; InitializeFromTileSource(tileSource); } - public ITileCache TileCache { get; private set; } - public bool Initialized { get; private set; } public string LegendText { get; } @@ -100,10 +94,22 @@ public AsyncTileFetcher TileFetcher { get; private set; } - public static WmtsLayerConfiguration CreateInitializedConfiguration(string capabilitiesUrl, string capabilityIdentifier, string preferredFormat) + /// + /// Creates a fully initialized instance of . + /// + /// The capabilities url of the WMTS. + /// The capability name to get tiles from. + /// The preferred tile image format, as MIME-type. + /// The new . + /// Thrown when any input argument is null. + /// Thrown when + /// is not an image MIME-type. + public static WmtsLayerConfiguration CreateInitializedConfiguration(string wmtsCapabilitiesUrl, string capabilityIdentifier, string preferredFormat) { - ITileSource tileSource = GetConfiguredTileSource(capabilitiesUrl, capabilityIdentifier, preferredFormat); - return new WmtsLayerConfiguration(capabilitiesUrl, tileSource); + ValidateConfigurationParameters(wmtsCapabilitiesUrl, capabilityIdentifier, preferredFormat); + + ITileSource tileSource = GetConfiguredTileSource(wmtsCapabilitiesUrl, capabilityIdentifier, preferredFormat); + return new WmtsLayerConfiguration(wmtsCapabilitiesUrl, tileSource); } public IConfiguration Clone() @@ -123,7 +129,25 @@ InitializeFromTileSource(tileSource); } + private ITileCache TileCache { get; set; } + /// + /// Validates a . + /// + /// The source to be validated. + /// Returns . + /// Thrown when + /// doesn't contain a . + private static ITileSource ValidateTileSource(ITileSource tileSource) + { + if (!(tileSource.Schema is WmtsTileSchema)) + { + throw new CannotCreateTileCacheException(Resources.WmtsLayerConfiguration_ValidateTileSource_TileSource_must_have_WmtsTileSchema); + } + return tileSource; + } + + /// /// Validate the configuration parameters. /// /// The capabilities url of the WMTS. @@ -148,7 +172,8 @@ } if (!preferredFormat.StartsWith("image/")) { - throw new ArgumentException("Specified image format is not a MIME type.", nameof(preferredFormat)); + throw new ArgumentException(Resources.WmtsLayerConfiguration_ValidateConfigurationParameters_PreferredFormat_must_be_mimetype, + nameof(preferredFormat)); } } @@ -158,7 +183,7 @@ /// The URL of the tile source server. /// The identifier of the tile source. /// The preferred tile image format, as MIME-type. - /// The tile source, or null if no matching tile source could be found. + /// The tile source. /// Thrown when unable to retrieve /// the configured tile source. private static ITileSource GetConfiguredTileSource(string capabilitiesUri, string capabilityIdentifier, string preferredFormat) @@ -167,8 +192,8 @@ ITileSource tileSource = tileSources.FirstOrDefault(ts => IsMatch(ts, capabilityIdentifier, preferredFormat)); if (tileSource == null) { - string message = string.Format("Niet in staat om de databron met naam '{0}' te kunnen vinden bij de WTMS url '{1}'.", - capabilitiesUri, capabilityIdentifier); + string message = string.Format(Resources.WmtsLayerConfiguration_GetConfiguredTileSource_Cannot_find_LayerId_0_at_WmtsUrl_1_, + capabilityIdentifier, capabilitiesUri); throw new CannotFindTileSourceException(message); } return tileSource; @@ -210,15 +235,24 @@ /// The tile source to initialize for. /// Thrown when a critical error /// occurs when creating the tile cache. + /// Thrown when + /// does not allow for tiles to be retrieved. private void InitializeFromTileSource(ITileSource tileSource) { TileSource = tileSource; TileCache = CreateTileCache(); - ITileProvider provider = BruTileReflectionHelper.GetProviderFromTileSource(tileSource); - TileFetcher = new AsyncTileFetcher(provider, - BruTileSettings.MemoryCacheMinimum, - BruTileSettings.MemoryCacheMaximum, - TileCache); + try + { + ITileProvider provider = BruTileReflectionHelper.GetProviderFromTileSource(tileSource); + TileFetcher = new AsyncTileFetcher(provider, + BruTileSettings.MemoryCacheMinimum, + BruTileSettings.MemoryCacheMaximum, + TileCache); + } + catch (Exception e) when (e is NotSupportedException || e is ArgumentException) + { + throw new CannotReceiveTilesException(Resources.WmtsLayerConfiguration_InitializeFromTileSource_TileSource_does_not_allow_access_to_provider, e); + } Initialized = true; } } Index: Core/Components/src/Core.Components.DotSpatial/Properties/Resources.Designer.cs =================================================================== diff -u -rc0ec9f5dc0c96437c4088eea1284fe2cc33bfddd -rfa3b352bc1b1c01fc73a9a45268c5573807a6381 --- Core/Components/src/Core.Components.DotSpatial/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision c0ec9f5dc0c96437c4088eea1284fe2cc33bfddd) +++ Core/Components/src/Core.Components.DotSpatial/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision fa3b352bc1b1c01fc73a9a45268c5573807a6381) @@ -101,6 +101,82 @@ } /// + /// Looks up a localized string similar to Een kritieke fout is opgetreden bij het aanmaken van de cache.. + /// + internal static string PersistentCacheConfiguration_CreateTileCache_Critical_error_while_creating_tile_cache { + get { + return ResourceManager.GetString("PersistentCacheConfiguration_CreateTileCache_Critical_error_while_creating_tile_c" + + "ache", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Het pad naar bestandsmap '{0}' is niet geschikt om de kaart tegels in op te slaan.. + /// + internal static string PersistentCacheConfiguration_Invalid_path_for_persistent_cache { + get { + return ResourceManager.GetString("PersistentCacheConfiguration_Invalid_path_for_persistent_cache", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Een databron is niet volgens het WMTS protocol aangeleverd.. + /// + internal static string TileSourceFactory_GetWmtsTileSources_TileSource_without_WmtsTileSchema_error { + get { + return ResourceManager.GetString("TileSourceFactory_GetWmtsTileSources_TileSource_without_WmtsTileSchema_error", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Niet in staat om de databronnen op te halen bij de WMTS url '{0}'.. + /// + internal static string TileSourceFactory_ParseWmtsTileSources_Cannot_connect_to_WMTS_0_ { + get { + return ResourceManager.GetString("TileSourceFactory_ParseWmtsTileSources_Cannot_connect_to_WMTS_0_", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Niet in staat om de databron met naam '{0}' te kunnen vinden bij de WMTS url '{1}'.. + /// + internal static string WmtsLayerConfiguration_GetConfiguredTileSource_Cannot_find_LayerId_0_at_WmtsUrl_1_ { + get { + return ResourceManager.GetString("WmtsLayerConfiguration_GetConfiguredTileSource_Cannot_find_LayerId_0_at_WmtsUrl_1" + + "_", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Bron staat het niet toe om toegang te krijgen tot de kaart tegels.. + /// + internal static string WmtsLayerConfiguration_InitializeFromTileSource_TileSource_does_not_allow_access_to_provider { + get { + return ResourceManager.GetString("WmtsLayerConfiguration_InitializeFromTileSource_TileSource_does_not_allow_access_" + + "to_provider", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Afbeelding formaat moet opgegeven worden als MIME-type.. + /// + internal static string WmtsLayerConfiguration_ValidateConfigurationParameters_PreferredFormat_must_be_mimetype { + get { + return ResourceManager.GetString("WmtsLayerConfiguration_ValidateConfigurationParameters_PreferredFormat_must_be_mi" + + "metype", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Bron bevat geen WMTS schema.. + /// + internal static string WmtsLayerConfiguration_ValidateTileSource_TileSource_must_have_WmtsTileSchema { + get { + return ResourceManager.GetString("WmtsLayerConfiguration_ValidateTileSource_TileSource_must_have_WmtsTileSchema", resourceCulture); + } + } + + /// /// Looks up a localized string similar to Ongeldige transformatie parameters: transformatie moet omkeerbaar zijn.. /// internal static string WorldFile_Not_invertable_transformation_arguments_error { Index: Core/Components/src/Core.Components.DotSpatial/Properties/Resources.resx =================================================================== diff -u -rc0ec9f5dc0c96437c4088eea1284fe2cc33bfddd -rfa3b352bc1b1c01fc73a9a45268c5573807a6381 --- Core/Components/src/Core.Components.DotSpatial/Properties/Resources.resx (.../Resources.resx) (revision c0ec9f5dc0c96437c4088eea1284fe2cc33bfddd) +++ Core/Components/src/Core.Components.DotSpatial/Properties/Resources.resx (.../Resources.resx) (revision fa3b352bc1b1c01fc73a9a45268c5573807a6381) @@ -1,103 +1,122 @@  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - text/microsoft-resx - - - 1.3 - - - System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.3500.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.3500.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - + mimetype: application/x-microsoft.net.object.bytearray.base64 + value : The object must be serialized into a byte array + : using a System.ComponentModel.TypeConverter + : and then encoded with base64 encoding. + --> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + Het aantal kaart tegels voor de geheugen cache moeten positief zijn. @@ -107,4 +126,28 @@ Ongeldige transformatie parameters: transformatie moet omkeerbaar zijn. + + Bron staat het niet toe om toegang te krijgen tot de kaart tegels. + + + Een kritieke fout is opgetreden bij het aanmaken van de cache. + + + Het pad naar bestandsmap '{0}' is niet geschikt om de kaart tegels in op te slaan. + + + Niet in staat om de databronnen op te halen bij de WMTS url '{0}'. + + + Afbeelding formaat moet opgegeven worden als MIME-type. + + + Niet in staat om de databron met naam '{0}' te kunnen vinden bij de WMTS url '{1}'. + + + Bron bevat geen WMTS schema. + + + Een databron is niet volgens het WMTS protocol aangeleverd. + \ No newline at end of file Index: Core/Components/test/Core.Components.DotSpatial.Test/Core.Components.DotSpatial.Test.csproj =================================================================== diff -u -rc0ec9f5dc0c96437c4088eea1284fe2cc33bfddd -rfa3b352bc1b1c01fc73a9a45268c5573807a6381 --- Core/Components/test/Core.Components.DotSpatial.Test/Core.Components.DotSpatial.Test.csproj (.../Core.Components.DotSpatial.Test.csproj) (revision c0ec9f5dc0c96437c4088eea1284fe2cc33bfddd) +++ Core/Components/test/Core.Components.DotSpatial.Test/Core.Components.DotSpatial.Test.csproj (.../Core.Components.DotSpatial.Test.csproj) (revision fa3b352bc1b1c01fc73a9a45268c5573807a6381) @@ -10,6 +10,8 @@ Core.Components.DotSpatial.Test v4.0 512 + + true @@ -44,6 +46,14 @@ ..\..\..\..\packages\BruTile.0.19.0\lib\net40\BruTile.dll True + + ..\..\..\..\packages\BruTile.Desktop.0.19.0\lib\net40\BruTile.Desktop.dll + True + + + ..\..\..\..\packages\BruTile.Desktop.0.19.0\lib\net40\BruTile.MbTiles.dll + True + False ..\..\..\..\lib\DotSpatial.1.8\DotSpatial.Controls.dll @@ -79,6 +89,10 @@ + + ..\..\..\..\packages\System.Data.SQLite.Core.1.0.104.0\lib\net40\System.Data.SQLite.dll + True + @@ -91,7 +105,13 @@ + + + + + + @@ -159,6 +179,13 @@ + + + + This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + + + + + \ No newline at end of file Index: Core/Components/test/Core.Components.DotSpatial.TestUtil/Core.Components.DotSpatial.TestUtil.csproj =================================================================== diff -u -r16bd8076863c03907abeee60b16704aba1bdb1a0 -rfa3b352bc1b1c01fc73a9a45268c5573807a6381 --- Core/Components/test/Core.Components.DotSpatial.TestUtil/Core.Components.DotSpatial.TestUtil.csproj (.../Core.Components.DotSpatial.TestUtil.csproj) (revision 16bd8076863c03907abeee60b16704aba1bdb1a0) +++ Core/Components/test/Core.Components.DotSpatial.TestUtil/Core.Components.DotSpatial.TestUtil.csproj (.../Core.Components.DotSpatial.TestUtil.csproj) (revision fa3b352bc1b1c01fc73a9a45268c5573807a6381) @@ -60,6 +60,7 @@ + Index: Core/Components/test/Core.Components.DotSpatial.TestUtil/TestWmtsTileSource.cs =================================================================== diff -u -r16bd8076863c03907abeee60b16704aba1bdb1a0 -rfa3b352bc1b1c01fc73a9a45268c5573807a6381 --- Core/Components/test/Core.Components.DotSpatial.TestUtil/TestWmtsTileSource.cs (.../TestWmtsTileSource.cs) (revision 16bd8076863c03907abeee60b16704aba1bdb1a0) +++ Core/Components/test/Core.Components.DotSpatial.TestUtil/TestWmtsTileSource.cs (.../TestWmtsTileSource.cs) (revision fa3b352bc1b1c01fc73a9a45268c5573807a6381) @@ -57,33 +57,9 @@ private static WmtsTileSchema CreateWmtsTileSchema(WmtsMapData backgroundMapData) { - WmtsTileSchema schema = ConstructWmtsTileSchema(); - schema.Title = backgroundMapData.Name; - schema.Format = backgroundMapData.PreferredFormat; - - schema.Resolutions["1"] = new Resolution("1", 1); - - var regex1 = new Regex(@"(?.+)\((?.+)\)"); - Match match = regex1.Match(backgroundMapData.SelectedCapabilityIdentifier); - schema.Layer = match.Groups["Layer"].Value; - schema.TileMatrixSet = match.Groups["TileMatrixSet"].Value; - - var regex2 = new Regex(@"EPSG:(?\d+)"); - Match potentialMatch = regex2.Match(schema.TileMatrixSet); - schema.Srs = potentialMatch.Success ? - $"EPSG:{potentialMatch.Groups["SrsNumber"]}" : - "EPSG:3857"; - - return schema; + return TileSchemaFactory.CreateWmtsTileSchema(backgroundMapData); } - private static WmtsTileSchema ConstructWmtsTileSchema() - { - return (WmtsTileSchema) typeof(WmtsTileSchema) - .GetConstructor(BindingFlags.NonPublic | BindingFlags.Instance, null, Type.EmptyTypes, null) - .Invoke(null); - } - private static byte[] GetStubTile(Uri arg) { if (pngTileDataStub == null) Index: Core/Components/test/Core.Components.DotSpatial.TestUtil/TileSchemaFactory.cs =================================================================== diff -u --- Core/Components/test/Core.Components.DotSpatial.TestUtil/TileSchemaFactory.cs (revision 0) +++ Core/Components/test/Core.Components.DotSpatial.TestUtil/TileSchemaFactory.cs (revision fa3b352bc1b1c01fc73a9a45268c5573807a6381) @@ -0,0 +1,70 @@ +// Copyright (C) Stichting Deltares 2016. 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 Lesser 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 Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser 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.Reflection; +using System.Text.RegularExpressions; +using BruTile; +using BruTile.Wmts; +using Core.Components.Gis.Data; + +namespace Core.Components.DotSpatial.TestUtil +{ + /// + /// Factory class to create instances of . + /// + public static class TileSchemaFactory + { + /// + /// Create a based on a instance. + /// + /// The data for which the schema will be based upon. + /// The newly created tile schema. + public static WmtsTileSchema CreateWmtsTileSchema(WmtsMapData backgroundMapData) + { + WmtsTileSchema schema = ConstructWmtsTileSchema(); + schema.Title = backgroundMapData.Name; + schema.Format = backgroundMapData.PreferredFormat; + + schema.Resolutions["1"] = new Resolution("1", 1); + + var regex1 = new Regex(@"(?.+)\((?.+)\)"); + Match match = regex1.Match(backgroundMapData.SelectedCapabilityIdentifier); + schema.Layer = match.Groups["Layer"].Value; + schema.TileMatrixSet = match.Groups["TileMatrixSet"].Value; + + var regex2 = new Regex(@"EPSG:(?\d+)"); + Match potentialMatch = regex2.Match(schema.TileMatrixSet); + schema.Srs = potentialMatch.Success ? + $"EPSG:{potentialMatch.Groups["SrsNumber"]}" : + "EPSG:3857"; + + return schema; + } + + private static WmtsTileSchema ConstructWmtsTileSchema() + { + return (WmtsTileSchema)typeof(WmtsTileSchema) + .GetConstructor(BindingFlags.NonPublic | BindingFlags.Instance, null, Type.EmptyTypes, null) + .Invoke(null); + } + } +} \ No newline at end of file Index: Core/Plugins/test/Core.Plugins.ProjectExplorer.Test/Exceptions/PluginActivationExceptionTest.cs =================================================================== diff -u -r49c5da81f49a23dd6e66526d264a08bf510e6963 -rfa3b352bc1b1c01fc73a9a45268c5573807a6381 --- Core/Plugins/test/Core.Plugins.ProjectExplorer.Test/Exceptions/PluginActivationExceptionTest.cs (.../PluginActivationExceptionTest.cs) (revision 49c5da81f49a23dd6e66526d264a08bf510e6963) +++ Core/Plugins/test/Core.Plugins.ProjectExplorer.Test/Exceptions/PluginActivationExceptionTest.cs (.../PluginActivationExceptionTest.cs) (revision fa3b352bc1b1c01fc73a9a45268c5573807a6381) @@ -27,72 +27,6 @@ namespace Core.Plugins.ProjectExplorer.Test.Exceptions { [TestFixture] - public class PluginActivationExceptionTest - { - [Test] - public void DefaultConstructor_InnerExceptionNullAndMessageDefault() - { - // Setup - string expectedMessage = string.Format("Exception of type '{0}' was thrown.", typeof(PluginActivationException).FullName); - - // Call - var exception = new PluginActivationException(); - - // Assert - Assert.IsInstanceOf(exception); - Assert.IsNull(exception.InnerException); - Assert.AreEqual(expectedMessage, exception.Message); - } - - [Test] - public void Constructor_WithCustomMessage_InnerExceptionNullAndMessageSetToCustom() - { - // Setup - const string expectedMessage = "Some exception message"; - - // Call - var exception = new PluginActivationException(expectedMessage); - - // Assert - Assert.IsNull(exception.InnerException); - Assert.AreEqual(expectedMessage, exception.Message); - } - - [Test] - public void Constructor_WithCustomMessageAndInnerException_InnerExceptionSetAndMessageSetToCustom() - { - // Setup - const string expectedMessage = "Some exception message"; - Exception expectedInnerException = new Exception(); - - // Call - var exception = new PluginActivationException(expectedMessage, expectedInnerException); - - // Assert - Assert.AreSame(expectedInnerException, exception.InnerException); - Assert.AreEqual(expectedMessage, exception.Message); - } - - [Test] - public void Constructor_SerializationRoundTrip_ExceptionProperlyInitialized() - { - // Setup - var originalInnerException = new Exception("inner"); - var originalException = new PluginActivationException("outer", originalInnerException); - - // Precondition - Assert.IsNotNull(originalException.InnerException); - Assert.IsNull(originalException.InnerException.InnerException); - - // Call - PluginActivationException persistedException = SerializationTestHelper.SerializeAndDeserializeException(originalException); - - // Assert - Assert.AreEqual(originalException.Message, persistedException.Message); - Assert.IsNotNull(persistedException.InnerException); - Assert.AreEqual(originalException.InnerException.GetType(), persistedException.InnerException.GetType()); - Assert.AreEqual(originalException.InnerException.Message, persistedException.InnerException.Message); - Assert.IsNull(persistedException.InnerException.InnerException); - } - } + public class PluginActivationExceptionTest : + CustomExceptionDesignGuidelinesTestFixture {} } \ No newline at end of file Index: Migration/Scripts/test/Migration.Scripts.Data.Test/Exceptions/CriticalMigrationExceptionTest.cs =================================================================== diff -u -raf53f335d0fa6920f7a5c4ab27b112bae9eeaede -rfa3b352bc1b1c01fc73a9a45268c5573807a6381 --- Migration/Scripts/test/Migration.Scripts.Data.Test/Exceptions/CriticalMigrationExceptionTest.cs (.../CriticalMigrationExceptionTest.cs) (revision af53f335d0fa6920f7a5c4ab27b112bae9eeaede) +++ Migration/Scripts/test/Migration.Scripts.Data.Test/Exceptions/CriticalMigrationExceptionTest.cs (.../CriticalMigrationExceptionTest.cs) (revision fa3b352bc1b1c01fc73a9a45268c5573807a6381) @@ -27,89 +27,6 @@ namespace Migration.Scripts.Data.Test.Exceptions { [TestFixture] - public class CriticalMigrationExceptionTest - { - [Test] - [SetCulture("en-US")] - public void DefaultConstructor_ExpectedValues() - { - // Call - var exception = new CriticalMigrationException(); - - // Assert - Assert.IsInstanceOf(exception); - var expectedMessage = $"Exception of type '{exception.GetType()}' was thrown."; - Assert.AreEqual(expectedMessage, exception.Message); - CollectionAssert.IsEmpty(exception.Data); - Assert.IsNull(exception.HelpLink); - Assert.IsNull(exception.InnerException); - Assert.IsNull(exception.Source); - Assert.IsNull(exception.StackTrace); - Assert.IsNull(exception.TargetSite); - } - - [Test] - public void MessageConstructor_ExpectedValues() - { - // Setup - const string messageText = ""; - - // Call - var exception = new CriticalMigrationException(messageText); - - // Assert - Assert.IsInstanceOf(exception); - Assert.AreEqual(messageText, exception.Message); - CollectionAssert.IsEmpty(exception.Data); - Assert.IsNull(exception.HelpLink); - Assert.IsNull(exception.InnerException); - Assert.IsNull(exception.Source); - Assert.IsNull(exception.StackTrace); - Assert.IsNull(exception.TargetSite); - } - - [Test] - public void MessageAndInnerExceptionConstructor_ExpectedValues() - { - // Setup - var innerException = new Exception(); - const string messageText = ""; - - // Call - var exception = new CriticalMigrationException(messageText, innerException); - - // Assert - Assert.IsInstanceOf(exception); - Assert.AreEqual(messageText, exception.Message); - CollectionAssert.IsEmpty(exception.Data); - Assert.IsNull(exception.HelpLink); - Assert.AreSame(innerException, exception.InnerException); - Assert.IsNull(exception.Source); - Assert.IsNull(exception.StackTrace); - Assert.IsNull(exception.TargetSite); - } - - [Test] - public void Constructor_SerializationRoundTrip_ExceptionProperlyInitialized() - { - // Setup - var originalInnerException = new Exception("inner"); - var originalException = new CriticalMigrationException("outer", originalInnerException); - - // Precondition - Assert.IsNotNull(originalException.InnerException); - Assert.IsNull(originalException.InnerException.InnerException); - - // Call - CriticalMigrationException persistedException = SerializationTestHelper.SerializeAndDeserializeException( - originalException); - - // Assert - Assert.AreEqual(originalException.Message, persistedException.Message); - Assert.IsNotNull(persistedException.InnerException); - Assert.AreEqual(originalException.InnerException.GetType(), persistedException.InnerException.GetType()); - Assert.AreEqual(originalException.InnerException.Message, persistedException.InnerException.Message); - Assert.IsNull(persistedException.InnerException.InnerException); - } - } + public class CriticalMigrationExceptionTest : + CustomExceptionDesignGuidelinesTestFixture {} } \ No newline at end of file Index: Ringtoets/Common/test/Ringtoets.Common.IO.Test/Exceptions/CriticalFileValidationExceptionTest.cs =================================================================== diff -u -r49c5da81f49a23dd6e66526d264a08bf510e6963 -rfa3b352bc1b1c01fc73a9a45268c5573807a6381 --- Ringtoets/Common/test/Ringtoets.Common.IO.Test/Exceptions/CriticalFileValidationExceptionTest.cs (.../CriticalFileValidationExceptionTest.cs) (revision 49c5da81f49a23dd6e66526d264a08bf510e6963) +++ Ringtoets/Common/test/Ringtoets.Common.IO.Test/Exceptions/CriticalFileValidationExceptionTest.cs (.../CriticalFileValidationExceptionTest.cs) (revision fa3b352bc1b1c01fc73a9a45268c5573807a6381) @@ -27,88 +27,6 @@ namespace Ringtoets.Common.IO.Test.Exceptions { [TestFixture] - public class CriticalFileValidationExceptionTest - { - [Test] - [SetCulture("en-US")] - public void DefaultConstructor_ExpectedValues() - { - // Call - var exception = new CriticalFileValidationException(); - - // Assert - Assert.IsInstanceOf(exception); - var expectedMessage = string.Format("Exception of type '{0}' was thrown.", exception.GetType()); - Assert.AreEqual(expectedMessage, exception.Message); - CollectionAssert.IsEmpty(exception.Data); - Assert.IsNull(exception.HelpLink); - Assert.IsNull(exception.InnerException); - Assert.IsNull(exception.Source); - Assert.IsNull(exception.StackTrace); - Assert.IsNull(exception.TargetSite); - } - - [Test] - public void MessageConstructor_ExpectedValues() - { - // Setup - const string messageText = ""; - - // Call - var exception = new CriticalFileValidationException(messageText); - - // Assert - Assert.IsInstanceOf(exception); - Assert.AreEqual(messageText, exception.Message); - CollectionAssert.IsEmpty(exception.Data); - Assert.IsNull(exception.HelpLink); - Assert.IsNull(exception.InnerException); - Assert.IsNull(exception.Source); - Assert.IsNull(exception.StackTrace); - Assert.IsNull(exception.TargetSite); - } - - [Test] - public void MessageAndInnerExceptionConstructor_ExpectedValues() - { - // Setup - var innerException = new Exception(); - const string messageText = ""; - - // Call - var exception = new CriticalFileValidationException(messageText, innerException); - - // Assert - Assert.IsInstanceOf(exception); - Assert.AreEqual(messageText, exception.Message); - CollectionAssert.IsEmpty(exception.Data); - Assert.IsNull(exception.HelpLink); - Assert.AreSame(innerException, exception.InnerException); - Assert.IsNull(exception.Source); - Assert.IsNull(exception.StackTrace); - Assert.IsNull(exception.TargetSite); - } - - [Test] - public void Constructor_SerializationRoundTrip_ExceptionProperlyInitialized() - { - // Setup - var originalInnerException = new Exception("inner"); - var originalException = new CriticalFileValidationException("outer", originalInnerException); - - // Precondition - Assert.IsNotNull(originalException.InnerException); - Assert.IsNull(originalException.InnerException.InnerException); - - // Call - CriticalFileValidationException persistedException = SerializationTestHelper.SerializeAndDeserializeException(originalException); - - // Assert - Assert.AreEqual(originalException.Message, persistedException.Message); - Assert.IsNotNull(persistedException.InnerException); - Assert.AreEqual(originalException.InnerException.GetType(), persistedException.InnerException.GetType()); - Assert.AreEqual(originalException.InnerException.Message, persistedException.InnerException.Message); - Assert.IsNull(persistedException.InnerException.InnerException); - } - } + public class CriticalFileValidationExceptionTest : + CustomExceptionDesignGuidelinesTestFixture {} } \ No newline at end of file Index: Ringtoets/HydraRing/test/Ringtoets.HydraRing.Calculation.Test/Exceptions/HydraRingCalculationExceptionTest.cs =================================================================== diff -u -rccda7c4eae626e537cf8497367664bef0095c19f -rfa3b352bc1b1c01fc73a9a45268c5573807a6381 --- Ringtoets/HydraRing/test/Ringtoets.HydraRing.Calculation.Test/Exceptions/HydraRingCalculationExceptionTest.cs (.../HydraRingCalculationExceptionTest.cs) (revision ccda7c4eae626e537cf8497367664bef0095c19f) +++ Ringtoets/HydraRing/test/Ringtoets.HydraRing.Calculation.Test/Exceptions/HydraRingCalculationExceptionTest.cs (.../HydraRingCalculationExceptionTest.cs) (revision fa3b352bc1b1c01fc73a9a45268c5573807a6381) @@ -27,72 +27,6 @@ namespace Ringtoets.HydraRing.Calculation.Test.Exceptions { [TestFixture] - public class HydraRingCalculationExceptionTest - { - [Test] - public void DefaultConstructor_InnerExceptionNullAndMessageDefault() - { - // Setup - string expectedMessage = string.Format("Exception of type '{0}' was thrown.", typeof(HydraRingCalculationException).FullName); - - // Call - HydraRingCalculationException exception = new HydraRingCalculationException(); - - // Assert - Assert.IsInstanceOf(exception); - Assert.IsNull(exception.InnerException); - Assert.AreEqual(expectedMessage, exception.Message); - } - - [Test] - public void Constructor_WithCustomMessage_InnerExceptionNullAndMessageSetToCustom() - { - // Setup - const string expectedMessage = "Some exception message"; - - // Call - HydraRingCalculationException exception = new HydraRingCalculationException(expectedMessage); - - // Assert - Assert.IsNull(exception.InnerException); - Assert.AreEqual(expectedMessage, exception.Message); - } - - [Test] - public void Constructor_WithCustomMessageAndInnerException_InnerExceptionSetAndMessageSetToCustom() - { - // Setup - const string expectedMessage = "Some exception message"; - Exception expectedInnerException = new Exception(); - - // Call - HydraRingCalculationException exception = new HydraRingCalculationException(expectedMessage, expectedInnerException); - - // Assert - Assert.AreSame(expectedInnerException, exception.InnerException); - Assert.AreEqual(expectedMessage, exception.Message); - } - - [Test] - public void Constructor_SerializationRoundTrip_ExceptionProperlyInitialized() - { - // Setup - var originalInnerException = new Exception("inner"); - var originalException = new HydraRingCalculationException("outer", originalInnerException); - - // Precondition - Assert.IsNotNull(originalException.InnerException); - Assert.IsNull(originalException.InnerException.InnerException); - - // Call - HydraRingCalculationException persistedException = SerializationTestHelper.SerializeAndDeserializeException(originalException); - - // Assert - Assert.AreEqual(originalException.Message, persistedException.Message); - Assert.IsNotNull(persistedException.InnerException); - Assert.AreEqual(originalException.InnerException.GetType(), persistedException.InnerException.GetType()); - Assert.AreEqual(originalException.InnerException.Message, persistedException.InnerException.Message); - Assert.IsNull(persistedException.InnerException.InnerException); - } - } + public class HydraRingCalculationExceptionTest : + CustomExceptionDesignGuidelinesTestFixture {} } \ No newline at end of file Index: Ringtoets/HydraRing/test/Ringtoets.HydraRing.Calculation.Test/Exceptions/HydraRingFileParserExceptionTest.cs =================================================================== diff -u -r12fa48e392e145311f2f6fe5822a8692594aaf0f -rfa3b352bc1b1c01fc73a9a45268c5573807a6381 --- Ringtoets/HydraRing/test/Ringtoets.HydraRing.Calculation.Test/Exceptions/HydraRingFileParserExceptionTest.cs (.../HydraRingFileParserExceptionTest.cs) (revision 12fa48e392e145311f2f6fe5822a8692594aaf0f) +++ Ringtoets/HydraRing/test/Ringtoets.HydraRing.Calculation.Test/Exceptions/HydraRingFileParserExceptionTest.cs (.../HydraRingFileParserExceptionTest.cs) (revision fa3b352bc1b1c01fc73a9a45268c5573807a6381) @@ -27,72 +27,6 @@ namespace Ringtoets.HydraRing.Calculation.Test.Exceptions { [TestFixture] - public class HydraRingFileParserExceptionTest - { - [Test] - public void DefaultConstructor_InnerExceptionNullAndMessageDefault() - { - // Setup - string expectedMessage = string.Format("Exception of type '{0}' was thrown.", typeof(HydraRingFileParserException).FullName); - - // Call - HydraRingFileParserException exception = new HydraRingFileParserException(); - - // Assert - Assert.IsInstanceOf(exception); - Assert.IsNull(exception.InnerException); - Assert.AreEqual(expectedMessage, exception.Message); - } - - [Test] - public void Constructor_WithCustomMessage_InnerExceptionNullAndMessageSetToCustom() - { - // Setup - const string expectedMessage = "Some exception message"; - - // Call - HydraRingFileParserException exception = new HydraRingFileParserException(expectedMessage); - - // Assert - Assert.IsNull(exception.InnerException); - Assert.AreEqual(expectedMessage, exception.Message); - } - - [Test] - public void Constructor_WithCustomMessageAndInnerException_InnerExceptionSetAndMessageSetToCustom() - { - // Setup - const string expectedMessage = "Some exception message"; - Exception expectedInnerException = new Exception(); - - // Call - HydraRingFileParserException exception = new HydraRingFileParserException(expectedMessage, expectedInnerException); - - // Assert - Assert.AreSame(expectedInnerException, exception.InnerException); - Assert.AreEqual(expectedMessage, exception.Message); - } - - [Test] - public void Constructor_SerializationRoundTrip_ExceptionProperlyInitialized() - { - // Setup - var originalInnerException = new Exception("inner"); - var originalException = new HydraRingFileParserException("outer", originalInnerException); - - // Precondition - Assert.IsNotNull(originalException.InnerException); - Assert.IsNull(originalException.InnerException.InnerException); - - // Call - HydraRingFileParserException persistedException = SerializationTestHelper.SerializeAndDeserializeException(originalException); - - // Assert - Assert.AreEqual(originalException.Message, persistedException.Message); - Assert.IsNotNull(persistedException.InnerException); - Assert.AreEqual(originalException.InnerException.GetType(), persistedException.InnerException.GetType()); - Assert.AreEqual(originalException.InnerException.Message, persistedException.InnerException.Message); - Assert.IsNull(persistedException.InnerException.InnerException); - } - } + public class HydraRingFileParserExceptionTest : + CustomExceptionDesignGuidelinesTestFixture {} } \ No newline at end of file Index: Ringtoets/HydraRing/test/Ringtoets.HydraRing.IO.Test/Exceptions/HydraulicBoundaryDatabaseReadExceptionTest.cs =================================================================== diff -u -r49c5da81f49a23dd6e66526d264a08bf510e6963 -rfa3b352bc1b1c01fc73a9a45268c5573807a6381 --- Ringtoets/HydraRing/test/Ringtoets.HydraRing.IO.Test/Exceptions/HydraulicBoundaryDatabaseReadExceptionTest.cs (.../HydraulicBoundaryDatabaseReadExceptionTest.cs) (revision 49c5da81f49a23dd6e66526d264a08bf510e6963) +++ Ringtoets/HydraRing/test/Ringtoets.HydraRing.IO.Test/Exceptions/HydraulicBoundaryDatabaseReadExceptionTest.cs (.../HydraulicBoundaryDatabaseReadExceptionTest.cs) (revision fa3b352bc1b1c01fc73a9a45268c5573807a6381) @@ -27,74 +27,6 @@ namespace Ringtoets.HydraRing.IO.Test.Exceptions { [TestFixture] - public class HydraulicBoundaryDatabaseReadExceptionTest - { - [Test] - public void DefaultConstructor_InnerExceptionNullAndMessageDefault() - { - // Setup - string expectedMessage = string.Format("Exception of type '{0}' was thrown.", typeof(HydraulicBoundaryDatabaseReadException).FullName); - - // Call - HydraulicBoundaryDatabaseReadException exception = new HydraulicBoundaryDatabaseReadException(); - - // Assert - Assert.IsInstanceOf(exception); - Assert.IsNull(exception.InnerException); - Assert.AreEqual(expectedMessage, exception.Message); - } - - [Test] - public void Constructor_WithCustomMessage_InnerExceptionNullAndMessageSetToCustom() - { - // Setup - const string expectedMessage = "Some exception message"; - - // Call - HydraulicBoundaryDatabaseReadException exception = new HydraulicBoundaryDatabaseReadException(expectedMessage); - - // Assert - Assert.IsInstanceOf(exception); - Assert.IsNull(exception.InnerException); - Assert.AreEqual(expectedMessage, exception.Message); - } - - [Test] - public void Constructor_WithCustomMessageAndInnerException_InnerExceptionSetAndMessageSetToCustom() - { - // Setup - const string expectedMessage = "Some exception message"; - Exception expectedInnerException = new Exception(); - - // Call - HydraulicBoundaryDatabaseReadException exception = new HydraulicBoundaryDatabaseReadException(expectedMessage, expectedInnerException); - - // Assert - Assert.IsInstanceOf(exception); - Assert.AreSame(expectedInnerException, exception.InnerException); - Assert.AreEqual(expectedMessage, exception.Message); - } - - [Test] - public void Constructor_SerializationRoundTrip_ExceptionProperlyInitialized() - { - // Setup - var originalInnerException = new Exception("inner"); - var originalException = new HydraulicBoundaryDatabaseReadException("outer", originalInnerException); - - // Precondition - Assert.IsNotNull(originalException.InnerException); - Assert.IsNull(originalException.InnerException.InnerException); - - // Call - HydraulicBoundaryDatabaseReadException persistedException = SerializationTestHelper.SerializeAndDeserializeException(originalException); - - // Assert - Assert.AreEqual(originalException.Message, persistedException.Message); - Assert.IsNotNull(persistedException.InnerException); - Assert.AreEqual(originalException.InnerException.GetType(), persistedException.InnerException.GetType()); - Assert.AreEqual(originalException.InnerException.Message, persistedException.InnerException.Message); - Assert.IsNull(persistedException.InnerException.InnerException); - } - } + public class HydraulicBoundaryDatabaseReadExceptionTest : + CustomExceptionDesignGuidelinesTestFixture {} } \ No newline at end of file Index: Ringtoets/Piping/src/Ringtoets.Piping.IO/Exceptions/PipingSoilProfileReadException.cs =================================================================== diff -u -r49c5da81f49a23dd6e66526d264a08bf510e6963 -rfa3b352bc1b1c01fc73a9a45268c5573807a6381 --- Ringtoets/Piping/src/Ringtoets.Piping.IO/Exceptions/PipingSoilProfileReadException.cs (.../PipingSoilProfileReadException.cs) (revision 49c5da81f49a23dd6e66526d264a08bf510e6963) +++ Ringtoets/Piping/src/Ringtoets.Piping.IO/Exceptions/PipingSoilProfileReadException.cs (.../PipingSoilProfileReadException.cs) (revision fa3b352bc1b1c01fc73a9a45268c5573807a6381) @@ -32,38 +32,51 @@ [Serializable] public sealed class PipingSoilProfileReadException : Exception { - private const string profileNameKey = "ProfileName"; + private const string profileNameKey = nameof(ProfileName); /// /// Initializes a new instance of the class. /// - /// The name of the profile for which this exception was thrown. - public PipingSoilProfileReadException(string profileName) - { - ProfileName = profileName; - } + public PipingSoilProfileReadException() {} /// + /// Initializes a new instance of the class + /// with a specified error message. + /// + /// The error message that explains the reason for the exception. + public PipingSoilProfileReadException(string message) : base(message) {} + + /// /// Initializes a new instance of the class /// with a specified error message. /// - /// The name of the profile for which this exception was thrown. /// The message that describes the error. - public PipingSoilProfileReadException(string profileName, string message) + /// The name of the profile for which this exception was thrown. + public PipingSoilProfileReadException(string message, string profileName) : base(message) { ProfileName = profileName; } /// + /// Initializes a new instance of the class + /// with a specified error message. + /// + /// 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 PipingSoilProfileReadException(string message, Exception inner) + : base(message, inner) {} + + /// /// 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 name of the profile for which this exception was thrown. /// The error message that explains the reason for the exception. + /// The name of the profile for which this exception was thrown. /// The exception that is the cause of the current exception, or a - /// null reference if no inner exception is specified. - public PipingSoilProfileReadException(string profileName, string message, Exception innerException) + /// null reference if no inner exception is specified. + public PipingSoilProfileReadException(string message, string profileName, Exception innerException) : base(message, innerException) { ProfileName = profileName; Index: Ringtoets/Piping/src/Ringtoets.Piping.IO/SoilProfile/LayerProperties.cs =================================================================== diff -u -rb2b9fdf365e70928a05c57966eeed30d9050e528 -rfa3b352bc1b1c01fc73a9a45268c5573807a6381 --- Ringtoets/Piping/src/Ringtoets.Piping.IO/SoilProfile/LayerProperties.cs (.../LayerProperties.cs) (revision b2b9fdf365e70928a05c57966eeed30d9050e528) +++ Ringtoets/Piping/src/Ringtoets.Piping.IO/SoilProfile/LayerProperties.cs (.../LayerProperties.cs) (revision fa3b352bc1b1c01fc73a9a45268c5573807a6381) @@ -95,7 +95,7 @@ var message = new FileReaderErrorMessageBuilder(reader.Path) .WithSubject(string.Format(Resources.PipingSoilProfileReader_SoilProfileName_0_, profileName)) .Build(string.Format(Resources.PipingSoilProfileReader_Profile_has_invalid_value_on_Column_0_, readColumn)); - throw new PipingSoilProfileReadException(profileName, message, e); + throw new PipingSoilProfileReadException(message, profileName, e); } } Index: Ringtoets/Piping/src/Ringtoets.Piping.IO/SoilProfile/SoilProfile1DReader.cs =================================================================== diff -u -rad11d25e651c47162ecf08d11a05d40bba0bebca -rfa3b352bc1b1c01fc73a9a45268c5573807a6381 --- Ringtoets/Piping/src/Ringtoets.Piping.IO/SoilProfile/SoilProfile1DReader.cs (.../SoilProfile1DReader.cs) (revision ad11d25e651c47162ecf08d11a05d40bba0bebca) +++ Ringtoets/Piping/src/Ringtoets.Piping.IO/SoilProfile/SoilProfile1DReader.cs (.../SoilProfile1DReader.cs) (revision fa3b352bc1b1c01fc73a9a45268c5573807a6381) @@ -86,7 +86,7 @@ var message = new FileReaderErrorMessageBuilder(path) .WithSubject(string.Format(Resources.PipingSoilProfileReader_SoilProfileName_0_, profileName)) .Build(e.Message); - throw new PipingSoilProfileReadException(profileName, message, e); + throw new PipingSoilProfileReadException(message, profileName, e); } } @@ -124,15 +124,15 @@ var message = new FileReaderErrorMessageBuilder(filePath) .WithSubject(string.Format(Resources.PipingSoilProfileReader_SoilProfileName_0_, profileName)) .Build(errorMessage); - return new PipingSoilProfileReadException(profileName, message, innerException); + return new PipingSoilProfileReadException(message, profileName, innerException); } private static PipingSoilProfileReadException CreatePipingSoilProfileReadException(string filePath, string profileName, Exception innerException) { var message = new FileReaderErrorMessageBuilder(filePath) .WithSubject(string.Format(Resources.PipingSoilProfileReader_SoilProfileName_0_, profileName)) .Build(innerException.Message); - return new PipingSoilProfileReadException(profileName, message, innerException); + return new PipingSoilProfileReadException(message, profileName, innerException); } private class Layer1DProperties : LayerProperties @@ -192,7 +192,7 @@ var message = new FileReaderErrorMessageBuilder(reader.Path) .WithSubject(string.Format(Resources.PipingSoilProfileReader_SoilProfileName_0_, profileName)) .Build(string.Format(Resources.PipingSoilProfileReader_Profile_has_invalid_value_on_Column_0_, readColumn)); - throw new PipingSoilProfileReadException(profileName, message, e); + throw new PipingSoilProfileReadException(message, profileName, e); } } } Index: Ringtoets/Piping/src/Ringtoets.Piping.IO/SoilProfile/SoilProfile2DReader.cs =================================================================== diff -u -r7b3f00698f1c53c6464df710234f7b4b716e9bd3 -rfa3b352bc1b1c01fc73a9a45268c5573807a6381 --- Ringtoets/Piping/src/Ringtoets.Piping.IO/SoilProfile/SoilProfile2DReader.cs (.../SoilProfile2DReader.cs) (revision 7b3f00698f1c53c6464df710234f7b4b716e9bd3) +++ Ringtoets/Piping/src/Ringtoets.Piping.IO/SoilProfile/SoilProfile2DReader.cs (.../SoilProfile2DReader.cs) (revision fa3b352bc1b1c01fc73a9a45268c5573807a6381) @@ -155,15 +155,15 @@ var message = new FileReaderErrorMessageBuilder(filePath) .WithSubject(string.Format(Resources.PipingSoilProfileReader_SoilProfileName_0_, profileName)) .Build(errorMessage); - return new PipingSoilProfileReadException(profileName, message, innerException); + return new PipingSoilProfileReadException(message, profileName, innerException); } private static PipingSoilProfileReadException CreatePipingSoilProfileReadException(string filePath, string profileName, Exception innerException) { var message = new FileReaderErrorMessageBuilder(filePath) .WithSubject(string.Format(Resources.PipingSoilProfileReader_SoilProfileName_0_, profileName)) .Build(innerException.Message); - return new PipingSoilProfileReadException(profileName, message, innerException); + return new PipingSoilProfileReadException(message, profileName, innerException); } private class RequiredProfileProperties Index: Ringtoets/Piping/test/Ringtoets.Piping.Data.Test/Exceptions/RingtoetsPipingSurfaceLineExceptionTest.cs =================================================================== diff -u -r49c5da81f49a23dd6e66526d264a08bf510e6963 -rfa3b352bc1b1c01fc73a9a45268c5573807a6381 --- Ringtoets/Piping/test/Ringtoets.Piping.Data.Test/Exceptions/RingtoetsPipingSurfaceLineExceptionTest.cs (.../RingtoetsPipingSurfaceLineExceptionTest.cs) (revision 49c5da81f49a23dd6e66526d264a08bf510e6963) +++ Ringtoets/Piping/test/Ringtoets.Piping.Data.Test/Exceptions/RingtoetsPipingSurfaceLineExceptionTest.cs (.../RingtoetsPipingSurfaceLineExceptionTest.cs) (revision fa3b352bc1b1c01fc73a9a45268c5573807a6381) @@ -27,88 +27,6 @@ namespace Ringtoets.Piping.Data.Test.Exceptions { [TestFixture] - public class RingtoetsPipingSurfaceLineExceptionExceptionTest - { - [Test] - [SetCulture("en-US")] - public void DefaultConstructor_ExpectedValues() - { - // Call - var exception = new RingtoetsPipingSurfaceLineException(); - - // Assert - Assert.IsInstanceOf(exception); - var expectedMessage = string.Format("Exception of type '{0}' was thrown.", exception.GetType()); - Assert.AreEqual(expectedMessage, exception.Message); - CollectionAssert.IsEmpty(exception.Data); - Assert.IsNull(exception.HelpLink); - Assert.IsNull(exception.InnerException); - Assert.IsNull(exception.Source); - Assert.IsNull(exception.StackTrace); - Assert.IsNull(exception.TargetSite); - } - - [Test] - public void MessageConstructor_ExpectedValues() - { - // Setup - const string messageText = ""; - - // Call - var exception = new RingtoetsPipingSurfaceLineException(messageText); - - // Assert - Assert.IsInstanceOf(exception); - Assert.AreEqual(messageText, exception.Message); - CollectionAssert.IsEmpty(exception.Data); - Assert.IsNull(exception.HelpLink); - Assert.IsNull(exception.InnerException); - Assert.IsNull(exception.Source); - Assert.IsNull(exception.StackTrace); - Assert.IsNull(exception.TargetSite); - } - - [Test] - public void MessageAndInnerExceptionConstructor_ExpectedValues() - { - // Setup - var innerException = new Exception(); - const string messageText = ""; - - // Call - var exception = new RingtoetsPipingSurfaceLineException(messageText, innerException); - - // Assert - Assert.IsInstanceOf(exception); - Assert.AreEqual(messageText, exception.Message); - CollectionAssert.IsEmpty(exception.Data); - Assert.IsNull(exception.HelpLink); - Assert.AreEqual(innerException, exception.InnerException); - Assert.IsNull(exception.Source); - Assert.IsNull(exception.StackTrace); - Assert.IsNull(exception.TargetSite); - } - - [Test] - public void Constructor_SerializationRoundTrip_ExceptionProperlyInitialized() - { - // Setup - var originalInnerException = new Exception("inner"); - var originalException = new RingtoetsPipingSurfaceLineException("outer", originalInnerException); - - // Precondition - Assert.IsNotNull(originalException.InnerException); - Assert.IsNull(originalException.InnerException.InnerException); - - // Call - RingtoetsPipingSurfaceLineException persistedException = SerializationTestHelper.SerializeAndDeserializeException(originalException); - - // Assert - Assert.AreEqual(originalException.Message, persistedException.Message); - Assert.IsNotNull(persistedException.InnerException); - Assert.AreEqual(originalException.InnerException.GetType(), persistedException.InnerException.GetType()); - Assert.AreEqual(originalException.InnerException.Message, persistedException.InnerException.Message); - Assert.IsNull(persistedException.InnerException.InnerException); - } - } + public class RingtoetsPipingSurfaceLineExceptionTest : + CustomExceptionDesignGuidelinesTestFixture {} } \ No newline at end of file Index: Ringtoets/Piping/test/Ringtoets.Piping.IO.Test/Builders/SoilLayerConversionExceptionTest.cs =================================================================== diff -u -r49c5da81f49a23dd6e66526d264a08bf510e6963 -rfa3b352bc1b1c01fc73a9a45268c5573807a6381 --- Ringtoets/Piping/test/Ringtoets.Piping.IO.Test/Builders/SoilLayerConversionExceptionTest.cs (.../SoilLayerConversionExceptionTest.cs) (revision 49c5da81f49a23dd6e66526d264a08bf510e6963) +++ Ringtoets/Piping/test/Ringtoets.Piping.IO.Test/Builders/SoilLayerConversionExceptionTest.cs (.../SoilLayerConversionExceptionTest.cs) (revision fa3b352bc1b1c01fc73a9a45268c5573807a6381) @@ -27,72 +27,6 @@ namespace Ringtoets.Piping.IO.Test.Builders { [TestFixture] - public class SoilLayerConversionExceptionTest - { - [Test] - public void DefaultConstructor_InnerExceptionNullAndMessageDefault() - { - // Setup - var expectedMessage = string.Format("Exception of type '{0}' was thrown.", - typeof(SoilLayerConversionException).FullName); - - // Call - var exception = new SoilLayerConversionException(); - - // Assert - Assert.IsNull(exception.InnerException); - Assert.AreEqual(expectedMessage, exception.Message); - } - - [Test] - public void Constructor_WithCustomMessage_InnerExceptionNullAndMessageSetToCustom() - { - // Setup - var expectedMessage = "Some exception message"; - - // Call - var exception = new SoilLayerConversionException(expectedMessage); - - // Assert - Assert.IsNull(exception.InnerException); - Assert.AreEqual(expectedMessage, exception.Message); - } - - [Test] - public void Constructor_WithCustomMessageAndInnerException_InnerExceptionSetAndMessageSetToCustom() - { - // Setup - var expectedMessage = "Some exception message"; - var expectedInnerException = new Exception(); - - // Call - var exception = new SoilLayerConversionException(expectedMessage, expectedInnerException); - - // Assert - Assert.AreSame(expectedInnerException, exception.InnerException); - Assert.AreEqual(expectedMessage, exception.Message); - } - - [Test] - public void Constructor_SerializationRoundTrip_ExceptionProperlyInitialized() - { - // Setup - var originalInnerException = new Exception("inner"); - var originalException = new SoilLayerConversionException("outer", originalInnerException); - - // Precondition - Assert.IsNotNull(originalException.InnerException); - Assert.IsNull(originalException.InnerException.InnerException); - - // Call - SoilLayerConversionException persistedException = SerializationTestHelper.SerializeAndDeserializeException(originalException); - - // Assert - Assert.AreEqual(originalException.Message, persistedException.Message); - Assert.IsNotNull(persistedException.InnerException); - Assert.AreEqual(originalException.InnerException.GetType(), persistedException.InnerException.GetType()); - Assert.AreEqual(originalException.InnerException.Message, persistedException.InnerException.Message); - Assert.IsNull(persistedException.InnerException.InnerException); - } - } + public class SoilLayerConversionExceptionTest : + CustomExceptionDesignGuidelinesTestFixture {} } \ No newline at end of file Index: Ringtoets/Piping/test/Ringtoets.Piping.IO.Test/Builders/SoilProfileBuilderExceptionTest.cs =================================================================== diff -u -r49c5da81f49a23dd6e66526d264a08bf510e6963 -rfa3b352bc1b1c01fc73a9a45268c5573807a6381 --- Ringtoets/Piping/test/Ringtoets.Piping.IO.Test/Builders/SoilProfileBuilderExceptionTest.cs (.../SoilProfileBuilderExceptionTest.cs) (revision 49c5da81f49a23dd6e66526d264a08bf510e6963) +++ Ringtoets/Piping/test/Ringtoets.Piping.IO.Test/Builders/SoilProfileBuilderExceptionTest.cs (.../SoilProfileBuilderExceptionTest.cs) (revision fa3b352bc1b1c01fc73a9a45268c5573807a6381) @@ -27,72 +27,6 @@ namespace Ringtoets.Piping.IO.Test.Builders { [TestFixture] - public class SoilProfileBuilderExceptionTest - { - [Test] - public void DefaultConstructor_InnerExceptionNullAndMessageDefault() - { - // Setup - var expectedMessage = string.Format("Exception of type '{0}' was thrown.", - typeof(SoilProfileBuilderException).FullName); - - // Call - var exception = new SoilProfileBuilderException(); - - // Assert - Assert.IsNull(exception.InnerException); - Assert.AreEqual(expectedMessage, exception.Message); - } - - [Test] - public void Constructor_WithCustomMessage_InnerExceptionNullAndMessageSetToCustom() - { - // Setup - var expectedMessage = "Some exception message"; - - // Call - var exception = new SoilProfileBuilderException(expectedMessage); - - // Assert - Assert.IsNull(exception.InnerException); - Assert.AreEqual(expectedMessage, exception.Message); - } - - [Test] - public void Constructor_WithCustomMessageAndInnerException_InnerExceptionSetAndMessageSetToCustom() - { - // Setup - var expectedMessage = "Some exception message"; - var expectedInnerException = new Exception(); - - // Call - var exception = new SoilProfileBuilderException(expectedMessage, expectedInnerException); - - // Assert - Assert.AreSame(expectedInnerException, exception.InnerException); - Assert.AreEqual(expectedMessage, exception.Message); - } - - [Test] - public void Constructor_SerializationRoundTrip_ExceptionProperlyInitialized() - { - // Setup - var originalInnerException = new Exception("inner"); - var originalException = new SoilProfileBuilderException("outer", originalInnerException); - - // Precondition - Assert.IsNotNull(originalException.InnerException); - Assert.IsNull(originalException.InnerException.InnerException); - - // Call - SoilProfileBuilderException persistedException = SerializationTestHelper.SerializeAndDeserializeException(originalException); - - // Assert - Assert.AreEqual(originalException.Message, persistedException.Message); - Assert.IsNotNull(persistedException.InnerException); - Assert.AreEqual(originalException.InnerException.GetType(), persistedException.InnerException.GetType()); - Assert.AreEqual(originalException.InnerException.Message, persistedException.InnerException.Message); - Assert.IsNull(persistedException.InnerException.InnerException); - } - } + public class SoilProfileBuilderExceptionTest : + CustomExceptionDesignGuidelinesTestFixture {} } \ No newline at end of file Index: Ringtoets/Piping/test/Ringtoets.Piping.IO.Test/Exceptions/PipingSoilProfileReadExceptionTest.cs =================================================================== diff -u -r49c5da81f49a23dd6e66526d264a08bf510e6963 -rfa3b352bc1b1c01fc73a9a45268c5573807a6381 --- Ringtoets/Piping/test/Ringtoets.Piping.IO.Test/Exceptions/PipingSoilProfileReadExceptionTest.cs (.../PipingSoilProfileReadExceptionTest.cs) (revision 49c5da81f49a23dd6e66526d264a08bf510e6963) +++ Ringtoets/Piping/test/Ringtoets.Piping.IO.Test/Exceptions/PipingSoilProfileReadExceptionTest.cs (.../PipingSoilProfileReadExceptionTest.cs) (revision fa3b352bc1b1c01fc73a9a45268c5573807a6381) @@ -27,79 +27,81 @@ namespace Ringtoets.Piping.IO.Test.Exceptions { [TestFixture] - public class PipingSoilProfileReadExceptionTest + public class PipingSoilProfileReadExceptionTest : + CustomExceptionDesignGuidelinesTestFixture { [Test] - public void Constructor_WithProfileName_InnerExceptionNullMessageDefaultAndProfileNameSet() + public void TypeParameterAndMessageConstructor_ExpectedValues() { // Setup - var profileName = "name"; - var expectedMessage = string.Format("Exception of type '{0}' was thrown.", - typeof(PipingSoilProfileReadException).FullName); + string profileName = ""; + const string messageText = ""; // Call - var exception = new PipingSoilProfileReadException(profileName); + var exception = new PipingSoilProfileReadException(messageText, profileName); // Assert - Assert.IsNull(exception.InnerException); + base.AssertMessageConstructedInstance(exception, messageText, false); Assert.AreEqual(profileName, exception.ProfileName); - Assert.AreEqual(expectedMessage, exception.Message); + Assert.AreEqual(1, exception.Data.Count); + Assert.AreEqual(exception.ProfileName, exception.Data[nameof(exception.ProfileName)]); } [Test] - public void Constructor_WithCustomMessage_InnerExceptionNullAndMessageSetToCustom() + public void TypeParameterAndMessageAndInnerExceptionConstructor_ExpectedValues() { // Setup - var profileName = "name"; - var expectedMessage = "Some exception message"; + var innerException = new Exception(); + string profileName = ""; + const string messageText = ""; // Call - var exception = new PipingSoilProfileReadException(profileName, expectedMessage); + var exception = new PipingSoilProfileReadException(messageText, profileName, innerException); // Assert - Assert.IsNull(exception.InnerException); + AssertMessageAndInnerExceptionConstructedInstance(exception, messageText, innerException, false); Assert.AreEqual(profileName, exception.ProfileName); - Assert.AreEqual(expectedMessage, exception.Message); + Assert.AreEqual(1, exception.Data.Count); + Assert.AreEqual(exception.ProfileName, exception.Data[nameof(exception.ProfileName)]); } - [Test] - public void Constructor_WithCustomMessageAndInnerException_InnerExceptionSetAndMessageSetToCustom() + protected override void AssertDefaultConstructedInstance(PipingSoilProfileReadException exception) { - // Setup - var profileName = "name"; - var expectedMessage = "Some exception message"; - var expectedInnerException = new Exception(); + base.AssertDefaultConstructedInstance(exception); + CollectionAssert.IsEmpty(exception.Data); + Assert.IsNull(exception.ProfileName); + } - // Call - var exception = new PipingSoilProfileReadException(profileName, expectedMessage, expectedInnerException); + protected override void AssertMessageConstructedInstance(PipingSoilProfileReadException exception, string messageText, + bool assertData = true) + { + base.AssertMessageConstructedInstance(exception, messageText, assertData); + if (assertData) + { + Assert.IsNull(exception.ProfileName); + } + } - // Assert - Assert.AreSame(expectedInnerException, exception.InnerException); - Assert.AreEqual(profileName, exception.ProfileName); - Assert.AreEqual(expectedMessage, exception.Message); + protected override void AssertMessageAndInnerExceptionConstructedInstance(PipingSoilProfileReadException exception, string messageText, + Exception innerException, bool assertData = true) + { + base.AssertMessageAndInnerExceptionConstructedInstance(exception, messageText, innerException, assertData); + if (assertData) + { + Assert.IsNull(exception.ProfileName); + } } - [Test] - public void Constructor_SerializationRoundTrip_ExceptionProperlyInitialized() + protected override PipingSoilProfileReadException CreateFullyConfiguredException() { - // Setup var originalInnerException = new Exception("inner"); - var originalException = new PipingSoilProfileReadException("", "outer", originalInnerException); + return new PipingSoilProfileReadException("", "", originalInnerException); + } - // Precondition - Assert.IsNotNull(originalException.InnerException); - Assert.IsNull(originalException.InnerException.InnerException); - - // Call - PipingSoilProfileReadException persistedException = SerializationTestHelper.SerializeAndDeserializeException(originalException); - - // Assert - Assert.AreEqual(originalException.Message, persistedException.Message); + protected override void AssertRoundTripResult(PipingSoilProfileReadException originalException, PipingSoilProfileReadException persistedException) + { + base.AssertRoundTripResult(originalException, persistedException); Assert.AreEqual(originalException.ProfileName, persistedException.ProfileName); - Assert.IsNotNull(persistedException.InnerException); - Assert.AreEqual(originalException.InnerException.GetType(), persistedException.InnerException.GetType()); - Assert.AreEqual(originalException.InnerException.Message, persistedException.InnerException.Message); - Assert.IsNull(persistedException.InnerException.InnerException); } } } \ No newline at end of file Index: Ringtoets/Piping/test/Ringtoets.Piping.IO.Test/Exceptions/StochasticSoilProfileReadExceptionTest.cs =================================================================== diff -u -r49c5da81f49a23dd6e66526d264a08bf510e6963 -rfa3b352bc1b1c01fc73a9a45268c5573807a6381 --- Ringtoets/Piping/test/Ringtoets.Piping.IO.Test/Exceptions/StochasticSoilProfileReadExceptionTest.cs (.../StochasticSoilProfileReadExceptionTest.cs) (revision 49c5da81f49a23dd6e66526d264a08bf510e6963) +++ Ringtoets/Piping/test/Ringtoets.Piping.IO.Test/Exceptions/StochasticSoilProfileReadExceptionTest.cs (.../StochasticSoilProfileReadExceptionTest.cs) (revision fa3b352bc1b1c01fc73a9a45268c5573807a6381) @@ -27,74 +27,6 @@ namespace Ringtoets.Piping.IO.Test.Exceptions { [TestFixture] - public class StochasticSoilProfileReadExceptionTest - { - [Test] - public void DefaultConstructor_InnerExceptionNullAndMessageDefault() - { - // Setup - string expectedMessage = string.Format("Exception of type '{0}' was thrown.", typeof(StochasticSoilProfileReadException).FullName); - - // Call - StochasticSoilProfileReadException exception = new StochasticSoilProfileReadException(); - - // Assert - Assert.IsInstanceOf(exception); - Assert.IsNull(exception.InnerException); - Assert.AreEqual(expectedMessage, exception.Message); - } - - [Test] - public void Constructor_WithCustomMessage_InnerExceptionNullAndMessageSetToCustom() - { - // Setup - const string expectedMessage = "Some exception message"; - - // Call - StochasticSoilProfileReadException exception = new StochasticSoilProfileReadException(expectedMessage); - - // Assert - Assert.IsInstanceOf(exception); - Assert.IsNull(exception.InnerException); - Assert.AreEqual(expectedMessage, exception.Message); - } - - [Test] - public void Constructor_WithCustomMessageAndInnerException_InnerExceptionSetAndMessageSetToCustom() - { - // Setup - const string expectedMessage = "Some exception message"; - Exception expectedInnerException = new Exception(); - - // Call - StochasticSoilProfileReadException exception = new StochasticSoilProfileReadException(expectedMessage, expectedInnerException); - - // Assert - Assert.IsInstanceOf(exception); - Assert.AreSame(expectedInnerException, exception.InnerException); - Assert.AreEqual(expectedMessage, exception.Message); - } - - [Test] - public void Constructor_SerializationRoundTrip_ExceptionProperlyInitialized() - { - // Setup - var originalInnerException = new Exception("inner"); - var originalException = new StochasticSoilProfileReadException("outer", originalInnerException); - - // Precondition - Assert.IsNotNull(originalException.InnerException); - Assert.IsNull(originalException.InnerException.InnerException); - - // Call - StochasticSoilProfileReadException persistedException = SerializationTestHelper.SerializeAndDeserializeException(originalException); - - // Assert - Assert.AreEqual(originalException.Message, persistedException.Message); - Assert.IsNotNull(persistedException.InnerException); - Assert.AreEqual(originalException.InnerException.GetType(), persistedException.InnerException.GetType()); - Assert.AreEqual(originalException.InnerException.Message, persistedException.InnerException.Message); - Assert.IsNull(persistedException.InnerException.InnerException); - } - } + public class StochasticSoilProfileReadExceptionTest : + CustomExceptionDesignGuidelinesTestFixture {} } \ No newline at end of file Index: Ringtoets/Piping/test/Ringtoets.Piping.KernelWrapper.Test/PipingCalculatorExceptionTest.cs =================================================================== diff -u -r49c5da81f49a23dd6e66526d264a08bf510e6963 -rfa3b352bc1b1c01fc73a9a45268c5573807a6381 --- Ringtoets/Piping/test/Ringtoets.Piping.KernelWrapper.Test/PipingCalculatorExceptionTest.cs (.../PipingCalculatorExceptionTest.cs) (revision 49c5da81f49a23dd6e66526d264a08bf510e6963) +++ Ringtoets/Piping/test/Ringtoets.Piping.KernelWrapper.Test/PipingCalculatorExceptionTest.cs (.../PipingCalculatorExceptionTest.cs) (revision fa3b352bc1b1c01fc73a9a45268c5573807a6381) @@ -26,72 +26,6 @@ namespace Ringtoets.Piping.KernelWrapper.Test { [TestFixture] - public class PipingCalculatorExceptionTest - { - [Test] - public void DefaultConstructor_InnerExceptionNullAndMessageDefault() - { - // Setup - var expectedMessage = string.Format("Exception of type '{0}' was thrown.", - typeof(PipingCalculatorException).FullName); - - // Call - var exception = new PipingCalculatorException(); - - // Assert - Assert.IsNull(exception.InnerException); - Assert.AreEqual(expectedMessage, exception.Message); - } - - [Test] - public void Constructor_WithCustomMessage_InnerExceptionNullAndMessageSetToCustom() - { - // Setup - var expectedMessage = "Some exception message"; - - // Call - var exception = new PipingCalculatorException(expectedMessage); - - // Assert - Assert.IsNull(exception.InnerException); - Assert.AreEqual(expectedMessage, exception.Message); - } - - [Test] - public void Constructor_WithCustomMessageAndInnerException_InnerExceptionSetAndMessageSetToCustom() - { - // Setup - var expectedMessage = "Some exception message"; - var expectedInnerException = new Exception(); - - // Call - var exception = new PipingCalculatorException(expectedMessage, expectedInnerException); - - // Assert - Assert.AreSame(expectedInnerException, exception.InnerException); - Assert.AreEqual(expectedMessage, exception.Message); - } - - [Test] - public void Constructor_SerializationRoundTrip_ExceptionProperlyInitialized() - { - // Setup - var originalInnerException = new Exception("inner"); - var originalException = new PipingCalculatorException("outer", originalInnerException); - - // Precondition - Assert.IsNotNull(originalException.InnerException); - Assert.IsNull(originalException.InnerException.InnerException); - - // Call - PipingCalculatorException persistedException = SerializationTestHelper.SerializeAndDeserializeException(originalException); - - // Assert - Assert.AreEqual(originalException.Message, persistedException.Message); - Assert.IsNotNull(persistedException.InnerException); - Assert.AreEqual(originalException.InnerException.GetType(), persistedException.InnerException.GetType()); - Assert.AreEqual(originalException.InnerException.Message, persistedException.InnerException.Message); - Assert.IsNull(persistedException.InnerException.InnerException); - } - } + public class PipingCalculatorExceptionTest : + CustomExceptionDesignGuidelinesTestFixture {} } \ No newline at end of file Index: Ringtoets/Piping/test/Ringtoets.Piping.KernelWrapper.Test/PipingProfileCreatorExceptionTest.cs =================================================================== diff -u -r49c5da81f49a23dd6e66526d264a08bf510e6963 -rfa3b352bc1b1c01fc73a9a45268c5573807a6381 --- Ringtoets/Piping/test/Ringtoets.Piping.KernelWrapper.Test/PipingProfileCreatorExceptionTest.cs (.../PipingProfileCreatorExceptionTest.cs) (revision 49c5da81f49a23dd6e66526d264a08bf510e6963) +++ Ringtoets/Piping/test/Ringtoets.Piping.KernelWrapper.Test/PipingProfileCreatorExceptionTest.cs (.../PipingProfileCreatorExceptionTest.cs) (revision fa3b352bc1b1c01fc73a9a45268c5573807a6381) @@ -26,72 +26,6 @@ namespace Ringtoets.Piping.KernelWrapper.Test { [TestFixture] - public class PipingProfileCreatorExceptionTest - { - [Test] - public void DefaultConstructor_InnerExceptionNullAndMessageDefault() - { - // Setup - var expectedMessage = string.Format("Exception of type '{0}' was thrown.", - typeof(PipingProfileCreatorException).FullName); - - // Call - var exception = new PipingProfileCreatorException(); - - // Assert - Assert.IsNull(exception.InnerException); - Assert.AreEqual(expectedMessage, exception.Message); - } - - [Test] - public void Constructor_WithCustomMessage_InnerExceptionNullAndMessageSetToCustom() - { - // Setup - var expectedMessage = "Some exception message"; - - // Call - var exception = new PipingProfileCreatorException(expectedMessage); - - // Assert - Assert.IsNull(exception.InnerException); - Assert.AreEqual(expectedMessage, exception.Message); - } - - [Test] - public void Constructor_WithCustomMessageAndInnerException_InnerExceptionSetAndMessageSetToCustom() - { - // Setup - var expectedMessage = "Some exception message"; - var expectedInnerException = new Exception(); - - // Call - var exception = new PipingProfileCreatorException(expectedMessage, expectedInnerException); - - // Assert - Assert.AreSame(expectedInnerException, exception.InnerException); - Assert.AreEqual(expectedMessage, exception.Message); - } - - [Test] - public void Constructor_SerializationRoundTrip_ExceptionProperlyInitialized() - { - // Setup - var originalInnerException = new Exception("inner"); - var originalException = new PipingProfileCreatorException("outer", originalInnerException); - - // Precondition - Assert.IsNotNull(originalException.InnerException); - Assert.IsNull(originalException.InnerException.InnerException); - - // Call - PipingProfileCreatorException persistedException = SerializationTestHelper.SerializeAndDeserializeException(originalException); - - // Assert - Assert.AreEqual(originalException.Message, persistedException.Message); - Assert.IsNotNull(persistedException.InnerException); - Assert.AreEqual(originalException.InnerException.GetType(), persistedException.InnerException.GetType()); - Assert.AreEqual(originalException.InnerException.Message, persistedException.InnerException.Message); - Assert.IsNull(persistedException.InnerException.InnerException); - } - } + public class PipingProfileCreatorExceptionTest : + CustomExceptionDesignGuidelinesTestFixture {} } \ No newline at end of file