Index: Ringtoets/Migration/src/Riskeer.Migration.Core/ProjectDatabaseSourceFile.cs
===================================================================
diff -u
--- Ringtoets/Migration/src/Riskeer.Migration.Core/ProjectDatabaseSourceFile.cs (revision 0)
+++ Ringtoets/Migration/src/Riskeer.Migration.Core/ProjectDatabaseSourceFile.cs (revision f00628f6e8118bc33753ab916e0fdff864dfd894)
@@ -0,0 +1,77 @@
+// 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;
+using Core.Common.Base.IO;
+using Core.Common.Base.Storage;
+using Core.Common.IO.Readers;
+using Riskeer.Migration.Core.Properties;
+
+namespace Riskeer.Migration.Core
+{
+ ///
+ /// Class that provides methods for the migration database source file.
+ ///
+ public class ProjectDatabaseSourceFile : SqLiteDatabaseReaderBase
+ {
+ ///
+ /// Creates a new instance of the class.
+ ///
+ /// The path to the source file.
+ /// Thrown when:
+ ///
+ /// - The contains invalid characters.
+ /// - No file could be found at .
+ /// - Unable to open database file.
+ ///
+ ///
+ public ProjectDatabaseSourceFile(string databaseFilePath) : base(databaseFilePath) {}
+
+ ///
+ /// Gets the version of the project source file at location .
+ ///
+ /// The version of the file.
+ /// Thrown when the file is not a valid
+ /// project source file.
+ public string GetVersion()
+ {
+ string versionQuery = ProjectDatabaseQueryBuilder.GetVersionQuery();
+ try
+ {
+ using (IDataReader dataReader = CreateDataReader(versionQuery, null))
+ {
+ if (!dataReader.Read())
+ {
+ return string.Empty;
+ }
+
+ return dataReader.Read(VersionTableDefinitions.Version);
+ }
+ }
+ catch (SystemException exception)
+ {
+ throw new StorageValidationException(string.Format(Resources.RingtoetsDatabaseSourceFile_Invalid_Ringtoets_File_Path_0,
+ Path), exception);
+ }
+ }
+ }
+}
\ No newline at end of file
Fisheye: Tag f00628f6e8118bc33753ab916e0fdff864dfd894 refers to a dead (removed) revision in file `Ringtoets/Migration/src/Riskeer.Migration.Core/RingtoetsDatabaseSourceFile.cs'.
Fisheye: No comparison available. Pass `N' to diff?
Index: Ringtoets/Migration/src/Riskeer.Migration.Core/RingtoetsVersionedFile.cs
===================================================================
diff -u -reb0ce91f3f0fb3c543ef2b1875e5ad9e6356fa08 -rf00628f6e8118bc33753ab916e0fdff864dfd894
--- Ringtoets/Migration/src/Riskeer.Migration.Core/RingtoetsVersionedFile.cs (.../RingtoetsVersionedFile.cs) (revision eb0ce91f3f0fb3c543ef2b1875e5ad9e6356fa08)
+++ Ringtoets/Migration/src/Riskeer.Migration.Core/RingtoetsVersionedFile.cs (.../RingtoetsVersionedFile.cs) (revision f00628f6e8118bc33753ab916e0fdff864dfd894)
@@ -52,7 +52,7 @@
public string GetVersion()
{
- using (var sourceFile = new RingtoetsDatabaseSourceFile(Location))
+ using (var sourceFile = new ProjectDatabaseSourceFile(Location))
{
return sourceFile.GetVersion();
}
Index: Ringtoets/Migration/src/Riskeer.Migration.Core/Riskeer.Migration.Core.csproj
===================================================================
diff -u -r8f08a982730454fd4e91b5ef635fc553e6d63707 -rf00628f6e8118bc33753ab916e0fdff864dfd894
--- Ringtoets/Migration/src/Riskeer.Migration.Core/Riskeer.Migration.Core.csproj (.../Riskeer.Migration.Core.csproj) (revision 8f08a982730454fd4e91b5ef635fc553e6d63707)
+++ Ringtoets/Migration/src/Riskeer.Migration.Core/Riskeer.Migration.Core.csproj (.../Riskeer.Migration.Core.csproj) (revision f00628f6e8118bc33753ab916e0fdff864dfd894)
@@ -28,7 +28,7 @@
-
+
Index: Ringtoets/Migration/test/Riskeer.Migration.Core.Test/ProjectDatabaseSourceFileTest.cs
===================================================================
diff -u
--- Ringtoets/Migration/test/Riskeer.Migration.Core.Test/ProjectDatabaseSourceFileTest.cs (revision 0)
+++ Ringtoets/Migration/test/Riskeer.Migration.Core.Test/ProjectDatabaseSourceFileTest.cs (revision f00628f6e8118bc33753ab916e0fdff864dfd894)
@@ -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 ProjectDatabaseSourceFileTest
+ {
+ 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 ProjectDatabaseSourceFile(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 ProjectDatabaseSourceFile(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 ProjectDatabaseSourceFile(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 ProjectDatabaseSourceFile(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 ProjectDatabaseSourceFile(filePath))
+ {
+ // Call
+ string version = file.GetVersion();
+
+ // Assert
+ Assert.IsEmpty(version);
+ }
+ }
+ }
+}
\ No newline at end of file
Fisheye: Tag f00628f6e8118bc33753ab916e0fdff864dfd894 refers to a dead (removed) revision in file `Ringtoets/Migration/test/Riskeer.Migration.Core.Test/RingtoetsDatabaseSourceFileTest.cs'.
Fisheye: No comparison available. Pass `N' to diff?
Index: Ringtoets/Migration/test/Riskeer.Migration.Core.Test/Riskeer.Migration.Core.Test.csproj
===================================================================
diff -u -r8f08a982730454fd4e91b5ef635fc553e6d63707 -rf00628f6e8118bc33753ab916e0fdff864dfd894
--- Ringtoets/Migration/test/Riskeer.Migration.Core.Test/Riskeer.Migration.Core.Test.csproj (.../Riskeer.Migration.Core.Test.csproj) (revision 8f08a982730454fd4e91b5ef635fc553e6d63707)
+++ Ringtoets/Migration/test/Riskeer.Migration.Core.Test/Riskeer.Migration.Core.Test.csproj (.../Riskeer.Migration.Core.Test.csproj) (revision f00628f6e8118bc33753ab916e0fdff864dfd894)
@@ -25,7 +25,7 @@
-
+