Index: Ringtoets/HydraRing/src/Ringtoets.HydraRing.Calculation/Parsers/ConvergenceParser.cs
===================================================================
diff -u -r31caf3dc885ae62d4b3772eb0421a3155101bcf4 -r4bf03fe0c441a3f3d439bc7ffe09350227435178
--- Ringtoets/HydraRing/src/Ringtoets.HydraRing.Calculation/Parsers/ConvergenceParser.cs (.../ConvergenceParser.cs) (revision 31caf3dc885ae62d4b3772eb0421a3155101bcf4)
+++ Ringtoets/HydraRing/src/Ringtoets.HydraRing.Calculation/Parsers/ConvergenceParser.cs (.../ConvergenceParser.cs) (revision 4bf03fe0c441a3f3d439bc7ffe09350227435178)
@@ -76,25 +76,23 @@
}
catch (SQLiteException e)
{
- throw new HydraRingFileParserException(Resources.Parse_Cannot_read_convergence_in_output_file, e);
+ throw new HydraRingFileParserException(Resources.ParseFile_Cannot_read_result_in_output_file, e);
}
- catch (HydraRingDatabaseReaderException)
+ catch (Exception e) when (e is HydraRingDatabaseReaderException || e is InvalidCastException)
{
- throw new HydraRingFileParserException(Resources.Parse_No_convergence_found_in_output_file);
+ throw new HydraRingFileParserException(Resources.ParseFile_No_convergence_found_in_output_file, e);
}
}
///
/// Reads the result of the .
///
/// The reader to get the result from.
+ /// Thrown when the the result
+ /// cannot be converted to the output format.
private void ReadResult(HydraRingDatabaseReader reader)
{
- object result = reader.ReadColumn(convergedColumnName);
- if (result != null)
- {
- Output = Convert.ToBoolean(result);
- }
+ Output = Convert.ToBoolean(reader.ReadColumn(convergedColumnName));
}
}
}
\ No newline at end of file
Index: Ringtoets/HydraRing/src/Ringtoets.HydraRing.Calculation/Parsers/DunesBoundaryConditionsCalculationParser.cs
===================================================================
diff -u -r5fcfd3d73f28585c211086ad413fc5d177ecd6b2 -r4bf03fe0c441a3f3d439bc7ffe09350227435178
--- Ringtoets/HydraRing/src/Ringtoets.HydraRing.Calculation/Parsers/DunesBoundaryConditionsCalculationParser.cs (.../DunesBoundaryConditionsCalculationParser.cs) (revision 5fcfd3d73f28585c211086ad413fc5d177ecd6b2)
+++ Ringtoets/HydraRing/src/Ringtoets.HydraRing.Calculation/Parsers/DunesBoundaryConditionsCalculationParser.cs (.../DunesBoundaryConditionsCalculationParser.cs) (revision 4bf03fe0c441a3f3d439bc7ffe09350227435178)
@@ -20,12 +20,11 @@
// All rights reserved.
using System;
-using System.Globalization;
-using System.IO;
+using System.Data.SQLite;
using Ringtoets.HydraRing.Calculation.Data.Output;
using Ringtoets.HydraRing.Calculation.Exceptions;
using Ringtoets.HydraRing.Calculation.Properties;
-using Ringtoets.HydraRing.IO;
+using Ringtoets.HydraRing.Calculation.Readers;
namespace Ringtoets.HydraRing.Calculation.Parsers
{
@@ -34,154 +33,78 @@
///
public class DunesBoundaryConditionsCalculationParser : IHydraRingFileParser
{
- private const string waterLevelText = "Considered water level";
- private const string waveHeightText = "Computed wave height";
- private const string wavePeriodText = "Computed wave period";
+ private const string sectionIdParameterName = "@sectionId";
+ private const string waveHeightColumnName = "WaveHeight";
+ private const string wavePeriodColumnName = "WavePeriod";
+ private const string waterLevelColumnName = "WaterLevel";
- private const char equalsCharacter = '=';
+ private readonly string query = "SELECT " +
+ $"max(case when OutputVarId is 3 then d.Value end) {waveHeightColumnName}, " +
+ $"max(case when OutputVarId is 4 then d.Value end) {wavePeriodColumnName}, " +
+ $"max(case when OutputVarId is 23 then d.Value end) {waterLevelColumnName} " +
+ "FROM DesignPointResults as d " +
+ $"WHERE SectionId = {sectionIdParameterName} " +
+ "AND OuterIterationId=(select max(OuterIterationId) FROM DesignPointResults) " +
+ "GROUP BY OuterIterationId;";
- private double? waterLevel;
- private double? waveHeight;
- private double? wavePeriod;
-
///
/// Gets the output that was parsed from the output file.
///
public DunesBoundaryConditionsCalculationOutput Output { get; private set; }
public void Parse(string workingDirectory, int sectionId)
{
- string fileName = $"{sectionId}{HydraRingFileConstants.OutputFileSuffix}";
-
- try
+ if (workingDirectory == null)
{
- ReadFile(Path.Combine(workingDirectory, fileName));
- SetOutput();
+ throw new ArgumentNullException(nameof(workingDirectory));
}
- catch (Exception e)
- {
- throw new HydraRingFileParserException(Resources.DunesBoundaryConditionsCalculationParser_Parse_Error_while_parsing_output, e);
- }
- }
- private void SetOutput()
- {
- if (waterLevel != null && waveHeight != null && wavePeriod != null)
- {
- Output = new DunesBoundaryConditionsCalculationOutput(waterLevel.Value,
- waveHeight.Value,
- wavePeriod.Value);
- }
+ ParseFile(workingDirectory, sectionId);
}
///
- /// Opens and reads the file at .
+ /// Parses the file.
///
- /// The path to the output file.
- /// Thrown when the stream does not support reading.
- /// Thrown when is too long.
- /// Thrown when the file can't be opened due to missing
- /// the required persmissions.
- /// Thrown when an I/O error occurred while opening the file.
- /// Thrown when the string that is tried to parse
- /// does not represent a number in a valid format.
- /// Thrown when the string that is tried to parse
- /// represents a number that is less than
- /// or greater than .
- private void ReadFile(string filePath)
+ /// 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)
{
- if (File.Exists(filePath))
+ try
{
- using (var file = new StreamReader(File.OpenRead(filePath)))
+ using (var reader = new HydraRingDatabaseReader(workingDirectory, query, sectionId))
{
- while (!file.EndOfStream)
- {
- string currentLine = file.ReadLine();
-
- waterLevel = TryParseWaterLevel(currentLine) ?? waterLevel;
- waveHeight = TryParseWaveHeight(currentLine) ?? waveHeight;
- wavePeriod = TryParseWavePeriod(currentLine) ?? wavePeriod;
- }
+ reader.Execute();
+ ReadResult(reader);
}
}
- }
-
- ///
- /// Tries to parse the water level from the given .
- ///
- /// The line to parse.
- /// When the line contains the water level a numeric value that represents the water level.
- /// null otherwise.
- /// Thrown when
- /// does not represent a number in a valid format.
- /// Thrown when
- /// represents a number that is less than
- /// or greater than .
- private static double? TryParseWaterLevel(string line)
- {
- if (line.Contains(waterLevelText))
+ catch (SQLiteException e)
{
- string resultAsString = line.Split(equalsCharacter)[1].Trim();
- return ParseStringResult(resultAsString);
+ throw new HydraRingFileParserException(Resources.ParseFile_Cannot_read_result_in_output_file, e);
}
- return null;
- }
-
- ///
- /// Tries to parse the wave height from the given .
- ///
- /// The line to parse.
- /// When the line contains the wave height a numeric value that represents the wave height.
- /// null otherwise.
- /// Thrown when
- /// does not represent a number in a valid format.
- /// Thrown when
- /// represents a number that is less than
- /// or greater than .
- private static double? TryParseWaveHeight(string line)
- {
- if (line.Contains(waveHeightText))
+ catch (Exception e) when (e is HydraRingDatabaseReaderException || e is InvalidCastException)
{
- string resultAsString = line.Split(equalsCharacter)[1].Trim();
- return ParseStringResult(resultAsString);
+ throw new HydraRingFileParserException(Resources.DunesBoundaryConditionsCalculationParser_ParseFile_No_dunes_hydraulic_boundaries_found_in_output_file, e);
}
- return null;
}
///
- /// Tries to parse the wave period from the given .
+ /// Reads the result of the .
///
- /// The line to parse.
- /// When the line contains the wave period a numeric value that represents the wave period.
- /// null otherwise.
- /// Thrown when
- /// does not represent a number in a valid format.
- /// Thrown when
- /// represents a number that is less than
- /// or greater than .
- private static double? TryParseWavePeriod(string line)
+ /// The reader to get the result from.
+ /// Thrown when the the result
+ /// cannot be converted to the output format.
+ private void ReadResult(HydraRingDatabaseReader reader)
{
- if (line.Contains(wavePeriodText))
- {
- string resultAsString = line.Split(equalsCharacter)[1].Trim();
- return ParseStringResult(resultAsString);
- }
- return null;
- }
+ double waveHeight = Convert.ToDouble(reader.ReadColumn(waveHeightColumnName));
+ double wavePeriod = Convert.ToDouble(reader.ReadColumn(wavePeriodColumnName));
+ double waterLevel = Convert.ToDouble(reader.ReadColumn(waterLevelColumnName));
- ///
- /// Parses the to a .
- ///
- /// The result to parse.
- /// The parsed number.
- /// Thrown when
- /// does not represent a number in a valid format.
- /// Thrown when
- /// represents a number that is less than
- /// or greater than .
- private static double ParseStringResult(string resultAsString)
- {
- return double.Parse(resultAsString, CultureInfo.InvariantCulture);
+ Output = new DunesBoundaryConditionsCalculationOutput(waterLevel,
+ waveHeight,
+ wavePeriod);
}
}
}
\ No newline at end of file
Index: Ringtoets/HydraRing/src/Ringtoets.HydraRing.Calculation/Properties/Resources.Designer.cs
===================================================================
diff -u -r31caf3dc885ae62d4b3772eb0421a3155101bcf4 -r4bf03fe0c441a3f3d439bc7ffe09350227435178
--- Ringtoets/HydraRing/src/Ringtoets.HydraRing.Calculation/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision 31caf3dc885ae62d4b3772eb0421a3155101bcf4)
+++ Ringtoets/HydraRing/src/Ringtoets.HydraRing.Calculation/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision 4bf03fe0c441a3f3d439bc7ffe09350227435178)
@@ -82,11 +82,12 @@
}
///
- /// Looks up a localized string similar to Er is een fout opgetreden bij het lezen van het uitvoerbestand..
+ /// Looks up a localized string similar to Er zijn geen berekende hydraulische randvoorwaarden voor duinen gevonden in de Hydra-Ring uitvoerdatabase..
///
- internal static string DunesBoundaryConditionsCalculationParser_Parse_Error_while_parsing_output {
+ internal static string DunesBoundaryConditionsCalculationParser_ParseFile_No_dunes_hydraulic_boundaries_found_in_output_file {
get {
- return ResourceManager.GetString("DunesBoundaryConditionsCalculationParser_Parse_Error_while_parsing_output", resourceCulture);
+ return ResourceManager.GetString("DunesBoundaryConditionsCalculationParser_ParseFile_No_dunes_hydraulic_boundaries_" +
+ "found_in_output_file", resourceCulture);
}
}
@@ -119,29 +120,29 @@
}
///
- /// Looks up a localized string similar to Er kon geen resultaat voor convergentie gelezen worden uit de Hydra-Ring uitvoerdatabase..
+ /// Looks up a localized string similar to Kan het Hydra-Ring last_error bestand {0} niet lezen uit de map {1}..
///
- internal static string Parse_Cannot_read_convergence_in_output_file {
+ internal static string Parse_Cannot_read_last_error_Filename_0_from_FolderPath_1_ {
get {
- return ResourceManager.GetString("Parse_Cannot_read_convergence_in_output_file", resourceCulture);
+ return ResourceManager.GetString("Parse_Cannot_read_last_error_Filename_0_from_FolderPath_1_", resourceCulture);
}
}
///
- /// Looks up a localized string similar to Kan het Hydra-Ring last_error bestand {0} niet lezen uit de map {1}..
+ /// Looks up a localized string similar to Er kon geen resultaat gelezen worden uit de Hydra-Ring uitvoerdatabase..
///
- internal static string Parse_Cannot_read_last_error_Filename_0_from_FolderPath_1_ {
+ internal static string ParseFile_Cannot_read_result_in_output_file {
get {
- return ResourceManager.GetString("Parse_Cannot_read_last_error_Filename_0_from_FolderPath_1_", resourceCulture);
+ return ResourceManager.GetString("ParseFile_Cannot_read_result_in_output_file", resourceCulture);
}
}
///
/// Looks up a localized string similar to Er is geen resultaat voor convergentie gevonden in de Hydra-Ring uitvoerdatabase..
///
- internal static string Parse_No_convergence_found_in_output_file {
+ internal static string ParseFile_No_convergence_found_in_output_file {
get {
- return ResourceManager.GetString("Parse_No_convergence_found_in_output_file", resourceCulture);
+ return ResourceManager.GetString("ParseFile_No_convergence_found_in_output_file", resourceCulture);
}
}
}
Index: Ringtoets/HydraRing/src/Ringtoets.HydraRing.Calculation/Properties/Resources.resx
===================================================================
diff -u -r31caf3dc885ae62d4b3772eb0421a3155101bcf4 -r4bf03fe0c441a3f3d439bc7ffe09350227435178
--- Ringtoets/HydraRing/src/Ringtoets.HydraRing.Calculation/Properties/Resources.resx (.../Resources.resx) (revision 31caf3dc885ae62d4b3772eb0421a3155101bcf4)
+++ Ringtoets/HydraRing/src/Ringtoets.HydraRing.Calculation/Properties/Resources.resx (.../Resources.resx) (revision 4bf03fe0c441a3f3d439bc7ffe09350227435178)
@@ -126,16 +126,16 @@
Er is een kritische fout opgetreden bij het uitvoeren van de berekening.
-
- Er is een fout opgetreden bij het lezen van het uitvoerbestand.
+
+ Er kon geen resultaat gelezen worden uit de Hydra-Ring uitvoerdatabase.
-
- Er kon geen resultaat voor convergentie gelezen worden uit de Hydra-Ring uitvoerdatabase.
-
-
+
Er is geen resultaat voor convergentie gevonden in de Hydra-Ring uitvoerdatabase.
Er is geen resultaat gevonden in de Hydra-Ring uitvoerdatabase.
+
+ Er zijn geen berekende hydraulische randvoorwaarden voor duinen gevonden in de Hydra-Ring uitvoerdatabase.
+
\ No newline at end of file
Index: Ringtoets/HydraRing/test/Ringtoets.HydraRing.Calculation.Test/Parsers/ConvergenceParserTest.cs
===================================================================
diff -u -r31caf3dc885ae62d4b3772eb0421a3155101bcf4 -r4bf03fe0c441a3f3d439bc7ffe09350227435178
--- Ringtoets/HydraRing/test/Ringtoets.HydraRing.Calculation.Test/Parsers/ConvergenceParserTest.cs (.../ConvergenceParserTest.cs) (revision 31caf3dc885ae62d4b3772eb0421a3155101bcf4)
+++ Ringtoets/HydraRing/test/Ringtoets.HydraRing.Calculation.Test/Parsers/ConvergenceParserTest.cs (.../ConvergenceParserTest.cs) (revision 4bf03fe0c441a3f3d439bc7ffe09350227435178)
@@ -40,6 +40,7 @@
private const string convergenceOnBothForSection1 = "ConvergenceOnBothSection1";
private const string noConvergenceForSection1 = "NoConvergenceSection1";
private const string convergenceOnAllButLastIterationForSection1 = "ConvergenceOnAllButLastIteration";
+ private const string convergenceNull = "ConvergenceNull";
private static readonly string testDirectory = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.HydraRing.Calculation, Path.Combine("Parsers", nameof(ConvergenceParser)));
[Test]
@@ -54,13 +55,13 @@
}
[Test]
- public void Parse_WithoutWorkingDirectory_ThrowsArgumentNullException()
+ public void Parse_WorkingDirectoryNull_ThrowsArgumentNullException()
{
// Setup
var parser = new ConvergenceParser();
// Call
- TestDelegate test = () => parser.Parse(null, 0);
+ TestDelegate test = () => parser.Parse(null, 1);
// Assert
var exception = Assert.Throws(test);
@@ -75,7 +76,7 @@
var parser = new ConvergenceParser();
// Call
- TestDelegate test = () => parser.Parse(path, 0);
+ TestDelegate test = () => parser.Parse(path, 1);
// Assert
var exception = Assert.Throws(test);
@@ -90,12 +91,12 @@
var parser = new ConvergenceParser();
// Call
- TestDelegate test = () => parser.Parse(path, 0);
+ TestDelegate test = () => parser.Parse(path, 1);
// Assert
var exception = Assert.Throws(test);
Assert.IsInstanceOf(exception.InnerException);
- Assert.AreEqual("Er kon geen resultaat voor convergentie gelezen worden uit de Hydra-Ring uitvoerdatabase.", exception.Message);
+ Assert.AreEqual("Er kon geen resultaat gelezen worden uit de Hydra-Ring uitvoerdatabase.", exception.Message);
}
[Test]
@@ -106,11 +107,12 @@
var parser = new ConvergenceParser();
// Call
- TestDelegate test = () => parser.Parse(path, 0);
+ TestDelegate test = () => parser.Parse(path, 1);
// Assert
var exception = Assert.Throws(test);
Assert.AreEqual("Er is geen resultaat voor convergentie gevonden in de Hydra-Ring uitvoerdatabase.", exception.Message);
+ Assert.IsInstanceOf(exception.InnerException);
}
[Test]
@@ -126,9 +128,26 @@
// Assert
var exception = Assert.Throws(test);
Assert.AreEqual("Er is geen resultaat voor convergentie gevonden in de Hydra-Ring uitvoerdatabase.", exception.Message);
+ Assert.IsInstanceOf(exception.InnerException);
}
[Test]
+ public void Parse_ResultNull_ThrowHydraRingFileParserException()
+ {
+ // Setup
+ string path = Path.Combine(testDirectory, convergenceNull);
+ var parser = new ConvergenceParser();
+
+ // Call
+ TestDelegate test = () => parser.Parse(path, 1);
+
+ // Assert
+ var exception = Assert.Throws(test);
+ Assert.AreEqual("Er is geen resultaat voor convergentie gevonden in de Hydra-Ring uitvoerdatabase.", exception.Message);
+ Assert.IsInstanceOf(exception.InnerException);
+ }
+
+ [Test]
[TestCase(noConvergenceForSection1)]
[TestCase(convergenceOnAllButLastIterationForSection1)]
public void Parse_WithWorkingDirectoryWithFileWithFalseResult_SetOutputFalse(string testSubDirectory)
Index: Ringtoets/HydraRing/test/Ringtoets.HydraRing.Calculation.Test/Parsers/DunesBoundaryConditionsCalculationParserTest.cs
===================================================================
diff -u -r90c3ff1fbab8c843e1fae9d630df8b6797679463 -r4bf03fe0c441a3f3d439bc7ffe09350227435178
--- Ringtoets/HydraRing/test/Ringtoets.HydraRing.Calculation.Test/Parsers/DunesBoundaryConditionsCalculationParserTest.cs (.../DunesBoundaryConditionsCalculationParserTest.cs) (revision 90c3ff1fbab8c843e1fae9d630df8b6797679463)
+++ Ringtoets/HydraRing/test/Ringtoets.HydraRing.Calculation.Test/Parsers/DunesBoundaryConditionsCalculationParserTest.cs (.../DunesBoundaryConditionsCalculationParserTest.cs) (revision 4bf03fe0c441a3f3d439bc7ffe09350227435178)
@@ -20,6 +20,7 @@
// All rights reserved.
using System;
+using System.Data.SQLite;
using System.IO;
using System.Security.AccessControl;
using Core.Common.TestUtil;
@@ -32,10 +33,19 @@
[TestFixture]
public class DunesBoundaryConditionsCalculationParserTest
{
- private const int sectionId = 1;
- private readonly string testDataPath = Path.Combine(TestHelper.GetTestDataPath(TestDataPath.Ringtoets.HydraRing.Calculation, "Parsers"), "DunesBoundaryConditionsParser");
- private readonly string outputFileName = sectionId + "-output.txt";
+ private const string emptyWorkingDirectory = "EmptyWorkingDirectory";
+ private const string invalidFileInDirectory = "InvalidFile";
+ private const string emptyFileInDirectory = "EmptyDatabase";
+ private const string noResultsOnLastIteration = "ResultsOnAllButLastIteration";
+ private const string permissionDenied = "NoPermissionsToRead";
+ private const string validFileNoWaveHeight = "ValidFileNoWaveHeight";
+ private const string validFileNoWavePeriod = "ValidFileNoWavePeriod";
+ private const string validFileNoWaterLevel = "ValidFileNoWaterLevel";
+ private const string validFile= "ValidFile";
+ private readonly string testDirectory = Path.Combine(TestHelper.GetTestDataPath(TestDataPath.Ringtoets.HydraRing.Calculation, "Parsers"),
+ "DunesBoundaryConditionsParser");
+
[Test]
public void Constructor_ExpectedValues()
{
@@ -48,113 +58,138 @@
}
[Test]
- public void Parse_NotExistingOutputFile_OutputNull()
+ public void Parse_WorkingDirectoryNull_ThrowsArgumentNullException()
{
// Setup
var parser = new DunesBoundaryConditionsCalculationParser();
// Call
- parser.Parse(testDataPath, sectionId);
+ TestDelegate test = () => parser.Parse(null, 1);
// Assert
- Assert.IsNull(parser.Output);
+ var exception = Assert.Throws(test);
+ Assert.AreEqual("workingDirectory", exception.ParamName);
}
[Test]
- public void Parse_EmptyOutputFile_OutputNull()
+ public void Parse_WithWorkingDirectoryWithoutExpectedFile_ThrowsHydraRingFileParserException()
{
// Setup
+ string path = Path.Combine(testDirectory, emptyWorkingDirectory);
var parser = new DunesBoundaryConditionsCalculationParser();
- var workingDirectory = Path.Combine(testDataPath, "empty");
// Call
- parser.Parse(workingDirectory, sectionId);
+ TestDelegate test = () => parser.Parse(path, 1);
// Assert
- Assert.IsNull(parser.Output);
- Assert.IsTrue(TestHelper.CanOpenFileForWrite(Path.Combine(workingDirectory, outputFileName)));
+ var exception = Assert.Throws(test);
+ Assert.IsInstanceOf(exception.InnerException);
}
[Test]
- public void Parse_ValidHydraRingOutputFile_OutputSetWithExpectedCalculationResult()
+ public void Parse_WithWorkingDirectoryWithInvalidOutputFile_ThrowsHydraRingFileParserException()
{
// Setup
+ string path = Path.Combine(testDirectory, invalidFileInDirectory);
var parser = new DunesBoundaryConditionsCalculationParser();
- var workingDirectory = Path.Combine(testDataPath, "valid");
// Call
- parser.Parse(workingDirectory, sectionId);
+ TestDelegate test = () => parser.Parse(path, 1);
// Assert
- Assert.AreEqual(4.82912, parser.Output.WaterLevel);
- Assert.AreEqual(2.88936, parser.Output.WaveHeight);
- Assert.AreEqual(10.65437, parser.Output.WavePeriod);
- Assert.IsTrue(TestHelper.CanOpenFileForWrite(Path.Combine(workingDirectory, outputFileName)));
+ var exception = Assert.Throws(test);
+ Assert.IsInstanceOf(exception.InnerException);
+ Assert.AreEqual("Er kon geen resultaat gelezen worden uit de Hydra-Ring uitvoerdatabase.", exception.Message);
}
[Test]
- public void Parse_InvalidHydraRingOutputFileWaterLevelMissing_OutputNull()
+ public void Parse_WithWorkingDirectoryWithEmptyFile_ThrowsHydraRingFileParserException()
{
// Setup
+ string path = Path.Combine(testDirectory, emptyFileInDirectory);
var parser = new DunesBoundaryConditionsCalculationParser();
- var workingDirectory = Path.Combine(testDataPath, "output-no-waterLevel");
// Call
- parser.Parse(workingDirectory, sectionId);
+ TestDelegate test = () => parser.Parse(path, 1);
// Assert
- Assert.IsNull(parser.Output);
- Assert.IsTrue(TestHelper.CanOpenFileForWrite(Path.Combine(workingDirectory, outputFileName)));
+ var exception = Assert.Throws(test);
+ Assert.AreEqual("Er zijn geen berekende hydraulische randvoorwaarden voor duinen gevonden in de Hydra-Ring uitvoerdatabase.", exception.Message);
+ Assert.IsInstanceOf(exception.InnerException);
}
[Test]
- public void Parse_InvalidHydraRingOutputFileWaveHeightMissing_OutputNull()
+ public void Parse_ErrorWhileReadingFile_ThrowsHydraRingFileParserException()
{
// Setup
var parser = new DunesBoundaryConditionsCalculationParser();
- var workingDirectory = Path.Combine(testDataPath, "output-no-waveHeight");
+ var workingDirectory = Path.Combine(testDirectory, permissionDenied);
+ using (new DirectoryPermissionsRevoker(testDirectory, FileSystemRights.ReadData))
+ {
+ // Call
+ TestDelegate call = () => parser.Parse(workingDirectory, 1);
+
+ // Assert
+ var exception = Assert.Throws(call);
+ var expectedMessage = "Er kon geen resultaat gelezen worden uit de Hydra-Ring uitvoerdatabase.";
+ Assert.AreEqual(expectedMessage, exception.Message);
+ Assert.IsInstanceOf(exception.InnerException);
+ }
+ }
+
+ [Test]
+ [TestCase(validFileNoWaveHeight)]
+ [TestCase(validFileNoWavePeriod)]
+ [TestCase(validFileNoWaterLevel)]
+ [TestCase(noResultsOnLastIteration)]
+ public void Parse_NotAllColumnsHasResults_ThrowHydraRingFileParserException(string subFolder)
+ {
+ // Setup
+ string path = Path.Combine(testDirectory, subFolder);
+ var parser = new DunesBoundaryConditionsCalculationParser();
+
// Call
- parser.Parse(workingDirectory, sectionId);
+ TestDelegate test = () => parser.Parse(path, 1);
// Assert
- Assert.IsNull(parser.Output);
- Assert.IsTrue(TestHelper.CanOpenFileForWrite(Path.Combine(workingDirectory, outputFileName)));
+ var exception = Assert.Throws(test);
+ Assert.AreEqual("Er zijn geen berekende hydraulische randvoorwaarden voor duinen gevonden in de Hydra-Ring uitvoerdatabase.", exception.Message);
+ Assert.IsInstanceOf(exception.InnerException);
}
+
+
[Test]
- public void Parse_InvalidHydraRingOutputFileWavePeriodMissing_OutputNull()
+ public void Parse_ValidDataForOtherSection_ThrowsHydraRingFileParserException()
{
// Setup
+ string path = Path.Combine(testDirectory, validFile);
var parser = new DunesBoundaryConditionsCalculationParser();
- var workingDirectory = Path.Combine(testDataPath, "output-no-wavePeriod");
// Call
- parser.Parse(workingDirectory, sectionId);
+ TestDelegate test = () => parser.Parse(path, 0);
// Assert
- Assert.IsNull(parser.Output);
- Assert.IsTrue(TestHelper.CanOpenFileForWrite(Path.Combine(workingDirectory, outputFileName)));
+ var exception = Assert.Throws(test);
+ Assert.AreEqual("Er zijn geen berekende hydraulische randvoorwaarden voor duinen gevonden in de Hydra-Ring uitvoerdatabase.", exception.Message);
+ Assert.IsInstanceOf(exception.InnerException);
}
[Test]
- public void Parse_ErrorWhileReadingFile_ThrowsHydraRingFileParserExceptionWithInnerException()
+ public void Parse_ValidData_OutputSet()
{
// Setup
+ string path = Path.Combine(testDirectory, validFile);
var parser = new DunesBoundaryConditionsCalculationParser();
- var workingDirectory = Path.Combine(testDataPath, "NoPermissionsToRead");
- using (new DirectoryPermissionsRevoker(testDataPath, FileSystemRights.ReadData))
- {
- // Call
- TestDelegate call = () => parser.Parse(workingDirectory, 1);
+ // Call
+ parser.Parse(path, 1);
- // Assert
- var exception = Assert.Throws(call);
- var expectedMessage = "Er is een fout opgetreden bij het lezen van het uitvoerbestand.";
- Assert.AreEqual(expectedMessage, exception.Message);
- Assert.IsInstanceOf(exception.InnerException);
- }
+ // Assert
+ Assert.AreEqual(4.29026, parser.Output.WaterLevel);
+ Assert.AreEqual(10.1528, parser.Output.WaveHeight);
+ Assert.AreEqual(19.1762, parser.Output.WavePeriod);
}
}
}
\ No newline at end of file
Index: Ringtoets/HydraRing/test/Ringtoets.HydraRing.Calculation.Test/test-data/Parsers/ConvergenceParser/ConvergenceNull/output.sqlite
===================================================================
diff -u
Binary files differ
Index: Ringtoets/HydraRing/test/Ringtoets.HydraRing.Calculation.Test/test-data/Parsers/DunesBoundaryConditionsParser/EmptyDatabase/output.sqlite
===================================================================
diff -u
Binary files differ
Index: Ringtoets/HydraRing/test/Ringtoets.HydraRing.Calculation.Test/test-data/Parsers/DunesBoundaryConditionsParser/InvalidFile/output.sqlite
===================================================================
diff -u
--- Ringtoets/HydraRing/test/Ringtoets.HydraRing.Calculation.Test/test-data/Parsers/DunesBoundaryConditionsParser/InvalidFile/output.sqlite (revision 0)
+++ Ringtoets/HydraRing/test/Ringtoets.HydraRing.Calculation.Test/test-data/Parsers/DunesBoundaryConditionsParser/InvalidFile/output.sqlite (revision 4bf03fe0c441a3f3d439bc7ffe09350227435178)
@@ -0,0 +1 @@
\ No newline at end of file
Index: Ringtoets/HydraRing/test/Ringtoets.HydraRing.Calculation.Test/test-data/Parsers/DunesBoundaryConditionsParser/ResultsOnAllButLastIteration/output.sqlite
===================================================================
diff -u
Binary files differ
Index: Ringtoets/HydraRing/test/Ringtoets.HydraRing.Calculation.Test/test-data/Parsers/DunesBoundaryConditionsParser/ValidFile/output.sqlite
===================================================================
diff -u
Binary files differ
Index: Ringtoets/HydraRing/test/Ringtoets.HydraRing.Calculation.Test/test-data/Parsers/DunesBoundaryConditionsParser/ValidFileNoWaterLevel/output.sqlite
===================================================================
diff -u
Binary files differ
Index: Ringtoets/HydraRing/test/Ringtoets.HydraRing.Calculation.Test/test-data/Parsers/DunesBoundaryConditionsParser/ValidFileNoWaveHeight/output.sqlite
===================================================================
diff -u
Binary files differ
Index: Ringtoets/HydraRing/test/Ringtoets.HydraRing.Calculation.Test/test-data/Parsers/DunesBoundaryConditionsParser/ValidFileNoWavePeriod/output.sqlite
===================================================================
diff -u
Binary files differ
Fisheye: Tag 4bf03fe0c441a3f3d439bc7ffe09350227435178 refers to a dead (removed) revision in file `Ringtoets/HydraRing/test/Ringtoets.HydraRing.Calculation.Test/test-data/Parsers/DunesBoundaryConditionsParser/empty/1-output.txt'.
Fisheye: No comparison available. Pass `N' to diff?
Fisheye: Tag 4bf03fe0c441a3f3d439bc7ffe09350227435178 refers to a dead (removed) revision in file `Ringtoets/HydraRing/test/Ringtoets.HydraRing.Calculation.Test/test-data/Parsers/DunesBoundaryConditionsParser/valid/1-output.txt'.
Fisheye: No comparison available. Pass `N' to diff?