Index: Migration/Core/test/Migration.Core.Storage.Test/test-data/EmptyDatabase.rtd =================================================================== diff -u Binary files differ Index: Migration/Scripts/src/Migration.Scripts.Data/MigrationScript.cs =================================================================== diff -u -r83fbfb9ccbeaef0916d3485f89d48fdae9b8eb1d -rf5120263f838eaf211d8f73ca08a78c22e9777fb --- Migration/Scripts/src/Migration.Scripts.Data/MigrationScript.cs (.../MigrationScript.cs) (revision 83fbfb9ccbeaef0916d3485f89d48fdae9b8eb1d) +++ Migration/Scripts/src/Migration.Scripts.Data/MigrationScript.cs (.../MigrationScript.cs) (revision f5120263f838eaf211d8f73ca08a78c22e9777fb) @@ -23,6 +23,7 @@ using System.Data.SQLite; using System.IO; using Migration.Scripts.Data.Exceptions; +using Migration.Scripts.Data.Properties; namespace Migration.Scripts.Data { @@ -95,7 +96,7 @@ } catch (SQLiteException exception) { - throw new CriticalDatabaseMigrationException("Migratie is niet gelukt.", exception); + throw new CriticalDatabaseMigrationException(Resources.Migrate_failed, exception); } } } Index: Migration/Scripts/src/Migration.Scripts.Data/Properties/Resources.Designer.cs =================================================================== diff -u -r5aa0269872b446cab9f68c55dead92b6c5f49a64 -rf5120263f838eaf211d8f73ca08a78c22e9777fb --- Migration/Scripts/src/Migration.Scripts.Data/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision 5aa0269872b446cab9f68c55dead92b6c5f49a64) +++ Migration/Scripts/src/Migration.Scripts.Data/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision f5120263f838eaf211d8f73ca08a78c22e9777fb) @@ -82,26 +82,26 @@ } /// - /// Looks up a localized string similar to /* ---------------------------------------------------- */ - ////* Generated by Enterprise Architect Version 12.0 */ - ////* Created On : 12-Jan-2017 2:31:23 PM */ - ////* DBMS : SQLite */ - ////* ---------------------------------------------------- */ - /// - ////* Drop Tables */ - /// - ///DROP TABLE IF EXISTS 'VersionEntity' - ///; - /// - ///DROP TABLE IF EXISTS 'GrassCoverErosionInwardsDikeHeightOutputEntity' - ///; - /// - ///DROP TABLE IF EXISTS 'ProjectEntity' - ///; - /// - ///DROP TABLE IF EXISTS 'StabilityPointStructuresCalculationEntity' - ///; - /// + /// Looks up a localized string similar to /* ---------------------------------------------------- */ + ////* Generated by Enterprise Architect Version 12.0 */ + ////* Created On : 12-Jan-2017 2:31:23 PM */ + ////* DBMS : SQLite */ + ////* ---------------------------------------------------- */ + /// + ////* Drop Tables */ + /// + ///DROP TABLE IF EXISTS 'VersionEntity' + ///; + /// + ///DROP TABLE IF EXISTS 'GrassCoverErosionInwardsDikeHeightOutputEntity' + ///; + /// + ///DROP TABLE IF EXISTS 'ProjectEntity' + ///; + /// + ///DROP TABLE IF EXISTS 'StabilityPointStructuresCalculationEntity' + ///; + /// ///DROP TABLE IF E [rest of string was truncated]";. /// public static string DatabaseStructure17_1 { @@ -111,6 +111,15 @@ } /// + /// Looks up a localized string similar to Het migreren van de data is mislukt.. + /// + public static string Migrate_failed { + get { + return ResourceManager.GetString("Migrate_failed", resourceCulture); + } + } + + /// /// Looks up a localized string similar to CREATE TABLE 'InvalidVersionScriptCalled' ///( /// 'VersionId' INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, @@ -127,39 +136,29 @@ } /// - /// Looks up a localized string similar to ATTACH [{0}] AS SOURCEPROJECT; + /// Looks up a localized string similar to PRAGMA foreign_keys = OFF; /// - ///INSERT INTO VersionEntity ( - /// [VersionId], - /// [Version], - /// [Timestamp], - /// [FingerPrint]) - ///SELECT - /// [VersionId], - /// "17.1", - /// [Timestamp], - /// [FingerPrint] - ///FROM [SOURCEPROJECT].VersionEntity; + ///ATTACH DATABASE [{0}] AS SOURCEPROJECT; /// - ///INSERT INTO ProjectEntity - ///SELECT * FROM [SOURCEPROJECT].ProjectEntity; - /// - ///INSERT INTO AssessmentSectionEntity ( - /// [AssessmentSectionEntityId], - /// [ProjectEntityId], - /// [Id], - /// [Name], - /// [Comments], - /// [Norm], - /// [HydraulicDatabaseVersion], - /// [HydraulicDatabaseLocation], - /// [Composition], - /// [Referen [rest of string was truncated]";. + ///INSERT INTO AssessmentSectionEntity SELECT * FROM [SOURCEPROJECT].AssessmentSectionEntity; + ///INSERT INTO CalculationGroupEntity SELECT * FROM [SOURCEPROJECT].CalculationGroupEntity; + ///INSERT INTO CharacteristicPointEntity SELECT * FROM [SOURCEPROJECT].CharacteristicPointEntity; + ///INSERT INTO ClosingStructureEntity SELECT * FROM [SOURCEPROJECT].ClosingStructureEntity; + ///INSERT INTO ClosingStructuresFailureMechanismMetaEntity SELECT * FROM [ [rest of string was truncated]";. /// public static string Migration_4_171 { get { return ResourceManager.GetString("Migration_4_171", resourceCulture); } } + + /// + /// Looks up a localized string similar to Het bestand '{0}' is moet een geldig Ringtoets database bestand zijn.. + /// + public static string RingtoetsDatabaseSourceFile_Invalid_Ringtoets_File_Path_0 { + get { + return ResourceManager.GetString("RingtoetsDatabaseSourceFile_Invalid_Ringtoets_File_Path_0", resourceCulture); + } + } } } Index: Migration/Scripts/src/Migration.Scripts.Data/Properties/Resources.resx =================================================================== diff -u -r5aa0269872b446cab9f68c55dead92b6c5f49a64 -rf5120263f838eaf211d8f73ca08a78c22e9777fb --- Migration/Scripts/src/Migration.Scripts.Data/Properties/Resources.resx (.../Resources.resx) (revision 5aa0269872b446cab9f68c55dead92b6c5f49a64) +++ Migration/Scripts/src/Migration.Scripts.Data/Properties/Resources.resx (.../Resources.resx) (revision f5120263f838eaf211d8f73ca08a78c22e9777fb) @@ -127,4 +127,10 @@ ..\Resources\Migration_4_17.0.sql;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;Windows-1252 + + Het migreren van de data is mislukt. + + + Het bestand '{0}' is moet een geldig Ringtoets database bestand zijn. + \ No newline at end of file Index: Migration/Scripts/src/Migration.Scripts.Data/RingtoetsDatabaseSourceFile.cs =================================================================== diff -u -r5aa0269872b446cab9f68c55dead92b6c5f49a64 -rf5120263f838eaf211d8f73ca08a78c22e9777fb --- Migration/Scripts/src/Migration.Scripts.Data/RingtoetsDatabaseSourceFile.cs (.../RingtoetsDatabaseSourceFile.cs) (revision 5aa0269872b446cab9f68c55dead92b6c5f49a64) +++ Migration/Scripts/src/Migration.Scripts.Data/RingtoetsDatabaseSourceFile.cs (.../RingtoetsDatabaseSourceFile.cs) (revision f5120263f838eaf211d8f73ca08a78c22e9777fb) @@ -24,6 +24,7 @@ using Core.Common.Base.Storage; using Core.Common.IO.Exceptions; using Core.Common.IO.Readers; +using Migration.Scripts.Data.Properties; namespace Migration.Scripts.Data { @@ -67,7 +68,7 @@ } catch (SystemException exception) { - throw new StorageValidationException("$Het bestand '{FilePath}' is geen geldig Ringtoets database bestand.", exception); + throw new StorageValidationException(string.Format(Resources.RingtoetsDatabaseSourceFile_Invalid_Ringtoets_File_Path_0, Path), exception); } } } Index: Migration/Scripts/src/Migration.Scripts.Data/VersionedFile.cs =================================================================== diff -u -r6846763244edb70b20baed7e886e4d9092bfae0e -rf5120263f838eaf211d8f73ca08a78c22e9777fb --- Migration/Scripts/src/Migration.Scripts.Data/VersionedFile.cs (.../VersionedFile.cs) (revision 6846763244edb70b20baed7e886e4d9092bfae0e) +++ Migration/Scripts/src/Migration.Scripts.Data/VersionedFile.cs (.../VersionedFile.cs) (revision f5120263f838eaf211d8f73ca08a78c22e9777fb) @@ -20,6 +20,7 @@ // All rights reserved. using System; +using Core.Common.Base.Storage; using Core.Common.IO.Exceptions; using Core.Common.Utils; @@ -63,6 +64,7 @@ /// Unable to open file at . /// /// + /// Thrown when is not a valid file. public string GetVersion() { using (var sourceFile = new RingtoetsDatabaseSourceFile(Location)) Index: Migration/Scripts/test/Migration.Scripts.Data.Test/Migration.Scripts.Data.Test.csproj =================================================================== diff -u -r48d44fbda8f7ffb4c347aba4b4bb26d9c75487db -rf5120263f838eaf211d8f73ca08a78c22e9777fb --- Migration/Scripts/test/Migration.Scripts.Data.Test/Migration.Scripts.Data.Test.csproj (.../Migration.Scripts.Data.Test.csproj) (revision 48d44fbda8f7ffb4c347aba4b4bb26d9c75487db) +++ Migration/Scripts/test/Migration.Scripts.Data.Test/Migration.Scripts.Data.Test.csproj (.../Migration.Scripts.Data.Test.csproj) (revision f5120263f838eaf211d8f73ca08a78c22e9777fb) @@ -60,6 +60,8 @@ + + @@ -70,6 +72,10 @@ + + {3BBFD65B-B277-4E50-AE6D-BD24C3434609} + Core.Common.Base + {E344867E-9AC9-44C8-88A5-8185681679A9} Core.Common.IO Index: Migration/Scripts/test/Migration.Scripts.Data.Test/MigrationScriptTest.cs =================================================================== diff -u -r747809ca347ed4c7762c31b2bd643eac4d22b02d -rf5120263f838eaf211d8f73ca08a78c22e9777fb --- Migration/Scripts/test/Migration.Scripts.Data.Test/MigrationScriptTest.cs (.../MigrationScriptTest.cs) (revision 747809ca347ed4c7762c31b2bd643eac4d22b02d) +++ Migration/Scripts/test/Migration.Scripts.Data.Test/MigrationScriptTest.cs (.../MigrationScriptTest.cs) (revision f5120263f838eaf211d8f73ca08a78c22e9777fb) @@ -106,7 +106,7 @@ // Assert CriticalDatabaseMigrationException exception = Assert.Throws(call); - Assert.AreEqual("Migratie is niet gelukt.", exception.Message); + Assert.AreEqual("Het migreren van de data is mislukt.", exception.Message); Assert.IsInstanceOf(exception.InnerException); } @@ -124,10 +124,8 @@ // Assert Assert.IsNotNull(upgradedFile); - using (new FileDisposeHelper(upgradedFile.Location)) - { - Assert.IsTrue(File.Exists(upgradedFile.Location)); - } + Assert.IsTrue(File.Exists(upgradedFile.Location)); + using (new FileDisposeHelper(upgradedFile.Location)) {} } [Test] Index: Migration/Scripts/test/Migration.Scripts.Data.Test/RingtoetsDatabaseQueryBuilderTest.cs =================================================================== diff -u --- Migration/Scripts/test/Migration.Scripts.Data.Test/RingtoetsDatabaseQueryBuilderTest.cs (revision 0) +++ Migration/Scripts/test/Migration.Scripts.Data.Test/RingtoetsDatabaseQueryBuilderTest.cs (revision f5120263f838eaf211d8f73ca08a78c22e9777fb) @@ -0,0 +1,40 @@ +// 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 NUnit.Framework; + +namespace Migration.Scripts.Data.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: Migration/Scripts/test/Migration.Scripts.Data.Test/RingtoetsDatabaseSourceFileTest.cs =================================================================== diff -u --- Migration/Scripts/test/Migration.Scripts.Data.Test/RingtoetsDatabaseSourceFileTest.cs (revision 0) +++ Migration/Scripts/test/Migration.Scripts.Data.Test/RingtoetsDatabaseSourceFileTest.cs (revision f5120263f838eaf211d8f73ca08a78c22e9777fb) @@ -0,0 +1,138 @@ +// 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.IO; +using Core.Common.Base.Storage; +using Core.Common.IO.Exceptions; +using Core.Common.IO.Readers; +using Core.Common.TestUtil; +using NUnit.Framework; + +namespace Migration.Scripts.Data.Test +{ + [TestFixture] + public class RingtoetsDatabaseSourceFileTest + { + [Test] + public void Constructor_NonExistingPath_ThrowsCriticalFileReadException() + { + // Setup + string filename = Path.GetRandomFileName(); + string filePath = TestHelper.GetTestDataPath(TestDataPath.Migration.Core.Storage, 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(TestDataPath.Migration.Core.Storage, 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(TestDataPath.Migration.Core.Storage, 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}' is moet een geldig Ringtoets database bestand zijn.", + message); + } + } + + [Test] + public void GetVersion_EmptyRingtoetsDatabaseFile_ReturnsEmpty() + { + // Setup + string filePath = TestHelper.GetTestDataPath(TestDataPath.Migration.Core.Storage, "EmptyDatabase.rtd"); + + using (var file = new RingtoetsDatabaseSourceFile(filePath)) + { + // Call + string version = file.GetVersion(); + + // Assert + Assert.AreEqual(string.Empty, version); + } + } + + [Test] + public void GetVersion_ValidRingtoetsDatabaseFile_ReturnsVersion() + { + // Setup + string filePath = TestHelper.GetTestDataPath(TestDataPath.Migration.Core.Storage, "Demo164.rtd"); + + using (var file = new RingtoetsDatabaseSourceFile(filePath)) + { + // Call + string version = file.GetVersion(); + + // Assert + Assert.AreEqual("4", version); + } + } + } +} \ No newline at end of file