Index: Ringtoets/Common/src/Ringtoets.Common.IO/Properties/Resources.Designer.cs
===================================================================
diff -u -rf2a9c4ae5677049bb5d34537984c114965daa251 -r23cc3cd6c57276d0cc0670abf9ec519b488e85ab
--- Ringtoets/Common/src/Ringtoets.Common.IO/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision f2a9c4ae5677049bb5d34537984c114965daa251)
+++ Ringtoets/Common/src/Ringtoets.Common.IO/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision 23cc3cd6c57276d0cc0670abf9ec519b488e85ab)
@@ -160,6 +160,15 @@
}
///
+ /// Looks up a localized string similar to Het XML-document dat de configuratie voor de berekeningen beschrijft is niet geldig. De validatie geeft de volgende melding: {0}.
+ ///
+ public static string CalculationConfigurationReader_Configuration_contains_no_valid_xml_Reason_2 {
+ get {
+ return ResourceManager.GetString("CalculationConfigurationReader_Configuration_contains_no_valid_xml_Reason_2", resourceCulture);
+ }
+ }
+
+ ///
/// Looks up a localized string similar to Het XML-document dat de configuratie voor de berekeningen beschrijft bevat geen berekeningselementen..
///
public static string CalculationConfigurationReader_No_configuration_items_found {
@@ -1236,7 +1245,6 @@
///
/// Looks up a localized string similar to <?xml version="1.0" encoding="utf-8"?>
- ///
///<!--
///Copyright (C) Stichting Deltares 2016. All rights reserved.
///
@@ -1248,7 +1256,7 @@
///(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 warrant [rest of string was truncated]";.
+ ///but WITHOUT ANY WARRANTY; without even the implied warranty [rest of string was truncated]";.
///
public static string StochastStandardDeviationSchema {
get {
@@ -1258,7 +1266,6 @@
///
/// Looks up a localized string similar to <?xml version="1.0" encoding="utf-8"?>
- ///
///<!--
///Copyright (C) Stichting Deltares 2016. All rights reserved.
///
@@ -1270,7 +1277,7 @@
///(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 warrant [rest of string was truncated]";.
+ ///but WITHOUT ANY WARRANTY; without even the implied warranty [rest of string was truncated]";.
///
public static string StochastVariationCoefficientSchema {
get {
Index: Ringtoets/Common/src/Ringtoets.Common.IO/Properties/Resources.resx
===================================================================
diff -u -rd347acb3d57c61fd3baa1e883551807417db6698 -r23cc3cd6c57276d0cc0670abf9ec519b488e85ab
--- Ringtoets/Common/src/Ringtoets.Common.IO/Properties/Resources.resx (.../Resources.resx) (revision d347acb3d57c61fd3baa1e883551807417db6698)
+++ Ringtoets/Common/src/Ringtoets.Common.IO/Properties/Resources.resx (.../Resources.resx) (revision 23cc3cd6c57276d0cc0670abf9ec519b488e85ab)
@@ -565,4 +565,7 @@
..\resources\stochastvariationcoefficientschema.xsd;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;Windows-1252
+
+ Het XML-document dat de configuratie voor de berekeningen beschrijft is niet geldig. De validatie geeft de volgende melding: {0}
+
\ No newline at end of file
Index: Ringtoets/Common/src/Ringtoets.Common.IO/Readers/CalculationConfigurationReader.cs
===================================================================
diff -u -r9c07cee1e1a14a24e2d949bf9b32f294f0988f1f -r23cc3cd6c57276d0cc0670abf9ec519b488e85ab
--- Ringtoets/Common/src/Ringtoets.Common.IO/Readers/CalculationConfigurationReader.cs (.../CalculationConfigurationReader.cs) (revision 9c07cee1e1a14a24e2d949bf9b32f294f0988f1f)
+++ Ringtoets/Common/src/Ringtoets.Common.IO/Readers/CalculationConfigurationReader.cs (.../CalculationConfigurationReader.cs) (revision 23cc3cd6c57276d0cc0670abf9ec519b488e85ab)
@@ -135,10 +135,15 @@
{
return XDocument.Load(xmlFilePath, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo | LoadOptions.SetBaseUri);
}
+ catch (XmlException exception)
+ {
+ string exceptionMessage = string.Format(Resources.CalculationConfigurationReader_Configuration_contains_no_valid_xml_Reason_2,
+ exception.Message);
+
+ throw new CriticalFileReadException(new FileReaderErrorMessageBuilder(xmlFilePath).Build(exceptionMessage), exception);
+ }
catch (Exception exception)
- when (exception is InvalidOperationException
- || exception is XmlException
- || exception is IOException)
+ when (exception is InvalidOperationException || exception is IOException)
{
string message = new FileReaderErrorMessageBuilder(xmlFilePath)
.Build(CoreCommonUtilsResources.Error_General_IO_Import_ErrorMessage);
Index: Ringtoets/Common/test/Ringtoets.Common.IO.Test/Readers/CalculationConfigurationReaderTest.cs
===================================================================
diff -u -r92df0a0ac0a4e0ccd5d7505d748f55167c2aac81 -r23cc3cd6c57276d0cc0670abf9ec519b488e85ab
--- Ringtoets/Common/test/Ringtoets.Common.IO.Test/Readers/CalculationConfigurationReaderTest.cs (.../CalculationConfigurationReaderTest.cs) (revision 92df0a0ac0a4e0ccd5d7505d748f55167c2aac81)
+++ Ringtoets/Common/test/Ringtoets.Common.IO.Test/Readers/CalculationConfigurationReaderTest.cs (.../CalculationConfigurationReaderTest.cs) (revision 23cc3cd6c57276d0cc0670abf9ec519b488e85ab)
@@ -55,6 +55,29 @@
}
}
+ private static IEnumerable InvalidXml
+ {
+ get
+ {
+ yield return new TestCaseData(
+ "empty.xml",
+ "Root element is missing.")
+ .SetName("FileDoesNotContainValidXml_empty.xml");
+ yield return new TestCaseData(
+ "textContent.xml",
+ "Data at the root level is invalid. Line 1, position 1.")
+ .SetName("FileDoesNotContainValidXml_textContent.xml");
+ yield return new TestCaseData(
+ "invalidXmlContent.xml",
+ "The 'map' start tag on line 4 position 4 does not match the end tag of 'configuratie'. Line 5, position 3.")
+ .SetName("FileDoesNotContainValidXml_invalidXmlContent.xml");
+ yield return new TestCaseData(
+ "withoutQoutationMarks.xml",
+ "'Nieuw' is an unexpected token. The expected token is '\"' or '''. Line 3, position 20.")
+ .SetName("FileDoesNotContainValidXml_withoutQoutationMarks.xml");
+ }
+ }
+
[Test]
[TestCase("")]
[TestCase(" ")]
@@ -116,10 +139,8 @@
}
[Test]
- [TestCase("empty.xml")]
- [TestCase("textContent.xml")]
- [TestCase("invalidXmlContent.xml")]
- public void Constructor_FileDoesNotContainValidXml_ThrowCriticalFileReadException(string fileName)
+ [TestCaseSource(nameof(InvalidXml))]
+ public void Constructor_FileDoesNotContainValidXml_ThrowCriticalFileReadException(string fileName, string expectedInnerMessage)
{
// Setup
string filePath = Path.Combine(testDirectoryPath, fileName);
@@ -128,10 +149,13 @@
TestDelegate call = () => new CalculationConfigurationReader(filePath, validMainSchemaDefinition, new Dictionary());
// Assert
- string expectedMessage = $"Fout bij het lezen van bestand '{filePath}': het bestand kon niet worden geopend. Mogelijk is het bestand corrupt of in gebruik door een andere applicatie.";
var exception = Assert.Throws(call);
+ string expectedMessage = $"Fout bij het lezen van bestand '{filePath}': " +
+ "het XML-document dat de configuratie voor de berekeningen beschrijft is niet geldig. " +
+ $"De validatie geeft de volgende melding: {expectedInnerMessage}";
Assert.AreEqual(expectedMessage, exception.Message);
Assert.IsInstanceOf(exception.InnerException);
+ Assert.IsTrue(exception.InnerException?.Message.Contains(expectedInnerMessage));
}
[Test]
Index: Ringtoets/Common/test/Ringtoets.Common.IO.Test/test-data/CalculationConfigurationReader/withoutQoutationMarks.xml
===================================================================
diff -u
--- Ringtoets/Common/test/Ringtoets.Common.IO.Test/test-data/CalculationConfigurationReader/withoutQoutationMarks.xml (revision 0)
+++ Ringtoets/Common/test/Ringtoets.Common.IO.Test/test-data/CalculationConfigurationReader/withoutQoutationMarks.xml (revision 23cc3cd6c57276d0cc0670abf9ec519b488e85ab)
@@ -0,0 +1,19 @@
+
+
+
+ YM_2_12-2_dk_12
+ 3
+ 0.5
+ 4
+ 0.3
+ 1.0
+ Profiel 2
+ 65
+
+ false
+ havendam
+ 0
+ true
+
+
+
\ No newline at end of file