Index: Ringtoets/Common/src/Ringtoets.Common.IO/FileImporters/HydraulicBoundaryDatabaseImporter.cs =================================================================== diff -u -r01542a3183009070b6cc1035cb9bceeca2301f61 -r640c6bce50d2ef282bef96ee5686fbe2f893384e --- Ringtoets/Common/src/Ringtoets.Common.IO/FileImporters/HydraulicBoundaryDatabaseImporter.cs (.../HydraulicBoundaryDatabaseImporter.cs) (revision 01542a3183009070b6cc1035cb9bceeca2301f61) +++ Ringtoets/Common/src/Ringtoets.Common.IO/FileImporters/HydraulicBoundaryDatabaseImporter.cs (.../HydraulicBoundaryDatabaseImporter.cs) (revision 640c6bce50d2ef282bef96ee5686fbe2f893384e) @@ -30,7 +30,7 @@ using Ringtoets.Common.Data.Hydraulics; using Ringtoets.Common.IO.HydraRing; using Ringtoets.Common.IO.Properties; -using Ringtoets.HydraRing.IO.HydraulicBoundaryDatabaseContext; +using Ringtoets.HydraRing.IO.HydraulicBoundaryDatabase; using Ringtoets.HydraRing.IO.HydraulicLocationConfigurationDatabaseContext; namespace Ringtoets.Common.IO.FileImporters Index: Ringtoets/Common/src/Ringtoets.Common.IO/HydraRing/HydraulicBoundaryDatabaseHelper.cs =================================================================== diff -u -rf8c28b3b04cdabb62ea37772efcb1f4ebbbf2b9e -r640c6bce50d2ef282bef96ee5686fbe2f893384e --- Ringtoets/Common/src/Ringtoets.Common.IO/HydraRing/HydraulicBoundaryDatabaseHelper.cs (.../HydraulicBoundaryDatabaseHelper.cs) (revision f8c28b3b04cdabb62ea37772efcb1f4ebbbf2b9e) +++ Ringtoets/Common/src/Ringtoets.Common.IO/HydraRing/HydraulicBoundaryDatabaseHelper.cs (.../HydraulicBoundaryDatabaseHelper.cs) (revision 640c6bce50d2ef282bef96ee5686fbe2f893384e) @@ -26,7 +26,7 @@ using Core.Common.Utils; using Ringtoets.Common.Data.Hydraulics; using Ringtoets.Common.IO.Properties; -using Ringtoets.HydraRing.IO.HydraulicBoundaryDatabaseContext; +using Ringtoets.HydraRing.IO.HydraulicBoundaryDatabase; using Ringtoets.HydraRing.IO.HydraulicLocationConfigurationDatabaseContext; using HydraRingResources = Ringtoets.HydraRing.IO.Properties.Resources; Index: Ringtoets/HydraRing/src/Ringtoets.HydraRing.IO/HydraulicBoundaryDatabase/GeneralTableDefinitions.cs =================================================================== diff -u --- Ringtoets/HydraRing/src/Ringtoets.HydraRing.IO/HydraulicBoundaryDatabase/GeneralTableDefinitions.cs (revision 0) +++ Ringtoets/HydraRing/src/Ringtoets.HydraRing.IO/HydraulicBoundaryDatabase/GeneralTableDefinitions.cs (revision 640c6bce50d2ef282bef96ee5686fbe2f893384e) @@ -0,0 +1,35 @@ +// Copyright (C) Stichting Deltares 2017. 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. + +namespace Ringtoets.HydraRing.IO.HydraulicBoundaryDatabase +{ + /// + /// Defines the table and column names of the table 'General' in the hydraulic boundary database. + /// + internal static class GeneralTableDefinitions + { + internal const string TableName = "General"; + internal const string RegionName = "NameRegion"; + internal const string TrackId = "TrackId"; + internal const string CreationDate = "CreationDate"; + internal const string GeneratedVersion = "GeneratedVersion"; + } +} \ No newline at end of file Index: Ringtoets/HydraRing/src/Ringtoets.HydraRing.IO/HydraulicBoundaryDatabase/HrdLocationsTableDefinitions.cs =================================================================== diff -u --- Ringtoets/HydraRing/src/Ringtoets.HydraRing.IO/HydraulicBoundaryDatabase/HrdLocationsTableDefinitions.cs (revision 0) +++ Ringtoets/HydraRing/src/Ringtoets.HydraRing.IO/HydraulicBoundaryDatabase/HrdLocationsTableDefinitions.cs (revision 640c6bce50d2ef282bef96ee5686fbe2f893384e) @@ -0,0 +1,37 @@ +// Copyright (C) Stichting Deltares 2017. 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. + +namespace Ringtoets.HydraRing.IO.HydraulicBoundaryDatabase +{ + /// + /// Defines the table and column names of the table 'HRDLocations' in the hydraulic boundary database. + /// + public static class HrdLocationsTableDefinitions + { + internal const string TableName = "HRDLocations"; + internal const string HrdLocationId = "HRDLocationId"; + internal const string LocationTypeId = "LocationTypeId"; + internal const string Name = "Name"; + internal const string XCoordinate = "XCoordinate"; + internal const string YCoordinate = "YCoordinate"; + internal const string Count = "nrOfRows"; + } +} \ No newline at end of file Fisheye: Tag 06f9145d8180df7fd26eac086a3f431c181e4d64 refers to a dead (removed) revision in file `Ringtoets/HydraRing/src/Ringtoets.HydraRing.IO/HydraulicBoundaryDatabase/HydraulicBoundaryDatabaseQueryBuilder.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Ringtoets/HydraRing/src/Ringtoets.HydraRing.IO/HydraulicBoundaryDatabase/HydraulicBoundarySqLiteDatabaseReader.cs =================================================================== diff -u --- Ringtoets/HydraRing/src/Ringtoets.HydraRing.IO/HydraulicBoundaryDatabase/HydraulicBoundarySqLiteDatabaseReader.cs (revision 0) +++ Ringtoets/HydraRing/src/Ringtoets.HydraRing.IO/HydraulicBoundaryDatabase/HydraulicBoundarySqLiteDatabaseReader.cs (revision 640c6bce50d2ef282bef96ee5686fbe2f893384e) @@ -0,0 +1,209 @@ +// Copyright (C) Stichting Deltares 2017. 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 System.Data.SQLite; +using Core.Common.Base.IO; +using Core.Common.IO.Exceptions; +using Core.Common.IO.Readers; +using Core.Common.Utils.Builders; +using Ringtoets.HydraRing.IO.Properties; + +namespace Ringtoets.HydraRing.IO.HydraulicBoundaryDatabase +{ + /// + /// This class reads a SqLite database file and constructs + /// instances from this database. + /// + public class HydraulicBoundarySqLiteDatabaseReader : SqLiteDatabaseReaderBase + { + private IDataReader sqliteDataReader; + + /// + /// Creates a new instance of , + /// which will use the as its source. + /// + /// The path of the database file to open. + /// Thrown when: + /// + /// The contains invalid characters. + /// No file could be found at . + /// + /// + public HydraulicBoundarySqLiteDatabaseReader(string databaseFilePath) : base(databaseFilePath) {} + + /// + /// Gets a value indicating whether or not more hydraulic boundary locations can + /// be read using the . + /// + public bool HasNext { get; private set; } + + public void PrepareReadLocation() + { + CloseDataReader(); + HasNext = false; + + sqliteDataReader = CreateDataReader(HydraulicBoundaryDatabaseQueryBuilder.GetRelevantLocationsQuery()); + MoveNext(); + } + + /// + /// Reads the next location from the database. + /// + /// A new instance of based on the data read from + /// the database or null if no data is available. + /// Thrown when the database contains incorrect values for required properties. + public ReadHydraulicBoundaryLocation ReadLocation() + { + if (!HasNext) + { + return null; + } + + try + { + var id = sqliteDataReader.Read(HrdLocationsTableDefinitions.HrdLocationId); + var name = sqliteDataReader.Read(HrdLocationsTableDefinitions.Name); + var x = sqliteDataReader.Read(HrdLocationsTableDefinitions.XCoordinate); + var y = sqliteDataReader.Read(HrdLocationsTableDefinitions.YCoordinate); + + return new ReadHydraulicBoundaryLocation(id, name, x, y); + } + catch (ConversionException e) + { + string message = new FileReaderErrorMessageBuilder(Path).Build(Resources.HydraulicBoundaryDatabaseReader_Critical_Unexpected_value_on_column); + throw new LineParseException(message, e); + } + finally + { + MoveNext(); + } + } + + /// + /// Gets the database version from the metadata table. + /// + /// The version found in the database, or if the version + /// cannot be found. + /// Thrown when a query could not be executed on the database schema. + public string GetVersion() + { + string versionQuery = HydraulicBoundaryDatabaseQueryBuilder.GetVersionQuery(); + try + { + using (IDataReader dataReader = CreateDataReader(versionQuery, null)) + { + return !dataReader.Read() ? string.Empty : Convert.ToString(dataReader[GeneralTableDefinitions.GeneratedVersion]); + } + } + catch (SQLiteException exception) + { + string message = new FileReaderErrorMessageBuilder(Path).Build(Resources.Error_HydraulicBoundaryLocation_read_from_database); + throw new CriticalFileReadException(message, exception); + } + } + + /// + /// Gets the track id from the metadata table. + /// + /// The track id found in the database, or 0 if the track id + /// cannot be found. + /// Thrown when the database returned incorrect + /// values for required properties. + /// Thrown when a query could not be executed on the database schema. + public long GetTrackId() + { + string trackQuery = HydraulicBoundaryDatabaseQueryBuilder.GetTrackIdQuery(); + var sqliteParameter = new SQLiteParameter + { + DbType = DbType.String + }; + try + { + using (IDataReader dataReader = CreateDataReader(trackQuery, sqliteParameter)) + { + return !dataReader.Read() ? 0 : Convert.ToInt64(dataReader[GeneralTableDefinitions.TrackId]); + } + } + catch (InvalidCastException exception) + { + string message = new FileReaderErrorMessageBuilder(Path).Build(Resources.HydraulicBoundaryDatabaseReader_Critical_Unexpected_value_on_column); + throw new LineParseException(message, exception); + } + catch (SQLiteException exception) + { + string message = new FileReaderErrorMessageBuilder(Path).Build(Resources.Error_HydraulicBoundaryLocation_read_from_database); + throw new CriticalFileReadException(message, exception); + } + } + + /// + /// Gets the amount of locations that can be read from the database. + /// + /// The amount of locations that can be read. + /// Thrown when a query could not be executed on the database schema. + public int GetLocationCount() + { + string locationCountQuery = HydraulicBoundaryDatabaseQueryBuilder.GetRelevantLocationsCountQuery(); + var sqliteParameter = new SQLiteParameter + { + DbType = DbType.String + }; + + try + { + using (IDataReader dataReader = CreateDataReader(locationCountQuery, sqliteParameter)) + { + return !dataReader.Read() ? 0 : Convert.ToInt32(dataReader[HrdLocationsTableDefinitions.Count]); + } + } + catch (InvalidCastException) + { + return 0; + } + catch (SQLiteException exception) + { + string message = new FileReaderErrorMessageBuilder(Path).Build(Resources.Error_HydraulicBoundaryLocation_read_from_database); + throw new CriticalFileReadException(message, exception); + } + } + + protected override void Dispose(bool disposing) + { + CloseDataReader(); + base.Dispose(disposing); + } + + /// + /// Moves the reader to the next record in the database. + /// + private void MoveNext() + { + HasNext = MoveNext(sqliteDataReader); + } + + private void CloseDataReader() + { + sqliteDataReader?.Dispose(); + } + } +} \ No newline at end of file Index: Ringtoets/HydraRing/src/Ringtoets.HydraRing.IO/HydraulicBoundaryDatabase/ReadHydraulicBoundaryLocation.cs =================================================================== diff -u --- Ringtoets/HydraRing/src/Ringtoets.HydraRing.IO/HydraulicBoundaryDatabase/ReadHydraulicBoundaryLocation.cs (revision 0) +++ Ringtoets/HydraRing/src/Ringtoets.HydraRing.IO/HydraulicBoundaryDatabase/ReadHydraulicBoundaryLocation.cs (revision 640c6bce50d2ef282bef96ee5686fbe2f893384e) @@ -0,0 +1,72 @@ +// Copyright (C) Stichting Deltares 2017. 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; + +namespace Ringtoets.HydraRing.IO.HydraulicBoundaryDatabase +{ + /// + /// Location that is read from a hydraulic boundary database file. + /// + public class ReadHydraulicBoundaryLocation + { + /// + /// Creates a new instance of . + /// + /// The database id of the read hydraulic boundary location. + /// The name of the read hydraulic boundary location. + /// The x coordinate of the read hydraulic boundary location. + /// The y coordinate of the read hydraulic boundary location. + /// Thrown when is null. + public ReadHydraulicBoundaryLocation(long id, string name, double coordinateX, double coordinateY) + { + if (name == null) + { + throw new ArgumentNullException(nameof(name)); + } + + Id = id; + Name = name; + CoordinateX = coordinateX; + CoordinateY = coordinateY; + } + + /// + /// Gets the database id of the read hydraulic boundary location. + /// + public long Id { get; } + + /// + /// Gets the name of the read hydraulic boundary location. + /// + public string Name { get; } + + /// + /// Gets the x coordinate of the read hydraulic boundary location. + /// + public double CoordinateX { get; } + + /// + /// Gets the y coordinate of the read hydraulic boundary location. + /// + public double CoordinateY { get; } + } +} \ No newline at end of file Fisheye: Tag 640c6bce50d2ef282bef96ee5686fbe2f893384e refers to a dead (removed) revision in file `Ringtoets/HydraRing/src/Ringtoets.HydraRing.IO/HydraulicBoundaryDatabaseContext/GeneralTableDefinitions.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 640c6bce50d2ef282bef96ee5686fbe2f893384e refers to a dead (removed) revision in file `Ringtoets/HydraRing/src/Ringtoets.HydraRing.IO/HydraulicBoundaryDatabaseContext/HrdLocationsTableDefinitions.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 640c6bce50d2ef282bef96ee5686fbe2f893384e refers to a dead (removed) revision in file `Ringtoets/HydraRing/src/Ringtoets.HydraRing.IO/HydraulicBoundaryDatabaseContext/HydraulicBoundaryDatabaseQueryBuilder.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 640c6bce50d2ef282bef96ee5686fbe2f893384e refers to a dead (removed) revision in file `Ringtoets/HydraRing/src/Ringtoets.HydraRing.IO/HydraulicBoundaryDatabaseContext/HydraulicBoundarySqLiteDatabaseReader.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 640c6bce50d2ef282bef96ee5686fbe2f893384e refers to a dead (removed) revision in file `Ringtoets/HydraRing/src/Ringtoets.HydraRing.IO/HydraulicBoundaryDatabaseContext/ReadHydraulicBoundaryLocation.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Ringtoets/HydraRing/src/Ringtoets.HydraRing.IO/Ringtoets.HydraRing.IO.csproj =================================================================== diff -u -r01542a3183009070b6cc1035cb9bceeca2301f61 -r640c6bce50d2ef282bef96ee5686fbe2f893384e --- Ringtoets/HydraRing/src/Ringtoets.HydraRing.IO/Ringtoets.HydraRing.IO.csproj (.../Ringtoets.HydraRing.IO.csproj) (revision 01542a3183009070b6cc1035cb9bceeca2301f61) +++ Ringtoets/HydraRing/src/Ringtoets.HydraRing.IO/Ringtoets.HydraRing.IO.csproj (.../Ringtoets.HydraRing.IO.csproj) (revision 640c6bce50d2ef282bef96ee5686fbe2f893384e) @@ -21,11 +21,11 @@ - - - - - + + + + + Index: Ringtoets/HydraRing/test/Ringtoets.HydraRing.IO.Test/HydraulicBoundaryDatabase/HydraulicBoundaryDatabaseQueryBuilderTest.cs =================================================================== diff -u --- Ringtoets/HydraRing/test/Ringtoets.HydraRing.IO.Test/HydraulicBoundaryDatabase/HydraulicBoundaryDatabaseQueryBuilderTest.cs (revision 0) +++ Ringtoets/HydraRing/test/Ringtoets.HydraRing.IO.Test/HydraulicBoundaryDatabase/HydraulicBoundaryDatabaseQueryBuilderTest.cs (revision 640c6bce50d2ef282bef96ee5686fbe2f893384e) @@ -0,0 +1,82 @@ +// Copyright (C) Stichting Deltares 2017. 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; +using Ringtoets.HydraRing.IO.HydraulicBoundaryDatabase; + +namespace Ringtoets.HydraRing.IO.Test.HydraulicBoundaryDatabase +{ + [TestFixture] + public class HydraulicBoundaryDatabaseQueryBuilderTest + { + [Test] + public void GetVersionQuery_Always_ReturnsExpectedValues() + { + // Setup + const string expectedQuery = "SELECT (NameRegion || CreationDate || TrackId) as GeneratedVersion FROM General LIMIT 0,1;"; + + // Call + string query = HydraulicBoundaryDatabaseQueryBuilder.GetVersionQuery(); + + // Assert + Assert.AreEqual(expectedQuery, query); + } + + [Test] + public void GetTrackIdQuery_Always_ReturnsExpectedValues() + { + // Setup + const string expectedQuery = "SELECT TrackId FROM General LIMIT 0,1;"; + + // Call + string query = HydraulicBoundaryDatabaseQueryBuilder.GetTrackIdQuery(); + + // Assert + Assert.AreEqual(expectedQuery, query); + } + + [Test] + public void GetRelevantLocationsCountQuery_Always_ReturnsExpectedValues() + { + // Setup + const string expectedQuery = "SELECT count(HRDLocationId) as nrOfRows FROM HRDLocations WHERE LocationTypeId > 1;"; + + // Call + string query = HydraulicBoundaryDatabaseQueryBuilder.GetRelevantLocationsCountQuery(); + + // Assert + Assert.AreEqual(expectedQuery, query); + } + + [Test] + public void GetRelevantLocationsQuery_Always_ReturnsExpectedValues() + { + // Setup + const string expectedQuery = "SELECT HRDLocationId, Name, XCoordinate, YCoordinate FROM HRDLocations WHERE LocationTypeId > 1;"; + + // Call + string query = HydraulicBoundaryDatabaseQueryBuilder.GetRelevantLocationsQuery(); + + // Assert + Assert.AreEqual(expectedQuery, query); + } + } +} \ No newline at end of file Index: Ringtoets/HydraRing/test/Ringtoets.HydraRing.IO.Test/HydraulicBoundaryDatabase/HydraulicBoundarySqLiteDatabaseReaderTest.cs =================================================================== diff -u --- Ringtoets/HydraRing/test/Ringtoets.HydraRing.IO.Test/HydraulicBoundaryDatabase/HydraulicBoundarySqLiteDatabaseReaderTest.cs (revision 0) +++ Ringtoets/HydraRing/test/Ringtoets.HydraRing.IO.Test/HydraulicBoundaryDatabase/HydraulicBoundarySqLiteDatabaseReaderTest.cs (revision 640c6bce50d2ef282bef96ee5686fbe2f893384e) @@ -0,0 +1,393 @@ +// Copyright (C) Stichting Deltares 2017. 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.Generic; +using System.Data.SQLite; +using System.IO; +using Core.Common.Base.IO; +using Core.Common.IO.Exceptions; +using Core.Common.IO.Readers; +using Core.Common.TestUtil; +using Core.Common.Utils.Builders; +using NUnit.Framework; +using Ringtoets.HydraRing.IO.HydraulicBoundaryDatabase; + +namespace Ringtoets.HydraRing.IO.Test.HydraulicBoundaryDatabase +{ + [TestFixture] + public class HydraulicBoundarySqLiteDatabaseReaderTest + { + private readonly string testDataPath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.HydraRing.IO, "HydraulicBoundarySqLiteDatabaseReader"); + + [Test] + public void Constructor_NonExistingPath_ThrowsCriticalFileReadException() + { + // Setup + string testFile = Path.Combine(testDataPath, "none.sqlite"); + string expectedMessage = new FileReaderErrorMessageBuilder(testFile).Build("Het bestand bestaat niet."); + + // Call + TestDelegate test = () => new HydraulicBoundarySqLiteDatabaseReader(testFile).Dispose(); + + // Assert + var exception = Assert.Throws(test); + Assert.AreEqual(expectedMessage, exception.Message); + } + + [Test] + [TestCase(null)] + [TestCase("")] + public void Constructor_FileNullOrEmpty_ThrowsCriticalFileReadException(string fileName) + { + // Setup + string expectedMessage = $"Fout bij het lezen van bestand '{fileName}': bestandspad mag niet leeg of ongedefinieerd zijn."; + + // Call + TestDelegate test = () => new HydraulicBoundarySqLiteDatabaseReader(fileName).Dispose(); + + // Assert + var exception = Assert.Throws(test); + Assert.AreEqual(expectedMessage, exception.Message); + } + + [Test] + public void GetVersion_InvalidColumns_DoesNotThrowException() + { + // Setup + string dbFile = Path.Combine(testDataPath, "corruptschema.sqlite"); + + // Precondition + Assert.IsTrue(TestHelper.CanOpenFileForWrite(dbFile), "Precondition: file can be opened for edits."); + using (var hydraulicBoundarySqLiteDatabaseReader = new HydraulicBoundarySqLiteDatabaseReader(dbFile)) + { + var version = "some version"; + // Call + TestDelegate test = () => version = hydraulicBoundarySqLiteDatabaseReader.GetVersion(); + + // Assert + Assert.DoesNotThrow(test); + const string expectedVersion = "Namedate7"; + Assert.AreEqual(expectedVersion, version); + } + Assert.IsTrue(TestHelper.CanOpenFileForWrite(dbFile)); + } + + [Test] + public void GetVersion_EmptyDatabase_ThrowsCriticalFileReadException() + { + // Setup + string dbFile = Path.Combine(testDataPath, "empty.sqlite"); + string expectedException = new FileReaderErrorMessageBuilder(dbFile).Build("Kon geen locaties verkrijgen van de database."); + + // Precondition + Assert.IsTrue(TestHelper.CanOpenFileForWrite(dbFile), "Precondition: file can be opened for edits."); + using (var hydraulicBoundarySqLiteDatabaseReader = new HydraulicBoundarySqLiteDatabaseReader(dbFile)) + { + // Call + TestDelegate test = () => hydraulicBoundarySqLiteDatabaseReader.GetVersion(); + + // Assert + var exception = Assert.Throws(test); + Assert.AreEqual(expectedException, exception.Message); + Assert.IsInstanceOf(exception.InnerException); + } + Assert.IsTrue(TestHelper.CanOpenFileForWrite(dbFile)); + } + + [Test] + public void Constructor_ValidFile_ExpectedValues() + { + // Setup + string dbFile = Path.Combine(testDataPath, "complete.sqlite"); + + // Call + using (var hydraulicBoundarySqLiteDatabaseReader = new HydraulicBoundarySqLiteDatabaseReader(dbFile)) + { + // Assert + Assert.IsFalse(hydraulicBoundarySqLiteDatabaseReader.HasNext); + } + Assert.IsTrue(TestHelper.CanOpenFileForWrite(dbFile)); + } + + [Test] + public void GetLocationCount_ValidFile_ExpectedValues() + { + // Setup + const int expectedNrOfLocations = 18; + string dbFile = Path.Combine(testDataPath, "complete.sqlite"); + + using (var hydraulicBoundarySqLiteDatabaseReader = new HydraulicBoundarySqLiteDatabaseReader(dbFile)) + { + // Call + int nrOfLocations = hydraulicBoundarySqLiteDatabaseReader.GetLocationCount(); + + // Assert + Assert.AreEqual(expectedNrOfLocations, nrOfLocations); + Assert.IsFalse(hydraulicBoundarySqLiteDatabaseReader.HasNext); + } + Assert.IsTrue(TestHelper.CanOpenFileForWrite(dbFile)); + } + + [Test] + public void GetLocationCount_EmptyDatabase_ThrowsCriticalFileReadException() + { + // Setup + string dbFile = Path.Combine(testDataPath, "empty.sqlite"); + string expectedException = new FileReaderErrorMessageBuilder(dbFile).Build("Kon geen locaties verkrijgen van de database."); + + // Precondition + Assert.IsTrue(TestHelper.CanOpenFileForWrite(dbFile), "Precondition: file can be opened for edits."); + using (var hydraulicBoundarySqLiteDatabaseReader = new HydraulicBoundarySqLiteDatabaseReader(dbFile)) + { + // Call + TestDelegate test = () => hydraulicBoundarySqLiteDatabaseReader.GetLocationCount(); + + // Assert + var exception = Assert.Throws(test); + Assert.AreEqual(expectedException, exception.Message); + Assert.IsInstanceOf(exception.InnerException); + } + Assert.IsTrue(TestHelper.CanOpenFileForWrite(dbFile)); + } + + [Test] + public void GetVersion_ValidFile_ExpectedValues() + { + // Setup + const string expectedVersion = "Dutch coast South19-11-2015 12:0013"; + string dbFile = Path.Combine(testDataPath, "complete.sqlite"); + + using (var hydraulicBoundarySqLiteDatabaseReader = new HydraulicBoundarySqLiteDatabaseReader(dbFile)) + { + // Call + string version = hydraulicBoundarySqLiteDatabaseReader.GetVersion(); + + // Assert + Assert.AreEqual(expectedVersion, version); + Assert.IsFalse(hydraulicBoundarySqLiteDatabaseReader.HasNext); + } + Assert.IsTrue(TestHelper.CanOpenFileForWrite(dbFile)); + } + + [Test] + public void GetTrackId_ValidFile_ExpectedValues() + { + // Setup + const long expectedTrackId = 13; + string dbFile = Path.Combine(testDataPath, "complete.sqlite"); + + using (var hydraulicBoundarySqLiteDatabaseReader = new HydraulicBoundarySqLiteDatabaseReader(dbFile)) + { + // Call + long trackId = hydraulicBoundarySqLiteDatabaseReader.GetTrackId(); + + // Assert + Assert.AreEqual(expectedTrackId, trackId); + Assert.IsFalse(hydraulicBoundarySqLiteDatabaseReader.HasNext); + } + Assert.IsTrue(TestHelper.CanOpenFileForWrite(dbFile)); + } + + [Test] + public void GetTrackId_EmptyDatabase_ThrowsCriticalFileReadException() + { + // Setup + string dbFile = Path.Combine(testDataPath, "empty.sqlite"); + string expectedException = new FileReaderErrorMessageBuilder(dbFile).Build("Kon geen locaties verkrijgen van de database."); + + // Precondition + Assert.IsTrue(TestHelper.CanOpenFileForWrite(dbFile), "Precondition: file can be opened for edits."); + using (var hydraulicBoundarySqLiteDatabaseReader = new HydraulicBoundarySqLiteDatabaseReader(dbFile)) + { + // Call + TestDelegate test = () => hydraulicBoundarySqLiteDatabaseReader.GetTrackId(); + + // Assert + var exception = Assert.Throws(test); + Assert.AreEqual(expectedException, exception.Message); + Assert.IsInstanceOf(exception.InnerException); + } + Assert.IsTrue(TestHelper.CanOpenFileForWrite(dbFile)); + } + + [Test] + public void GetTrackId_InvalidColumns_ThrowsLineParseException() + { + // Setup + string dbFile = Path.Combine(testDataPath, "corruptschema.sqlite"); + string expectedMessage = new FileReaderErrorMessageBuilder(dbFile).Build("Kritieke fout opgetreden bij het uitlezen van waardes uit kolommen in de database."); + + // Precondition + Assert.IsTrue(TestHelper.CanOpenFileForWrite(dbFile), "Precondition: file can be opened for edits."); + + using (var hydraulicBoundarySqLiteDatabaseReader = new HydraulicBoundarySqLiteDatabaseReader(dbFile)) + { + // Call + TestDelegate test = () => hydraulicBoundarySqLiteDatabaseReader.GetTrackId(); + + // Assert + var exception = Assert.Throws(test); + Assert.AreEqual(expectedMessage, exception.Message); + Assert.IsInstanceOf(exception.InnerException); + } + Assert.IsTrue(TestHelper.CanOpenFileForWrite(dbFile)); + } + + [Test] + public void ReadLocation_InvalidColumns_ThrowsLineParseException() + { + // Setup + string dbFile = Path.Combine(testDataPath, "corruptschema.sqlite"); + string expectedMessage = new FileReaderErrorMessageBuilder(dbFile).Build("Kritieke fout opgetreden bij het uitlezen van waardes uit kolommen in de database."); + + // Precondition + Assert.IsTrue(TestHelper.CanOpenFileForWrite(dbFile), "Precondition: file can be opened for edits."); + + using (var hydraulicBoundarySqLiteDatabaseReader = new HydraulicBoundarySqLiteDatabaseReader(dbFile)) + { + // Call + hydraulicBoundarySqLiteDatabaseReader.PrepareReadLocation(); + TestDelegate test = () => hydraulicBoundarySqLiteDatabaseReader.ReadLocation(); + + // Assert + var exception = Assert.Throws(test); + Assert.AreEqual(expectedMessage, exception.Message); + Assert.IsInstanceOf(exception.InnerException); + } + Assert.IsTrue(TestHelper.CanOpenFileForWrite(dbFile)); + } + + [Test] + public void ReadLocation_ValidFileReadOneLocation_ExpectedValues() + { + // Setup + string dbFile = Path.Combine(testDataPath, "complete.sqlite"); + + using (var hydraulicBoundarySqLiteDatabaseReader = new HydraulicBoundarySqLiteDatabaseReader(dbFile)) + { + // Call + hydraulicBoundarySqLiteDatabaseReader.PrepareReadLocation(); + ReadHydraulicBoundaryLocation location = hydraulicBoundarySqLiteDatabaseReader.ReadLocation(); + + // Assert + Assert.IsNotNull(location); + } + Assert.IsTrue(TestHelper.CanOpenFileForWrite(dbFile)); + } + + [Test] + public void ReadLocation_ValidFilereadAllLocations_ExpectedValues() + { + // Setup + const int nrOfLocations = 18; + string dbFile = Path.Combine(testDataPath, "complete.sqlite"); + var boundaryLocations = new List(); + CollectionAssert.IsEmpty(boundaryLocations); + + using (var hydraulicBoundarySqLiteDatabaseReader = new HydraulicBoundarySqLiteDatabaseReader(dbFile)) + { + // Call + hydraulicBoundarySqLiteDatabaseReader.PrepareReadLocation(); + for (var i = 0; i < nrOfLocations; i++) + { + boundaryLocations.Add(hydraulicBoundarySqLiteDatabaseReader.ReadLocation()); + } + + // Assert + Assert.IsFalse(hydraulicBoundarySqLiteDatabaseReader.HasNext); + Assert.IsNull(hydraulicBoundarySqLiteDatabaseReader.ReadLocation()); + } + + CollectionAssert.AllItemsAreInstancesOfType(boundaryLocations, typeof(ReadHydraulicBoundaryLocation)); + Assert.IsTrue(TestHelper.CanOpenFileForWrite(dbFile)); + } + + [Test] + public void ParameteredConstructor_PathToExistingFile_ExpectedValues() + { + // Setup + string dbFile = Path.Combine(testDataPath, "emptyschema.sqlite"); + + // Call + using (var hydraulicBoundaryDatabaseReader = new HydraulicBoundarySqLiteDatabaseReader(dbFile)) + { + // Assert + Assert.AreEqual(dbFile, hydraulicBoundaryDatabaseReader.Path); + Assert.IsInstanceOf(hydraulicBoundaryDatabaseReader); + } + } + + [Test] + public void Constructor_EmptyDatabase_HasNextFalse() + { + // Setup + string dbFile = Path.Combine(testDataPath, "emptyschema.sqlite"); + + // Call + using (var hydraulicBoundaryDatabaseReader = new HydraulicBoundarySqLiteDatabaseReader(dbFile)) + { + // Assert + Assert.IsFalse(hydraulicBoundaryDatabaseReader.HasNext); + } + } + + [Test] + public void Dispose_AfterConstruction_CorrectlyReleasesFile() + { + // Setup + string dbFile = Path.Combine(testDataPath, "complete.sqlite"); + Assert.IsTrue(TestHelper.CanOpenFileForWrite(dbFile), "Precondition failed: The file should be writable to begin with."); + + // Call + new HydraulicBoundarySqLiteDatabaseReader(dbFile).Dispose(); + + // Assert + Assert.IsTrue(TestHelper.CanOpenFileForWrite(dbFile)); + } + + [Test] + public void Dispose_WhenReadLocation_CorrectlyReleasesFile() + { + // Setup + string dbFile = Path.Combine(testDataPath, "complete.sqlite"); + Assert.IsTrue(TestHelper.CanOpenFileForWrite(dbFile), "Precondition failed: The file should be writable to begin with."); + + HydraulicBoundarySqLiteDatabaseReader hydraulicBoundarySqLiteDatabaseReader = null; + ReadHydraulicBoundaryLocation boundaryLocation; + try + { + hydraulicBoundarySqLiteDatabaseReader = new HydraulicBoundarySqLiteDatabaseReader(dbFile); + hydraulicBoundarySqLiteDatabaseReader.PrepareReadLocation(); + boundaryLocation = hydraulicBoundarySqLiteDatabaseReader.ReadLocation(); + } + finally + { + // Call + hydraulicBoundarySqLiteDatabaseReader?.Dispose(); + } + + // Assert + Assert.NotNull(boundaryLocation); + Assert.IsTrue(TestHelper.CanOpenFileForWrite(dbFile)); + } + } +} \ No newline at end of file Index: Ringtoets/HydraRing/test/Ringtoets.HydraRing.IO.Test/HydraulicBoundaryDatabase/ReadHydraulicBoundaryLocationTest.cs =================================================================== diff -u --- Ringtoets/HydraRing/test/Ringtoets.HydraRing.IO.Test/HydraulicBoundaryDatabase/ReadHydraulicBoundaryLocationTest.cs (revision 0) +++ Ringtoets/HydraRing/test/Ringtoets.HydraRing.IO.Test/HydraulicBoundaryDatabase/ReadHydraulicBoundaryLocationTest.cs (revision 640c6bce50d2ef282bef96ee5686fbe2f893384e) @@ -0,0 +1,62 @@ +// Copyright (C) Stichting Deltares 2017. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// All names, logos, and references to "Deltares" are registered trademarks of +// Stichting Deltares and remain full property of Stichting Deltares at all times. +// All rights reserved. + +using System; +using NUnit.Framework; +using Ringtoets.HydraRing.IO.HydraulicBoundaryDatabase; + +namespace Ringtoets.HydraRing.IO.Test.HydraulicBoundaryDatabase +{ + [TestFixture] + public class ReadHydraulicBoundaryLocationTest + { + [Test] + public void Constructor_NameNull_ThrowsArgumentNullException() + { + // Call + TestDelegate call = () => new ReadHydraulicBoundaryLocation(1, null, 2, 3); + + // Assert + string paramName = Assert.Throws(call).ParamName; + Assert.AreEqual("name", paramName); + } + + [Test] + public void Constructor_Always_ExpectedValues() + { + // Setup + const long id = 1; + const string name = "name"; + var random = new Random(11); + double xCoordinate = random.NextDouble(); + double yCoordinate = random.NextDouble(); + + // Call + var readHydraulicBoundaryLocation = new ReadHydraulicBoundaryLocation(id, name, xCoordinate, yCoordinate); + + // Assert + Assert.AreEqual(id, readHydraulicBoundaryLocation.Id); + Assert.AreEqual(name, readHydraulicBoundaryLocation.Name); + Assert.AreEqual(xCoordinate, readHydraulicBoundaryLocation.CoordinateX); + Assert.AreEqual(yCoordinate, readHydraulicBoundaryLocation.CoordinateY); + } + } +} \ No newline at end of file Fisheye: Tag 640c6bce50d2ef282bef96ee5686fbe2f893384e refers to a dead (removed) revision in file `Ringtoets/HydraRing/test/Ringtoets.HydraRing.IO.Test/HydraulicBoundaryDatabaseContext/HydraulicBoundaryDatabaseQueryBuilderTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 640c6bce50d2ef282bef96ee5686fbe2f893384e refers to a dead (removed) revision in file `Ringtoets/HydraRing/test/Ringtoets.HydraRing.IO.Test/HydraulicBoundaryDatabaseContext/HydraulicBoundarySqLiteDatabaseReaderTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 640c6bce50d2ef282bef96ee5686fbe2f893384e refers to a dead (removed) revision in file `Ringtoets/HydraRing/test/Ringtoets.HydraRing.IO.Test/HydraulicBoundaryDatabaseContext/ReadHydraulicBoundaryLocationTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Ringtoets/HydraRing/test/Ringtoets.HydraRing.IO.Test/Ringtoets.HydraRing.IO.Test.csproj =================================================================== diff -u -rbf02b4dc139679e0c7a89d2a6bcd71ace25fa7b9 -r640c6bce50d2ef282bef96ee5686fbe2f893384e --- Ringtoets/HydraRing/test/Ringtoets.HydraRing.IO.Test/Ringtoets.HydraRing.IO.Test.csproj (.../Ringtoets.HydraRing.IO.Test.csproj) (revision bf02b4dc139679e0c7a89d2a6bcd71ace25fa7b9) +++ Ringtoets/HydraRing/test/Ringtoets.HydraRing.IO.Test/Ringtoets.HydraRing.IO.Test.csproj (.../Ringtoets.HydraRing.IO.Test.csproj) (revision 640c6bce50d2ef282bef96ee5686fbe2f893384e) @@ -20,9 +20,9 @@ - - - + + +