Index: Ringtoets/Migration/src/Riskeer.Migration.Core/ProjectFileMigrator.cs
===================================================================
diff -u -r28dbb95c1b189efc997079ca51c01a507f5b7543 -r88df85e961c13418c6c42e1d5264ef22fda28c65
--- Ringtoets/Migration/src/Riskeer.Migration.Core/ProjectFileMigrator.cs (.../ProjectFileMigrator.cs) (revision 28dbb95c1b189efc997079ca51c01a507f5b7543)
+++ Ringtoets/Migration/src/Riskeer.Migration.Core/ProjectFileMigrator.cs (.../ProjectFileMigrator.cs) (revision 88df85e961c13418c6c42e1d5264ef22fda28c65)
@@ -89,7 +89,7 @@
string upgradeQuery = GetStringOfStream(upgradeStream);
- return new RingtoetsUpgradeScript(fromVersion, toVersion, upgradeQuery, LogPath);
+ return new ProjectUpgradeScript(fromVersion, toVersion, upgradeQuery, LogPath);
}
#endregion
Index: Ringtoets/Migration/src/Riskeer.Migration.Core/ProjectUpgradeScript.cs
===================================================================
diff -u
--- Ringtoets/Migration/src/Riskeer.Migration.Core/ProjectUpgradeScript.cs (revision 0)
+++ Ringtoets/Migration/src/Riskeer.Migration.Core/ProjectUpgradeScript.cs (revision 88df85e961c13418c6c42e1d5264ef22fda28c65)
@@ -0,0 +1,85 @@
+// Copyright (C) Stichting Deltares 2018. 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 Migration.Scripts.Data;
+using Migration.Scripts.Data.Exceptions;
+using Ringtoets.Common.Util;
+using Riskeer.Migration.Core.Properties;
+
+namespace Riskeer.Migration.Core
+{
+ ///
+ /// Class that provides methods for the upgrading a for a specific version.
+ ///
+ public class ProjectUpgradeScript : UpgradeScript
+ {
+ private readonly string upgradeQuery;
+ private readonly string logDatabaseLocation;
+
+ ///
+ /// Creates a new instance of the class.
+ ///
+ /// The source version was designed for.
+ /// The target version was designed for.
+ /// The SQL query to upgrade from to .
+ /// The location to the log database.
+ /// Thrown when:
+ ///
+ /// - is not a valid project version,
+ /// - is not a valid project version,
+ /// - is empty, null, or consists out of only whitespace characters.
+ ///
+ public ProjectUpgradeScript(string fromVersion, string toVersion, string query, string logDatabaseLocation)
+ : base(fromVersion, toVersion)
+ {
+ if (string.IsNullOrWhiteSpace(query))
+ {
+ throw new ArgumentException(@"Query must have a value.", nameof(query));
+ }
+
+ RingtoetsVersionHelper.ValidateVersion(fromVersion);
+ RingtoetsVersionHelper.ValidateVersion(toVersion);
+
+ upgradeQuery = query;
+ this.logDatabaseLocation = logDatabaseLocation;
+ }
+
+ protected override void PerformUpgrade(string sourceLocation, string targetLocation)
+ {
+ try
+ {
+ string query = string.Format(upgradeQuery, sourceLocation, logDatabaseLocation);
+ using (var databaseFile = new ProjectDatabaseFile(targetLocation))
+ {
+ databaseFile.OpenDatabaseConnection();
+ databaseFile.ExecuteQuery(query);
+ }
+ }
+ catch (SQLiteException exception)
+ {
+ throw new CriticalMigrationException(string.Format(Resources.RingtoetsUpgradeScript_Upgrading_Version_0_To_Version_1_Failed,
+ FromVersion(), ToVersion()), exception);
+ }
+ }
+ }
+}
\ No newline at end of file
Fisheye: Tag 88df85e961c13418c6c42e1d5264ef22fda28c65 refers to a dead (removed) revision in file `Ringtoets/Migration/src/Riskeer.Migration.Core/RingtoetsUpgradeScript.cs'.
Fisheye: No comparison available. Pass `N' to diff?
Index: Ringtoets/Migration/src/Riskeer.Migration.Core/Riskeer.Migration.Core.csproj
===================================================================
diff -u -r28dbb95c1b189efc997079ca51c01a507f5b7543 -r88df85e961c13418c6c42e1d5264ef22fda28c65
--- Ringtoets/Migration/src/Riskeer.Migration.Core/Riskeer.Migration.Core.csproj (.../Riskeer.Migration.Core.csproj) (revision 28dbb95c1b189efc997079ca51c01a507f5b7543)
+++ Ringtoets/Migration/src/Riskeer.Migration.Core/Riskeer.Migration.Core.csproj (.../Riskeer.Migration.Core.csproj) (revision 88df85e961c13418c6c42e1d5264ef22fda28c65)
@@ -30,7 +30,7 @@
-
+
Index: Ringtoets/Migration/test/Riskeer.Migration.Core.Test/ProjectUpgradeScriptTest.cs
===================================================================
diff -u
--- Ringtoets/Migration/test/Riskeer.Migration.Core.Test/ProjectUpgradeScriptTest.cs (revision 0)
+++ Ringtoets/Migration/test/Riskeer.Migration.Core.Test/ProjectUpgradeScriptTest.cs (revision 88df85e961c13418c6c42e1d5264ef22fda28c65)
@@ -0,0 +1,178 @@
+// Copyright (C) Stichting Deltares 2018. 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 Core.Common.TestUtil;
+using Migration.Scripts.Data;
+using Migration.Scripts.Data.Exceptions;
+using NUnit.Framework;
+using Ringtoets.Common.Util;
+
+namespace Riskeer.Migration.Core.Test
+{
+ [TestFixture]
+ public class ProjectUpgradeScriptTest
+ {
+ [Test]
+ [TestCase("")]
+ [TestCase(null)]
+ public void Constructor_FromVersionNullOrEmpty_ThrowsArgumentException(string fromVersion)
+ {
+ // Setup
+ const string query = "Valid query";
+ string toVersion = RingtoetsVersionHelper.GetCurrentDatabaseVersion();
+
+ // Call
+ TestDelegate call = () => new ProjectUpgradeScript(fromVersion, toVersion, query, string.Empty);
+
+ // Assert
+ string paramName = Assert.Throws(call).ParamName;
+ Assert.AreEqual("fromVersion", paramName);
+ }
+
+ [Test]
+ [TestCase("")]
+ [TestCase(null)]
+ public void Constructor_ToVersionNullOrEmpty_ThrowsArgumentException(string toVersion)
+ {
+ // Setup
+ string fromVersion = RingtoetsVersionHelper.GetCurrentDatabaseVersion();
+ const string query = "Valid query";
+
+ // Call
+ TestDelegate call = () => new ProjectUpgradeScript(fromVersion, toVersion, query, string.Empty);
+
+ // Assert
+ string paramName = Assert.Throws(call).ParamName;
+ Assert.AreEqual("toVersion", paramName);
+ }
+
+ [Test]
+ [TestCase("4")]
+ public void Constructor_InvalidFromVersion_ThrowsArgumentException(string fromVersion)
+ {
+ // Setup
+ const string query = "Valid query";
+ string toVersion = RingtoetsVersionHelper.GetCurrentDatabaseVersion();
+
+ // Call
+ TestDelegate call = () => new ProjectUpgradeScript(fromVersion, toVersion, query, string.Empty);
+
+ // Assert
+ string expectedMessage = $@"'{fromVersion}' is geen geldige Ringtoets versie.";
+ TestHelper.AssertThrowsArgumentExceptionAndTestMessage(call, expectedMessage);
+ }
+
+ [Test]
+ [TestCase("4")]
+ public void Constructor_InvalidToVersion_ThrowsArgumentException(string toVersion)
+ {
+ // Setup
+ string fromVersion = RingtoetsVersionHelper.GetCurrentDatabaseVersion();
+ const string query = "Valid query";
+
+ // Call
+ TestDelegate call = () => new ProjectUpgradeScript(fromVersion, toVersion, query, string.Empty);
+
+ // Assert
+ string expectedMessage = $@"'{toVersion}' is geen geldige Ringtoets versie.";
+ TestHelper.AssertThrowsArgumentExceptionAndTestMessage(call, expectedMessage);
+ }
+
+ [Test]
+ [TestCase("")]
+ [TestCase(" ")]
+ [TestCase(null)]
+ public void Constructor_InvalidQuery_ThrowsArgumentException(string query)
+ {
+ // Setup
+ string fromVersion = RingtoetsVersionHelper.GetCurrentDatabaseVersion();
+ string toVersion = RingtoetsVersionHelper.GetCurrentDatabaseVersion();
+
+ // Call
+ TestDelegate call = () => new ProjectUpgradeScript(fromVersion, toVersion, query, string.Empty);
+
+ // Assert
+ string paramName = Assert.Throws(call).ParamName;
+ Assert.AreEqual("query", paramName);
+ }
+
+ [Test]
+ public void Constructor_ValidParameters_ReturnsExpectedValues()
+ {
+ // Setup
+ string fromVersion = RingtoetsVersionHelper.GetCurrentDatabaseVersion();
+ string toVersion = RingtoetsVersionHelper.GetCurrentDatabaseVersion();
+ const string query = ";";
+
+ // Call
+ var upgradeScript = new ProjectUpgradeScript(fromVersion, toVersion, query, string.Empty);
+
+ // Assert
+ Assert.IsInstanceOf(upgradeScript);
+ Assert.AreEqual(fromVersion, upgradeScript.FromVersion());
+ Assert.AreEqual(toVersion, upgradeScript.ToVersion());
+ }
+
+ [Test]
+ public void Upgrade_UpgradeFails_ThrowsCriticalMigrationException()
+ {
+ // Setup
+ string fromVersion = RingtoetsVersionHelper.GetCurrentDatabaseVersion();
+ string toVersion = RingtoetsVersionHelper.GetCurrentDatabaseVersion();
+
+ string fileLocation = TestHelper.GetScratchPadPath(nameof(Upgrade_UpgradeFails_ThrowsCriticalMigrationException));
+ var upgradeScript = new ProjectUpgradeScript(fromVersion, toVersion, "THIS WILL FAIL", string.Empty);
+
+ using (new FileDisposeHelper(fileLocation))
+ {
+ // Call
+ TestDelegate call = () => upgradeScript.Upgrade(fileLocation, fileLocation);
+
+ // Assert
+ var exception = Assert.Throws(call);
+ Assert.AreEqual($"Het migreren van het Ringtoets projectbestand van versie '{fromVersion}' naar '{fromVersion}' is mislukt.",
+ exception.Message);
+ Assert.IsInstanceOf(exception.InnerException);
+ }
+ }
+
+ [Test]
+ public void Upgrade_ValidParameters_ExpectedProperties()
+ {
+ // Setup
+ string filePath = TestHelper.GetScratchPadPath(nameof(Upgrade_ValidParameters_ExpectedProperties));
+ string fromVersion = RingtoetsVersionHelper.GetCurrentDatabaseVersion();
+ string toVersion = RingtoetsVersionHelper.GetCurrentDatabaseVersion();
+
+ var upgradeScript = new ProjectUpgradeScript(fromVersion, toVersion, ";", "");
+
+ // Call
+ upgradeScript.Upgrade("c:\\file.ext", filePath);
+
+ // Assert
+ Assert.IsTrue(File.Exists(filePath));
+ File.Delete(filePath);
+ }
+ }
+}
\ No newline at end of file
Fisheye: Tag 88df85e961c13418c6c42e1d5264ef22fda28c65 refers to a dead (removed) revision in file `Ringtoets/Migration/test/Riskeer.Migration.Core.Test/RingtoetsUpgradeScriptTest.cs'.
Fisheye: No comparison available. Pass `N' to diff?
Index: Ringtoets/Migration/test/Riskeer.Migration.Core.Test/Riskeer.Migration.Core.Test.csproj
===================================================================
diff -u -r28dbb95c1b189efc997079ca51c01a507f5b7543 -r88df85e961c13418c6c42e1d5264ef22fda28c65
--- Ringtoets/Migration/test/Riskeer.Migration.Core.Test/Riskeer.Migration.Core.Test.csproj (.../Riskeer.Migration.Core.Test.csproj) (revision 28dbb95c1b189efc997079ca51c01a507f5b7543)
+++ Ringtoets/Migration/test/Riskeer.Migration.Core.Test/Riskeer.Migration.Core.Test.csproj (.../Riskeer.Migration.Core.Test.csproj) (revision 88df85e961c13418c6c42e1d5264ef22fda28c65)
@@ -27,7 +27,7 @@
-
+