Index: Ringtoets/HydraRing/src/Ringtoets.HydraRing.IO/HydraulicLocationConfigurationDatabase/HydraulicLocationConfigurationDatabaseQueryBuilder.cs
===================================================================
diff -u -r2a81f01756e227d5ce93717b21b87e8a5cd5fcbb -r72ef8cf380c5528ec1d61dc62b8ea61e8920a361
--- Ringtoets/HydraRing/src/Ringtoets.HydraRing.IO/HydraulicLocationConfigurationDatabase/HydraulicLocationConfigurationDatabaseQueryBuilder.cs (.../HydraulicLocationConfigurationDatabaseQueryBuilder.cs) (revision 2a81f01756e227d5ce93717b21b87e8a5cd5fcbb)
+++ Ringtoets/HydraRing/src/Ringtoets.HydraRing.IO/HydraulicLocationConfigurationDatabase/HydraulicLocationConfigurationDatabaseQueryBuilder.cs (.../HydraulicLocationConfigurationDatabaseQueryBuilder.cs) (revision 72ef8cf380c5528ec1d61dc62b8ea61e8920a361)
@@ -37,5 +37,34 @@
$"WHERE {LocationsTableDefinitions.TrackId} = @{LocationsTableDefinitions.TrackId} " +
$"ORDER BY {LocationsTableDefinitions.HrdLocationId};";
}
+
+ ///
+ /// Gets the query to determine whether data related to the scenario information is present in the database.
+ ///
+ /// The query to determine the presence of the scenario information in the database.
+ public static string GetIsScenarioInformationPresentQuery()
+ {
+ return $"SELECT COUNT() = 1 AS {ScenarioInformationTableDefinitions.IsScenarioInformationPresent} " +
+ "FROM sqlite_master WHERE type = 'table' " +
+ $"AND name='{ScenarioInformationTableDefinitions.TableName}';";
+ }
+
+ ///
+ /// Gets the query to get the scenario information from the database.
+ ///
+ /// The query to get the scenario information from the database.
+ public static string GetScenarioInformationQuery()
+ {
+ return $"SELECT {ScenarioInformationTableDefinitions.ScenarioName}, " +
+ $"{ScenarioInformationTableDefinitions.Year}, " +
+ $"{ScenarioInformationTableDefinitions.Scope}, " +
+ $"{ScenarioInformationTableDefinitions.SeaLevel}, " +
+ $"{ScenarioInformationTableDefinitions.RiverDischarge}, " +
+ $"{ScenarioInformationTableDefinitions.LakeLevel}, " +
+ $"{ScenarioInformationTableDefinitions.WindDirection}, " +
+ $"{ScenarioInformationTableDefinitions.WindSpeed}, " +
+ $"{ScenarioInformationTableDefinitions.Comment} " +
+ $"FROM {ScenarioInformationTableDefinitions.TableName};";
+ }
}
}
\ No newline at end of file
Index: Ringtoets/HydraRing/src/Ringtoets.HydraRing.IO/HydraulicLocationConfigurationDatabase/HydraulicLocationConfigurationDatabaseReader.cs
===================================================================
diff -u -r8e4f3d24c6dc2bb0536a5585358732bb74b7f9bf -r72ef8cf380c5528ec1d61dc62b8ea61e8920a361
--- Ringtoets/HydraRing/src/Ringtoets.HydraRing.IO/HydraulicLocationConfigurationDatabase/HydraulicLocationConfigurationDatabaseReader.cs (.../HydraulicLocationConfigurationDatabaseReader.cs) (revision 8e4f3d24c6dc2bb0536a5585358732bb74b7f9bf)
+++ Ringtoets/HydraRing/src/Ringtoets.HydraRing.IO/HydraulicLocationConfigurationDatabase/HydraulicLocationConfigurationDatabaseReader.cs (.../HydraulicLocationConfigurationDatabaseReader.cs) (revision 72ef8cf380c5528ec1d61dc62b8ea61e8920a361)
@@ -66,8 +66,8 @@
{
bool isScenarioInformationPresent = IsScenarioInformationTablePresent();
IEnumerable configurationSettings =
- isScenarioInformationPresent
- ? GetConfigurationSettings()
+ isScenarioInformationPresent
+ ? GetConfigurationSettings()
: Enumerable.Empty();
return new ReadHydraulicLocationConfigurationDatabase(GetLocationIdsByTrackId(trackId),
@@ -167,20 +167,35 @@
/// Determines whether the table related to the scenario information is present in the database.
///
/// true if the table is present; false otherwise.
- /// Thrown when the database query failed.
- /// Thrown when the information could not be read from the database file..
+ /// Thrown when the information could not be read from the database file.
+ /// Thrown when the database returned incorrect values for
+ /// required properties.
private bool IsScenarioInformationTablePresent()
{
- const string validationQuery = "SELECT COUNT() = 1 AS IsScenarioInformationPresent FROM sqlite_master WHERE type = 'table' AND name='ScenarioInformation'";
- using (IDataReader dataReader = CreateDataReader(validationQuery))
+ string query = HydraulicLocationConfigurationDatabaseQueryBuilder.GetIsScenarioInformationPresentQuery();
+
+ try
{
- if (dataReader.Read())
+ using (IDataReader dataReader = CreateDataReader(query))
{
- return Convert.ToBoolean(dataReader["IsScenarioInformationPresent"]);
- }
+ if (dataReader.Read())
+ {
+ return Convert.ToBoolean(dataReader[ScenarioInformationTableDefinitions.IsScenarioInformationPresent]);
+ }
+ string message = new FileReaderErrorMessageBuilder(Path).Build(Resources.HydraulicBoundaryDatabaseReader_Critical_Unexpected_value_on_column);
+ throw new CriticalFileReadException(message);
+ }
+ }
+ catch (SQLiteException exception)
+ {
+ string message = new FileReaderErrorMessageBuilder(Path).Build(Resources.HydraulicLocationConfigurationDatabaseReader_Critical_Unexpected_Exception);
+ throw new CriticalFileReadException(message, exception);
+ }
+ catch (InvalidCastException exception)
+ {
string message = new FileReaderErrorMessageBuilder(Path).Build(Resources.HydraulicBoundaryDatabaseReader_Critical_Unexpected_value_on_column);
- throw new CriticalFileReadException(message);
+ throw new LineParseException(message, exception);
}
}
@@ -193,7 +208,7 @@
/// required properties.
private IEnumerable GetConfigurationSettingsFromDatabase()
{
- const string query = "SELECT * FROM ScenarioInformation";
+ string query = HydraulicLocationConfigurationDatabaseQueryBuilder.GetScenarioInformationQuery();
var readSettings = new List();
using (IDataReader dataReader = CreateDataReader(query))
{
@@ -211,22 +226,21 @@
///
/// The which is used to read the data.
/// The read .
- /// Thrown when the settings could not be read.
/// Thrown when the database returned incorrect values for
/// required properties.
private ReadHydraulicLocationConfigurationDatabaseSettings ReadSetting(IDataReader reader)
{
try
{
- var scenarioName = reader.Read("ScenarioName");
- var year = reader.Read("Year");
- var scope = reader.Read("Scope");
- var seaLevel = reader.Read("SeaLevel");
- var riverDischarge = reader.Read("RiverDischarge");
- var lakeLevel = reader.Read("LakeLevel");
- var windDirection = reader.Read("WindDirection");
- var windSpeed = reader.Read("WindSpeed");
- var comment = reader.Read("Comment");
+ var scenarioName = reader.Read(ScenarioInformationTableDefinitions.ScenarioName);
+ var year = reader.Read(ScenarioInformationTableDefinitions.Year);
+ var scope = reader.Read(ScenarioInformationTableDefinitions.Scope);
+ var seaLevel = reader.Read(ScenarioInformationTableDefinitions.SeaLevel);
+ var riverDischarge = reader.Read(ScenarioInformationTableDefinitions.RiverDischarge);
+ var lakeLevel = reader.Read(ScenarioInformationTableDefinitions.LakeLevel);
+ var windDirection = reader.Read(ScenarioInformationTableDefinitions.WindDirection);
+ var windSpeed = reader.Read(ScenarioInformationTableDefinitions.WindSpeed);
+ var comment = reader.Read(ScenarioInformationTableDefinitions.Comment);
return new ReadHydraulicLocationConfigurationDatabaseSettings(scenarioName, year, scope,
seaLevel, riverDischarge, lakeLevel,
@@ -237,11 +251,6 @@
string message = new FileReaderErrorMessageBuilder(Path).Build(Resources.HydraulicBoundaryDatabaseReader_Critical_Unexpected_value_on_column);
throw new LineParseException(message, e);
}
- catch (ArgumentException e)
- {
- string message = new FileReaderErrorMessageBuilder(Path).Build(Resources.HydraulicBoundaryDatabaseReader_Critical_Unexpected_value_on_column);
- throw new CriticalFileReadException(message, e);
- }
}
}
}
\ No newline at end of file
Index: Ringtoets/HydraRing/src/Ringtoets.HydraRing.IO/HydraulicLocationConfigurationDatabase/ScenarioInformationTableDefinitions.cs
===================================================================
diff -u
--- Ringtoets/HydraRing/src/Ringtoets.HydraRing.IO/HydraulicLocationConfigurationDatabase/ScenarioInformationTableDefinitions.cs (revision 0)
+++ Ringtoets/HydraRing/src/Ringtoets.HydraRing.IO/HydraulicLocationConfigurationDatabase/ScenarioInformationTableDefinitions.cs (revision 72ef8cf380c5528ec1d61dc62b8ea61e8920a361)
@@ -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.
+
+namespace Ringtoets.HydraRing.IO.HydraulicLocationConfigurationDatabase
+{
+ ///
+ /// Defines the table and column names of the table 'ScenarioInformation' in the hydraulic location
+ /// configuration database.
+ ///
+ public static class ScenarioInformationTableDefinitions
+ {
+ public const string ScenarioName = "ScenarioName";
+ public const string Year = "Year";
+ public const string Scope = "Scope";
+ public const string SeaLevel = "SeaLevel";
+ public const string RiverDischarge = "RiverDischarge";
+ public const string LakeLevel = "LakeLevel";
+ public const string WindDirection = "WindDirection";
+ public const string WindSpeed = "WindSpeed";
+ public const string Comment = "Comment";
+ public const string IsScenarioInformationPresent = "IsScenarioInformationPresent";
+ public const string TableName = "ScenarioInformation";
+ }
+}
\ No newline at end of file
Index: Ringtoets/HydraRing/src/Ringtoets.HydraRing.IO/Ringtoets.HydraRing.IO.csproj
===================================================================
diff -u -rbfe1469d892b8690f3164a472069902e17d7e60c -r72ef8cf380c5528ec1d61dc62b8ea61e8920a361
--- Ringtoets/HydraRing/src/Ringtoets.HydraRing.IO/Ringtoets.HydraRing.IO.csproj (.../Ringtoets.HydraRing.IO.csproj) (revision bfe1469d892b8690f3164a472069902e17d7e60c)
+++ Ringtoets/HydraRing/src/Ringtoets.HydraRing.IO/Ringtoets.HydraRing.IO.csproj (.../Ringtoets.HydraRing.IO.csproj) (revision 72ef8cf380c5528ec1d61dc62b8ea61e8920a361)
@@ -32,6 +32,7 @@
+
True
Index: Ringtoets/HydraRing/test/Ringtoets.HydraRing.IO.Test/HydraulicLocationConfigurationDatabase/HydraulicLocationConfigurationDatabaseQueryBuilderTest.cs
===================================================================
diff -u -r2a81f01756e227d5ce93717b21b87e8a5cd5fcbb -r72ef8cf380c5528ec1d61dc62b8ea61e8920a361
--- Ringtoets/HydraRing/test/Ringtoets.HydraRing.IO.Test/HydraulicLocationConfigurationDatabase/HydraulicLocationConfigurationDatabaseQueryBuilderTest.cs (.../HydraulicLocationConfigurationDatabaseQueryBuilderTest.cs) (revision 2a81f01756e227d5ce93717b21b87e8a5cd5fcbb)
+++ Ringtoets/HydraRing/test/Ringtoets.HydraRing.IO.Test/HydraulicLocationConfigurationDatabase/HydraulicLocationConfigurationDatabaseQueryBuilderTest.cs (.../HydraulicLocationConfigurationDatabaseQueryBuilderTest.cs) (revision 72ef8cf380c5528ec1d61dc62b8ea61e8920a361)
@@ -28,7 +28,7 @@
public class HydraulicLocationConfigurationDatabaseQueryBuilderTest
{
[Test]
- public void GetLocationIdsByTrackIdQuery_Always_ReturnsExpectedValues()
+ public void GetLocationIdsByTrackIdQuery_Always_ReturnsExpectedValue()
{
// Call
string query = HydraulicLocationConfigurationDatabaseQueryBuilder.GetLocationIdsByTrackIdQuery();
@@ -37,5 +37,30 @@
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/Ringtoets.HydraRing.IO.Test/HydraulicLocationConfigurationDatabase/HydraulicLocationConfigurationDatabaseReaderTest.cs
===================================================================
diff -u -r8e4f3d24c6dc2bb0536a5585358732bb74b7f9bf -r72ef8cf380c5528ec1d61dc62b8ea61e8920a361
--- Ringtoets/HydraRing/test/Ringtoets.HydraRing.IO.Test/HydraulicLocationConfigurationDatabase/HydraulicLocationConfigurationDatabaseReaderTest.cs (.../HydraulicLocationConfigurationDatabaseReaderTest.cs) (revision 8e4f3d24c6dc2bb0536a5585358732bb74b7f9bf)
+++ Ringtoets/HydraRing/test/Ringtoets.HydraRing.IO.Test/HydraulicLocationConfigurationDatabase/HydraulicLocationConfigurationDatabaseReaderTest.cs (.../HydraulicLocationConfigurationDatabaseReaderTest.cs) (revision 72ef8cf380c5528ec1d61dc62b8ea61e8920a361)
@@ -178,10 +178,10 @@
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.");
+ 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);
+ Assert.IsInstanceOf(exception.InnerException);
}
}
Index: Ringtoets/HydraRing/test/Ringtoets.HydraRing.IO.Test/HydraulicLocationConfigurationDatabase/ScenarioInformationTableDefinitionsTest.cs
===================================================================
diff -u
--- Ringtoets/HydraRing/test/Ringtoets.HydraRing.IO.Test/HydraulicLocationConfigurationDatabase/ScenarioInformationTableDefinitionsTest.cs (revision 0)
+++ Ringtoets/HydraRing/test/Ringtoets.HydraRing.IO.Test/HydraulicLocationConfigurationDatabase/ScenarioInformationTableDefinitionsTest.cs (revision 72ef8cf380c5528ec1d61dc62b8ea61e8920a361)
@@ -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 Ringtoets.HydraRing.IO.HydraulicLocationConfigurationDatabase;
+
+namespace Ringtoets.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/Ringtoets.HydraRing.IO.Test/Ringtoets.HydraRing.IO.Test.csproj
===================================================================
diff -u -rbfe1469d892b8690f3164a472069902e17d7e60c -r72ef8cf380c5528ec1d61dc62b8ea61e8920a361
--- Ringtoets/HydraRing/test/Ringtoets.HydraRing.IO.Test/Ringtoets.HydraRing.IO.Test.csproj (.../Ringtoets.HydraRing.IO.Test.csproj) (revision bfe1469d892b8690f3164a472069902e17d7e60c)
+++ Ringtoets/HydraRing/test/Ringtoets.HydraRing.IO.Test/Ringtoets.HydraRing.IO.Test.csproj (.../Ringtoets.HydraRing.IO.Test.csproj) (revision 72ef8cf380c5528ec1d61dc62b8ea61e8920a361)
@@ -32,6 +32,7 @@
+