Index: Application/Ringtoets/src/Application.Ringtoets.MigrationConsole/RingtoetsMigrationTool.cs
===================================================================
diff -u -r18607ec1398cf284f9126c36558b2c6b49f61880 -raf53f335d0fa6920f7a5c4ab27b112bae9eeaede
--- Application/Ringtoets/src/Application.Ringtoets.MigrationConsole/RingtoetsMigrationTool.cs (.../RingtoetsMigrationTool.cs) (revision 18607ec1398cf284f9126c36558b2c6b49f61880)
+++ Application/Ringtoets/src/Application.Ringtoets.MigrationConsole/RingtoetsMigrationTool.cs (.../RingtoetsMigrationTool.cs) (revision af53f335d0fa6920f7a5c4ab27b112bae9eeaede)
@@ -57,7 +57,7 @@
DisplayException(exception);
DisplayAllCommands();
- if (exception is CriticalDatabaseMigrationException || exception is NotSupportedException)
+ if (exception is CriticalMigrationException || exception is NotSupportedException)
{
Exit(ErrorCode.ErrorBadCommand);
return;
Index: Application/Ringtoets/test/Application.Ringtoets.Migration.Test/Application.Ringtoets.Migration.Test.csproj
===================================================================
diff -u -r090bf03ca13a96b9e7c0a71b89f6853c303f7c02 -raf53f335d0fa6920f7a5c4ab27b112bae9eeaede
--- Application/Ringtoets/test/Application.Ringtoets.Migration.Test/Application.Ringtoets.Migration.Test.csproj (.../Application.Ringtoets.Migration.Test.csproj) (revision 090bf03ca13a96b9e7c0a71b89f6853c303f7c02)
+++ Application/Ringtoets/test/Application.Ringtoets.Migration.Test/Application.Ringtoets.Migration.Test.csproj (.../Application.Ringtoets.Migration.Test.csproj) (revision af53f335d0fa6920f7a5c4ab27b112bae9eeaede)
@@ -56,6 +56,7 @@
Properties\GlobalAssembly.cs
+
Index: Application/Ringtoets/test/Application.Ringtoets.Migration.Test/RingtoetsCreateScriptTest.cs
===================================================================
diff -u
--- Application/Ringtoets/test/Application.Ringtoets.Migration.Test/RingtoetsCreateScriptTest.cs (revision 0)
+++ Application/Ringtoets/test/Application.Ringtoets.Migration.Test/RingtoetsCreateScriptTest.cs (revision af53f335d0fa6920f7a5c4ab27b112bae9eeaede)
@@ -0,0 +1,126 @@
+// 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 General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see .
+//
+// All names, logos, and references to "Deltares" are registered trademarks of
+// Stichting Deltares and remain full property of Stichting Deltares at all times.
+// All rights reserved.
+
+using System;
+using System.IO;
+using Core.Common.TestUtil;
+using Migration.Scripts.Data;
+using NUnit.Framework;
+
+namespace Application.Ringtoets.Migration.Test
+{
+ [TestFixture]
+ public class RingtoetsCreateScriptTest
+ {
+ [Test]
+ [TestCase("")]
+ [TestCase(null)]
+ public void Constructor_InvalidVersion_ThrowsArgumentException(string version)
+ {
+ // Setup
+ const string query = "Valid query";
+
+ // Call
+ TestDelegate call = () => new RingtoetsCreateScript(version, query);
+
+ // Assert
+ string paramName = Assert.Throws(call).ParamName;
+ Assert.AreEqual("version", paramName);
+ }
+
+ [Test]
+ [TestCase("")]
+ [TestCase(" ")]
+ [TestCase(null)]
+ public void Constructor_InvalidQuery_ThrowsArgumentException(string query)
+ {
+ // Setup
+ const string version = "Valid version";
+
+ // Call
+ TestDelegate call = () => new RingtoetsCreateScript(version, query);
+
+ // Assert
+ string paramName = Assert.Throws(call).ParamName;
+ Assert.AreEqual("query", paramName);
+ }
+
+ [Test]
+ public void Constructor_ValidParameters_ExpectedValues()
+ {
+ // Setup
+ const string query = "Valid query";
+ const string version = "Valid version";
+
+ // Call
+ var createScript = new RingtoetsCreateScript(version, query);
+
+ // Assert
+ Assert.IsInstanceOf(createScript);
+ Assert.AreEqual(version, createScript.Version());
+ }
+
+ [Test]
+ public void CreateEmptyVersionedFile_FileDoesNotExist_ReturnsVersionedFile()
+ {
+ // Setup
+ const string query = ";";
+ const string version = "Valid version";
+
+ string targetFilename = Path.GetRandomFileName();
+ string filePath = TestHelper.GetTestDataPath(TestDataPath.Application.Ringtoets.Migration, targetFilename);
+ var createScript = new RingtoetsCreateScript(version, query);
+
+ // Call
+ IVersionedFile versionedFile = createScript.CreateEmptyVersionedFile(filePath);
+
+ // Assert
+ Assert.IsTrue(File.Exists(versionedFile.Location));
+ using (new FileDisposeHelper(filePath)) { }
+ }
+
+ [Test]
+ public void CreateEmptyVersionedFile_FileExistsButNotWritable_ThrowsArgumentException()
+ {
+ // Setup
+ const string query = ";";
+ const string version = "Valid version";
+
+ string filename = Path.GetRandomFileName();
+ string filePath = TestHelper.GetTestDataPath(TestDataPath.Application.Ringtoets.Migration, filename);
+ var createScript = new RingtoetsCreateScript(version, query);
+
+ using (new FileDisposeHelper(filePath))
+ {
+ FileAttributes attributes = File.GetAttributes(filePath);
+ File.SetAttributes(filePath, attributes | FileAttributes.ReadOnly);
+
+ // Call
+ TestDelegate call = () => createScript.CreateEmptyVersionedFile(filePath);
+
+ // Assert
+ ArgumentException exception = Assert.Throws(call);
+ Assert.AreEqual("path", exception.ParamName);
+ File.SetAttributes(filePath, attributes);
+ }
+ }
+ }
+}
\ No newline at end of file
Index: Application/Ringtoets/test/Application.Ringtoets.Migration.Test/RingtoetsSqLiteDatabaseFileMigratorTest.cs
===================================================================
diff -u -r214922706cd2559757df5b96982bd99cf0fe9cfa -raf53f335d0fa6920f7a5c4ab27b112bae9eeaede
--- Application/Ringtoets/test/Application.Ringtoets.Migration.Test/RingtoetsSqLiteDatabaseFileMigratorTest.cs (.../RingtoetsSqLiteDatabaseFileMigratorTest.cs) (revision 214922706cd2559757df5b96982bd99cf0fe9cfa)
+++ Application/Ringtoets/test/Application.Ringtoets.Migration.Test/RingtoetsSqLiteDatabaseFileMigratorTest.cs (.../RingtoetsSqLiteDatabaseFileMigratorTest.cs) (revision af53f335d0fa6920f7a5c4ab27b112bae9eeaede)
@@ -139,7 +139,7 @@
TestDelegate call = () => migrator.Migrate(fromVersionedFile, newVersion, targetFilePath);
// Assert
- CriticalDatabaseMigrationException exception = Assert.Throws(call);
+ CriticalMigrationException exception = Assert.Throws(call);
Assert.That(exception.Message.StartsWith("Er is een onverwachte fout opgetreden tijdens het verplaatsen van het gemigreerde bestand '"));
Assert.That(exception.Message.EndsWith($"' naar '{targetFilePath}'."));
Assert.IsInstanceOf(exception.InnerException);
@@ -159,7 +159,7 @@
TestDelegate call = () => migrator.Migrate(fromVersionedFile, newVersion, sourceFilePath);
// Assert
- CriticalDatabaseMigrationException exception = Assert.Throws(call);
+ CriticalMigrationException exception = Assert.Throws(call);
Assert.AreEqual("Het bestandspad van het uitvoerbestand moet anders zijn dan het bestandspad van het bronbestand.",
exception.Message);
}
@@ -186,7 +186,7 @@
TestDelegate call = () => migrator.Migrate(fromVersionedFile, newVersion, targetFilePath);
// Assert
- CriticalDatabaseMigrationException exception = Assert.Throws(call);
+ CriticalMigrationException exception = Assert.Throws(call);
Assert.That(exception.Message.StartsWith("Er is een onverwachte fout opgetreden tijdens het verplaatsen van het gemigreerde bestand '"));
Assert.That(exception.Message.EndsWith($"' naar '{targetFilePath}'."));
Assert.IsInstanceOf(exception.InnerException);
@@ -213,7 +213,7 @@
TestDelegate call = () => migrator.Migrate(fromVersionedFile, newVersion, targetFilePath);
// Assert
- string message = Assert.Throws(call).Message;
+ string message = Assert.Throws(call).Message;
Assert.AreEqual($"Het is niet mogelijk om versie 4 te migreren naar versie {newVersion}", message);
}
@@ -231,7 +231,7 @@
TestDelegate call = () => migrator.Migrate(fromVersionedFile, "17.1", targetFilePath);
// Assert
- string message = Assert.Throws(call).Message;
+ string message = Assert.Throws(call).Message;
Assert.AreEqual("Het upgraden van versie 8 is niet ondersteund.", message);
}
}
Index: Migration/Core/src/Migration.Core.Storage/VersionedFileMigrator.cs
===================================================================
diff -u -r5e9874d26ba517fd2271c5319aebbc879d7d27f3 -raf53f335d0fa6920f7a5c4ab27b112bae9eeaede
--- Migration/Core/src/Migration.Core.Storage/VersionedFileMigrator.cs (.../VersionedFileMigrator.cs) (revision 5e9874d26ba517fd2271c5319aebbc879d7d27f3)
+++ Migration/Core/src/Migration.Core.Storage/VersionedFileMigrator.cs (.../VersionedFileMigrator.cs) (revision af53f335d0fa6920f7a5c4ab27b112bae9eeaede)
@@ -31,19 +31,19 @@
namespace Migration.Core.Storage
{
///
- /// Class that provides methods for migrating a .
+ /// Class that provides methods for migrating a .
///
public abstract class VersionedFileMigrator
{
- private readonly IOrderedEnumerable migrationScripts;
+ private readonly IOrderedEnumerable fileMigrationScripts;
private readonly RingtoetsVersionComparer ringtoetsVersionComparer;
///
- /// Creates a new instance of the class.
+ /// Creates a new instance of the class.
///
protected VersionedFileMigrator()
{
- migrationScripts = GetAvailableMigrations()
+ fileMigrationScripts = GetAvailableMigrations()
.OrderBy(ms => ms.SupportedVersion())
.ThenByDescending(ms => ms.TargetVersion());
ringtoetsVersionComparer = new RingtoetsVersionComparer();
@@ -56,7 +56,7 @@
/// true if is supported, false otherwise.
public bool IsVersionSupported(string fromVersion)
{
- return !string.IsNullOrWhiteSpace(fromVersion) && migrationScripts.Any(ms => ms.SupportedVersion().Equals(fromVersion));
+ return !string.IsNullOrWhiteSpace(fromVersion) && fileMigrationScripts.Any(ms => ms.SupportedVersion().Equals(fromVersion));
}
///
@@ -78,25 +78,25 @@
/// The source versioned file to migrate from.
/// The version to upgrade to.
/// The location where the migrated file needs to be saved.
- /// Thrown when migrating
+ /// Thrown when migrating
/// to a new version on location failed.
public void Migrate(IVersionedFile fromVersionedFile, string toVersion, string newFileLocation)
{
if (Path.GetFullPath(fromVersionedFile.Location).Equals(Path.GetFullPath(newFileLocation)))
{
- throw new CriticalDatabaseMigrationException(Resources.Migrate_Target_File_Path_Must_Differ_From_Source_File_Path);
+ throw new CriticalMigrationException(Resources.Migrate_Target_File_Path_Must_Differ_From_Source_File_Path);
}
string fromVersion = fromVersionedFile.GetVersion();
if (!IsVersionSupported(fromVersion))
{
- throw new CriticalDatabaseMigrationException(string.Format(Resources.Upgrade_Version_0_Not_Supported,
+ throw new CriticalMigrationException(string.Format(Resources.Upgrade_Version_0_Not_Supported,
fromVersion));
}
- MigrationScript migrationScript = GetMigrationScript(fromVersion, toVersion);
+ FileMigrationScript migrationScript = GetMigrationScript(fromVersion, toVersion);
if (migrationScript == null)
{
- throw new CriticalDatabaseMigrationException(string.Format(Resources.Migrate_From_Version_0_To_Version_1_Not_Supported,
+ throw new CriticalMigrationException(string.Format(Resources.Migrate_From_Version_0_To_Version_1_Not_Supported,
fromVersion, toVersion));
}
@@ -116,7 +116,7 @@
{
var message = string.Format(Resources.Migrate_Unable_To_Move_From_Location_0_To_Location_1,
upgradedVersionFile.Location, newFileLocation);
- throw new CriticalDatabaseMigrationException(message, exception);
+ throw new CriticalMigrationException(message, exception);
}
}
}
@@ -125,9 +125,9 @@
protected abstract IEnumerable GetAvailableCreateScripts();
- private MigrationScript GetMigrationScript(string fromVersion, string toVersion)
+ private FileMigrationScript GetMigrationScript(string fromVersion, string toVersion)
{
- var supportedMigrationScripts = migrationScripts.Where(ms => ms.SupportedVersion()
+ var supportedMigrationScripts = fileMigrationScripts.Where(ms => ms.SupportedVersion()
.Equals(fromVersion));
if (!supportedMigrationScripts.Any())
@@ -139,7 +139,7 @@
?? supportedMigrationScripts.FirstOrDefault(ms => ringtoetsVersionComparer.Compare(toVersion, ms.TargetVersion()) > 0);
}
- private IEnumerable GetAvailableMigrations()
+ private IEnumerable GetAvailableMigrations()
{
IEnumerable migrationStreams = GetAvailableUpgradeScripts();
IEnumerable createScripts = GetAvailableCreateScripts();
@@ -149,7 +149,7 @@
CreateScript createScript = createScripts.FirstOrDefault(cs => cs.Version().Equals(migrationScript.ToVersion()));
if (createScript != null)
{
- yield return new MigrationScript(createScript, migrationScript);
+ yield return new FileMigrationScript(createScript, migrationScript);
}
}
}
Fisheye: Tag af53f335d0fa6920f7a5c4ab27b112bae9eeaede refers to a dead (removed) revision in file `Migration/Scripts/src/Migration.Scripts.Data/Exceptions/CriticalDatabaseMigrationException.cs'.
Fisheye: No comparison available. Pass `N' to diff?
Index: Migration/Scripts/src/Migration.Scripts.Data/Exceptions/CriticalMigrationException.cs
===================================================================
diff -u
--- Migration/Scripts/src/Migration.Scripts.Data/Exceptions/CriticalMigrationException.cs (revision 0)
+++ Migration/Scripts/src/Migration.Scripts.Data/Exceptions/CriticalMigrationException.cs (revision af53f335d0fa6920f7a5c4ab27b112bae9eeaede)
@@ -0,0 +1,58 @@
+// 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 General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see .
+//
+// All names, logos, and references to "Deltares" are registered trademarks of
+// Stichting Deltares and remain full property of Stichting Deltares at all times.
+// All rights reserved.
+
+using System;
+using System.Runtime.Serialization;
+
+namespace Migration.Scripts.Data.Exceptions
+{
+ ///
+ /// The exception that is thrown when a migration encounters a critical error during the migration.
+ ///
+ [Serializable]
+ public class CriticalMigrationException : Exception
+ {
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ public CriticalMigrationException() {}
+
+ ///
+ /// Initializes a new instance of the class
+ /// with a specified error message.
+ ///
+ /// The error message that explains the reason for the exception.
+ public CriticalMigrationException(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 CriticalMigrationException(string message, Exception inner) : base(message, inner) {}
+
+ protected CriticalMigrationException(SerializationInfo info, StreamingContext context)
+ : base(info, context) {}
+ }
+}
\ No newline at end of file
Index: Migration/Scripts/src/Migration.Scripts.Data/FileMigrationScript.cs
===================================================================
diff -u
--- Migration/Scripts/src/Migration.Scripts.Data/FileMigrationScript.cs (revision 0)
+++ Migration/Scripts/src/Migration.Scripts.Data/FileMigrationScript.cs (revision af53f335d0fa6920f7a5c4ab27b112bae9eeaede)
@@ -0,0 +1,103 @@
+// 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 General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see .
+//
+// All names, logos, and references to "Deltares" are registered trademarks of
+// Stichting Deltares and remain full property of Stichting Deltares at all times.
+// All rights reserved.
+
+using System;
+using System.Data.SQLite;
+using System.IO;
+using Migration.Scripts.Data.Exceptions;
+using Migration.Scripts.Data.Properties;
+
+namespace Migration.Scripts.Data
+{
+ ///
+ /// Class that provides methods for migration a .
+ ///
+ public class FileMigrationScript
+ {
+ private readonly CreateScript createScript;
+ private readonly UpgradeScript upgradeScript;
+
+ ///
+ /// Creates a new instance of .
+ ///
+ /// The create script to use for migrating.
+ /// The upgrade script to use for migrating.
+ /// Thrown when any of the input parameters is null.
+ public FileMigrationScript(CreateScript createScript, UpgradeScript upgradeScript)
+ {
+ if (createScript == null)
+ {
+ throw new ArgumentNullException(nameof(createScript));
+ }
+ if (upgradeScript == null)
+ {
+ throw new ArgumentNullException(nameof(upgradeScript));
+ }
+ this.createScript = createScript;
+ this.upgradeScript = upgradeScript;
+ }
+
+ ///
+ /// Gets the supported version.
+ ///
+ /// The supported version.
+ public string SupportedVersion()
+ {
+ return upgradeScript.FromVersion();
+ }
+
+ ///
+ /// Gets the target version.
+ ///
+ /// The target version.
+ public string TargetVersion()
+ {
+ return upgradeScript.ToVersion();
+ }
+
+ ///
+ /// Uses to upgrade to a new .
+ ///
+ ///
+ /// The upgraded .
+ /// Thrown when is null.
+ /// Thrown when migration failed.
+ public IVersionedFile Upgrade(IVersionedFile sourceVersionedFile)
+ {
+ if (sourceVersionedFile == null)
+ {
+ throw new ArgumentNullException(nameof(sourceVersionedFile));
+ }
+ var newLocation = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
+
+ try
+ {
+ IVersionedFile newVersionedFile = createScript.CreateEmptyVersionedFile(newLocation);
+ upgradeScript.Upgrade(sourceVersionedFile, newVersionedFile);
+ return newVersionedFile;
+ }
+ catch (SQLiteException exception)
+ {
+ throw new CriticalMigrationException(Resources.Migrate_failed, exception);
+ }
+ }
+ }
+}
\ No newline at end of file
Index: Migration/Scripts/src/Migration.Scripts.Data/Migration.Scripts.Data.csproj
===================================================================
diff -u -r090bf03ca13a96b9e7c0a71b89f6853c303f7c02 -raf53f335d0fa6920f7a5c4ab27b112bae9eeaede
--- Migration/Scripts/src/Migration.Scripts.Data/Migration.Scripts.Data.csproj (.../Migration.Scripts.Data.csproj) (revision 090bf03ca13a96b9e7c0a71b89f6853c303f7c02)
+++ Migration/Scripts/src/Migration.Scripts.Data/Migration.Scripts.Data.csproj (.../Migration.Scripts.Data.csproj) (revision af53f335d0fa6920f7a5c4ab27b112bae9eeaede)
@@ -45,9 +45,9 @@
Properties\GlobalAssembly.cs
-
+
-
+ True
Fisheye: Tag af53f335d0fa6920f7a5c4ab27b112bae9eeaede refers to a dead (removed) revision in file `Migration/Scripts/src/Migration.Scripts.Data/MigrationScript.cs'.
Fisheye: No comparison available. Pass `N' to diff?
Index: Migration/Scripts/src/Migration.Scripts.Data/UpgradeScript.cs
===================================================================
diff -u -r58d375a1c6b920e8597eae37dde622fda6a456ee -raf53f335d0fa6920f7a5c4ab27b112bae9eeaede
--- Migration/Scripts/src/Migration.Scripts.Data/UpgradeScript.cs (.../UpgradeScript.cs) (revision 58d375a1c6b920e8597eae37dde622fda6a456ee)
+++ Migration/Scripts/src/Migration.Scripts.Data/UpgradeScript.cs (.../UpgradeScript.cs) (revision af53f335d0fa6920f7a5c4ab27b112bae9eeaede)
@@ -80,12 +80,12 @@
///
/// The source file to upgrade from.
/// The target file to upgrade to.
- /// Thrown when:
+ /// Thrown when:
///
/// is null,
/// is null.
///
- /// Thrown when executing query failed.
+ /// Thrown when executing query failed.
public void Upgrade(IVersionedFile source, IVersionedFile target)
{
if (source == null)
Fisheye: Tag af53f335d0fa6920f7a5c4ab27b112bae9eeaede refers to a dead (removed) revision in file `Migration/Scripts/test/Migration.Scripts.Data.Test/Exceptions/CriticalDatabaseMigrationExceptionTest.cs'.
Fisheye: No comparison available. Pass `N' to diff?
Index: Migration/Scripts/test/Migration.Scripts.Data.Test/Exceptions/CriticalMigrationExceptionTest.cs
===================================================================
diff -u
--- Migration/Scripts/test/Migration.Scripts.Data.Test/Exceptions/CriticalMigrationExceptionTest.cs (revision 0)
+++ Migration/Scripts/test/Migration.Scripts.Data.Test/Exceptions/CriticalMigrationExceptionTest.cs (revision af53f335d0fa6920f7a5c4ab27b112bae9eeaede)
@@ -0,0 +1,115 @@
+// 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 General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see .
+//
+// All names, logos, and references to "Deltares" are registered trademarks of
+// Stichting Deltares and remain full property of Stichting Deltares at all times.
+// All rights reserved.
+
+using System;
+using Core.Common.TestUtil;
+using Migration.Scripts.Data.Exceptions;
+using NUnit.Framework;
+
+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);
+ }
+ }
+}
\ No newline at end of file
Index: Migration/Scripts/test/Migration.Scripts.Data.Test/FileMigrationScriptTest.cs
===================================================================
diff -u
--- Migration/Scripts/test/Migration.Scripts.Data.Test/FileMigrationScriptTest.cs (revision 0)
+++ Migration/Scripts/test/Migration.Scripts.Data.Test/FileMigrationScriptTest.cs (revision af53f335d0fa6920f7a5c4ab27b112bae9eeaede)
@@ -0,0 +1,110 @@
+// 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 General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see .
+//
+// All names, logos, and references to "Deltares" are registered trademarks of
+// Stichting Deltares and remain full property of Stichting Deltares at all times.
+// All rights reserved.
+
+using System;
+using NUnit.Framework;
+using Rhino.Mocks;
+
+namespace Migration.Scripts.Data.Test
+{
+ [TestFixture]
+ public class FileMigrationScriptTest
+ {
+ [Test]
+ public void Constructor_CreateScriptNull_ThrowsArgumentNullException()
+ {
+ // Setup
+ var upgradeScript = new TestUpgradeScript("1", "2");
+
+ // Call
+ TestDelegate call = () => new FileMigrationScript(null, upgradeScript);
+
+ // Assert
+ string paramName = Assert.Throws(call).ParamName;
+ Assert.AreEqual("createScript", paramName);
+ }
+
+ [Test]
+ public void Constructor_UpgradeScriptNull_ThrowsArgumentNullException()
+ {
+ // Setup
+ var createScript = new TestCreateScript("1", ";");
+
+ // Call
+ TestDelegate call = () => new FileMigrationScript(createScript, null);
+
+ // Assert
+ string paramName = Assert.Throws(call).ParamName;
+ Assert.AreEqual("upgradeScript", paramName);
+ }
+
+ [Test]
+ public void Constructor_ValidParameters_ExpectedProperties()
+ {
+ // Setup
+ var createScript = new TestCreateScript("2", ";");
+ var upgradeScript = new TestUpgradeScript("1", "2");
+
+ // Call
+ var migrationScript = new FileMigrationScript(createScript, upgradeScript);
+
+ // Assert
+ Assert.AreEqual(upgradeScript.FromVersion(), migrationScript.SupportedVersion());
+ Assert.AreEqual(upgradeScript.ToVersion(), migrationScript.TargetVersion());
+ }
+
+ [Test]
+ public void Upgrade_VersionedFileNull_ThrowsArgumentNullException()
+ {
+ // Setup
+ var createScript = new TestCreateScript("2", ";");
+ var upgradeScript = new TestUpgradeScript("1", "2");
+ var migrationScript = new FileMigrationScript(createScript, upgradeScript);
+
+ // Call
+ TestDelegate call = () => migrationScript.Upgrade(null);
+
+ // Assert
+ string paramName = Assert.Throws(call).ParamName;
+ Assert.AreEqual("sourceVersionedFile", paramName);
+ }
+
+ [Test]
+ public void Upgrade_ValidParameters_ExpectedProperties()
+ {
+ // Setup
+ var mockRepository = new MockRepository();
+ var versionedFile = mockRepository.Stub();
+ mockRepository.ReplayAll();
+
+ var createScript = new TestCreateScript("2", ";");
+ var upgradeScript = new TestUpgradeScript("1", "2");
+ var migrationScript = new FileMigrationScript(createScript, upgradeScript);
+
+ // Call
+ IVersionedFile upgradedFile = migrationScript.Upgrade(versionedFile);
+
+ // Assert
+ Assert.IsNotNull(upgradedFile);
+ mockRepository.VerifyAll();
+ }
+ }
+}
\ No newline at end of file
Index: Migration/Scripts/test/Migration.Scripts.Data.Test/Migration.Scripts.Data.Test.csproj
===================================================================
diff -u -r090bf03ca13a96b9e7c0a71b89f6853c303f7c02 -raf53f335d0fa6920f7a5c4ab27b112bae9eeaede
--- Migration/Scripts/test/Migration.Scripts.Data.Test/Migration.Scripts.Data.Test.csproj (.../Migration.Scripts.Data.Test.csproj) (revision 090bf03ca13a96b9e7c0a71b89f6853c303f7c02)
+++ Migration/Scripts/test/Migration.Scripts.Data.Test/Migration.Scripts.Data.Test.csproj (.../Migration.Scripts.Data.Test.csproj) (revision af53f335d0fa6920f7a5c4ab27b112bae9eeaede)
@@ -55,8 +55,8 @@
Properties\GlobalAssembly.cs
-
-
+
+
Fisheye: Tag af53f335d0fa6920f7a5c4ab27b112bae9eeaede refers to a dead (removed) revision in file `Migration/Scripts/test/Migration.Scripts.Data.Test/MigrationScriptTest.cs'.
Fisheye: No comparison available. Pass `N' to diff?
Index: Migration/Scripts/test/Migration.Scripts.Data.Test/UpgradeScriptTest.cs
===================================================================
diff -u -r58d375a1c6b920e8597eae37dde622fda6a456ee -raf53f335d0fa6920f7a5c4ab27b112bae9eeaede
--- Migration/Scripts/test/Migration.Scripts.Data.Test/UpgradeScriptTest.cs (.../UpgradeScriptTest.cs) (revision 58d375a1c6b920e8597eae37dde622fda6a456ee)
+++ Migration/Scripts/test/Migration.Scripts.Data.Test/UpgradeScriptTest.cs (.../UpgradeScriptTest.cs) (revision af53f335d0fa6920f7a5c4ab27b112bae9eeaede)
@@ -20,8 +20,6 @@
// All rights reserved.
using System;
-using System.IO;
-using Core.Common.TestUtil;
using NUnit.Framework;
using Rhino.Mocks;