Index: Ringtoets/Common/src/Ringtoets.Common.IO/Readers/CombinedXmlSchemaDefinition.cs =================================================================== diff -u -r7683c48cab2de71c7e6e3960f43d491660a4b552 -r1d2bc8f06f058cf7bf75fffa684ceca7961ec1de --- Ringtoets/Common/src/Ringtoets.Common.IO/Readers/CombinedXmlSchemaDefinition.cs (.../CombinedXmlSchemaDefinition.cs) (revision 7683c48cab2de71c7e6e3960f43d491660a4b552) +++ Ringtoets/Common/src/Ringtoets.Common.IO/Readers/CombinedXmlSchemaDefinition.cs (.../CombinedXmlSchemaDefinition.cs) (revision 1d2bc8f06f058cf7bf75fffa684ceca7961ec1de) @@ -32,8 +32,7 @@ namespace Ringtoets.Common.IO.Readers { /// - /// Container for one or more related/nested schema definitions, representing a combined - /// XML Schema Definition (XSD). + /// Container for related/nested schema definitions, representing a combined XML Schema Definition (XSD). /// public class CombinedXmlSchemaDefinition { @@ -42,11 +41,11 @@ /// /// Creates a new instance of . /// - /// A string representing the main schema definition. + /// A string representing the main schema definition. /// A containing - /// one or more nested schema definitions; the keys should represent unique file names by which - /// the schema definitions can be referenced from , the - /// values should represent the corresponding schema definition strings. + /// zero to more nested schema definitions. The keys should represent unique file names by which + /// the schema definitions can be referenced from ; the + /// values should represent their corresponding schema definition string. /// Thrown when /// is null. /// Thrown when: @@ -90,9 +89,9 @@ /// /// Check the provided schema definitions for not being null, empty or only containing white spaces. /// - /// A string representing the main schema definition. + /// A string representing the main schema definition. /// A containing - /// one or more nested schema definitions. + /// zero to more nested schema definitions. /// Thrown when /// is null. /// Thrown when: @@ -115,14 +114,14 @@ if (nestedSchemaDefinitions.Values.Any(string.IsNullOrWhiteSpace)) { - throw new ArgumentException($"'{nameof(nestedSchemaDefinitions)}' holds a nested schema definition value that equals null, is empty or only contains white spaces."); + throw new ArgumentException($"'{nameof(nestedSchemaDefinitions)}' contains one or more nested schema definitions that equal null, are empty or only contain white spaces."); } } /// - /// Compiles the based on the provided main schema definition string. + /// Compiles the based on the provided main schema definition. /// - /// A string representing the main schema definition. + /// A string representing the main schema definition. /// Thrown when , /// all together with its referenced nested schema definitions, contains an invalid schema /// definition. @@ -136,7 +135,7 @@ catch (Exception exception) when (exception is XmlException || exception is XmlSchemaException) { - throw new ArgumentException($"'{nameof(mainSchemaDefinition)}' containing invalid schema definition: {exception.Message}", exception); + throw new ArgumentException($"'{nameof(mainSchemaDefinition)}' invalid: {exception.Message}", exception); } } @@ -152,7 +151,7 @@ /// Creates a new instance of . /// /// A containing - /// one or more nested schema definitions. + /// zero to more nested schema definitions. public NestedSchemaDefinitionsResolver(IDictionary nestedSchemaDefinitions) { this.nestedSchemaDefinitions = nestedSchemaDefinitions; @@ -168,7 +167,7 @@ } /// - /// Gets whether or not all nested schema definitions are used. + /// Gets whether all nested schema definitions are used. /// public bool AllNestedSchemaDefinitionsReferenced { Index: Ringtoets/Common/src/Ringtoets.Common.IO/Readers/ConfigurationReader.cs =================================================================== diff -u -re8d6d0512bc28b0af2bd1e8fae1f0bd9e976300c -r1d2bc8f06f058cf7bf75fffa684ceca7961ec1de --- Ringtoets/Common/src/Ringtoets.Common.IO/Readers/ConfigurationReader.cs (.../ConfigurationReader.cs) (revision e8d6d0512bc28b0af2bd1e8fae1f0bd9e976300c) +++ Ringtoets/Common/src/Ringtoets.Common.IO/Readers/ConfigurationReader.cs (.../ConfigurationReader.cs) (revision 1d2bc8f06f058cf7bf75fffa684ceca7961ec1de) @@ -49,23 +49,32 @@ /// Creates a new instance of . /// /// The file path to the XML file. - /// A string representing the main schema definition. + /// A string representing the main schema definition. /// A containing - /// one or more nested schema definitions; the keys should represent unique file names by which - /// the schema definitions can be referenced from , the - /// values should represent the corresponding schema definition strings. + /// zero to more nested schema definitions. The keys should represent unique file names by which + /// the schema definitions can be referenced from ; the + /// values should represent their corresponding schema definition string. + /// Thrown when + /// is null. /// Thrown when: /// /// is invalid. - /// is null or empty. - /// contains an invalid schema definition. + /// is invalid. + /// contains invalid schema definition values. + /// , all together with its referenced + /// , contains an invalid schema definition. + /// contains schema definitions that are not + /// referenced by . + /// does not reference the default schema definition + /// ConfiguratieSchema.xsd. /// /// /// Thrown when: /// /// points to a file that does not exist. /// points to a file that does not contain valid XML. /// points to a file that does not pass the schema validation. + /// points to a file that does not contain configuration elements. /// /// protected ConfigurationReader(string xmlFilePath, string mainSchemaDefinition, IDictionary nestedSchemaDefinitions) @@ -137,14 +146,14 @@ } /// - /// Validates the provided XML document based on the provided XML Schema Definition (XSD). + /// Validates the provided XML document based on the provided schema definitions. /// /// The XML document to validate. - /// A string representing the main schema definition. - /// A containing - /// one or more nested schema definitions /// The file path the XML document is loaded from. - /// Thrown when the provided XML document does not match the provided XML Schema Definition (XSD). + /// A string representing the main schema definition. + /// A containing + /// zero to more nested schema definitions + /// Thrown when the provided XML document does not match the provided schema definitions. private static void ValidateToSchema(XDocument document, string xmlFilePath, string mainSchemaDefinition, IDictionary nestedSchemaDefinitions) { var combinedXmlSchemaDefinition = new CombinedXmlSchemaDefinition(mainSchemaDefinition, nestedSchemaDefinitions @@ -170,7 +179,7 @@ } /// - /// Validates whether or not the provided XML document is empty. + /// Validates whether the provided XML document is not empty. /// /// The XML document to validate. /// The file path the XML document is loaded from. Index: Ringtoets/Common/test/Ringtoets.Common.IO.Test/Readers/CombinedXmlSchemaDefinitionTest.cs =================================================================== diff -u -r7683c48cab2de71c7e6e3960f43d491660a4b552 -r1d2bc8f06f058cf7bf75fffa684ceca7961ec1de --- Ringtoets/Common/test/Ringtoets.Common.IO.Test/Readers/CombinedXmlSchemaDefinitionTest.cs (.../CombinedXmlSchemaDefinitionTest.cs) (revision 7683c48cab2de71c7e6e3960f43d491660a4b552) +++ Ringtoets/Common/test/Ringtoets.Common.IO.Test/Readers/CombinedXmlSchemaDefinitionTest.cs (.../CombinedXmlSchemaDefinitionTest.cs) (revision 1d2bc8f06f058cf7bf75fffa684ceca7961ec1de) @@ -93,18 +93,18 @@ // Assert var exception = Assert.Throws(call); - Assert.AreEqual("'nestedSchemaDefinitions' holds a nested schema definition value that equals null, is empty or only contains white spaces.", exception.Message); + Assert.AreEqual("'nestedSchemaDefinitions' contains one or more nested schema definitions that equal null, are empty or only contain white spaces.", exception.Message); } [Test] [TestCase("textContent.xsd", - "'mainSchemaDefinition' containing invalid schema definition: Data at the root level is invalid. Line 1, position 1.", + "'mainSchemaDefinition' invalid: Data at the root level is invalid. Line 1, position 1.", typeof(XmlException))] [TestCase("invalidXsdContent.xsd", - "'mainSchemaDefinition' containing invalid schema definition: The 'http://www.w3.org/2001/XMLSchema:redefine' element is not supported in this context.", + "'mainSchemaDefinition' invalid: The 'http://www.w3.org/2001/XMLSchema:redefine' element is not supported in this context.", typeof(XmlSchemaException))] [TestCase("referencingUndefinedNestedSchemaDefinition.xsd", - "'mainSchemaDefinition' containing invalid schema definition: 'SchemaLocation' must successfully resolve if contains any child other than .", + "'mainSchemaDefinition' invalid: 'SchemaLocation' must successfully resolve if contains any child other than .", typeof(XmlSchemaException))] public void Constructor_InvalidMainSchemaDefinition_ThrowArgumentException(string invalidMainSchemaDefinition, string expectedMessage, @@ -132,10 +132,10 @@ [Test] [TestCase("textContent.xsd", - "'mainSchemaDefinition' containing invalid schema definition: The 'genericElement' element is not declared.", + "'mainSchemaDefinition' invalid: The 'genericElement' element is not declared.", typeof(XmlSchemaException))] [TestCase("invalidXsdContent.xsd", - "'mainSchemaDefinition' containing invalid schema definition: Cannot load the schema from the location 'NestedSchemaDefinition2.xsd' - The 'http://www.w3.org/2001/XMLSchema:redefine' element is not supported in this context.", + "'mainSchemaDefinition' invalid: Cannot load the schema from the location 'NestedSchemaDefinition2.xsd' - The 'http://www.w3.org/2001/XMLSchema:redefine' element is not supported in this context.", typeof(XmlSchemaException))] public void Constructor_InvalidNestedSchemaDefinition_ThrowArgumentException(string invalidNestedSchemaDefinition, string expectedMessage, @@ -230,7 +230,7 @@ { // Setup string xmlFilePath = Path.Combine(testDirectoryPath, "invalidXmlDocument.xml"); - XDocument validXmlDocument = XDocument.Load(xmlFilePath, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo | LoadOptions.SetBaseUri); + XDocument invalidXmlDocument = XDocument.Load(xmlFilePath, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo | LoadOptions.SetBaseUri); var combinedXmlSchemaDefinition = new CombinedXmlSchemaDefinition(validMainSchemaDefinition, new Dictionary { @@ -243,7 +243,7 @@ }); // Call - TestDelegate call = () => combinedXmlSchemaDefinition.Validate(validXmlDocument); + TestDelegate call = () => combinedXmlSchemaDefinition.Validate(invalidXmlDocument); // Assert Assert.Throws(call); Index: Ringtoets/Common/test/Ringtoets.Common.IO.Test/Readers/ConfigurationReaderTest.cs =================================================================== diff -u -re8d6d0512bc28b0af2bd1e8fae1f0bd9e976300c -r1d2bc8f06f058cf7bf75fffa684ceca7961ec1de --- Ringtoets/Common/test/Ringtoets.Common.IO.Test/Readers/ConfigurationReaderTest.cs (.../ConfigurationReaderTest.cs) (revision e8d6d0512bc28b0af2bd1e8fae1f0bd9e976300c) +++ Ringtoets/Common/test/Ringtoets.Common.IO.Test/Readers/ConfigurationReaderTest.cs (.../ConfigurationReaderTest.cs) (revision 1d2bc8f06f058cf7bf75fffa684ceca7961ec1de) @@ -24,7 +24,6 @@ using System.IO; using System.Xml; using System.Xml.Linq; -using System.Xml.Schema; using Core.Common.IO.Exceptions; using Core.Common.TestUtil; using NUnit.Framework; @@ -35,7 +34,7 @@ [TestFixture] public class ConfigurationReaderTest { - private readonly string schemaString; + private readonly string validMainSchemaDefinition; private readonly string testDirectoryPath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Common.IO, "ConfigurationReader"); @@ -47,7 +46,7 @@ public void Constructor_NoFilePath_ThrowArgumentException(string invalidFilePath) { // Call - TestDelegate call = () => new TestConfigurationReader(invalidFilePath, schemaString); + TestDelegate call = () => new TestConfigurationReader(invalidFilePath, validMainSchemaDefinition, new Dictionary()); // Assert string expectedMessage = $"Fout bij het lezen van bestand '{invalidFilePath}': bestandspad mag niet leeg of ongedefinieerd zijn."; @@ -59,12 +58,11 @@ { // Setup char[] invalidPathChars = Path.GetInvalidPathChars(); - string validFilePath = Path.Combine(testDirectoryPath, "validConfiguration.xml"); string invalidFilePath = validFilePath.Replace("Config", invalidPathChars[3].ToString()); // Call - TestDelegate call = () => new TestConfigurationReader(invalidFilePath, schemaString); + TestDelegate call = () => new TestConfigurationReader(invalidFilePath, validMainSchemaDefinition, new Dictionary()); // Assert string expectedMessage = $"Fout bij het lezen van bestand '{invalidFilePath}': " @@ -79,7 +77,7 @@ string invalidFilePath = Path.Combine(testDirectoryPath, Path.DirectorySeparatorChar.ToString()); // Call - TestDelegate call = () => new TestConfigurationReader(invalidFilePath, schemaString); + TestDelegate call = () => new TestConfigurationReader(invalidFilePath, validMainSchemaDefinition, new Dictionary()); // Assert string expectedMessage = $"Fout bij het lezen van bestand '{invalidFilePath}': bestandspad mag niet verwijzen naar een lege bestandsnaam."; @@ -93,7 +91,7 @@ string invalidFilePath = Path.Combine(testDirectoryPath, "notExisting.xml"); // Call - TestDelegate call = () => new TestConfigurationReader(invalidFilePath, schemaString); + TestDelegate call = () => new TestConfigurationReader(invalidFilePath, validMainSchemaDefinition, new Dictionary()); // Assert string expectedMessage = $"Fout bij het lezen van bestand '{invalidFilePath}': het bestand bestaat niet."; @@ -102,51 +100,6 @@ } [Test] - [TestCase("")] - [TestCase(" ")] - [TestCase(null)] - public void Constructor_NoSchemaString_ThrowArgumentException(string invalidSchemaString) - { - // Setup - string filePath = Path.Combine(testDirectoryPath, "validConfiguration.xml"); - - // Call - TestDelegate call = () => new TestConfigurationReader(filePath, invalidSchemaString); - - // Assert - var exception = Assert.Throws(call); - Assert.AreEqual("'mainSchemaDefinition' null, empty or only containing white spaces.", exception.Message); - } - - [Test] - [TestCase("textContent.xsd", - "'mainSchemaDefinition' containing invalid schema definition: Data at the root level is invalid. Line 1, position 1.", - typeof(XmlException))] - [TestCase("invalidXsdContent.xsd", - "'mainSchemaDefinition' containing invalid schema definition: The 'http://www.w3.org/2001/XMLSchema:redefine' element is not supported in this context.", - typeof(XmlSchemaException))] - [TestCase("notReferencingBaseXsd.xsd", - "'nestedSchemaDefinitions' contains one or more schema definitions that are not referenced.")] - public void Constructor_InvalidSchemaString_ThrowArgumentException(string fileName, string expectedMessage, Type expectedInnerExceptionType = null) - { - // Setup - string filePath = Path.Combine(testDirectoryPath, "validConfiguration.xml"); - string xsdPath = Path.Combine(testDirectoryPath, fileName); - - // Call - TestDelegate call = () => new TestConfigurationReader(filePath, File.ReadAllText(xsdPath)); - - // Assert - var exception = Assert.Throws(call); - Assert.AreEqual(expectedMessage, exception.Message); - - if (expectedInnerExceptionType != null) - { - Assert.IsInstanceOf(expectedInnerExceptionType, exception.InnerException); - } - } - - [Test] [TestCase("empty.xml")] [TestCase("textContent.xml")] [TestCase("invalidXmlContent.xml")] @@ -156,7 +109,7 @@ string filePath = Path.Combine(testDirectoryPath, fileName); // Call - TestDelegate call = () => new TestConfigurationReader(filePath, schemaString); + TestDelegate call = () => new TestConfigurationReader(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."; @@ -176,7 +129,7 @@ fileDisposeHelper.LockFiles(); // Call - TestDelegate call = () => new TestConfigurationReader(path, schemaString); + TestDelegate call = () => new TestConfigurationReader(path, validMainSchemaDefinition, new Dictionary()); // Assert string expectedMessage = $"Fout bij het lezen van bestand '{path}': het bestand kon niet worden geopend. Mogelijk is het bestand corrupt of in gebruik door een andere applicatie."; @@ -187,13 +140,28 @@ } [Test] + public void Constructor_MainSchemaDefinitionNotReferencingDefaultSchema_ThrowArgumentException() + { + // Setup + string filePath = Path.Combine(testDirectoryPath, "validConfiguration.xml"); + string xsdPath = Path.Combine(testDirectoryPath, "mainSchemaDefinitionNotReferencingDefaultSchema.xsd"); + + // Call + TestDelegate call = () => new TestConfigurationReader(filePath, File.ReadAllText(xsdPath), new Dictionary()); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("'nestedSchemaDefinitions' contains one or more schema definitions that are not referenced.", exception.Message); + } + + [Test] public void Constructor_FileInvalidBasedOnSchemaDefinition_ThrowCriticalFileReadExceptionWithExpectedMessage() { // Setup string filePath = Path.Combine(testDirectoryPath, "invalidFolderNoName.xml"); // Call - TestDelegate call = () => new TestConfigurationReader(filePath, schemaString); + TestDelegate call = () => new TestConfigurationReader(filePath, validMainSchemaDefinition, new Dictionary()); // Assert string expectedMessage = $"Fout bij het lezen van bestand '{filePath}': het XML-document dat de configuratie" + @@ -205,13 +173,15 @@ public ConfigurationReaderTest() { - schemaString = File.ReadAllText(Path.Combine(testDirectoryPath, "validConfigurationSchema.xsd")); + validMainSchemaDefinition = File.ReadAllText(Path.Combine(testDirectoryPath, "validConfigurationSchema.xsd")); } private class TestConfigurationReader : ConfigurationReader { - public TestConfigurationReader(string xmlFilePath, string mainSchemaDefinition) - : base(xmlFilePath, mainSchemaDefinition, new Dictionary()) {} + public TestConfigurationReader(string xmlFilePath, + string mainSchemaDefinition, + IDictionary nestedSchemaDefinitions) + : base(xmlFilePath, mainSchemaDefinition, nestedSchemaDefinitions) {} protected override TestReadConfigurationItem ParseCalculationElement(XElement calculationElement) { Index: Ringtoets/Common/test/Ringtoets.Common.IO.Test/test-data/ConfigurationReader/mainSchemaDefinitionNotReferencingDefaultSchema.xsd =================================================================== diff -u --- Ringtoets/Common/test/Ringtoets.Common.IO.Test/test-data/ConfigurationReader/mainSchemaDefinitionNotReferencingDefaultSchema.xsd (revision 0) +++ Ringtoets/Common/test/Ringtoets.Common.IO.Test/test-data/ConfigurationReader/mainSchemaDefinitionNotReferencingDefaultSchema.xsd (revision 1d2bc8f06f058cf7bf75fffa684ceca7961ec1de) @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file