Index: Ringtoets.sln =================================================================== diff -u -r1cb73e10d2d1cd95df70d7c5926c2c679f602139 -r963fecfe944d68897b03b6a7df5ba45a53bdfdeb --- Ringtoets.sln (.../Ringtoets.sln) (revision 1cb73e10d2d1cd95df70d7c5926c2c679f602139) +++ Ringtoets.sln (.../Ringtoets.sln) (revision 963fecfe944d68897b03b6a7df5ba45a53bdfdeb) @@ -514,7 +514,7 @@ {C90B77DA-E421-43CC-B82E-529651BC21AC} = {C90B77DA-E421-43CC-B82E-529651BC21AC} EndProjectSection EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Riskeer.HydraRing.IO.Test", "Ringtoets\HydraRing\test\Ringtoets.HydraRing.IO.Test\Riskeer.HydraRing.IO.Test.csproj", "{CA7B5888-2BC9-4FE2-9F58-FBC6D7ED8221}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Riskeer.HydraRing.IO.Test", "Ringtoets\HydraRing\test\Riskeer.HydraRing.IO.Test\Riskeer.HydraRing.IO.Test.csproj", "{CA7B5888-2BC9-4FE2-9F58-FBC6D7ED8221}" ProjectSection(ProjectDependencies) = postProject {C90B77DA-E421-43CC-B82E-529651BC21AC} = {C90B77DA-E421-43CC-B82E-529651BC21AC} EndProjectSection Fisheye: Tag 963fecfe944d68897b03b6a7df5ba45a53bdfdeb refers to a dead (removed) revision in file `Ringtoets/HydraRing/test/Ringtoets.HydraRing.IO.Test/HydraulicBoundaryDatabase/GeneralTableDefinitionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 963fecfe944d68897b03b6a7df5ba45a53bdfdeb refers to a dead (removed) revision in file `Ringtoets/HydraRing/test/Ringtoets.HydraRing.IO.Test/HydraulicBoundaryDatabase/HrdLocationsTableDefinitionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 963fecfe944d68897b03b6a7df5ba45a53bdfdeb refers to a dead (removed) revision in file `Ringtoets/HydraRing/test/Ringtoets.HydraRing.IO.Test/HydraulicBoundaryDatabase/HydraulicBoundaryDatabaseQueryBuilderTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 963fecfe944d68897b03b6a7df5ba45a53bdfdeb refers to a dead (removed) revision in file `Ringtoets/HydraRing/test/Ringtoets.HydraRing.IO.Test/HydraulicBoundaryDatabase/HydraulicBoundaryDatabaseReaderTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 963fecfe944d68897b03b6a7df5ba45a53bdfdeb refers to a dead (removed) revision in file `Ringtoets/HydraRing/test/Ringtoets.HydraRing.IO.Test/HydraulicBoundaryDatabase/ReadHydraulicBoundaryDatabaseTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 963fecfe944d68897b03b6a7df5ba45a53bdfdeb refers to a dead (removed) revision in file `Ringtoets/HydraRing/test/Ringtoets.HydraRing.IO.Test/HydraulicBoundaryDatabase/ReadHydraulicBoundaryLocationTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 963fecfe944d68897b03b6a7df5ba45a53bdfdeb refers to a dead (removed) revision in file `Ringtoets/HydraRing/test/Ringtoets.HydraRing.IO.Test/HydraulicLocationConfigurationDatabase/HydraulicLocationConfigurationDatabaseQueryBuilderTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 963fecfe944d68897b03b6a7df5ba45a53bdfdeb refers to a dead (removed) revision in file `Ringtoets/HydraRing/test/Ringtoets.HydraRing.IO.Test/HydraulicLocationConfigurationDatabase/HydraulicLocationConfigurationDatabaseReaderTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 963fecfe944d68897b03b6a7df5ba45a53bdfdeb refers to a dead (removed) revision in file `Ringtoets/HydraRing/test/Ringtoets.HydraRing.IO.Test/HydraulicLocationConfigurationDatabase/LocationsTableDefinitionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 963fecfe944d68897b03b6a7df5ba45a53bdfdeb refers to a dead (removed) revision in file `Ringtoets/HydraRing/test/Ringtoets.HydraRing.IO.Test/HydraulicLocationConfigurationDatabase/ReadHydraulicLocationConfigurationDatabaseSettingsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 963fecfe944d68897b03b6a7df5ba45a53bdfdeb refers to a dead (removed) revision in file `Ringtoets/HydraRing/test/Ringtoets.HydraRing.IO.Test/HydraulicLocationConfigurationDatabase/ReadHydraulicLocationConfigurationDatabaseTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 963fecfe944d68897b03b6a7df5ba45a53bdfdeb refers to a dead (removed) revision in file `Ringtoets/HydraRing/test/Ringtoets.HydraRing.IO.Test/HydraulicLocationConfigurationDatabase/ReadHydraulicLocationMappingTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 963fecfe944d68897b03b6a7df5ba45a53bdfdeb refers to a dead (removed) revision in file `Ringtoets/HydraRing/test/Ringtoets.HydraRing.IO.Test/HydraulicLocationConfigurationDatabase/ScenarioInformationTableDefinitionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 963fecfe944d68897b03b6a7df5ba45a53bdfdeb refers to a dead (removed) revision in file `Ringtoets/HydraRing/test/Ringtoets.HydraRing.IO.Test/Properties/AssemblyInfo.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 963fecfe944d68897b03b6a7df5ba45a53bdfdeb refers to a dead (removed) revision in file `Ringtoets/HydraRing/test/Ringtoets.HydraRing.IO.Test/Riskeer.HydraRing.IO.Test.csproj'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 963fecfe944d68897b03b6a7df5ba45a53bdfdeb refers to a dead (removed) revision in file `Ringtoets/HydraRing/test/Ringtoets.HydraRing.IO.Test/packages.config'. Fisheye: No comparison available. Pass `N' to diff? Index: Ringtoets/HydraRing/test/Ringtoets.HydraRing.IO.Test/test-data/HydraulicBoundaryDatabaseReader/complete.sqlite =================================================================== diff -u -r99e4d6ea2e8c5c2e542357abb2577dd2cd942abf -r963fecfe944d68897b03b6a7df5ba45a53bdfdeb Binary files differ Index: Ringtoets/HydraRing/test/Ringtoets.HydraRing.IO.Test/test-data/HydraulicBoundaryDatabaseReader/corruptLocationSchema.sqlite =================================================================== diff -u -r992bb21b79b0b91860befe22bfc6c6f8c21101f1 -r963fecfe944d68897b03b6a7df5ba45a53bdfdeb Binary files differ Index: Ringtoets/HydraRing/test/Ringtoets.HydraRing.IO.Test/test-data/HydraulicBoundaryDatabaseReader/corruptschema.sqlite =================================================================== diff -u -r99e4d6ea2e8c5c2e542357abb2577dd2cd942abf -r963fecfe944d68897b03b6a7df5ba45a53bdfdeb Binary files differ Index: Ringtoets/HydraRing/test/Ringtoets.HydraRing.IO.Test/test-data/HydraulicBoundaryDatabaseReader/empty.sqlite =================================================================== diff -u -r99e4d6ea2e8c5c2e542357abb2577dd2cd942abf -r963fecfe944d68897b03b6a7df5ba45a53bdfdeb Binary files differ Index: Ringtoets/HydraRing/test/Ringtoets.HydraRing.IO.Test/test-data/HydraulicBoundaryDatabaseReader/emptyGeneral.sqlite =================================================================== diff -u -r8d83ee1765cd387e7b7c67575ac454d546671493 -r963fecfe944d68897b03b6a7df5ba45a53bdfdeb Binary files differ Index: Ringtoets/HydraRing/test/Ringtoets.HydraRing.IO.Test/test-data/HydraulicBoundaryDatabaseReader/emptyschema.sqlite =================================================================== diff -u -r99e4d6ea2e8c5c2e542357abb2577dd2cd942abf -r963fecfe944d68897b03b6a7df5ba45a53bdfdeb Binary files differ Index: Ringtoets/HydraRing/test/Ringtoets.HydraRing.IO.Test/test-data/HydraulicBoundaryDatabaseReader/incompleteVersion.sqlite =================================================================== diff -u -r992bb21b79b0b91860befe22bfc6c6f8c21101f1 -r963fecfe944d68897b03b6a7df5ba45a53bdfdeb Binary files differ Index: Ringtoets/HydraRing/test/Ringtoets.HydraRing.IO.Test/test-data/HydraulicLocationConfigurationDatabase/ambigousLocation.sqlite =================================================================== diff -u -rfef3460a27a37aaa34948649aae3dd9ae143041c -r963fecfe944d68897b03b6a7df5ba45a53bdfdeb Binary files differ Index: Ringtoets/HydraRing/test/Ringtoets.HydraRing.IO.Test/test-data/HydraulicLocationConfigurationDatabase/corruptschema.sqlite =================================================================== diff -u -rf8c28b3b04cdabb62ea37772efcb1f4ebbbf2b9e -r963fecfe944d68897b03b6a7df5ba45a53bdfdeb Binary files differ Index: Ringtoets/HydraRing/test/Ringtoets.HydraRing.IO.Test/test-data/HydraulicLocationConfigurationDatabase/empty.sqlite =================================================================== diff -u -r733d0d51adf737c52704cd80705507fdb34a2ba3 -r963fecfe944d68897b03b6a7df5ba45a53bdfdeb Binary files differ Index: Ringtoets/HydraRing/test/Ringtoets.HydraRing.IO.Test/test-data/HydraulicLocationConfigurationDatabase/hlcdWithScenarioInformation.sqlite =================================================================== diff -u -r8e4f3d24c6dc2bb0536a5585358732bb74b7f9bf -r963fecfe944d68897b03b6a7df5ba45a53bdfdeb Binary files differ Index: Ringtoets/HydraRing/test/Ringtoets.HydraRing.IO.Test/test-data/HydraulicLocationConfigurationDatabase/hlcdWithScenarioInformationInvalidData.sqlite =================================================================== diff -u -r8e4f3d24c6dc2bb0536a5585358732bb74b7f9bf -r963fecfe944d68897b03b6a7df5ba45a53bdfdeb Binary files differ Index: Ringtoets/HydraRing/test/Ringtoets.HydraRing.IO.Test/test-data/HydraulicLocationConfigurationDatabase/hlcdWithScenarioInformationMissingColumn.sqlite =================================================================== diff -u -r8e4f3d24c6dc2bb0536a5585358732bb74b7f9bf -r963fecfe944d68897b03b6a7df5ba45a53bdfdeb Binary files differ Index: Ringtoets/HydraRing/test/Ringtoets.HydraRing.IO.Test/test-data/HydraulicLocationConfigurationDatabase/hlcdWithoutScenarioInformation.sqlite =================================================================== diff -u -r8e4f3d24c6dc2bb0536a5585358732bb74b7f9bf -r963fecfe944d68897b03b6a7df5ba45a53bdfdeb Binary files differ Index: Ringtoets/HydraRing/test/Riskeer.HydraRing.IO.Test/HydraulicBoundaryDatabase/GeneralTableDefinitionsTest.cs =================================================================== diff -u --- Ringtoets/HydraRing/test/Riskeer.HydraRing.IO.Test/HydraulicBoundaryDatabase/GeneralTableDefinitionsTest.cs (revision 0) +++ Ringtoets/HydraRing/test/Riskeer.HydraRing.IO.Test/HydraulicBoundaryDatabase/GeneralTableDefinitionsTest.cs (revision 963fecfe944d68897b03b6a7df5ba45a53bdfdeb) @@ -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; +using Riskeer.HydraRing.IO.HydraulicBoundaryDatabase; + +namespace Riskeer.HydraRing.IO.Test.HydraulicBoundaryDatabase +{ + [TestFixture] + public class GeneralTableDefinitionsTest + { + [Test] + public void Constants_Always_ExpectedValues() + { + Assert.AreEqual("General", GeneralTableDefinitions.TableName); + Assert.AreEqual("NameRegion", GeneralTableDefinitions.RegionName); + Assert.AreEqual("TrackId", GeneralTableDefinitions.TrackId); + Assert.AreEqual("CreationDate", GeneralTableDefinitions.CreationDate); + Assert.AreEqual("GeneratedVersion", GeneralTableDefinitions.GeneratedVersion); + } + } +} \ No newline at end of file Index: Ringtoets/HydraRing/test/Riskeer.HydraRing.IO.Test/HydraulicBoundaryDatabase/HrdLocationsTableDefinitionsTest.cs =================================================================== diff -u --- Ringtoets/HydraRing/test/Riskeer.HydraRing.IO.Test/HydraulicBoundaryDatabase/HrdLocationsTableDefinitionsTest.cs (revision 0) +++ Ringtoets/HydraRing/test/Riskeer.HydraRing.IO.Test/HydraulicBoundaryDatabase/HrdLocationsTableDefinitionsTest.cs (revision 963fecfe944d68897b03b6a7df5ba45a53bdfdeb) @@ -0,0 +1,42 @@ +// 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; +using Riskeer.HydraRing.IO.HydraulicBoundaryDatabase; + +namespace Riskeer.HydraRing.IO.Test.HydraulicBoundaryDatabase +{ + [TestFixture] + public class HrdLocationsTableDefinitionsTest + { + [Test] + public void Constants_Always_ExpectedValues() + { + Assert.AreEqual("HRDLocations", HrdLocationsTableDefinitions.TableName); + Assert.AreEqual("HRDLocationId", HrdLocationsTableDefinitions.HrdLocationId); + Assert.AreEqual("LocationTypeId", HrdLocationsTableDefinitions.LocationTypeId); + Assert.AreEqual("Name", HrdLocationsTableDefinitions.Name); + Assert.AreEqual("XCoordinate", HrdLocationsTableDefinitions.XCoordinate); + Assert.AreEqual("YCoordinate", HrdLocationsTableDefinitions.YCoordinate); + Assert.AreEqual("nrOfRows", HrdLocationsTableDefinitions.Count); + } + } +} \ No newline at end of file Index: Ringtoets/HydraRing/test/Riskeer.HydraRing.IO.Test/HydraulicBoundaryDatabase/HydraulicBoundaryDatabaseQueryBuilderTest.cs =================================================================== diff -u --- Ringtoets/HydraRing/test/Riskeer.HydraRing.IO.Test/HydraulicBoundaryDatabase/HydraulicBoundaryDatabaseQueryBuilderTest.cs (revision 0) +++ Ringtoets/HydraRing/test/Riskeer.HydraRing.IO.Test/HydraulicBoundaryDatabase/HydraulicBoundaryDatabaseQueryBuilderTest.cs (revision 963fecfe944d68897b03b6a7df5ba45a53bdfdeb) @@ -0,0 +1,63 @@ +// 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; +using Riskeer.HydraRing.IO.HydraulicBoundaryDatabase; + +namespace Riskeer.HydraRing.IO.Test.HydraulicBoundaryDatabase +{ + [TestFixture] + public class HydraulicBoundaryDatabaseQueryBuilderTest + { + [Test] + public void GetVersionQuery_Always_ReturnsExpectedValues() + { + // Call + string query = HydraulicBoundaryDatabaseQueryBuilder.GetVersionQuery(); + + // Assert + const string expectedQuery = "SELECT (NameRegion || CreationDate || TrackId) as GeneratedVersion FROM General LIMIT 0,1;"; + Assert.AreEqual(expectedQuery, query); + } + + [Test] + public void GetTrackIdQuery_Always_ReturnsExpectedValues() + { + // Call + string query = HydraulicBoundaryDatabaseQueryBuilder.GetTrackIdQuery(); + + // Assert + const string expectedQuery = "SELECT TrackId FROM General LIMIT 0,1;"; + Assert.AreEqual(expectedQuery, query); + } + + [Test] + public void GetRelevantLocationsQuery_Always_ReturnsExpectedValues() + { + // Call + string query = HydraulicBoundaryDatabaseQueryBuilder.GetRelevantLocationsQuery(); + + // Assert + const string expectedQuery = "SELECT HRDLocationId, Name, XCoordinate, YCoordinate FROM HRDLocations WHERE LocationTypeId > 1;"; + Assert.AreEqual(expectedQuery, query); + } + } +} \ No newline at end of file Index: Ringtoets/HydraRing/test/Riskeer.HydraRing.IO.Test/HydraulicBoundaryDatabase/HydraulicBoundaryDatabaseReaderTest.cs =================================================================== diff -u --- Ringtoets/HydraRing/test/Riskeer.HydraRing.IO.Test/HydraulicBoundaryDatabase/HydraulicBoundaryDatabaseReaderTest.cs (revision 0) +++ Ringtoets/HydraRing/test/Riskeer.HydraRing.IO.Test/HydraulicBoundaryDatabase/HydraulicBoundaryDatabaseReaderTest.cs (revision 963fecfe944d68897b03b6a7df5ba45a53bdfdeb) @@ -0,0 +1,313 @@ +// 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 System.Linq; +using Core.Common.Base.IO; +using Core.Common.IO.Exceptions; +using Core.Common.IO.Readers; +using Core.Common.TestUtil; +using NUnit.Framework; +using Riskeer.HydraRing.IO.HydraulicBoundaryDatabase; + +namespace Riskeer.HydraRing.IO.Test.HydraulicBoundaryDatabase +{ + [TestFixture] + public class HydraulicBoundaryDatabaseReaderTest + { + private readonly string testDataPath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.HydraRing.IO, "HydraulicBoundaryDatabaseReader"); + + [Test] + public void Constructor_ValidFile_ExpectedValues() + { + // Setup + string hydraulicBoundaryDatabaseFile = Path.Combine(testDataPath, "complete.sqlite"); + + // Call + using (var reader = new HydraulicBoundaryDatabaseReader(hydraulicBoundaryDatabaseFile)) + { + // Assert + Assert.AreEqual(hydraulicBoundaryDatabaseFile, reader.Path); + Assert.IsInstanceOf(reader); + } + } + + [Test] + public void Constructor_NonExistingPath_ThrowsCriticalFileReadException() + { + // Setup + string hydraulicBoundaryDatabaseFile = Path.Combine(testDataPath, "doesNotExist.sqlite"); + + // Call + TestDelegate test = () => + { + using (new HydraulicBoundaryDatabaseReader(hydraulicBoundaryDatabaseFile)) {} + }; + + // Assert + string expectedMessage = $"Fout bij het lezen van bestand '{hydraulicBoundaryDatabaseFile}': het bestand bestaat niet."; + var exception = Assert.Throws(test); + Assert.AreEqual(expectedMessage, exception.Message); + } + + [Test] + [TestCase(null)] + [TestCase("")] + public void Constructor_FilePathNullOrEmpty_ThrowsCriticalFileReadException(string hydraulicBoundaryDatabaseFilePath) + { + // Call + TestDelegate test = () => + { + using (new HydraulicBoundaryDatabaseReader(hydraulicBoundaryDatabaseFilePath)) {} + }; + + // Assert + string expectedMessage = $"Fout bij het lezen van bestand '{hydraulicBoundaryDatabaseFilePath}': bestandspad mag niet leeg of ongedefinieerd zijn."; + var exception = Assert.Throws(test); + Assert.AreEqual(expectedMessage, exception.Message); + } + + [Test] + public void Read_EmptyDatabase_ThrowsCriticalFileReadException() + { + // Setup + string hydraulicBoundaryDatabaseFile = Path.Combine(testDataPath, "empty.sqlite"); + + using (var reader = new HydraulicBoundaryDatabaseReader(hydraulicBoundaryDatabaseFile)) + { + // Call + TestDelegate test = () => reader.Read(); + + // Assert + string expectedMessage = $"Fout bij het lezen van bestand '{hydraulicBoundaryDatabaseFile}': kon geen locaties verkrijgen van de database."; + var exception = Assert.Throws(test); + Assert.AreEqual(expectedMessage, exception.Message); + Assert.IsInstanceOf(exception.InnerException); + } + } + + [Test] + public void Read_DatabaseWithoutTrackId_ThrowsCriticalFileReadException() + { + // Setup + string hydraulicBoundaryDatabaseFile = Path.Combine(testDataPath, "emptyGeneral.sqlite"); + + using (var reader = new HydraulicBoundaryDatabaseReader(hydraulicBoundaryDatabaseFile)) + { + // Call + TestDelegate test = () => reader.Read(); + + // Assert + string expectedMessage = $"Fout bij het lezen van bestand '{hydraulicBoundaryDatabaseFile}': kritieke fout opgetreden bij het uitlezen van waardes uit kolommen in de database."; + var exception = Assert.Throws(test); + Assert.AreEqual(expectedMessage, exception.Message); + } + } + + [Test] + public void Read_InvalidTrackIdColumn_ThrowsLineParseException() + { + // Setup + string hydraulicBoundaryDatabaseFile = Path.Combine(testDataPath, "corruptschema.sqlite"); + + using (var reader = new HydraulicBoundaryDatabaseReader(hydraulicBoundaryDatabaseFile)) + { + // Call + TestDelegate test = () => reader.Read(); + + // Assert + var exception = Assert.Throws(test); + string expectedMessage = $"Fout bij het lezen van bestand '{hydraulicBoundaryDatabaseFile}': kritieke fout opgetreden bij het uitlezen van waardes uit kolommen in de database."; + Assert.AreEqual(expectedMessage, exception.Message); + Assert.IsInstanceOf(exception.InnerException); + } + } + + [Test] + public void Read_DatabaseSchemaInvalidLocationColumns_ThrowsLineParseException() + { + // Setup + string hydraulicBoundaryDatabaseFile = Path.Combine(testDataPath, "corruptLocationSchema.sqlite"); + + using (var reader = new HydraulicBoundaryDatabaseReader(hydraulicBoundaryDatabaseFile)) + { + // Call + TestDelegate test = () => reader.Read(); + + // Assert + var exception = Assert.Throws(test); + string expectedMessage = $"Fout bij het lezen van bestand '{hydraulicBoundaryDatabaseFile}': kritieke fout opgetreden bij het uitlezen van waardes uit kolommen in de database."; + Assert.AreEqual(expectedMessage, exception.Message); + Assert.IsInstanceOf(exception.InnerException); + } + } + + [Test] + public void Read_ValidFile_ReturnsReadHydraulicBoundaryDatabase() + { + // Setup + string hydraulicBoundaryDatabaseFile = Path.Combine(testDataPath, "complete.sqlite"); + + using (var reader = new HydraulicBoundaryDatabaseReader(hydraulicBoundaryDatabaseFile)) + { + // Call + ReadHydraulicBoundaryDatabase readDatabase = reader.Read(); + + // Assert + Assert.AreEqual("Dutch coast South19-11-2015 12:0013", readDatabase.Version); + Assert.AreEqual(13, readDatabase.TrackId); + Assert.AreEqual(18, readDatabase.Locations.Count()); + ReadHydraulicBoundaryLocation location = readDatabase.Locations.First(); + Assert.AreEqual(1, location.Id); + Assert.AreEqual("punt_flw_ 1", location.Name); + Assert.AreEqual(52697.5, location.CoordinateX); + Assert.AreEqual(427567.0, location.CoordinateY); + } + } + + [Test] + public void ReadTrackId_EmptyDatabase_ThrowsCriticalFileReadException() + { + // Setup + string hydraulicBoundaryDatabaseFile = Path.Combine(testDataPath, "emptyGeneral.sqlite"); + + using (var reader = new HydraulicBoundaryDatabaseReader(hydraulicBoundaryDatabaseFile)) + { + // Call + TestDelegate test = () => reader.ReadTrackId(); + + // Assert + string expectedMessage = $"Fout bij het lezen van bestand '{hydraulicBoundaryDatabaseFile}': kritieke fout opgetreden bij het uitlezen van waardes uit kolommen in de database."; + var exception = Assert.Throws(test); + Assert.AreEqual(expectedMessage, exception.Message); + } + } + + [Test] + public void ReadTrackId_InvalidDatabaseWithoutGeneralTable_ThrowsCriticalFileReadException() + { + // Setup + string hydraulicBoundaryDatabaseFile = Path.Combine(testDataPath, "empty.sqlite"); + + using (var reader = new HydraulicBoundaryDatabaseReader(hydraulicBoundaryDatabaseFile)) + { + // Call + TestDelegate test = () => reader.ReadTrackId(); + + // Assert + var exception = Assert.Throws(test); + string expectedMessage = $"Fout bij het lezen van bestand '{hydraulicBoundaryDatabaseFile}': kon geen locaties verkrijgen van de database."; + Assert.AreEqual(expectedMessage, exception.Message); + Assert.IsInstanceOf(exception.InnerException); + } + } + + [Test] + public void ReadTrackId_InvalidTrackIdColumn_ThrowsLineParseException() + { + // Setup + string hydraulicBoundaryDatabaseFile = Path.Combine(testDataPath, "corruptSchema.sqlite"); + + using (var reader = new HydraulicBoundaryDatabaseReader(hydraulicBoundaryDatabaseFile)) + { + // Call + TestDelegate test = () => reader.ReadTrackId(); + + // Assert + var exception = Assert.Throws(test); + string expectedMessage = $"Fout bij het lezen van bestand '{hydraulicBoundaryDatabaseFile}': kritieke fout opgetreden bij het uitlezen van waardes uit kolommen in de database."; + Assert.AreEqual(expectedMessage, exception.Message); + Assert.IsInstanceOf(exception.InnerException); + } + } + + [Test] + public void ReadTrackId_ValidFile_ReturnsReadVersion() + { + // Setup + string hydraulicBoundaryDatabaseFile = Path.Combine(testDataPath, "complete.sqlite"); + + using (var reader = new HydraulicBoundaryDatabaseReader(hydraulicBoundaryDatabaseFile)) + { + // Call + long trackId = reader.ReadTrackId(); + + // Assert + Assert.AreEqual(13, trackId); + } + } + + [Test] + public void ReadVersion_EmptyDatabase_ThrowsCriticalFileReadException() + { + // Setup + string hydraulicBoundaryDatabaseFile = Path.Combine(testDataPath, "emptyGeneral.sqlite"); + + using (var reader = new HydraulicBoundaryDatabaseReader(hydraulicBoundaryDatabaseFile)) + { + // Call + TestDelegate test = () => reader.ReadVersion(); + + // Assert + string expectedMessage = $"Fout bij het lezen van bestand '{hydraulicBoundaryDatabaseFile}': kritieke fout opgetreden bij het uitlezen van waardes uit kolommen in de database."; + var exception = Assert.Throws(test); + Assert.AreEqual(expectedMessage, exception.Message); + } + } + + [Test] + public void ReadVersion_InvalidTrackIdColumn_ThrowsCriticalFileReadException() + { + // Setup + string hydraulicBoundaryDatabaseFile = Path.Combine(testDataPath, "empty.sqlite"); + + using (var reader = new HydraulicBoundaryDatabaseReader(hydraulicBoundaryDatabaseFile)) + { + // Call + TestDelegate test = () => reader.ReadVersion(); + + // Assert + var exception = Assert.Throws(test); + string expectedMessage = $"Fout bij het lezen van bestand '{hydraulicBoundaryDatabaseFile}': kon geen locaties verkrijgen van de database."; + Assert.AreEqual(expectedMessage, exception.Message); + Assert.IsInstanceOf(exception.InnerException); + } + } + + [Test] + public void ReadVersion_ValidFile_ReturnsReadVersion() + { + // Setup + string hydraulicBoundaryDatabaseFile = Path.Combine(testDataPath, "complete.sqlite"); + + using (var reader = new HydraulicBoundaryDatabaseReader(hydraulicBoundaryDatabaseFile)) + { + // Call + string version= reader.ReadVersion(); + + // Assert + Assert.AreEqual("Dutch coast South19-11-2015 12:0013", version); + } + } + } +} \ No newline at end of file Index: Ringtoets/HydraRing/test/Riskeer.HydraRing.IO.Test/HydraulicBoundaryDatabase/ReadHydraulicBoundaryDatabaseTest.cs =================================================================== diff -u --- Ringtoets/HydraRing/test/Riskeer.HydraRing.IO.Test/HydraulicBoundaryDatabase/ReadHydraulicBoundaryDatabaseTest.cs (revision 0) +++ Ringtoets/HydraRing/test/Riskeer.HydraRing.IO.Test/HydraulicBoundaryDatabase/ReadHydraulicBoundaryDatabaseTest.cs (revision 963fecfe944d68897b03b6a7df5ba45a53bdfdeb) @@ -0,0 +1,49 @@ +// 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.Collections.Generic; +using System.Linq; +using NUnit.Framework; +using Riskeer.HydraRing.IO.HydraulicBoundaryDatabase; + +namespace Riskeer.HydraRing.IO.Test.HydraulicBoundaryDatabase +{ + [TestFixture] + public class ReadHydraulicBoundaryDatabaseTest + { + [Test] + public void Constructor_ExpectedValues() + { + // Setup + const long trackId = 1; + const string version = "version"; + IEnumerable locations = Enumerable.Empty(); + + // Call + var database = new ReadHydraulicBoundaryDatabase(trackId, version, locations); + + // Assert + Assert.AreEqual(trackId, database.TrackId); + Assert.AreEqual(version, database.Version); + Assert.AreSame(locations, database.Locations); + } + } +} \ No newline at end of file Index: Ringtoets/HydraRing/test/Riskeer.HydraRing.IO.Test/HydraulicBoundaryDatabase/ReadHydraulicBoundaryLocationTest.cs =================================================================== diff -u --- Ringtoets/HydraRing/test/Riskeer.HydraRing.IO.Test/HydraulicBoundaryDatabase/ReadHydraulicBoundaryLocationTest.cs (revision 0) +++ Ringtoets/HydraRing/test/Riskeer.HydraRing.IO.Test/HydraulicBoundaryDatabase/ReadHydraulicBoundaryLocationTest.cs (revision 963fecfe944d68897b03b6a7df5ba45a53bdfdeb) @@ -0,0 +1,62 @@ +// 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 NUnit.Framework; +using Riskeer.HydraRing.IO.HydraulicBoundaryDatabase; + +namespace Riskeer.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 Index: Ringtoets/HydraRing/test/Riskeer.HydraRing.IO.Test/HydraulicLocationConfigurationDatabase/HydraulicLocationConfigurationDatabaseQueryBuilderTest.cs =================================================================== diff -u --- Ringtoets/HydraRing/test/Riskeer.HydraRing.IO.Test/HydraulicLocationConfigurationDatabase/HydraulicLocationConfigurationDatabaseQueryBuilderTest.cs (revision 0) +++ Ringtoets/HydraRing/test/Riskeer.HydraRing.IO.Test/HydraulicLocationConfigurationDatabase/HydraulicLocationConfigurationDatabaseQueryBuilderTest.cs (revision 963fecfe944d68897b03b6a7df5ba45a53bdfdeb) @@ -0,0 +1,66 @@ +// 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; +using Riskeer.HydraRing.IO.HydraulicLocationConfigurationDatabase; + +namespace Riskeer.HydraRing.IO.Test.HydraulicLocationConfigurationDatabase +{ + [TestFixture] + public class HydraulicLocationConfigurationDatabaseQueryBuilderTest + { + [Test] + public void GetLocationIdsByTrackIdQuery_Always_ReturnsExpectedValue() + { + // Call + string query = HydraulicLocationConfigurationDatabaseQueryBuilder.GetLocationIdsByTrackIdQuery(); + + // Assert + const string expectedQuery = "SELECT LocationId, HRDLocationId FROM Locations WHERE TrackId = @TrackId ORDER BY HRDLocationId;"; + Assert.AreEqual(expectedQuery, query); + } + + [Test] + public void GetIsScenarioInformationPresentQuery_Always_ReturnsExpectedValue() + { + // Call + string query = HydraulicLocationConfigurationDatabaseQueryBuilder.GetIsScenarioInformationPresentQuery(); + + // Assert + const string expectedQuery = "SELECT COUNT() = 1 AS IsScenarioInformationPresent " + + "FROM sqlite_master WHERE type = 'table' " + + "AND name='ScenarioInformation';"; + Assert.AreEqual(expectedQuery, query); + } + + [Test] + public void GetScenarioInformationQuery_Always_ReturnsExpectedValue() + { + // Call + string query = HydraulicLocationConfigurationDatabaseQueryBuilder.GetScenarioInformationQuery(); + + // Assert + const string expectedQuery = "SELECT ScenarioName, Year, Scope, SeaLevel, RiverDischarge, LakeLevel, WindDirection, WindSpeed, Comment " + + "FROM ScenarioInformation;"; + Assert.AreEqual(expectedQuery, query); + } + } +} \ No newline at end of file Index: Ringtoets/HydraRing/test/Riskeer.HydraRing.IO.Test/HydraulicLocationConfigurationDatabase/HydraulicLocationConfigurationDatabaseReaderTest.cs =================================================================== diff -u --- Ringtoets/HydraRing/test/Riskeer.HydraRing.IO.Test/HydraulicLocationConfigurationDatabase/HydraulicLocationConfigurationDatabaseReaderTest.cs (revision 0) +++ Ringtoets/HydraRing/test/Riskeer.HydraRing.IO.Test/HydraulicLocationConfigurationDatabase/HydraulicLocationConfigurationDatabaseReaderTest.cs (revision 963fecfe944d68897b03b6a7df5ba45a53bdfdeb) @@ -0,0 +1,271 @@ +// 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.Generic; +using System.Data.SQLite; +using System.IO; +using System.Linq; +using Core.Common.Base.IO; +using Core.Common.IO.Exceptions; +using Core.Common.IO.Readers; +using Core.Common.TestUtil; +using Core.Common.Util.Builders; +using NUnit.Framework; +using Riskeer.HydraRing.IO.HydraulicLocationConfigurationDatabase; + +namespace Riskeer.HydraRing.IO.Test.HydraulicLocationConfigurationDatabase +{ + [TestFixture] + public class HydraulicLocationConfigurationDatabaseReaderTest + { + private readonly string testDataPath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.HydraRing.IO, "HydraulicLocationConfigurationDatabase"); + + [Test] + public void Constructor_InvalidFile_ThrowsCriticalFileReadException() + { + // Setup + string dbFile = Path.Combine(testDataPath, "none.sqlite"); + + // Call + TestDelegate test = () => + { + using (new HydraulicLocationConfigurationDatabaseReader(dbFile)) {} + }; + + // Assert + var exception = Assert.Throws(test); + string expectedMessage = new FileReaderErrorMessageBuilder(dbFile).Build("Het bestand bestaat niet."); + Assert.AreEqual(expectedMessage, exception.Message); + } + + [Test] + public void Constructor_ValidFile_ExpectedValues() + { + // Setup + string dbFile = Path.Combine(testDataPath, "hlcdWithoutScenarioInformation.sqlite"); + + // Call + using (var hydraulicBoundaryDatabaseReader = new HydraulicLocationConfigurationDatabaseReader(dbFile)) + { + // Assert + Assert.IsInstanceOf(hydraulicBoundaryDatabaseReader); + } + } + + [Test] + [TestCase(18169, 1000, 1801000)] + [TestCase(6, 1000, 0)] + public void Read_ValidFileWithoutScenarioInformation_ExpectedValues(int trackId, int hrdLocationId, int expectedLocationId) + { + // Setup + string dbFile = Path.Combine(testDataPath, "hlcdWithoutScenarioInformation.sqlite"); + + using (var hydraulicBoundaryDatabaseReader = new HydraulicLocationConfigurationDatabaseReader(dbFile)) + { + // Call + ReadHydraulicLocationConfigurationDatabase readHydraulicLocationConfigurationDatabase = hydraulicBoundaryDatabaseReader.Read(trackId); + + // Assert + long actualLocationId = readHydraulicLocationConfigurationDatabase.LocationIdMappings.Where(m => m.HrdLocationId == hrdLocationId) + .Select(m => m.HlcdLocationId) + .SingleOrDefault(); + Assert.AreEqual(expectedLocationId, actualLocationId); + Assert.IsNull(readHydraulicLocationConfigurationDatabase.ReadHydraulicLocationConfigurationDatabaseSettings); + } + } + + [Test] + [TestCase(18169, 1000, 1801000)] + [TestCase(6, 1000, 0)] + public void Read_ValidFileWithScenarioInformation_ExpectedValues(int trackId, int hrdLocationId, int expectedLocationId) + { + // Setup + string dbFile = Path.Combine(testDataPath, "hlcdWithScenarioInformation.sqlite"); + + using (var hydraulicBoundaryDatabaseReader = new HydraulicLocationConfigurationDatabaseReader(dbFile)) + { + // Call + ReadHydraulicLocationConfigurationDatabase readHydraulicLocationConfigurationDatabase = hydraulicBoundaryDatabaseReader.Read(trackId); + + // Assert + long actualLocationId = readHydraulicLocationConfigurationDatabase.LocationIdMappings.Where(m => m.HrdLocationId == hrdLocationId) + .Select(m => m.HlcdLocationId) + .SingleOrDefault(); + Assert.AreEqual(expectedLocationId, actualLocationId); + IEnumerable readHydraulicLocationConfigurationDatabaseSettings = + readHydraulicLocationConfigurationDatabase.ReadHydraulicLocationConfigurationDatabaseSettings; + Assert.AreEqual(2, readHydraulicLocationConfigurationDatabaseSettings.Count()); + + CollectionAssert.AreEqual(new[] + { + "ScenarioName WBI2017", + "ScenarioName WBI2018" + }, readHydraulicLocationConfigurationDatabaseSettings.Select(s => s.ScenarioName)); + CollectionAssert.AreEqual(new[] + { + 2023, + 2024 + }, readHydraulicLocationConfigurationDatabaseSettings.Select(s => s.Year)); + CollectionAssert.AreEqual(new[] + { + "Scope WBI2017", + "Scope WBI2018" + }, readHydraulicLocationConfigurationDatabaseSettings.Select(s => s.Scope)); + CollectionAssert.AreEqual(new[] + { + "SeaLevel WBI2017", + "SeaLevel WBI2018" + }, readHydraulicLocationConfigurationDatabaseSettings.Select(s => s.SeaLevel)); + CollectionAssert.AreEqual(new[] + { + "RiverDischarge WBI2017", + "RiverDischarge WBI2018" + }, readHydraulicLocationConfigurationDatabaseSettings.Select(s => s.RiverDischarge)); + CollectionAssert.AreEqual(new[] + { + "LakeLevel WBI2017", + "LakeLevel WBI2018" + }, readHydraulicLocationConfigurationDatabaseSettings.Select(s => s.LakeLevel)); + CollectionAssert.AreEqual(new[] + { + "WindDirection WBI2017", + "WindDirection WBI2018" + }, readHydraulicLocationConfigurationDatabaseSettings.Select(s => s.WindDirection)); + CollectionAssert.AreEqual(new[] + { + "WindSpeed WBI2017", + "WindSpeed WBI2018" + }, readHydraulicLocationConfigurationDatabaseSettings.Select(s => s.WindSpeed)); + CollectionAssert.AreEqual(new[] + { + "Comment WBI2017", + "Comment WBI2018" + }, readHydraulicLocationConfigurationDatabaseSettings.Select(s => s.Comment)); + } + } + + [Test] + public void Read_FileWithScenarioInformationAndMissingColumns_ThrowsCriticalFileReadException() + { + // Setup + const int trackId = 18169; + string dbFile = Path.Combine(testDataPath, "hlcdWithScenarioInformationMissingColumn.sqlite"); + + using (var hydraulicBoundaryDatabaseReader = new HydraulicLocationConfigurationDatabaseReader(dbFile)) + { + // Call + TestDelegate test = () => hydraulicBoundaryDatabaseReader.Read(trackId); + + // Assert + string expectedMessage = new FileReaderErrorMessageBuilder(dbFile).Build("Het bevragen van de database is mislukt."); + var exception = Assert.Throws(test); + Assert.AreEqual(expectedMessage, exception.Message); + Assert.IsInstanceOf(exception.InnerException); + } + } + + [Test] + public void Read_FileWithScenarioInformationAndInvalidData_ThrowsLineParseException() + { + // Setup + const int trackId = 18169; + string dbFile = Path.Combine(testDataPath, "hlcdWithScenarioInformationInvalidData.sqlite"); + + using (var hydraulicBoundaryDatabaseReader = new HydraulicLocationConfigurationDatabaseReader(dbFile)) + { + // Call + TestDelegate test = () => hydraulicBoundaryDatabaseReader.Read(trackId); + + // Assert + string expectedMessage = new FileReaderErrorMessageBuilder(dbFile).Build("Kritieke fout opgetreden bij het uitlezen van waardes uit kolommen in de database."); + var exception = Assert.Throws(test); + Assert.AreEqual(expectedMessage, exception.Message); + Assert.IsInstanceOf(exception.InnerException); + } + } + + [Test] + public void Read_AmbiguousLocations_ReturnsFirstLocationIdAndLogsWarning() + { + // Setup + string dbFile = Path.Combine(testDataPath, "ambigousLocation.sqlite"); + const int trackId = 18; + const int hrdLocationId = 1; + ReadHydraulicLocationConfigurationDatabase readHydraulicLocationConfigurationDatabase = null; + + using (var hydraulicBoundaryDatabaseReader = new HydraulicLocationConfigurationDatabaseReader(dbFile)) + { + // Call + Action call = () => readHydraulicLocationConfigurationDatabase = hydraulicBoundaryDatabaseReader.Read(trackId); + + // Assert + const int expectedLocationId = 1800001; + const string expectedMessage = "Er zijn meerdere resultaten gevonden, wat niet voor zou mogen komen. Neem contact op met de leverancier. Het eerste resultaat zal worden gebruikt."; + TestHelper.AssertLogMessageIsGenerated(call, expectedMessage, 1); + long actualLocationId = readHydraulicLocationConfigurationDatabase.LocationIdMappings.Where(m => m.HrdLocationId == hrdLocationId) + .Select(m => m.HlcdLocationId) + .Single(); + Assert.AreEqual(expectedLocationId, actualLocationId); + } + } + + [Test] + public void Read_InvalidColumns_ThrowsLineParseException() + { + // Setup + string dbFile = Path.Combine(testDataPath, "corruptschema.sqlite"); + const int trackId = 1; + + using (var hydraulicBoundaryDatabaseReader = new HydraulicLocationConfigurationDatabaseReader(dbFile)) + { + // Call + TestDelegate test = () => hydraulicBoundaryDatabaseReader.Read(trackId); + + // Assert + string expectedMessage = new FileReaderErrorMessageBuilder(dbFile).Build("Kritieke fout opgetreden bij het uitlezen van waardes uit kolommen in de database."); + var exception = Assert.Throws(test); + Assert.AreEqual(expectedMessage, exception.Message); + Assert.IsInstanceOf(exception.InnerException); + } + } + + [Test] + public void Read_EmptyFile_ThrowsCriticalFileReadException() + { + // Setup + string dbFile = Path.Combine(testDataPath, "empty.sqlite"); + const int trackId = 1; + + using (var hydraulicBoundaryDatabaseReader = new HydraulicLocationConfigurationDatabaseReader(dbFile)) + { + // Call + TestDelegate test = () => hydraulicBoundaryDatabaseReader.Read(trackId); + + // Assert + string expectedMessage = new FileReaderErrorMessageBuilder(dbFile).Build("Het bevragen van de database is mislukt."); + var exception = Assert.Throws(test); + Assert.AreEqual(expectedMessage, exception.Message); + Assert.IsInstanceOf(exception.InnerException); + } + } + } +} \ No newline at end of file Index: Ringtoets/HydraRing/test/Riskeer.HydraRing.IO.Test/HydraulicLocationConfigurationDatabase/LocationsTableDefinitionsTest.cs =================================================================== diff -u --- Ringtoets/HydraRing/test/Riskeer.HydraRing.IO.Test/HydraulicLocationConfigurationDatabase/LocationsTableDefinitionsTest.cs (revision 0) +++ Ringtoets/HydraRing/test/Riskeer.HydraRing.IO.Test/HydraulicLocationConfigurationDatabase/LocationsTableDefinitionsTest.cs (revision 963fecfe944d68897b03b6a7df5ba45a53bdfdeb) @@ -0,0 +1,39 @@ +// 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; +using Riskeer.HydraRing.IO.HydraulicLocationConfigurationDatabase; + +namespace Riskeer.HydraRing.IO.Test.HydraulicLocationConfigurationDatabase +{ + [TestFixture] + public class LocationsTableDefinitionsTest + { + [Test] + public void Constants_Always_ExpectedValues() + { + Assert.AreEqual("Locations", LocationsTableDefinitions.TableName); + Assert.AreEqual("HRDLocationId", LocationsTableDefinitions.HrdLocationId); + Assert.AreEqual("LocationId", LocationsTableDefinitions.LocationId); + Assert.AreEqual("TrackId", LocationsTableDefinitions.TrackId); + } + } +} \ No newline at end of file Index: Ringtoets/HydraRing/test/Riskeer.HydraRing.IO.Test/HydraulicLocationConfigurationDatabase/ReadHydraulicLocationConfigurationDatabaseSettingsTest.cs =================================================================== diff -u --- Ringtoets/HydraRing/test/Riskeer.HydraRing.IO.Test/HydraulicLocationConfigurationDatabase/ReadHydraulicLocationConfigurationDatabaseSettingsTest.cs (revision 0) +++ Ringtoets/HydraRing/test/Riskeer.HydraRing.IO.Test/HydraulicLocationConfigurationDatabase/ReadHydraulicLocationConfigurationDatabaseSettingsTest.cs (revision 963fecfe944d68897b03b6a7df5ba45a53bdfdeb) @@ -0,0 +1,86 @@ +// 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 NUnit.Framework; +using Riskeer.HydraRing.IO.HydraulicLocationConfigurationDatabase; + +namespace Riskeer.HydraRing.IO.Test.HydraulicLocationConfigurationDatabase +{ + [TestFixture] + public class ReadHydraulicLocationConfigurationDatabaseSettingsTest + { + [Test] + public void Constructor_WithArgumentsNull_ExpectedValues() + { + // Setup + var random = new Random(21); + int year = random.Next(); + + // Call + var settings = new ReadHydraulicLocationConfigurationDatabaseSettings(null, year, null, null, null, + null, null, null, null); + + // Assert + Assert.IsNull(settings.ScenarioName); + Assert.AreEqual(year, settings.Year); + Assert.IsNull(settings.Scope); + Assert.IsNull(settings.SeaLevel); + Assert.IsNull(settings.RiverDischarge); + Assert.IsNull(settings.LakeLevel); + Assert.IsNull(settings.WindDirection); + Assert.IsNull(settings.WindSpeed); + Assert.IsNull(settings.Comment); + } + + [Test] + public void Constructor_WithArgumentValues_ExpectedValues() + { + // Setup + var random = new Random(21); + const string scenarioName = "ScenarioName"; + int year = random.Next(); + const string scope = "Scope"; + const string seaLevel = "SeaLevel"; + const string riverDischarge = "RiverDischarge"; + const string lakeLevel = "LakeLevel"; + const string windDirection = "WindDirection"; + const string windSpeed = "WindSpeed"; + const string comment = "Comment"; + + // Call + var settings = new ReadHydraulicLocationConfigurationDatabaseSettings(scenarioName, year, scope, + seaLevel, riverDischarge, lakeLevel, + windDirection, windSpeed, comment); + + // Assert + Assert.AreEqual(scenarioName, settings.ScenarioName); + Assert.AreEqual(year, settings.Year); + Assert.AreEqual(scope, settings.Scope); + Assert.AreEqual(seaLevel, settings.SeaLevel); + Assert.AreEqual(riverDischarge, settings.RiverDischarge); + Assert.AreEqual(lakeLevel, settings.LakeLevel); + Assert.AreEqual(windDirection, settings.WindDirection); + Assert.AreEqual(windSpeed, settings.WindSpeed); + Assert.AreEqual(comment, settings.Comment); + } + } +} \ No newline at end of file Index: Ringtoets/HydraRing/test/Riskeer.HydraRing.IO.Test/HydraulicLocationConfigurationDatabase/ReadHydraulicLocationConfigurationDatabaseTest.cs =================================================================== diff -u --- Ringtoets/HydraRing/test/Riskeer.HydraRing.IO.Test/HydraulicLocationConfigurationDatabase/ReadHydraulicLocationConfigurationDatabaseTest.cs (revision 0) +++ Ringtoets/HydraRing/test/Riskeer.HydraRing.IO.Test/HydraulicLocationConfigurationDatabase/ReadHydraulicLocationConfigurationDatabaseTest.cs (revision 963fecfe944d68897b03b6a7df5ba45a53bdfdeb) @@ -0,0 +1,47 @@ +// 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.Collections.Generic; +using System.Linq; +using NUnit.Framework; +using Riskeer.HydraRing.IO.HydraulicLocationConfigurationDatabase; + +namespace Riskeer.HydraRing.IO.Test.HydraulicLocationConfigurationDatabase +{ + [TestFixture] + public class ReadHydraulicLocationConfigurationDatabaseTest + { + [Test] + public void Constructor_ExpectedValues() + { + // Setup + IEnumerable locationIdMappings = Enumerable.Empty(); + IEnumerable databaseSettings = Enumerable.Empty(); + + // Call + var readDatabase = new ReadHydraulicLocationConfigurationDatabase(locationIdMappings, databaseSettings); + + // Assert + Assert.AreSame(locationIdMappings, readDatabase.LocationIdMappings); + Assert.AreSame(databaseSettings, readDatabase.ReadHydraulicLocationConfigurationDatabaseSettings); + } + } +} \ No newline at end of file Index: Ringtoets/HydraRing/test/Riskeer.HydraRing.IO.Test/HydraulicLocationConfigurationDatabase/ReadHydraulicLocationMappingTest.cs =================================================================== diff -u --- Ringtoets/HydraRing/test/Riskeer.HydraRing.IO.Test/HydraulicLocationConfigurationDatabase/ReadHydraulicLocationMappingTest.cs (revision 0) +++ Ringtoets/HydraRing/test/Riskeer.HydraRing.IO.Test/HydraulicLocationConfigurationDatabase/ReadHydraulicLocationMappingTest.cs (revision 963fecfe944d68897b03b6a7df5ba45a53bdfdeb) @@ -0,0 +1,47 @@ +// 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 NUnit.Framework; +using Riskeer.HydraRing.IO.HydraulicLocationConfigurationDatabase; + +namespace Riskeer.HydraRing.IO.Test.HydraulicLocationConfigurationDatabase +{ + [TestFixture] + public class ReadHydraulicLocationMappingTest + { + [Test] + public void Constructor_ExpectedValues() + { + // Setup + var random = new Random(21); + long hrdLocationId = random.Next(); + long hlcdLocationId = random.Next(); + + // Call + var locationMapping = new ReadHydraulicLocationMapping(hrdLocationId, hlcdLocationId); + + // Assert + Assert.AreEqual(hrdLocationId, locationMapping.HrdLocationId); + Assert.AreEqual(hlcdLocationId, locationMapping.HlcdLocationId); + } + } +} \ No newline at end of file Index: Ringtoets/HydraRing/test/Riskeer.HydraRing.IO.Test/HydraulicLocationConfigurationDatabase/ScenarioInformationTableDefinitionsTest.cs =================================================================== diff -u --- Ringtoets/HydraRing/test/Riskeer.HydraRing.IO.Test/HydraulicLocationConfigurationDatabase/ScenarioInformationTableDefinitionsTest.cs (revision 0) +++ Ringtoets/HydraRing/test/Riskeer.HydraRing.IO.Test/HydraulicLocationConfigurationDatabase/ScenarioInformationTableDefinitionsTest.cs (revision 963fecfe944d68897b03b6a7df5ba45a53bdfdeb) @@ -0,0 +1,46 @@ +// 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; +using Riskeer.HydraRing.IO.HydraulicLocationConfigurationDatabase; + +namespace Riskeer.HydraRing.IO.Test.HydraulicLocationConfigurationDatabase +{ + [TestFixture] + public class ScenarioInformationTableDefinitionsTest + { + [Test] + public void Constants_Always_ExpectedValues() + { + Assert.AreEqual("ScenarioName", ScenarioInformationTableDefinitions.ScenarioName); + Assert.AreEqual("Year", ScenarioInformationTableDefinitions.Year); + Assert.AreEqual("Scope", ScenarioInformationTableDefinitions.Scope); + Assert.AreEqual("SeaLevel", ScenarioInformationTableDefinitions.SeaLevel); + Assert.AreEqual("RiverDischarge", ScenarioInformationTableDefinitions.RiverDischarge); + Assert.AreEqual("LakeLevel", ScenarioInformationTableDefinitions.LakeLevel); + Assert.AreEqual("WindDirection", ScenarioInformationTableDefinitions.WindDirection); + Assert.AreEqual("WindSpeed", ScenarioInformationTableDefinitions.WindSpeed); + Assert.AreEqual("Comment", ScenarioInformationTableDefinitions.Comment); + Assert.AreEqual("IsScenarioInformationPresent", ScenarioInformationTableDefinitions.IsScenarioInformationPresent); + Assert.AreEqual("ScenarioInformation", ScenarioInformationTableDefinitions.TableName); + } + } +} \ No newline at end of file Index: Ringtoets/HydraRing/test/Riskeer.HydraRing.IO.Test/Properties/AssemblyInfo.cs =================================================================== diff -u --- Ringtoets/HydraRing/test/Riskeer.HydraRing.IO.Test/Properties/AssemblyInfo.cs (revision 0) +++ Ringtoets/HydraRing/test/Riskeer.HydraRing.IO.Test/Properties/AssemblyInfo.cs (revision 963fecfe944d68897b03b6a7df5ba45a53bdfdeb) @@ -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.HydraRing.IO.Test")] +[assembly: AssemblyProduct("Riskeer.HydraRing.IO.Test")] \ No newline at end of file Index: Ringtoets/HydraRing/test/Riskeer.HydraRing.IO.Test/Riskeer.HydraRing.IO.Test.csproj =================================================================== diff -u --- Ringtoets/HydraRing/test/Riskeer.HydraRing.IO.Test/Riskeer.HydraRing.IO.Test.csproj (revision 0) +++ Ringtoets/HydraRing/test/Riskeer.HydraRing.IO.Test/Riskeer.HydraRing.IO.Test.csproj (revision 963fecfe944d68897b03b6a7df5ba45a53bdfdeb) @@ -0,0 +1,73 @@ + + + + {CA7B5888-2BC9-4FE2-9F58-FBC6D7ED8221} + Riskeer.HydraRing.IO.Test + Riskeer.HydraRing.IO.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 + True + + + + + + + + + + + + + + + + + + + + + Copying.licenseheader + + + + + + {3bbfd65b-b277-4e50-ae6d-bd24c3434609} + Core.Common.Base + + + {E344867E-9AC9-44C8-88A5-8185681679A9} + Core.Common.IO + + + {F49BD8B2-332A-4C91-A196-8CCE0A2C7D98} + Core.Common.Util + + + {D749EE4C-CE50-4C17-BF01-9A953028C126} + Core.Common.TestUtil + + + {B69D5B6C-6E14-4FA9-9EBC-8F97678CDB70} + Riskeer.HydraRing.IO + + + + + + 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/HydraRing/test/Riskeer.HydraRing.IO.Test/packages.config =================================================================== diff -u --- Ringtoets/HydraRing/test/Riskeer.HydraRing.IO.Test/packages.config (revision 0) +++ Ringtoets/HydraRing/test/Riskeer.HydraRing.IO.Test/packages.config (revision 963fecfe944d68897b03b6a7df5ba45a53bdfdeb) @@ -0,0 +1,27 @@ + + + + + + \ No newline at end of file Index: Ringtoets/HydraRing/test/Riskeer.HydraRing.IO.Test/test-data/HydraulicBoundaryDatabaseReader/complete.sqlite =================================================================== diff -u Binary files differ Index: Ringtoets/HydraRing/test/Riskeer.HydraRing.IO.Test/test-data/HydraulicBoundaryDatabaseReader/corruptLocationSchema.sqlite =================================================================== diff -u Binary files differ Index: Ringtoets/HydraRing/test/Riskeer.HydraRing.IO.Test/test-data/HydraulicBoundaryDatabaseReader/corruptschema.sqlite =================================================================== diff -u Binary files differ Index: Ringtoets/HydraRing/test/Riskeer.HydraRing.IO.Test/test-data/HydraulicBoundaryDatabaseReader/empty.sqlite =================================================================== diff -u Binary files differ Index: Ringtoets/HydraRing/test/Riskeer.HydraRing.IO.Test/test-data/HydraulicBoundaryDatabaseReader/emptyGeneral.sqlite =================================================================== diff -u Binary files differ Index: Ringtoets/HydraRing/test/Riskeer.HydraRing.IO.Test/test-data/HydraulicBoundaryDatabaseReader/emptyschema.sqlite =================================================================== diff -u Binary files differ Index: Ringtoets/HydraRing/test/Riskeer.HydraRing.IO.Test/test-data/HydraulicBoundaryDatabaseReader/incompleteVersion.sqlite =================================================================== diff -u Binary files differ Index: Ringtoets/HydraRing/test/Riskeer.HydraRing.IO.Test/test-data/HydraulicLocationConfigurationDatabase/ambigousLocation.sqlite =================================================================== diff -u Binary files differ Index: Ringtoets/HydraRing/test/Riskeer.HydraRing.IO.Test/test-data/HydraulicLocationConfigurationDatabase/corruptschema.sqlite =================================================================== diff -u Binary files differ Index: Ringtoets/HydraRing/test/Riskeer.HydraRing.IO.Test/test-data/HydraulicLocationConfigurationDatabase/empty.sqlite =================================================================== diff -u Binary files differ Index: Ringtoets/HydraRing/test/Riskeer.HydraRing.IO.Test/test-data/HydraulicLocationConfigurationDatabase/hlcdWithScenarioInformation.sqlite =================================================================== diff -u Binary files differ Index: Ringtoets/HydraRing/test/Riskeer.HydraRing.IO.Test/test-data/HydraulicLocationConfigurationDatabase/hlcdWithScenarioInformationInvalidData.sqlite =================================================================== diff -u Binary files differ Index: Ringtoets/HydraRing/test/Riskeer.HydraRing.IO.Test/test-data/HydraulicLocationConfigurationDatabase/hlcdWithScenarioInformationMissingColumn.sqlite =================================================================== diff -u Binary files differ Index: Ringtoets/HydraRing/test/Riskeer.HydraRing.IO.Test/test-data/HydraulicLocationConfigurationDatabase/hlcdWithoutScenarioInformation.sqlite =================================================================== diff -u Binary files differ