Index: Ringtoets/HydraRing/src/Ringtoets.HydraRing.Calculation/Parsers/ConvergenceParser.cs
===================================================================
diff -u -r4bf03fe0c441a3f3d439bc7ffe09350227435178 -rc235d644419c9f398fd806f7dce2592f0974ac97
--- Ringtoets/HydraRing/src/Ringtoets.HydraRing.Calculation/Parsers/ConvergenceParser.cs (.../ConvergenceParser.cs) (revision 4bf03fe0c441a3f3d439bc7ffe09350227435178)
+++ Ringtoets/HydraRing/src/Ringtoets.HydraRing.Calculation/Parsers/ConvergenceParser.cs (.../ConvergenceParser.cs) (revision c235d644419c9f398fd806f7dce2592f0974ac97)
@@ -20,8 +20,6 @@
// All rights reserved.
using System;
-using System.Data.SQLite;
-using Ringtoets.HydraRing.Calculation.Exceptions;
using Ringtoets.HydraRing.Calculation.Properties;
using Ringtoets.HydraRing.Calculation.Readers;
@@ -53,38 +51,14 @@
throw new ArgumentNullException(nameof(workingDirectory));
}
- ParseFile(workingDirectory, sectionId);
+ HydraRingDatabaseParseHelper.Parse(workingDirectory,
+ getLastResultQuery,
+ sectionId,
+ Resources.ParseFile_No_convergence_found_in_output_file,
+ ReadResult);
}
///
- /// Parses the file.
- ///
- /// The path to the directory which contains
- /// the output of the Hydra-Ring calculation.
- /// The section id to get the output for.
- /// Thrown when the reader
- /// encounters an error while reading the database.
- private void ParseFile(string workingDirectory, int sectionId)
- {
- try
- {
- using (var reader = new HydraRingDatabaseReader(workingDirectory, getLastResultQuery, sectionId))
- {
- reader.Execute();
- ReadResult(reader);
- }
- }
- catch (SQLiteException e)
- {
- throw new HydraRingFileParserException(Resources.ParseFile_Cannot_read_result_in_output_file, e);
- }
- catch (Exception e) when (e is HydraRingDatabaseReaderException || e is InvalidCastException)
- {
- throw new HydraRingFileParserException(Resources.ParseFile_No_convergence_found_in_output_file, e);
- }
- }
-
- ///
/// Reads the result of the .
///
/// The reader to get the result from.
Index: Ringtoets/HydraRing/src/Ringtoets.HydraRing.Calculation/Parsers/DunesBoundaryConditionsCalculationParser.cs
===================================================================
diff -u -r4bf03fe0c441a3f3d439bc7ffe09350227435178 -rc235d644419c9f398fd806f7dce2592f0974ac97
--- Ringtoets/HydraRing/src/Ringtoets.HydraRing.Calculation/Parsers/DunesBoundaryConditionsCalculationParser.cs (.../DunesBoundaryConditionsCalculationParser.cs) (revision 4bf03fe0c441a3f3d439bc7ffe09350227435178)
+++ Ringtoets/HydraRing/src/Ringtoets.HydraRing.Calculation/Parsers/DunesBoundaryConditionsCalculationParser.cs (.../DunesBoundaryConditionsCalculationParser.cs) (revision c235d644419c9f398fd806f7dce2592f0974ac97)
@@ -20,9 +20,7 @@
// All rights reserved.
using System;
-using System.Data.SQLite;
using Ringtoets.HydraRing.Calculation.Data.Output;
-using Ringtoets.HydraRing.Calculation.Exceptions;
using Ringtoets.HydraRing.Calculation.Properties;
using Ringtoets.HydraRing.Calculation.Readers;
@@ -59,38 +57,14 @@
throw new ArgumentNullException(nameof(workingDirectory));
}
- ParseFile(workingDirectory, sectionId);
+ HydraRingDatabaseParseHelper.Parse(workingDirectory,
+ query,
+ sectionId,
+ Resources.DunesBoundaryConditionsCalculationParser_ParseFile_No_dunes_hydraulic_boundaries_found_in_output_file,
+ ReadResult);
}
///
- /// Parses the file.
- ///
- /// The path to the directory which contains
- /// the output of the Hydra-Ring calculation.
- /// The section id to get the output for.
- /// Thrown when the reader
- /// encounters an error while reading the database.
- private void ParseFile(string workingDirectory, int sectionId)
- {
- try
- {
- using (var reader = new HydraRingDatabaseReader(workingDirectory, query, sectionId))
- {
- reader.Execute();
- ReadResult(reader);
- }
- }
- catch (SQLiteException e)
- {
- throw new HydraRingFileParserException(Resources.ParseFile_Cannot_read_result_in_output_file, e);
- }
- catch (Exception e) when (e is HydraRingDatabaseReaderException || e is InvalidCastException)
- {
- throw new HydraRingFileParserException(Resources.DunesBoundaryConditionsCalculationParser_ParseFile_No_dunes_hydraulic_boundaries_found_in_output_file, e);
- }
- }
-
- ///
/// Reads the result of the .
///
/// The reader to get the result from.
Index: Ringtoets/HydraRing/src/Ringtoets.HydraRing.Calculation/Parsers/HydraRingDatabaseParseHelper.cs
===================================================================
diff -u
--- Ringtoets/HydraRing/src/Ringtoets.HydraRing.Calculation/Parsers/HydraRingDatabaseParseHelper.cs (revision 0)
+++ Ringtoets/HydraRing/src/Ringtoets.HydraRing.Calculation/Parsers/HydraRingDatabaseParseHelper.cs (revision c235d644419c9f398fd806f7dce2592f0974ac97)
@@ -0,0 +1,96 @@
+// Copyright (C) Stichting Deltares 2016. All rights reserved.
+//
+// This file is part of Ringtoets.
+//
+// Ringtoets is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see .
+//
+// All names, logos, and references to "Deltares" are registered trademarks of
+// Stichting Deltares and remain full property of Stichting Deltares at all times.
+// All rights reserved.
+
+using System;
+using System.Data.SQLite;
+using Ringtoets.HydraRing.Calculation.Exceptions;
+using Ringtoets.HydraRing.Calculation.Properties;
+using Ringtoets.HydraRing.Calculation.Readers;
+
+namespace Ringtoets.HydraRing.Calculation.Parsers
+{
+ ///
+ /// Helper class for methods that apply for parsing the output from the database.
+ ///
+ internal static class HydraRingDatabaseParseHelper
+ {
+ ///
+ /// Parses the file.
+ ///
+ /// The path to the directory which contains
+ /// the output of the Hydra-Ring calculation.
+ /// The query to perform when reading the database.
+ /// The section id to get the output for.
+ /// The exception message when there is no result.
+ /// The action to perform for getting the results of the
+ /// database.
+ /// Thrown when the reader
+ /// encounters an error while reading the database.
+ public static void Parse(string workingDirectory,
+ string query,
+ int sectionId,
+ string exceptionMessage,
+ Action readResultAction)
+ {
+ ValidateParameters(workingDirectory, query, exceptionMessage, readResultAction);
+
+ try
+ {
+ using (var reader = new HydraRingDatabaseReader(workingDirectory, query, sectionId))
+ {
+ reader.Execute();
+ readResultAction(reader);
+ }
+ }
+ catch (SQLiteException e)
+ {
+ throw new HydraRingFileParserException(Resources.ParseFile_Cannot_read_result_in_output_file, e);
+ }
+ catch (Exception e) when (e is HydraRingDatabaseReaderException || e is InvalidCastException)
+ {
+ throw new HydraRingFileParserException(exceptionMessage, e);
+ }
+ }
+
+ private static void ValidateParameters(string workingDirectory,
+ string query,
+ string exceptionMessage,
+ Action readResultAction)
+ {
+ if (workingDirectory == null)
+ {
+ throw new ArgumentNullException(nameof(workingDirectory));
+ }
+ if (query == null)
+ {
+ throw new ArgumentNullException(nameof(query));
+ }
+ if (exceptionMessage == null)
+ {
+ throw new ArgumentNullException(nameof(exceptionMessage));
+ }
+ if (readResultAction == null)
+ {
+ throw new ArgumentNullException(nameof(readResultAction));
+ }
+ }
+ }
+}
\ No newline at end of file
Index: Ringtoets/HydraRing/src/Ringtoets.HydraRing.Calculation/Ringtoets.HydraRing.Calculation.csproj
===================================================================
diff -u -r31caf3dc885ae62d4b3772eb0421a3155101bcf4 -rc235d644419c9f398fd806f7dce2592f0974ac97
--- Ringtoets/HydraRing/src/Ringtoets.HydraRing.Calculation/Ringtoets.HydraRing.Calculation.csproj (.../Ringtoets.HydraRing.Calculation.csproj) (revision 31caf3dc885ae62d4b3772eb0421a3155101bcf4)
+++ Ringtoets/HydraRing/src/Ringtoets.HydraRing.Calculation/Ringtoets.HydraRing.Calculation.csproj (.../Ringtoets.HydraRing.Calculation.csproj) (revision c235d644419c9f398fd806f7dce2592f0974ac97)
@@ -111,6 +111,7 @@
+
Index: Ringtoets/HydraRing/test/Ringtoets.HydraRing.Calculation.Test/Parsers/HydraRingDatabaseParseHelperTest.cs
===================================================================
diff -u
--- Ringtoets/HydraRing/test/Ringtoets.HydraRing.Calculation.Test/Parsers/HydraRingDatabaseParseHelperTest.cs (revision 0)
+++ Ringtoets/HydraRing/test/Ringtoets.HydraRing.Calculation.Test/Parsers/HydraRingDatabaseParseHelperTest.cs (revision c235d644419c9f398fd806f7dce2592f0974ac97)
@@ -0,0 +1,151 @@
+// Copyright (C) Stichting Deltares 2016. All rights reserved.
+//
+// This file is part of Ringtoets.
+//
+// Ringtoets is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see .
+//
+// All names, logos, and references to "Deltares" are registered trademarks of
+// Stichting Deltares and remain full property of Stichting Deltares at all times.
+// All rights reserved.
+
+using System;
+using System.IO;
+using Core.Common.TestUtil;
+using NUnit.Framework;
+using Ringtoets.HydraRing.Calculation.Exceptions;
+using Ringtoets.HydraRing.Calculation.Parsers;
+
+namespace Ringtoets.HydraRing.Calculation.Test.Parsers
+{
+ [TestFixture]
+ public class HydraRingDatabaseParseHelperTest
+ {
+ private const string emptyWorkingDirectory = "EmptyWorkingDirectory";
+ private const string emptyDatabase = "EmptyDatabase";
+ private const string validFile = "ValidFile";
+
+ private const string query = "SELECT * FROM IterateToGivenBetaConvergence " +
+ "WHERE OuterIterationId = (SELECT MAX(OuterIterationId) FROM IterateToGivenBetaConvergence);";
+
+ private static readonly string testDirectory = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.HydraRing.Calculation,
+ Path.Combine("Readers", nameof(HydraRingDatabaseParseHelper)));
+
+ [Test]
+ public void Parse_WorkingDirectoryNull_ThrowArgumentNullException()
+ {
+ // Call
+ TestDelegate test = () => HydraRingDatabaseParseHelper.Parse(null, "", 0, "", reader => { });
+
+ // Assert
+ var exception = Assert.Throws(test);
+ Assert.AreEqual("workingDirectory", exception.ParamName);
+ }
+
+ [Test]
+ public void Parse_QueryNull_ThrowArgumentNullException()
+ {
+ // Call
+ TestDelegate test = () => HydraRingDatabaseParseHelper.Parse("", null, 0, "", reader => { });
+
+ // Assert
+ var exception = Assert.Throws(test);
+ Assert.AreEqual("query", exception.ParamName);
+ }
+ [Test]
+ public void Parse_ExceptionMessageNull_ThrowArgumentNullException()
+ {
+ // Call
+ TestDelegate test = () => HydraRingDatabaseParseHelper.Parse("", "", 0, null, reader => { });
+
+ // Assert
+ var exception = Assert.Throws(test);
+ Assert.AreEqual("exceptionMessage", exception.ParamName);
+ }
+ [Test]
+ public void Parse_ReadResultActionNull_ThrowArgumentNullException()
+ {
+ // Call
+ TestDelegate test = () => HydraRingDatabaseParseHelper.Parse("", "", 0, "", null);
+
+ // Assert
+ var exception = Assert.Throws(test);
+ Assert.AreEqual("readResultAction", exception.ParamName);
+ }
+
+ [Test]
+ public void Parse_ReaderThrowsSQLiteException_ThrowHydraRingFileParserException()
+ {
+ // Setup
+ string directory = Path.Combine(testDirectory, emptyWorkingDirectory);
+
+ // Call
+ TestDelegate test = () => HydraRingDatabaseParseHelper.Parse(directory, query, 0, "", reader => { });
+
+ // Assert
+ var exception = Assert.Throws(test);
+ Assert.AreEqual("Er kon geen resultaat gelezen worden uit de Hydra-Ring uitvoerdatabase.", exception.Message);
+ }
+
+ [Test]
+ public void Parse_ReaderThrowsHydraRingDatabaseReaderException_ThrowHydraRingFileParserExceptionWithCustomMessage()
+ {
+ // Setup
+ const string customMessage = "Exception message";
+ string directory = Path.Combine(testDirectory, emptyDatabase);
+
+ // Call
+ TestDelegate test = () => HydraRingDatabaseParseHelper.Parse(directory, query, 0, customMessage, reader => { });
+
+ // Assert
+ var exception = Assert.Throws(test);
+ Assert.AreEqual(customMessage, exception.Message);
+ }
+
+ [Test]
+ public void Parse_ReadResultActionThrowsInvalidCastException_ThrowHydraRingFileParserExceptionWithCustomMessage()
+ {
+ // Setup
+ const string customMessage = "Exception message";
+ string directory = Path.Combine(testDirectory, validFile);
+
+ // Call
+ TestDelegate test = () => HydraRingDatabaseParseHelper.Parse(directory, query, 0, customMessage, reader =>
+ {
+ throw new InvalidCastException();
+ });
+
+ // Assert
+ var exception = Assert.Throws(test);
+ Assert.AreEqual(customMessage, exception.Message);
+ }
+
+ [Test]
+ public void Parse_ValidData_ReadResultActionPerformed()
+ {
+
+ // Setup
+ string directory = Path.Combine(testDirectory, validFile);
+ var performed = false;
+
+ // Call
+ HydraRingDatabaseParseHelper.Parse(directory, query, 0, "", reader =>
+ {
+ performed = true;
+ });
+
+ // Assert
+ Assert.IsTrue(performed);
+ }
+ }
+}
\ No newline at end of file
Index: Ringtoets/HydraRing/test/Ringtoets.HydraRing.Calculation.Test/Ringtoets.HydraRing.Calculation.Test.csproj
===================================================================
diff -u -r31caf3dc885ae62d4b3772eb0421a3155101bcf4 -rc235d644419c9f398fd806f7dce2592f0974ac97
--- Ringtoets/HydraRing/test/Ringtoets.HydraRing.Calculation.Test/Ringtoets.HydraRing.Calculation.Test.csproj (.../Ringtoets.HydraRing.Calculation.Test.csproj) (revision 31caf3dc885ae62d4b3772eb0421a3155101bcf4)
+++ Ringtoets/HydraRing/test/Ringtoets.HydraRing.Calculation.Test/Ringtoets.HydraRing.Calculation.Test.csproj (.../Ringtoets.HydraRing.Calculation.Test.csproj) (revision c235d644419c9f398fd806f7dce2592f0974ac97)
@@ -112,6 +112,7 @@
+
Index: Ringtoets/HydraRing/test/Ringtoets.HydraRing.Calculation.Test/test-data/Readers/HydraRingDatabaseParseHelper/EmptyDatabase/output.sqlite
===================================================================
diff -u
Binary files differ
Index: Ringtoets/HydraRing/test/Ringtoets.HydraRing.Calculation.Test/test-data/Readers/HydraRingDatabaseParseHelper/ValidFile/output.sqlite
===================================================================
diff -u
Binary files differ