Index: Ringtoets.sln =================================================================== diff -u -r5315fe0b9876f40e78b44ff60bf5d7ae63b05145 -r07ff2f80900d4e9b54e4a620cd82cdb80c8d2904 --- Ringtoets.sln (.../Ringtoets.sln) (revision 5315fe0b9876f40e78b44ff60bf5d7ae63b05145) +++ Ringtoets.sln (.../Ringtoets.sln) (revision 07ff2f80900d4e9b54e4a620cd82cdb80c8d2904) @@ -1942,7 +1942,7 @@ {C90B77DA-E421-43CC-B82E-529651BC21AC} = {C90B77DA-E421-43CC-B82E-529651BC21AC} EndProjectSection EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Riskeer.Migration.Core.Test", "Ringtoets\Migration\test\Ringtoets.Migration.Core.Test\Riskeer.Migration.Core.Test.csproj", "{40CF9BC7-3CDE-4AC0-B31A-851694821772}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Riskeer.Migration.Core.Test", "Ringtoets\Migration\test\Riskeer.Migration.Core.Test\Riskeer.Migration.Core.Test.csproj", "{40CF9BC7-3CDE-4AC0-B31A-851694821772}" ProjectSection(ProjectDependencies) = postProject {C90B77DA-E421-43CC-B82E-529651BC21AC} = {C90B77DA-E421-43CC-B82E-529651BC21AC} EndProjectSection Fisheye: Tag 07ff2f80900d4e9b54e4a620cd82cdb80c8d2904 refers to a dead (removed) revision in file `Ringtoets/Migration/test/Ringtoets.Migration.Core.Test/MigrationLogDatabaseReaderTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 07ff2f80900d4e9b54e4a620cd82cdb80c8d2904 refers to a dead (removed) revision in file `Ringtoets/Migration/test/Ringtoets.Migration.Core.Test/MigrationLogMessageTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 07ff2f80900d4e9b54e4a620cd82cdb80c8d2904 refers to a dead (removed) revision in file `Ringtoets/Migration/test/Ringtoets.Migration.Core.Test/Properties/AssemblyInfo.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 07ff2f80900d4e9b54e4a620cd82cdb80c8d2904 refers to a dead (removed) revision in file `Ringtoets/Migration/test/Ringtoets.Migration.Core.Test/RingtoetsCreateScriptTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 07ff2f80900d4e9b54e4a620cd82cdb80c8d2904 refers to a dead (removed) revision in file `Ringtoets/Migration/test/Ringtoets.Migration.Core.Test/RingtoetsDatabaseFileTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 07ff2f80900d4e9b54e4a620cd82cdb80c8d2904 refers to a dead (removed) revision in file `Ringtoets/Migration/test/Ringtoets.Migration.Core.Test/RingtoetsDatabaseQueryBuilderTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 07ff2f80900d4e9b54e4a620cd82cdb80c8d2904 refers to a dead (removed) revision in file `Ringtoets/Migration/test/Ringtoets.Migration.Core.Test/RingtoetsDatabaseSourceFileTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 07ff2f80900d4e9b54e4a620cd82cdb80c8d2904 refers to a dead (removed) revision in file `Ringtoets/Migration/test/Ringtoets.Migration.Core.Test/RingtoetsMigratorTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 07ff2f80900d4e9b54e4a620cd82cdb80c8d2904 refers to a dead (removed) revision in file `Ringtoets/Migration/test/Ringtoets.Migration.Core.Test/RingtoetsSqLiteDatabaseFileMigratorTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 07ff2f80900d4e9b54e4a620cd82cdb80c8d2904 refers to a dead (removed) revision in file `Ringtoets/Migration/test/Ringtoets.Migration.Core.Test/RingtoetsUpgradeScriptTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 07ff2f80900d4e9b54e4a620cd82cdb80c8d2904 refers to a dead (removed) revision in file `Ringtoets/Migration/test/Ringtoets.Migration.Core.Test/RingtoetsVersionedFileTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 07ff2f80900d4e9b54e4a620cd82cdb80c8d2904 refers to a dead (removed) revision in file `Ringtoets/Migration/test/Ringtoets.Migration.Core.Test/Riskeer.Migration.Core.Test.csproj'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 07ff2f80900d4e9b54e4a620cd82cdb80c8d2904 refers to a dead (removed) revision in file `Ringtoets/Migration/test/Ringtoets.Migration.Core.Test/packages.config'. Fisheye: No comparison available. Pass `N' to diff? Index: Ringtoets/Migration/test/Ringtoets.Migration.Core.Test/test-data/Empty valid Release 16.4.rtd =================================================================== diff -u -r6e0fe793473bfdafacfc1d89211c4d426b9209df -r07ff2f80900d4e9b54e4a620cd82cdb80c8d2904 Binary files differ Index: Ringtoets/Migration/test/Ringtoets.Migration.Core.Test/test-data/Empty valid Release 17.1.rtd =================================================================== diff -u -r6e0fe793473bfdafacfc1d89211c4d426b9209df -r07ff2f80900d4e9b54e4a620cd82cdb80c8d2904 Binary files differ Index: Ringtoets/Migration/test/Ringtoets.Migration.Core.Test/test-data/Empty valid Release 17.2.rtd =================================================================== diff -u -r6e0fe793473bfdafacfc1d89211c4d426b9209df -r07ff2f80900d4e9b54e4a620cd82cdb80c8d2904 Binary files differ Index: Ringtoets/Migration/test/Ringtoets.Migration.Core.Test/test-data/Empty valid Release 17.3.rtd =================================================================== diff -u -r6e0fe793473bfdafacfc1d89211c4d426b9209df -r07ff2f80900d4e9b54e4a620cd82cdb80c8d2904 Binary files differ Index: Ringtoets/Migration/test/Ringtoets.Migration.Core.Test/test-data/Empty valid Release 18.1.rtd =================================================================== diff -u -r4abfa78a7646ed9974c1765f39da457eb3bfd283 -r07ff2f80900d4e9b54e4a620cd82cdb80c8d2904 Binary files differ Index: Ringtoets/Migration/test/Ringtoets.Migration.Core.Test/test-data/EmptyDatabase.rtd =================================================================== diff -u -r6e0fe793473bfdafacfc1d89211c4d426b9209df -r07ff2f80900d4e9b54e4a620cd82cdb80c8d2904 Binary files differ Index: Ringtoets/Migration/test/Ringtoets.Migration.Core.Test/test-data/MigrationTestProject164.rtd =================================================================== diff -u -r6e0fe793473bfdafacfc1d89211c4d426b9209df -r07ff2f80900d4e9b54e4a620cd82cdb80c8d2904 Binary files differ Index: Ringtoets/Migration/test/Ringtoets.Migration.Core.Test/test-data/MigrationTestProject171.rtd =================================================================== diff -u -r6e0fe793473bfdafacfc1d89211c4d426b9209df -r07ff2f80900d4e9b54e4a620cd82cdb80c8d2904 Binary files differ Index: Ringtoets/Migration/test/Ringtoets.Migration.Core.Test/test-data/MigrationTestProject172.rtd =================================================================== diff -u -r6e0fe793473bfdafacfc1d89211c4d426b9209df -r07ff2f80900d4e9b54e4a620cd82cdb80c8d2904 Binary files differ Index: Ringtoets/Migration/test/Ringtoets.Migration.Core.Test/test-data/MigrationTestProject173.rtd =================================================================== diff -u -r3f909a53a418c22e355ba71a427a92fc1845efb7 -r07ff2f80900d4e9b54e4a620cd82cdb80c8d2904 Binary files differ Index: Ringtoets/Migration/test/Ringtoets.Migration.Core.Test/test-data/MigrationTestProject181.rtd =================================================================== diff -u -r6066f9fdd08ce787fbc222b3cdfabf2beee80eba -r07ff2f80900d4e9b54e4a620cd82cdb80c8d2904 Binary files differ Index: Ringtoets/Migration/test/Ringtoets.Migration.Core.Test/test-data/MigrationTestProject191.rtd =================================================================== diff -u -rf2a8f0fcaa69c61823c293f35bf7576ab3d17b89 -r07ff2f80900d4e9b54e4a620cd82cdb80c8d2904 Binary files differ Index: Ringtoets/Migration/test/Ringtoets.Migration.Core.Test/test-data/UnsupportedVersion8.rtd =================================================================== diff -u -r6e0fe793473bfdafacfc1d89211c4d426b9209df -r07ff2f80900d4e9b54e4a620cd82cdb80c8d2904 Binary files differ Index: Ringtoets/Migration/test/Ringtoets.Migration.Core.Test/test-data/emptyMigrationLog.sqlite =================================================================== diff -u -r6e0fe793473bfdafacfc1d89211c4d426b9209df -r07ff2f80900d4e9b54e4a620cd82cdb80c8d2904 Binary files differ Index: Ringtoets/Migration/test/Ringtoets.Migration.Core.Test/test-data/incompleteMigrationLog.sqlite =================================================================== diff -u -r6e0fe793473bfdafacfc1d89211c4d426b9209df -r07ff2f80900d4e9b54e4a620cd82cdb80c8d2904 Binary files differ Fisheye: Tag 07ff2f80900d4e9b54e4a620cd82cdb80c8d2904 refers to a dead (removed) revision in file `Ringtoets/Migration/test/Ringtoets.Migration.Core.Test/test-data/invalidMigrationLog.sqlite'. Fisheye: No comparison available. Pass `N' to diff? Index: Ringtoets/Migration/test/Ringtoets.Migration.Core.Test/test-data/validMigrationLog.sqlite =================================================================== diff -u -r6e0fe793473bfdafacfc1d89211c4d426b9209df -r07ff2f80900d4e9b54e4a620cd82cdb80c8d2904 Binary files differ Index: Ringtoets/Migration/test/Riskeer.Migration.Core.Test/MigrationLogDatabaseReaderTest.cs =================================================================== diff -u --- Ringtoets/Migration/test/Riskeer.Migration.Core.Test/MigrationLogDatabaseReaderTest.cs (revision 0) +++ Ringtoets/Migration/test/Riskeer.Migration.Core.Test/MigrationLogDatabaseReaderTest.cs (revision 07ff2f80900d4e9b54e4a620cd82cdb80c8d2904) @@ -0,0 +1,129 @@ +// 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.Collections.ObjectModel; +using System.Data.SQLite; +using Core.Common.Base.IO; +using Core.Common.IO.Readers; +using Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.Migration.Core.TestUtil; + +namespace Riskeer.Migration.Core.Test +{ + [TestFixture] + public class MigrationLogDatabaseReaderTest + { + private static readonly TestDataPath testPath = TestDataPath.Ringtoets.Migration.Core; + + [Test] + public void Constructor_ValidFilePath_ExpectedValues() + { + // Setup + string fileName = TestHelper.GetScratchPadPath(nameof(Constructor_ValidFilePath_ExpectedValues)); + + using (new FileDisposeHelper(fileName)) + { + // Call + using (var reader = new MigrationLogDatabaseReader(fileName)) + { + // Assert + Assert.IsInstanceOf(reader); + } + } + } + + [Test] + public void GetMigrationLogMessages_InvalidDatabaseFile_ThrowsCriticalFileReadException() + { + // Setup + string fileName = TestHelper.GetTestDataPath(testPath, "invalidMigrationLog.sqlite"); + + using (var reader = new MigrationLogDatabaseReader(fileName)) + { + // Call + TestDelegate test = () => reader.GetMigrationLogMessages(); + + // Assert + var exception = Assert.Throws(test); + Assert.AreEqual("Kritieke fout opgetreden bij het uitlezen van het Ringtoets logbestand van de migratie.", + exception.Message); + Assert.IsInstanceOf(exception.InnerException); + } + } + + [Test] + public void GetMigrationLogMessages_ValidMigrationLogFile_ReturnsExpectedLogMessages() + { + // Setup + string fileName = TestHelper.GetTestDataPath(testPath, "validMigrationLog.sqlite"); + + using (var reader = new MigrationLogDatabaseReader(fileName)) + { + // Call + ReadOnlyCollection messages = reader.GetMigrationLogMessages(); + + // Assert + Assert.AreEqual(2, messages.Count); + MigrationLogTestHelper.AssertMigrationLogMessageEqual(new MigrationLogMessage("version 1", "version 2", "some message"), + messages[0]); + MigrationLogTestHelper.AssertMigrationLogMessageEqual(new MigrationLogMessage("version 2", "version 3", "different message"), + messages[1]); + } + } + + [Test] + public void GetMigrationLogMessages_IncompleteMigrationLogFile_ThrowsCriticalFileReadException() + { + // Setup + string fileName = TestHelper.GetTestDataPath(testPath, "incompleteMigrationLog.sqlite"); + + using (var reader = new MigrationLogDatabaseReader(fileName)) + { + // Call + TestDelegate test = () => reader.GetMigrationLogMessages(); + + // Assert + var exception = Assert.Throws(test); + Assert.AreEqual("Kritieke fout opgetreden bij het uitlezen van het Ringtoets logbestand van de migratie.", + exception.Message); + Assert.IsInstanceOf(exception.InnerException); + } + } + + [Test] + public void GetMigrationLogMessages_EmptyMigrationLogFile_ReturnsEmptyLogMessages() + { + // Setup + string fileName = TestHelper.GetTestDataPath(testPath, "emptyMigrationLog.sqlite"); + + using (var reader = new MigrationLogDatabaseReader(fileName)) + { + // Call + ReadOnlyCollection messages = reader.GetMigrationLogMessages(); + + // Assert + Assert.AreEqual(0, messages.Count); + } + } + } +} \ No newline at end of file Index: Ringtoets/Migration/test/Riskeer.Migration.Core.Test/MigrationLogMessageTest.cs =================================================================== diff -u --- Ringtoets/Migration/test/Riskeer.Migration.Core.Test/MigrationLogMessageTest.cs (revision 0) +++ Ringtoets/Migration/test/Riskeer.Migration.Core.Test/MigrationLogMessageTest.cs (revision 07ff2f80900d4e9b54e4a620cd82cdb80c8d2904) @@ -0,0 +1,108 @@ +// 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 Core.Common.TestUtil; +using NUnit.Framework; + +namespace Riskeer.Migration.Core.Test +{ + [TestFixture] + public class MigrationLogMessageTest + { + [Test] + [TestCase("")] + [TestCase(null)] + public void Constructor_FromVersionNullOrEmpty_ThrowsArgumentException(string fromVersion) + { + // Setup + const string toVersion = "toVersion"; + const string message = "message"; + + // Call + TestDelegate test = () => new MigrationLogMessage(fromVersion, toVersion, message); + + // Assert + string paramName = TestHelper.AssertThrowsArgumentExceptionAndTestMessage( + test, + @"Parameter 'fromVersion' must contain a value") + .ParamName; + Assert.AreEqual("fromVersion", paramName); + } + + [Test] + [TestCase("")] + [TestCase(null)] + public void Constructor_ToVersionNullOrEmpty_ThrowsArgumentException(string toVersion) + { + // Setup + const string fromVersion = "fromVersion"; + const string message = "message"; + + // Call + TestDelegate test = () => new MigrationLogMessage(fromVersion, toVersion, message); + + // Assert + string paramName = TestHelper.AssertThrowsArgumentExceptionAndTestMessage( + test, + @"Parameter 'toVersion' must contain a value") + .ParamName; + Assert.AreEqual("toVersion", paramName); + } + + [Test] + [TestCase("")] + [TestCase(null)] + public void Constructor_MessageNullOrEmpty_ThrowsArgumentException(string message) + { + // Setup + const string fromVersion = "fromVersion"; + const string toVersion = "toVersion"; + + // Call + TestDelegate test = () => new MigrationLogMessage(fromVersion, toVersion, null); + + // Assert + string paramName = TestHelper.AssertThrowsArgumentExceptionAndTestMessage( + test, + @"Parameter 'message' must contain a value") + .ParamName; + Assert.AreEqual("message", paramName); + } + + [Test] + public void Constructor_ValidParameters_ExpectedPropertiesSet() + { + // Setup + const string fromVersion = "fromVersion"; + const string toVersion = "toVersion"; + const string message = "message"; + + // Call + var migrationLogMessage = new MigrationLogMessage(fromVersion, toVersion, message); + + // Assert + Assert.AreEqual(fromVersion, migrationLogMessage.FromVersion); + Assert.AreEqual(toVersion, migrationLogMessage.ToVersion); + Assert.AreEqual(message, migrationLogMessage.Message); + } + } +} \ No newline at end of file Index: Ringtoets/Migration/test/Riskeer.Migration.Core.Test/Properties/AssemblyInfo.cs =================================================================== diff -u --- Ringtoets/Migration/test/Riskeer.Migration.Core.Test/Properties/AssemblyInfo.cs (revision 0) +++ Ringtoets/Migration/test/Riskeer.Migration.Core.Test/Properties/AssemblyInfo.cs (revision 07ff2f80900d4e9b54e4a620cd82cdb80c8d2904) @@ -0,0 +1,25 @@ +// 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.Reflection; + +[assembly: AssemblyTitle("Riskeer.Migration.Core.Test")] +[assembly: AssemblyProduct("Riskeer.Migration.Core.Test")] \ No newline at end of file Index: Ringtoets/Migration/test/Riskeer.Migration.Core.Test/RingtoetsCreateScriptTest.cs =================================================================== diff -u --- Ringtoets/Migration/test/Riskeer.Migration.Core.Test/RingtoetsCreateScriptTest.cs (revision 0) +++ Ringtoets/Migration/test/Riskeer.Migration.Core.Test/RingtoetsCreateScriptTest.cs (revision 07ff2f80900d4e9b54e4a620cd82cdb80c8d2904) @@ -0,0 +1,165 @@ +// 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 RingtoetsCreateScriptTest + { + [Test] + [TestCase("")] + [TestCase(null)] + public void Constructor_VersionNullOrEmpty_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("4")] + public void Constructor_InvalidVersion_ThrowsArgumentException(string version) + { + // Setup + const string query = "Valid query"; + + // Call + TestDelegate call = () => new RingtoetsCreateScript(version, query); + + // Assert + string expectedMessage = $@"'{version}' is geen geldige Ringtoets versie."; + TestHelper.AssertThrowsArgumentExceptionAndTestMessage(call, expectedMessage); + } + + [Test] + [TestCase("")] + [TestCase(" ")] + [TestCase(null)] + public void Constructor_InvalidQuery_ThrowsArgumentException(string query) + { + // Setup + string version = RingtoetsVersionHelper.GetCurrentDatabaseVersion(); + + // 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"; + string version = RingtoetsVersionHelper.GetCurrentDatabaseVersion(); + + // Call + var createScript = new RingtoetsCreateScript(version, query); + + // Assert + Assert.IsInstanceOf(createScript); + Assert.AreEqual(version, createScript.GetVersion()); + } + + [Test] + public void CreateEmptyVersionedFile_FileDoesNotExist_ReturnsVersionedFile() + { + // Setup + const string query = ";"; + string version = RingtoetsVersionHelper.GetCurrentDatabaseVersion(); + + string filePath = TestHelper.GetScratchPadPath(nameof(CreateEmptyVersionedFile_FileDoesNotExist_ReturnsVersionedFile)); + var createScript = new RingtoetsCreateScript(version, query); + + // Call + IVersionedFile versionedFile = createScript.CreateEmptyVersionedFile(filePath); + + // Assert + Assert.IsTrue(File.Exists(versionedFile.Location)); + File.Delete(filePath); + } + + [Test] + public void CreateEmptyVersionedFile_FileExistsButNotWritable_ThrowsArgumentException() + { + // Setup + const string query = ";"; + string version = RingtoetsVersionHelper.GetCurrentDatabaseVersion(); + + string filePath = TestHelper.GetScratchPadPath(nameof(CreateEmptyVersionedFile_FileExistsButNotWritable_ThrowsArgumentException)); + 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 + var exception = Assert.Throws(call); + Assert.AreEqual("path", exception.ParamName); + File.SetAttributes(filePath, attributes); + } + } + + [Test] + public void CreateEmptyVersionedFile_QueryFails_ThrowsCriticalMigrationException() + { + // Setup + const string query = "THIS WILL FAIL"; + string version = RingtoetsVersionHelper.GetCurrentDatabaseVersion(); + + string filePath = TestHelper.GetScratchPadPath(nameof(CreateEmptyVersionedFile_QueryFails_ThrowsCriticalMigrationException)); + var createScript = new RingtoetsCreateScript(version, query); + + // Call + TestDelegate call = () => createScript.CreateEmptyVersionedFile(filePath); + + // Assert + using (new FileDisposeHelper(filePath)) + { + var exception = Assert.Throws(call); + Assert.AreEqual($"Het aanmaken van het Ringtoets projectbestand met versie '{version}' is mislukt.", + exception.Message); + Assert.IsInstanceOf(exception.InnerException); + } + } + } +} \ No newline at end of file Index: Ringtoets/Migration/test/Riskeer.Migration.Core.Test/RingtoetsDatabaseFileTest.cs =================================================================== diff -u --- Ringtoets/Migration/test/Riskeer.Migration.Core.Test/RingtoetsDatabaseFileTest.cs (revision 0) +++ Ringtoets/Migration/test/Riskeer.Migration.Core.Test/RingtoetsDatabaseFileTest.cs (revision 07ff2f80900d4e9b54e4a620cd82cdb80c8d2904) @@ -0,0 +1,159 @@ +// 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 NUnit.Framework; + +namespace Riskeer.Migration.Core.Test +{ + [TestFixture] + public class RingtoetsDatabaseFileTest + { + [Test] + [TestCase("")] + [TestCase(" ")] + [TestCase(null)] + public void Constructor_FilePathNullOrWhiteSpace_ThrowsArgumentException(string filePath) + { + // Call + TestDelegate call = () => + { + using (new RingtoetsDatabaseFile(filePath)) {} + }; + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual($"Fout bij het lezen van bestand '{filePath}': bestandspad mag niet leeg of ongedefinieerd zijn.", exception.Message); + } + + [Test] + public void Constructor_FileNotWritable_ThrowsArgumentException() + { + // Setup + string filePath = TestHelper.GetScratchPadPath($"{nameof(RingtoetsDatabaseFileTest)}.{nameof(Constructor_FileNotWritable_ThrowsArgumentException)}"); + + using (var helper = new FileDisposeHelper(filePath)) + { + helper.LockFiles(); + + // Call + TestDelegate call = () => + { + using (new RingtoetsDatabaseFile(filePath)) {} + }; + + // Assert + string expectedMessage = $"Er is een onverwachte fout opgetreden tijdens het schrijven van het bestand '{filePath}'."; + TestHelper.AssertThrowsArgumentExceptionAndTestMessage(call, expectedMessage); + } + } + + [Test] + [TestCase("")] + [TestCase(" ")] + [TestCase(null)] + public void ExecuteQuery_QueryIsNullOrWhiteSpace_ThrowsArgumentException(string query) + { + // Setup + string filename = Path.GetRandomFileName(); + string filePath = TestHelper.GetScratchPadPath(nameof(ExecuteQuery_QueryIsNullOrWhiteSpace_ThrowsArgumentException) + filename); + + using (new FileDisposeHelper(filePath)) + using (var databaseFile = new RingtoetsDatabaseFile(filePath)) + { + databaseFile.OpenDatabaseConnection(); + + // Call + TestDelegate call = () => databaseFile.ExecuteQuery(query); + + // Assert + TestHelper.AssertThrowsArgumentExceptionAndTestMessage(call, "Parameter must be a valid database script."); + } + } + + [Test] + public void ExecuteQuery_InvalidQuery_ThrowsSQLiteException() + { + // Setup + string filename = Path.GetRandomFileName(); + string filePath = TestHelper.GetScratchPadPath(nameof(ExecuteQuery_InvalidQuery_ThrowsSQLiteException) + filename); + + using (new FileDisposeHelper(filePath)) + using (var databaseFile = new RingtoetsDatabaseFile(filePath)) + { + databaseFile.OpenDatabaseConnection(); + + // Call + TestDelegate call = () => databaseFile.ExecuteQuery("THIS WILL FAIL"); + + // Assert + Assert.Throws(call); + } + } + + [Test] + public void ExecuteQuery_ValidQuery_CreatesFile() + { + // Setup + string filename = Path.GetRandomFileName(); + string filePath = TestHelper.GetScratchPadPath(filename); + + using (var databaseFile = new RingtoetsDatabaseFile(filePath)) + { + databaseFile.OpenDatabaseConnection(); + + // Call + databaseFile.ExecuteQuery(";"); + + // Assert + Assert.IsTrue(File.Exists(filePath)); + } + + using (new FileDisposeHelper(filePath)) {} + } + + [Test] + public void Dispose_AlreadyDisposed_DoesNotThrowException() + { + // Setup + string filename = Path.GetRandomFileName(); + string filePath = TestHelper.GetScratchPadPath(filename); + + // Call + TestDelegate call = () => + { + using (var databaseFile = new RingtoetsDatabaseFile(filePath)) + { + databaseFile.Dispose(); + } + }; + + using (new FileDisposeHelper(filePath)) + { + // Assert + Assert.DoesNotThrow(call); + } + } + } +} \ No newline at end of file Index: Ringtoets/Migration/test/Riskeer.Migration.Core.Test/RingtoetsDatabaseQueryBuilderTest.cs =================================================================== diff -u --- Ringtoets/Migration/test/Riskeer.Migration.Core.Test/RingtoetsDatabaseQueryBuilderTest.cs (revision 0) +++ Ringtoets/Migration/test/Riskeer.Migration.Core.Test/RingtoetsDatabaseQueryBuilderTest.cs (revision 07ff2f80900d4e9b54e4a620cd82cdb80c8d2904) @@ -0,0 +1,40 @@ +// 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 NUnit.Framework; + +namespace Riskeer.Migration.Core.Test +{ + [TestFixture] + public class RingtoetsDatabaseQueryBuilderTest + { + [Test] + public void GetVersionQuery_ReturnsExpectedQuery() + { + // Call + string getVersionQuery = RingtoetsDatabaseQueryBuilder.GetVersionQuery(); + + // Assert + Assert.AreEqual("SELECT Version FROM VersionEntity Order by Timestamp DESC LIMIT 1", + getVersionQuery); + } + } +} \ No newline at end of file Index: Ringtoets/Migration/test/Riskeer.Migration.Core.Test/RingtoetsDatabaseSourceFileTest.cs =================================================================== diff -u --- Ringtoets/Migration/test/Riskeer.Migration.Core.Test/RingtoetsDatabaseSourceFileTest.cs (revision 0) +++ Ringtoets/Migration/test/Riskeer.Migration.Core.Test/RingtoetsDatabaseSourceFileTest.cs (revision 07ff2f80900d4e9b54e4a620cd82cdb80c8d2904) @@ -0,0 +1,124 @@ +// 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.IO; +using Core.Common.Base.IO; +using Core.Common.Base.Storage; +using Core.Common.IO.Readers; +using Core.Common.TestUtil; +using NUnit.Framework; + +namespace Riskeer.Migration.Core.Test +{ + [TestFixture] + public class RingtoetsDatabaseSourceFileTest + { + private static readonly TestDataPath testPath = TestDataPath.Ringtoets.Migration.Core; + + [Test] + public void Constructor_NonExistingPath_ThrowsCriticalFileReadException() + { + // Setup + string fileName = Path.GetRandomFileName(); + string filePath = TestHelper.GetTestDataPath(testPath, fileName); + + // Call + TestDelegate test = () => + { + using (new RingtoetsDatabaseSourceFile(filePath)) {} + }; + + // Assert + var exception = Assert.Throws(test); + Assert.AreEqual($"Fout bij het lezen van bestand '{filePath}': het bestand bestaat niet.", + exception.Message); + } + + [Test] + [TestCase(null)] + [TestCase("")] + public void Constructor_FileNullOrEmpty_ThrowsCriticalFileReadException(string filePath) + { + // Call + TestDelegate test = () => + { + using (new RingtoetsDatabaseSourceFile(filePath)) {} + }; + + // Assert + var exception = Assert.Throws(test); + Assert.AreEqual($"Fout bij het lezen van bestand '{filePath}': bestandspad mag niet leeg of ongedefinieerd zijn.", + exception.Message); + } + + [Test] + public void Constructor_ValidPath_ExpectedProperties() + { + // Setup + string fileName = Path.GetRandomFileName(); + string filePath = TestHelper.GetTestDataPath(testPath, fileName); + + // Call + using (new FileDisposeHelper(filePath)) + using (var file = new RingtoetsDatabaseSourceFile(filePath)) + { + // Assert + Assert.IsInstanceOf(file); + } + } + + [Test] + public void GetVersion_EmptyFile_ThrowsStorageValidationException() + { + // Setup + string fileName = Path.GetRandomFileName(); + string filePath = TestHelper.GetTestDataPath(testPath, fileName); + + using (new FileDisposeHelper(filePath)) + using (var file = new RingtoetsDatabaseSourceFile(filePath)) + { + // Call + TestDelegate call = () => file.GetVersion(); + + // Assert + string message = Assert.Throws(call).Message; + Assert.AreEqual($"Het bestand '{filePath}' moet een geldig Ringtoets projectbestand zijn.", + message); + } + } + + [Test] + public void GetVersion_EmptyRingtoetsDatabaseFile_ReturnsEmpty() + { + // Setup + string filePath = TestHelper.GetTestDataPath(testPath, "EmptyDatabase.rtd"); + + using (var file = new RingtoetsDatabaseSourceFile(filePath)) + { + // Call + string version = file.GetVersion(); + + // Assert + Assert.IsEmpty(version); + } + } + } +} \ No newline at end of file Index: Ringtoets/Migration/test/Riskeer.Migration.Core.Test/RingtoetsMigratorTest.cs =================================================================== diff -u --- Ringtoets/Migration/test/Riskeer.Migration.Core.Test/RingtoetsMigratorTest.cs (revision 0) +++ Ringtoets/Migration/test/Riskeer.Migration.Core.Test/RingtoetsMigratorTest.cs (revision 07ff2f80900d4e9b54e4a620cd82cdb80c8d2904) @@ -0,0 +1,113 @@ +// 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 Migration.Core.Storage; +using NUnit.Framework; +using Rhino.Mocks; + +namespace Application.Ringtoets.Migration.Test +{ + [TestFixture] + public class RingtoetsMigratorTest + { + private MockRepository mocks; + + [SetUp] + public void Setup() + { + mocks = new MockRepository(); + } + + [TearDown] + public void TearDown() + { + mocks.VerifyAll(); + } + + [Test] + public void Constructor_InquiryHelperNull_ThrowsArgumentNullException() + { + // Call + TestDelegate call = () => new RingtoetsMigrator(null); + + // Assert + string paramName = Assert.Throws(call).ParamName; + Assert.AreEqual("versionedFileMigrator", paramName); + } + + [Test] + public void ShouldMigrate_SourcePathNull_ThrowsArgumentNullException() + { + // Setup + var versionedFileMigrator = mocks.Stub(); + var migrator = new RingtoetsMigrator(versionedFileMigrator); + + // Call + TestDelegate call = () => migrator.ShouldMigrate(null); + + // Assert + string paramName = Assert.Throws(call).ParamName; + Assert.AreEqual("sourcePath", paramName); + } + + [Test] + public void ShouldMigrateInvalidFilePath_ThrowsArgumentException() + { + // Setup + var versionedFileMigrator = mocks.Stub(); + var migrator = new RingtoetsMigrator(versionedFileMigrator); + + // Call + TestDelegate call = () => migrator.ShouldMigrate(null); + } + + [Test] + public void Migrate_SourcePathNull_ThrowsArgumentNullException() + { + // Setup + var versionedFileMigrator = mocks.Stub(); + var migrator = new RingtoetsMigrator(versionedFileMigrator); + + // Call + TestDelegate call = () => migrator.Migrate(null, string.Empty); + + // Assert + string paramName = Assert.Throws(call).ParamName; + Assert.AreEqual("sourcePath", paramName); + } + + [Test] + public void Migrate_TargetPathNull_ThrowsArgumentNullException() + { + // Setup + var versionedFileMigrator = mocks.Stub(); + var migrator = new RingtoetsMigrator(versionedFileMigrator); + + // Call + TestDelegate call = () => migrator.Migrate(string.Empty, null); + + // Assert + string paramName = Assert.Throws(call).ParamName; + Assert.AreEqual("targetPath", paramName); + } + } +} Index: Ringtoets/Migration/test/Riskeer.Migration.Core.Test/RingtoetsSqLiteDatabaseFileMigratorTest.cs =================================================================== diff -u --- Ringtoets/Migration/test/Riskeer.Migration.Core.Test/RingtoetsSqLiteDatabaseFileMigratorTest.cs (revision 0) +++ Ringtoets/Migration/test/Riskeer.Migration.Core.Test/RingtoetsSqLiteDatabaseFileMigratorTest.cs (revision 07ff2f80900d4e9b54e4a620cd82cdb80c8d2904) @@ -0,0 +1,312 @@ +// 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.Core.Storage; +using Migration.Scripts.Data.Exceptions; +using NUnit.Framework; +using Ringtoets.Migration.Core.TestUtil; + +namespace Riskeer.Migration.Core.Test +{ + [TestFixture] + public class RingtoetsSqLiteDatabaseFileMigratorTest + { + private static TestCaseData[] ValidFromVersions + { + get + { + return new[] + { + new TestCaseData("5"), + new TestCaseData("17.1"), + new TestCaseData("17.2"), + new TestCaseData("17.3") + }; + } + } + + [Test] + public void Constructor_ReturnsExpectedValues() + { + // Call + var migrator = new RingtoetsSqLiteDatabaseFileMigrator(); + + // Assert + Assert.IsInstanceOf(migrator); + } + + [Test] + [TestCaseSource(nameof(ValidFromVersions))] + public void IsVersionSupported_SupportedVersion_ReturnsTrue(string fromVersion) + { + // Setup + var migrator = new RingtoetsSqLiteDatabaseFileMigrator(); + + // Call + bool isSupported = migrator.IsVersionSupported(fromVersion); + + // Assert + Assert.IsTrue(isSupported); + } + + [Test] + [TestCase("16.4")] + [TestCase("19.2")] + public void IsVersionSupported_UnsupportedVersion_ReturnsFalse(string fromVersion) + { + // Setup + var migrator = new RingtoetsSqLiteDatabaseFileMigrator(); + + // Call + bool isSupported = migrator.IsVersionSupported(fromVersion); + + // Assert + Assert.IsFalse(isSupported); + } + + [Test] + public void NeedsMigrate_NeedsMigrate_ReturnsTrue() + { + // Setup + string sourceFilePath = RingtoetsProjectMigrationTestHelper.GetOutdatedSupportedProjectFilePath(); + var versionedFile = new RingtoetsVersionedFile(sourceFilePath); + var migrator = new RingtoetsSqLiteDatabaseFileMigrator(); + + // Call + bool needsMigrate = migrator.NeedsMigrate(versionedFile, "17.1"); + + // Assert + Assert.IsTrue(needsMigrate); + } + + [Test] + public void NeedsMigrate_DoesNotNeedMigration_ReturnsFalse() + { + // Setup + string sourceFilePath = RingtoetsProjectMigrationTestHelper.GetOutdatedSupportedProjectFilePath(); + var versionedFile = new RingtoetsVersionedFile(sourceFilePath); + var migrator = new RingtoetsSqLiteDatabaseFileMigrator(); + + // Call + bool needsMigrate = migrator.NeedsMigrate(versionedFile, "4"); + + // Assert + Assert.IsFalse(needsMigrate); + } + + [Test] + public void Migrate_ValidFilesWithoutLogFile_SavesFileAtNewLocation() + { + // Setup + const string newVersion = "17.1"; + string sourceFilePath = RingtoetsProjectMigrationTestHelper.GetOutdatedSupportedProjectFilePath(); + var fromVersionedFile = new RingtoetsVersionedFile(sourceFilePath); + + string targetFilePath = TestHelper.GetScratchPadPath(nameof(Migrate_ValidFilesWithoutLogFile_SavesFileAtNewLocation)); + var migrator = new RingtoetsSqLiteDatabaseFileMigrator(); + + using (new FileDisposeHelper(targetFilePath)) + { + // Call + migrator.Migrate(fromVersionedFile, newVersion, targetFilePath); + + // Assert + var toVersionedFile = new RingtoetsVersionedFile(targetFilePath); + Assert.AreEqual(newVersion, toVersionedFile.GetVersion()); + } + } + + [Test] + public void Migrate_ValidFilesWithLogFile_SavesFileAtNewLocation() + { + // Setup + const string newVersion = "17.1"; + string sourceFilePath = RingtoetsProjectMigrationTestHelper.GetOutdatedSupportedProjectFilePath(); + var fromVersionedFile = new RingtoetsVersionedFile(sourceFilePath); + + string targetFilePath = TestHelper.GetScratchPadPath(nameof(Migrate_ValidFilesWithLogFile_SavesFileAtNewLocation)); + string logFilePath = TestHelper.GetScratchPadPath(string.Concat(nameof(Migrate_ValidFilesWithLogFile_SavesFileAtNewLocation), ".log")); + var migrator = new RingtoetsSqLiteDatabaseFileMigrator + { + LogPath = logFilePath + }; + + using (new FileDisposeHelper(logFilePath)) + using (new FileDisposeHelper(targetFilePath)) + { + // Call + migrator.Migrate(fromVersionedFile, newVersion, targetFilePath); + + // Assert + var toVersionedFile = new RingtoetsVersionedFile(targetFilePath); + Assert.AreEqual(newVersion, toVersionedFile.GetVersion()); + } + } + + [Test] + public void Migrate_ValidFilesWithNonExistingLogFile_ThrowsCriticalDatabaseMigrationException() + { + // Setup + const string newVersion = "17.1"; + string sourceFilePath = RingtoetsProjectMigrationTestHelper.GetOutdatedSupportedProjectFilePath(); + var fromVersionedFile = new RingtoetsVersionedFile(sourceFilePath); + + string targetFilePath = TestHelper.GetScratchPadPath(nameof(Migrate_ValidFilesWithNonExistingLogFile_ThrowsCriticalDatabaseMigrationException)); + string logFilePath = TestHelper.GetScratchPadPath(string.Concat(nameof(Migrate_ValidFilesWithNonExistingLogFile_ThrowsCriticalDatabaseMigrationException), ".log")); + var migrator = new RingtoetsSqLiteDatabaseFileMigrator + { + LogPath = logFilePath + }; + + using (new FileDisposeHelper(targetFilePath)) + { + // Call + TestDelegate call = () => migrator.Migrate(fromVersionedFile, newVersion, targetFilePath); + + // Assert + var exception = Assert.Throws(call); + Assert.IsInstanceOf(exception.InnerException); + } + } + + [Test] + public void Migrate_TargetFileInUse_ThrowsCriticalDatabaseMigrationException() + { + // Setup + const string newVersion = "17.1"; + string sourceFilePath = RingtoetsProjectMigrationTestHelper.GetOutdatedSupportedProjectFilePath(); + var fromVersionedFile = new RingtoetsVersionedFile(sourceFilePath); + + string targetFilePath = TestHelper.GetScratchPadPath(nameof(Migrate_TargetFileInUse_ThrowsCriticalDatabaseMigrationException)); + var migrator = new RingtoetsSqLiteDatabaseFileMigrator(); + + using (var fileDisposeHelper = new FileDisposeHelper(targetFilePath)) + { + fileDisposeHelper.LockFiles(); + + // Call + TestDelegate call = () => migrator.Migrate(fromVersionedFile, newVersion, targetFilePath); + + // Assert + var exception = Assert.Throws(call); + StringAssert.StartsWith("Het gemigreerde projectbestand is aangemaakt op '", exception.Message); + StringAssert.EndsWith($"', maar er is een onverwachte fout opgetreden tijdens het verplaatsen naar '{targetFilePath}'.", + exception.Message); + Assert.IsInstanceOf(exception.InnerException); + } + } + + [Test] + public void Migrate_TargetFilePathEqualsSourcePath_ThrowsCriticalDatabaseMigrationException() + { + // Setup + const string newVersion = "17.1"; + string sourceFilePath = RingtoetsProjectMigrationTestHelper.GetOutdatedSupportedProjectFilePath(); + var fromVersionedFile = new RingtoetsVersionedFile(sourceFilePath); + var migrator = new RingtoetsSqLiteDatabaseFileMigrator(); + + // Call + TestDelegate call = () => migrator.Migrate(fromVersionedFile, newVersion, sourceFilePath); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("Het doelprojectpad moet anders zijn dan het bronprojectpad.", + exception.Message); + } + + [Test] + public void Migrate_TargetFileNotWritable_ThrowsCriticalDatabaseMigrationException() + { + // Setup + const string newVersion = "17.1"; + string sourceFilePath = RingtoetsProjectMigrationTestHelper.GetOutdatedSupportedProjectFilePath(); + var fromVersionedFile = new RingtoetsVersionedFile(sourceFilePath); + + string targetFilePath = TestHelper.GetScratchPadPath(nameof(Migrate_TargetFileNotWritable_ThrowsCriticalDatabaseMigrationException)); + var migrator = new RingtoetsSqLiteDatabaseFileMigrator(); + + using (new FileDisposeHelper(targetFilePath)) + { + FileAttributes attributes = File.GetAttributes(targetFilePath); + File.SetAttributes(targetFilePath, attributes | FileAttributes.ReadOnly); + + try + { + // Call + TestDelegate call = () => migrator.Migrate(fromVersionedFile, newVersion, targetFilePath); + + // Assert + var exception = Assert.Throws(call); + StringAssert.StartsWith("Het gemigreerde projectbestand is aangemaakt op '", + exception.Message); + StringAssert.EndsWith($"', maar er is een onverwachte fout opgetreden tijdens het verplaatsen naar '{targetFilePath}'.", + exception.Message); + Assert.IsInstanceOf(exception.InnerException); + } + finally + { + File.SetAttributes(targetFilePath, attributes); + } + } + } + + [Test] + public void Migrate_InvalidToVersion_ThrowsCriticalDatabaseMigrationException() + { + // Setup + const string newVersion = "6"; + string sourceFilePath = RingtoetsProjectMigrationTestHelper.GetOutdatedSupportedProjectFilePath(); + var fromVersionedFile = new RingtoetsVersionedFile(sourceFilePath); + + string targetFilePath = TestHelper.GetScratchPadPath(nameof(Migrate_InvalidToVersion_ThrowsCriticalDatabaseMigrationException)); + var migrator = new RingtoetsSqLiteDatabaseFileMigrator(); + + // Call + TestDelegate call = () => migrator.Migrate(fromVersionedFile, newVersion, targetFilePath); + + // Assert + string message = Assert.Throws(call).Message; + Assert.AreEqual($"Het migreren van een projectbestand met versie '5' naar versie '{newVersion}' is niet ondersteund.", message); + } + + [Test] + public void Migrate_UnsupportedVersion_ThrowsCriticalDatabaseMigrationException() + { + // Setup + string sourceFilePath = RingtoetsProjectMigrationTestHelper.GetOutdatedUnSupportedProjectFilePath(); + var fromVersionedFile = new RingtoetsVersionedFile(sourceFilePath); + + string targetFilePath = TestHelper.GetScratchPadPath(nameof(Migrate_UnsupportedVersion_ThrowsCriticalDatabaseMigrationException)); + var migrator = new RingtoetsSqLiteDatabaseFileMigrator(); + + // Call + TestDelegate call = () => migrator.Migrate(fromVersionedFile, "17.1", targetFilePath); + + // Assert + string message = Assert.Throws(call).Message; + Assert.AreEqual("Het migreren van een projectbestand met versie '8' naar versie '17.1' is niet ondersteund.", message); + } + } +} \ No newline at end of file Index: Ringtoets/Migration/test/Riskeer.Migration.Core.Test/RingtoetsUpgradeScriptTest.cs =================================================================== diff -u --- Ringtoets/Migration/test/Riskeer.Migration.Core.Test/RingtoetsUpgradeScriptTest.cs (revision 0) +++ Ringtoets/Migration/test/Riskeer.Migration.Core.Test/RingtoetsUpgradeScriptTest.cs (revision 07ff2f80900d4e9b54e4a620cd82cdb80c8d2904) @@ -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 RingtoetsUpgradeScriptTest + { + [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 RingtoetsUpgradeScript(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 RingtoetsUpgradeScript(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 RingtoetsUpgradeScript(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 RingtoetsUpgradeScript(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 RingtoetsUpgradeScript(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 RingtoetsUpgradeScript(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 RingtoetsUpgradeScript(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 RingtoetsUpgradeScript(fromVersion, toVersion, ";", ""); + + // Call + upgradeScript.Upgrade("c:\\file.ext", filePath); + + // Assert + Assert.IsTrue(File.Exists(filePath)); + File.Delete(filePath); + } + } +} \ No newline at end of file Index: Ringtoets/Migration/test/Riskeer.Migration.Core.Test/RingtoetsVersionedFileTest.cs =================================================================== diff -u --- Ringtoets/Migration/test/Riskeer.Migration.Core.Test/RingtoetsVersionedFileTest.cs (revision 0) +++ Ringtoets/Migration/test/Riskeer.Migration.Core.Test/RingtoetsVersionedFileTest.cs (revision 07ff2f80900d4e9b54e4a620cd82cdb80c8d2904) @@ -0,0 +1,114 @@ +// 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.IO; +using Core.Common.Base.IO; +using Core.Common.TestUtil; +using NUnit.Framework; + +namespace Riskeer.Migration.Core.Test +{ + [TestFixture] + public class RingtoetsVersionedFileTest + { + [Test] + [TestCase("")] + [TestCase(" ")] + [TestCase(null)] + public void Constructor_InvalidPath_ThrowsArgumentException(string filePath) + { + // Call + TestDelegate call = () => new RingtoetsVersionedFile(filePath); + + // Assert + string message = Assert.Throws(call).Message; + Assert.AreEqual($"Fout bij het lezen van bestand '{filePath}': bestandspad mag niet leeg of ongedefinieerd zijn.", message); + } + + [Test] + public void Constructor_ValidfilePath_ExpectedProperties() + { + // Setup + string filePath = TestHelper.GetTestDataPath(nameof(Constructor_ValidfilePath_ExpectedProperties)); + + // Call + var versionedFile = new RingtoetsVersionedFile(filePath); + + // Assert + Assert.AreEqual(filePath, versionedFile.Location); + } + + [Test] + public void GetVersion_FileDoesNotExist_ThrowsCriticalFileReadException() + { + // Setup + string filePath = TestHelper.GetTestDataPath(nameof(GetVersion_FileDoesNotExist_ThrowsCriticalFileReadException)); + + var sourceFile = new RingtoetsVersionedFile(filePath); + + // Precondition + Assert.IsFalse(File.Exists(filePath), $"File should not exist at location '{filePath}'"); + + // Call + TestDelegate call = () => sourceFile.GetVersion(); + + // Assert + Assert.Throws(call); + } + + [Test] + public void GetVersion_FileCannotBeRead_ThrowsCriticalFileReadException() + { + // Setup + string file = Path.GetRandomFileName(); + string filePath = TestHelper.GetScratchPadPath(file); + + var sourceFile = new RingtoetsVersionedFile(filePath); + + using (var fileDisposeHelper = new FileDisposeHelper(filePath)) + { + fileDisposeHelper.LockFiles(); + + // Call + TestDelegate call = () => sourceFile.GetVersion(); + + // Assert + Assert.Throws(call); + } + } + + [TestCase("MigrationTestProject164.rtd", "5")] + [TestCase("MigrationTestProject171.rtd", "17.1")] + public void GetVersion_ParameteredConstructor_ExpectedProperties(string file, string expectedVersion) + { + // Setup + string filePath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Migration.Core, file); + var sourceFile = new RingtoetsVersionedFile(filePath); + + // Call + string version = sourceFile.GetVersion(); + + // Assert + Assert.AreEqual(expectedVersion, version); + } + } +} \ No newline at end of file Index: Ringtoets/Migration/test/Riskeer.Migration.Core.Test/Riskeer.Migration.Core.Test.csproj =================================================================== diff -u --- Ringtoets/Migration/test/Riskeer.Migration.Core.Test/Riskeer.Migration.Core.Test.csproj (revision 0) +++ Ringtoets/Migration/test/Riskeer.Migration.Core.Test/Riskeer.Migration.Core.Test.csproj (revision 07ff2f80900d4e9b54e4a620cd82cdb80c8d2904) @@ -0,0 +1,82 @@ + + + + {40CF9BC7-3CDE-4AC0-B31A-851694821772} + Riskeer.Migration.Core.Test + Riskeer.Migration.Core.Test + + + + + ..\..\..\..\packages\NUnit.3.8.1\lib\net40\nunit.framework.dll + True + + + + + + ..\..\..\..\packages\System.Data.SQLite.Core.1.0.106.0\lib\net40\System.Data.SQLite.dll + + + + + + + + + + + + + + + + + Copying.licenseheader + + + Designer + + + + + {3BBFD65B-B277-4E50-AE6D-BD24C3434609} + Core.Common.Base + + + {E344867E-9AC9-44C8-88A5-8185681679A9} + Core.Common.IO + + + {D749EE4C-CE50-4C17-BF01-9A953028C126} + Core.Common.TestUtil + + + {efd7e662-5b69-4b71-a448-565b64e9c033} + Migration.Core.Storage + + + {d08db9e2-6861-44c8-a725-71a70274cc77} + Migration.Scripts.Data + + + {6A074D65-A81C-4C1C-8E24-F36C916E4ED7} + Ringtoets.Common.Util + + + {fac55b92-e259-43d6-b9a1-5bda6c834359} + Riskeer.Migration.Core + + + {C98D99C5-2ADD-4693-916C-71BF78750412} + Ringtoets.Migration.Core.TestUtil + + + + + + 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: Ringtoets/Migration/test/Riskeer.Migration.Core.Test/packages.config =================================================================== diff -u --- Ringtoets/Migration/test/Riskeer.Migration.Core.Test/packages.config (revision 0) +++ Ringtoets/Migration/test/Riskeer.Migration.Core.Test/packages.config (revision 07ff2f80900d4e9b54e4a620cd82cdb80c8d2904) @@ -0,0 +1,27 @@ + + + + + + \ No newline at end of file Index: Ringtoets/Migration/test/Riskeer.Migration.Core.Test/test-data/Empty valid Release 16.4.rtd =================================================================== diff -u Binary files differ Index: Ringtoets/Migration/test/Riskeer.Migration.Core.Test/test-data/Empty valid Release 17.1.rtd =================================================================== diff -u Binary files differ Index: Ringtoets/Migration/test/Riskeer.Migration.Core.Test/test-data/Empty valid Release 17.2.rtd =================================================================== diff -u Binary files differ Index: Ringtoets/Migration/test/Riskeer.Migration.Core.Test/test-data/Empty valid Release 17.3.rtd =================================================================== diff -u Binary files differ Index: Ringtoets/Migration/test/Riskeer.Migration.Core.Test/test-data/Empty valid Release 18.1.rtd =================================================================== diff -u Binary files differ Index: Ringtoets/Migration/test/Riskeer.Migration.Core.Test/test-data/EmptyDatabase.rtd =================================================================== diff -u Binary files differ Index: Ringtoets/Migration/test/Riskeer.Migration.Core.Test/test-data/MigrationTestProject164.rtd =================================================================== diff -u Binary files differ Index: Ringtoets/Migration/test/Riskeer.Migration.Core.Test/test-data/MigrationTestProject171.rtd =================================================================== diff -u Binary files differ Index: Ringtoets/Migration/test/Riskeer.Migration.Core.Test/test-data/MigrationTestProject172.rtd =================================================================== diff -u Binary files differ Index: Ringtoets/Migration/test/Riskeer.Migration.Core.Test/test-data/MigrationTestProject173.rtd =================================================================== diff -u Binary files differ Index: Ringtoets/Migration/test/Riskeer.Migration.Core.Test/test-data/MigrationTestProject181.rtd =================================================================== diff -u Binary files differ Index: Ringtoets/Migration/test/Riskeer.Migration.Core.Test/test-data/MigrationTestProject191.rtd =================================================================== diff -u Binary files differ Index: Ringtoets/Migration/test/Riskeer.Migration.Core.Test/test-data/UnsupportedVersion8.rtd =================================================================== diff -u Binary files differ Index: Ringtoets/Migration/test/Riskeer.Migration.Core.Test/test-data/emptyMigrationLog.sqlite =================================================================== diff -u Binary files differ Index: Ringtoets/Migration/test/Riskeer.Migration.Core.Test/test-data/incompleteMigrationLog.sqlite =================================================================== diff -u Binary files differ Index: Ringtoets/Migration/test/Riskeer.Migration.Core.Test/test-data/invalidMigrationLog.sqlite =================================================================== diff -u --- Ringtoets/Migration/test/Riskeer.Migration.Core.Test/test-data/invalidMigrationLog.sqlite (revision 0) +++ Ringtoets/Migration/test/Riskeer.Migration.Core.Test/test-data/invalidMigrationLog.sqlite (revision 07ff2f80900d4e9b54e4a620cd82cdb80c8d2904) @@ -0,0 +1 @@ \ No newline at end of file Index: Ringtoets/Migration/test/Riskeer.Migration.Core.Test/test-data/validMigrationLog.sqlite =================================================================== diff -u Binary files differ