Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Application.Ringtoets.Storage.csproj
===================================================================
diff -u -r39db35bed5aea7238bcb03d842598ee87a002390 -r985570095b487598c6c2ae93b92e2bce65bf7e90
--- Application/Ringtoets/src/Application.Ringtoets.Storage/Application.Ringtoets.Storage.csproj (.../Application.Ringtoets.Storage.csproj) (revision 39db35bed5aea7238bcb03d842598ee87a002390)
+++ Application/Ringtoets/src/Application.Ringtoets.Storage/Application.Ringtoets.Storage.csproj (.../Application.Ringtoets.Storage.csproj) (revision 985570095b487598c6c2ae93b92e2bce65bf7e90)
@@ -89,7 +89,6 @@
Resources.resx
- RingtoetsEntities.tt
Index: Application/Ringtoets/src/Application.Ringtoets.Storage/StorageSqLite.cs
===================================================================
diff -u -r4446122883b6ed79c3588f838854a2df9bdc5b6b -r985570095b487598c6c2ae93b92e2bce65bf7e90
--- Application/Ringtoets/src/Application.Ringtoets.Storage/StorageSqLite.cs (.../StorageSqLite.cs) (revision 4446122883b6ed79c3588f838854a2df9bdc5b6b)
+++ Application/Ringtoets/src/Application.Ringtoets.Storage/StorageSqLite.cs (.../StorageSqLite.cs) (revision 985570095b487598c6c2ae93b92e2bce65bf7e90)
@@ -8,6 +8,7 @@
using Application.Ringtoets.Storage.Properties;
using Core.Common.Base.Data;
using Core.Common.Base.Storage;
+using Core.Common.Utils;
using Core.Common.Utils.Builders;
using UtilsResources = Core.Common.Utils.Properties.Resources;
@@ -16,8 +17,11 @@
///
/// This class interacts with an SQLite database file using the Entity Framework.
///
- public class StorageSqLite : StorageToDatabaseFile, IStoreProject
+ public class StorageSqLite : IStoreProject
{
+ private string filePath;
+ private string connectionString;
+
///
/// Converts to a new in the database.
///
@@ -26,18 +30,18 @@
/// Returns the number of changes that were saved in .
/// Thrown when is null.
/// is invalid.
- /// Thrown when the database does not contain the table version.
- /// Thrown when was not created.
- /// Thrown when
+ /// Thrown when
///
+ /// The database does not contain the table version
+ /// THe file was not created.
/// Saving the to the database failed.
/// The connection to the database file failed.
///
///
public int SaveProjectAs(string databaseFilePath, Project project)
{
- ConnectToNew(databaseFilePath);
- using (var dbContext = new RingtoetsEntities(ConnectionString))
+ SetConnectionToNewFile(databaseFilePath);
+ using (var dbContext = new RingtoetsEntities(connectionString))
{
var entity = ProjectEntityConverter.InsertProjectEntity(dbContext.ProjectEntities, project);
try
@@ -48,11 +52,11 @@
}
catch (DataException exception)
{
- throw CreateUpdateStorageException(Resources.Error_Update_Database, exception);
+ throw CreateStorageWriterException(Resources.Error_Update_Database, exception);
}
catch (SystemException exception)
{
- throw CreateUpdateStorageException(Resources.Error_During_Connection, exception);
+ throw CreateStorageWriterException(Resources.Error_During_Connection, exception);
}
}
}
@@ -65,23 +69,23 @@
/// Returns the number of changes that were saved in .
/// Thrown when is null.
/// is invalid.
- /// Thrown when the database does not contain the table version.
- /// Thrown when does not exist.
/// Thrown when
///
+ /// does not exist.
+ /// The database does not contain the table version.
/// Saving the to the database failed.
/// The connection to the database file failed.
/// The related entity was not found in the database. Therefore, no update was possible.
///
///
public int SaveProject(string databaseFilePath, Project project)
{
- Connect(databaseFilePath);
+ SetConnectionToFile(databaseFilePath);
if (project == null)
{
throw new ArgumentNullException("project");
}
- using (var dbContext = new RingtoetsEntities(ConnectionString))
+ using (var dbContext = new RingtoetsEntities(connectionString))
{
try
{
@@ -90,15 +94,15 @@
}
catch (EntityNotFoundException)
{
- throw CreateUpdateStorageException(string.Format(Resources.Error_Entity_Not_Found_0_1, "project", project.StorageId));
+ throw CreateStorageWriterException(string.Format(Resources.Error_Entity_Not_Found_0_1, "project", project.StorageId));
}
catch (DataException exception)
{
- throw CreateUpdateStorageException(Resources.Error_Update_Database, exception);
+ throw CreateStorageWriterException(Resources.Error_Update_Database, exception);
}
catch (SystemException exception)
{
- throw CreateUpdateStorageException(Resources.Error_During_Connection, exception);
+ throw CreateStorageWriterException(Resources.Error_During_Connection, exception);
}
}
}
@@ -113,61 +117,86 @@
/// Thrown when the database does not contain the table version.
public Project LoadProject(string databaseFilePath)
{
- Connect(databaseFilePath);
- using (var dbContext = new RingtoetsEntities(ConnectionString))
+ SetConnectionToFile(databaseFilePath);
+ using (var dbContext = new RingtoetsEntities(connectionString))
{
return ProjectEntityConverter.GetProject(dbContext.ProjectEntities);
}
}
///
- /// Attempts to connect to existing storage file .
+ /// Throws a configured instance of when writing to the storage file failed.
///
+ /// The critical error message.
+ /// Optional: exception that caused this exception to be thrown.
+ /// Returns a new .
+ private StorageException CreateStorageWriterException(string errorMessage, Exception innerException = null)
+ {
+ var message = new FileWriterErrorMessageBuilder(filePath).Build(errorMessage);
+ return new StorageException(message, innerException);
+ }
+
+ ///
+ /// Throws a configured instance of when reading the storage file failed.
+ ///
+ /// The critical error message.
+ /// Optional: exception that caused this exception to be thrown.
+ /// Returns a new .
+ private StorageException CreateStorageReaderException(string errorMessage, Exception innerException = null)
+ {
+ var message = new FileReaderErrorMessageBuilder(filePath).Build(errorMessage);
+ return new StorageException(message, innerException);
+ }
+
+ ///
+ /// Attempts to set the connection to an existing storage file .
+ ///
/// Path to database file.
/// is invalid.
- /// Thrown when does not exist.
- /// Thrown when the database does not contain the table version.
- protected override void Connect(string databaseFilePath)
+ /// Thrown when:
+ /// does not exist/// the database does not contain the table version.
+ ///
+ ///
+ private void SetConnectionToFile(string databaseFilePath)
{
- base.Connect(databaseFilePath);
+ FileUtils.ValidateFilePath(databaseFilePath);
+ filePath = databaseFilePath;
if (!File.Exists(databaseFilePath))
{
- var message = new FileReaderErrorMessageBuilder(databaseFilePath).Build(UtilsResources.Error_File_does_not_exist);
- throw new CouldNotConnectException(message);
+ throw CreateStorageReaderException("", new CouldNotConnectException(UtilsResources.Error_File_does_not_exist));
}
- ConnectionString = SqLiteConnectionStringBuilder.BuildSqLiteEntityConnectionString(databaseFilePath);
+ connectionString = SqLiteConnectionStringBuilder.BuildSqLiteEntityConnectionString(databaseFilePath);
ValidateStorage();
}
///
- /// Creates a new (empty) Ringtoets database file.
+ /// Sets the connection to a newly created (empty) Ringtoets database file.
///
/// Path to database file.
/// is invalid.
- /// Thrown when was not created.
- /// Thrown when executing DatabaseStructure script fails.
- /// Thrown when the database does not contain the table version.
- private void ConnectToNew(string databaseFilePath)
+ /// Thrown when:
+ /// was not created
+ /// executing DatabaseStructure script failed
+ /// the database does not contain the table version.
+ ///
+ ///
+ private void SetConnectionToNewFile(string databaseFilePath)
{
- base.Connect(databaseFilePath);
+ StorageSqliteCreator.CreateDatabaseStructure(databaseFilePath);
- var creator = new StorageSqliteCreator();
- creator.CreateDatabaseStructure(databaseFilePath);
-
- Connect(databaseFilePath);
+ SetConnectionToFile(databaseFilePath);
}
///
/// Validates if the connected storage is a valid Ringtoets database.
///
- /// Thrown when ConnectionString has not been set.
- /// Thrown when the database does not contain the table version.
+ /// Thrown when the database does not contain the table version.
private void ValidateStorage()
{
- using (var dbContext = new RingtoetsEntities(ConnectionString))
+ using (var dbContext = new RingtoetsEntities(connectionString))
{
try
{
@@ -176,7 +205,7 @@
}
catch
{
- throw new StorageValidationException(string.Format(Resources.Error_Validating_Database_0, FilePath));
+ throw CreateStorageReaderException("", new StorageValidationException(string.Format(Resources.Error_Validating_Database_0, filePath)));
}
}
}
Index: Application/Ringtoets/src/Application.Ringtoets.Storage/StorageSqliteCreator.cs
===================================================================
diff -u -rf165ef32cdd4f7be892d0433578709272ee7a70e -r985570095b487598c6c2ae93b92e2bce65bf7e90
--- Application/Ringtoets/src/Application.Ringtoets.Storage/StorageSqliteCreator.cs (.../StorageSqliteCreator.cs) (revision f165ef32cdd4f7be892d0433578709272ee7a70e)
+++ Application/Ringtoets/src/Application.Ringtoets.Storage/StorageSqliteCreator.cs (.../StorageSqliteCreator.cs) (revision 985570095b487598c6c2ae93b92e2bce65bf7e90)
@@ -2,30 +2,32 @@
using System.IO;
using Application.Ringtoets.Storage.Properties;
using Core.Common.Base.Storage;
+using Core.Common.Utils;
+using Core.Common.Utils.Builders;
namespace Application.Ringtoets.Storage
{
///
/// This class interacts with an empty or new SQLite database file.
///
- public class StorageSqliteCreator : StorageToDatabaseFile
+ public static class StorageSqliteCreator
{
///
/// Creates the basic database structure for a Ringtoets database file.
///
/// Path to database file.
/// is invalid.
- /// Thrown when executing DatabaseStructure script fails.
- public void CreateDatabaseStructure(string databaseFilePath)
+ /// Thrown when executing DatabaseStructure script fails.
+ public static void CreateDatabaseStructure(string databaseFilePath)
{
- Connect(databaseFilePath);
+ FileUtils.ValidateFilePath(databaseFilePath);
if (!File.Exists(databaseFilePath))
{
SQLiteConnection.CreateFile(databaseFilePath);
}
- ConnectionString = SqLiteConnectionStringBuilder.BuildSqLiteConnectionString(databaseFilePath);
- using (var dbContext = new SQLiteConnection(ConnectionString))
+ var connectionString = SqLiteConnectionStringBuilder.BuildSqLiteConnectionString(databaseFilePath);
+ using (var dbContext = new SQLiteConnection(connectionString))
{
using (var command = dbContext.CreateCommand())
{
@@ -37,7 +39,8 @@
}
catch (SQLiteException exception)
{
- throw CreateUpdateStorageException(Resources.Error_Write_Structure_to_Database, exception);
+ var message = new FileWriterErrorMessageBuilder(databaseFilePath).Build(Resources.Error_Write_Structure_to_Database);
+ throw new StorageException(message, new UpdateStorageException("", exception));
}
}
}
Fisheye: Tag 985570095b487598c6c2ae93b92e2bce65bf7e90 refers to a dead (removed) revision in file `Application/Ringtoets/src/Application.Ringtoets.Storage/StorageToDatabaseFile.cs'.
Fisheye: No comparison available. Pass `N' to diff?
Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/StorageSqLiteTest.cs
===================================================================
diff -u -r49bb6b0268c1620312b82ce18ece76fdaf86a195 -r985570095b487598c6c2ae93b92e2bce65bf7e90
--- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/StorageSqLiteTest.cs (.../StorageSqLiteTest.cs) (revision 49bb6b0268c1620312b82ce18ece76fdaf86a195)
+++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/StorageSqLiteTest.cs (.../StorageSqLiteTest.cs) (revision 985570095b487598c6c2ae93b92e2bce65bf7e90)
@@ -38,31 +38,38 @@
[Test]
[TestCase("fileDoesNotExist")]
- public void LoadProject_NonExistingPath_ThrowsCouldNotConnectException(string nonExistingPath)
+ public void LoadProject_NonExistingPath_ThrowsStorageExceptionAndCouldNotConnectException(string nonExistingPath)
{
+ // SetUp
+ string expectedMessage = String.Format(@"Fout bij het lezen van bestand '{0}': ", nonExistingPath);
+ string expectedInnerMessage = "Het bestand bestaat niet.";
+
// Call
TestDelegate test = () => new StorageSqLite().LoadProject(nonExistingPath);
// Assert
- CouldNotConnectException exception = Assert.Throws(test);
- string expectedMessage = String.Format(@"Fout bij het lezen van bestand '{0}': Het bestand bestaat niet.", nonExistingPath);
+ StorageException exception = Assert.Throws(test);
+ Assert.IsInstanceOf(exception);
+ Assert.IsInstanceOf(exception.InnerException);
Assert.AreEqual(expectedMessage, exception.Message);
+ Assert.AreEqual(expectedInnerMessage, exception.InnerException.Message);
}
[Test]
[TestCase("empty.rtd")]
- public void LoadProject_InvalidRingtoetsFile_ThrowsStorageValidationException(string validPath)
+ public void LoadProject_InvalidRingtoetsFile_ThrowsStorageExceptionAndStorageValidationException(string validPath)
{
// Setup
- var dbFile = Path.Combine(testDataPath, validPath);
+ var tempFile = Path.Combine(testDataPath, validPath);
+ string expectedInnerMessage = String.Format(@"Het bestand '{0}' is geen geldig Ringtoets bestand.", tempFile);
// Call
- TestDelegate test = () => new StorageSqLite().LoadProject(dbFile);
+ TestDelegate test = () => new StorageSqLite().LoadProject(tempFile);
// Assert
- StorageValidationException exception = Assert.Throws(test);
- string expectedMessage = String.Format(@"Het bestand '{0}' is geen geldig Ringtoets bestand.", dbFile);
- Assert.AreEqual(expectedMessage, exception.Message);
+ StorageException exception = Assert.Throws(test);
+ Assert.IsInstanceOf(exception.InnerException);
+ Assert.AreEqual(expectedInnerMessage, exception.InnerException.Message);
}
[Test]
@@ -160,23 +167,24 @@
{
// Setup
var tempFile = Path.Combine(testDataPath, "tempProjectFile.rtd");
+ string expectedMessage = String.Format(@"Fout bij het schrijven naar bestand '{0}': Een fout is opgetreden met schrijven naar het nieuwe Ringtoets bestand.", tempFile);
var project = new Project();
var storage = new StorageSqLite();
// Call
TestDelegate test = () => storage.SaveProjectAs(tempFile, project);
- // Assert
- UpdateStorageException updateStorageException;
+ StorageException exception;
using (File.Create(tempFile)) // Locks file
{
- updateStorageException = Assert.Throws(test);
+ exception = Assert.Throws(test);
}
- string expectedMessage = String.Format("Fout bij het schrijven naar bestand '{0}': {1}",
- tempFile,
- "Een fout is opgetreden met schrijven naar het nieuwe Ringtoets bestand.");
- Assert.AreEqual(expectedMessage, updateStorageException.Message);
+ // Assert
+ Assert.IsInstanceOf(exception);
+ Assert.IsInstanceOf(exception.InnerException);
+ Assert.AreEqual(expectedMessage, exception.Message);
+
// Tear Down
TearDownTempRingtoetsFile(tempFile);
}
@@ -218,22 +226,25 @@
{
// Setup
var tempFile = Path.Combine(testDataPath, "tempProjectFile.rtd");
+ string expectedMessage = String.Format(@"Fout bij het lezen van bestand '{0}': ", tempFile);
+ string expectedInnerMessage = "Het bestand bestaat niet.";
var storage = new StorageSqLite();
// Call
TestDelegate test = () => storage.SaveProject(tempFile, null);
// Assert
- CouldNotConnectException exception = Assert.Throws(test);
- string expectedMessage = String.Format(@"Fout bij het lezen van bestand '{0}': Het bestand bestaat niet.", tempFile);
+ StorageException exception = Assert.Throws(test);
Assert.AreEqual(expectedMessage, exception.Message);
+ Assert.IsInstanceOf(exception.InnerException);
+ Assert.AreEqual(expectedInnerMessage, exception.InnerException.Message);
// Tear Down
TearDownTempRingtoetsFile(tempFile);
}
[Test]
- public void SaveProject_EmptyDatabaseFile_ThrowsUpdateStorageException()
+ public void SaveProject_EmptyDatabaseFile_ThrowsStorageException()
{
// Setup
var project = new Project
@@ -247,7 +258,7 @@
TestDelegate test = () => storage.SaveProject(tempFile, project);
// Assert
- UpdateStorageException exception = Assert.Throws(test);
+ StorageException exception = Assert.Throws(test);
string expectedMessage = String.Format(@"Fout bij het schrijven naar bestand '{0}'{1}: {2}", tempFile, "",
String.Format("Het object '{0}' met id '{1}' is niet gevonden.", "project", project.StorageId));
Assert.AreEqual(expectedMessage, exception.Message);
Index: Core/Common/src/Core.Common.Base/Core.Common.Base.csproj
===================================================================
diff -u -rbcbae879035d5472efff973990ba1194e38b2ea5 -r985570095b487598c6c2ae93b92e2bce65bf7e90
--- Core/Common/src/Core.Common.Base/Core.Common.Base.csproj (.../Core.Common.Base.csproj) (revision bcbae879035d5472efff973990ba1194e38b2ea5)
+++ Core/Common/src/Core.Common.Base/Core.Common.Base.csproj (.../Core.Common.Base.csproj) (revision 985570095b487598c6c2ae93b92e2bce65bf7e90)
@@ -84,6 +84,7 @@
Properties\GlobalAssembly.cs
+
Index: Core/Common/src/Core.Common.Base/Storage/IStoreProject.cs
===================================================================
diff -u -r85053cd7be8aa42587cc2b0e25d6b98b5a5c2893 -r985570095b487598c6c2ae93b92e2bce65bf7e90
--- Core/Common/src/Core.Common.Base/Storage/IStoreProject.cs (.../IStoreProject.cs) (revision 85053cd7be8aa42587cc2b0e25d6b98b5a5c2893)
+++ Core/Common/src/Core.Common.Base/Storage/IStoreProject.cs (.../IStoreProject.cs) (revision 985570095b487598c6c2ae93b92e2bce65bf7e90)
@@ -15,22 +15,31 @@
/// Returns the number of changes that were saved.
/// is invalid.
/// Thrown when no new storage was created.
- /// Thrown when updating the storage fails.
- /// Thrown when the storage is no valid Ringtoets project.
- /// Thrown when
+ /// Thrown when
///
+ /// No new storage was created.
+ /// The storage is no valid Ringtoets project.
/// Saving the to the storage failed.
/// The connection to the storage failed.
///
///
int SaveProjectAs(string connectionArguments, Project project);
///
- ///
+ /// Converts to an existing entity in the storage.
///
///
- ///
- ///
+ /// The to save.
+ /// Returns the number of changes that were saved.
+ /// Thrown when
+ ///
+ /// does not exist.
+ /// The storage is no valid Ringtoets project.
+ /// Saving the to the storage failed.
+ /// The connection to the storage failed.
+ /// The related entity was not found in the storage. Therefore, no update was possible.
+ ///
+ ///
int SaveProject(string connectionArguments, Project project);
///
@@ -44,4 +53,4 @@
/// Thrown when the storage is no valid Ringtoets project.
Project LoadProject(string connectionArguments);
}
-}
+}
\ No newline at end of file
Index: Core/Common/src/Core.Common.Base/Storage/StorageException.cs
===================================================================
diff -u
--- Core/Common/src/Core.Common.Base/Storage/StorageException.cs (revision 0)
+++ Core/Common/src/Core.Common.Base/Storage/StorageException.cs (revision 985570095b487598c6c2ae93b92e2bce65bf7e90)
@@ -0,0 +1,32 @@
+using System;
+
+namespace Core.Common.Base.Storage
+{
+ ///
+ /// The exception that is thrown when a storage execution failed.
+ ///
+ public class StorageException : Exception
+ {
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ public StorageException() {}
+
+ ///
+ /// Initializes a new instance of the class
+ /// with a specified error message.
+ ///
+ /// The error message that explains the reason for the exception.
+ public StorageException(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 StorageException(string message, Exception inner) : base(message, inner) {}
+ }
+}
\ No newline at end of file
Index: Core/Common/src/Core.Common.Gui/StorageCommandHandler.cs
===================================================================
diff -u -rf165ef32cdd4f7be892d0433578709272ee7a70e -r985570095b487598c6c2ae93b92e2bce65bf7e90
--- Core/Common/src/Core.Common.Gui/StorageCommandHandler.cs (.../StorageCommandHandler.cs) (revision f165ef32cdd4f7be892d0433578709272ee7a70e)
+++ Core/Common/src/Core.Common.Gui/StorageCommandHandler.cs (.../StorageCommandHandler.cs) (revision 985570095b487598c6c2ae93b92e2bce65bf7e90)
@@ -91,24 +91,12 @@
{
loadedProject = storage.LoadProject(filePath);
}
- catch (ArgumentException e)
+ catch (StorageException e)
{
- log.Warn(e.Message);
+ log.Warn(e.Message, e.InnerException);
log.Warn(Resources.Project_existing_project_opening_failed);
return false;
}
- catch (CouldNotConnectException e)
- {
- log.Warn(e.Message);
- log.Warn(Resources.Project_existing_project_opening_failed);
- return false;
- }
- catch (StorageValidationException e)
- {
- log.Warn(e.Message);
- log.Warn(Resources.Project_existing_project_opening_failed);
- return false;
- }
if (loadedProject == null)
{
@@ -245,13 +233,9 @@
storage.SaveProjectAs(filePath, gui.Project);
return true;
}
- catch (Exception e)
+ catch (StorageException e)
{
- if (!(e is ArgumentException || e is CouldNotConnectException || e is StorageValidationException || e is UpdateStorageException))
- {
- throw;
- }
- log.Warn(e.Message);
+ log.Warn(e.Message, e.InnerException);
log.Warn(Resources.Project_saving_project_failed);
return false;
}
@@ -264,13 +248,9 @@
storage.SaveProject(filePath, gui.Project);
return true;
}
- catch (Exception e)
+ catch (StorageException e)
{
- if (!(e is ArgumentException || e is CouldNotConnectException || e is StorageValidationException || e is UpdateStorageException))
- {
- throw;
- }
- log.Warn(e.Message);
+ log.Warn(e.Message, e.InnerException);
log.Warn(Resources.Project_saving_project_failed);
return false;
}
Index: Core/Common/test/Core.Common.Base.Test/Core.Common.Base.Test.csproj
===================================================================
diff -u -rbcbae879035d5472efff973990ba1194e38b2ea5 -r985570095b487598c6c2ae93b92e2bce65bf7e90
--- Core/Common/test/Core.Common.Base.Test/Core.Common.Base.Test.csproj (.../Core.Common.Base.Test.csproj) (revision bcbae879035d5472efff973990ba1194e38b2ea5)
+++ Core/Common/test/Core.Common.Base.Test/Core.Common.Base.Test.csproj (.../Core.Common.Base.Test.csproj) (revision 985570095b487598c6c2ae93b92e2bce65bf7e90)
@@ -86,6 +86,7 @@
+
Index: Core/Common/test/Core.Common.Base.Test/Storage/StorageExceptionTest.cs
===================================================================
diff -u
--- Core/Common/test/Core.Common.Base.Test/Storage/StorageExceptionTest.cs (revision 0)
+++ Core/Common/test/Core.Common.Base.Test/Storage/StorageExceptionTest.cs (revision 985570095b487598c6c2ae93b92e2bce65bf7e90)
@@ -0,0 +1,54 @@
+using System;
+using Core.Common.Base.Storage;
+using NUnit.Framework;
+
+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);
+ }
+ }
+}
\ No newline at end of file