Index: Ringtoets/Piping/src/Ringtoets.Piping.IO/Properties/Resources.Designer.cs
===================================================================
diff -u -r9fd6d5a7d2289de6a5c6447fe8e0a9019cf75701 -r9b940da26da12706c2b6665959e6de7f1a3dbc52
--- Ringtoets/Piping/src/Ringtoets.Piping.IO/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision 9fd6d5a7d2289de6a5c6447fe8e0a9019cf75701)
+++ Ringtoets/Piping/src/Ringtoets.Piping.IO/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision 9b940da26da12706c2b6665959e6de7f1a3dbc52)
@@ -195,9 +195,9 @@
///
/// Looks up a localized string similar to Het XML-document dat de configuratie voor de berekeningen beschrijft is niet geldig..
///
- public static string PipingCalculationGroupReader_Configuration_contains_no_valid_xml {
+ public static string PipingConfigurationReader_Configuration_contains_no_valid_xml {
get {
- return ResourceManager.GetString("PipingCalculationGroupReader_Configuration_contains_no_valid_xml", resourceCulture);
+ return ResourceManager.GetString("PipingConfigurationReader_Configuration_contains_no_valid_xml", resourceCulture);
}
}
Index: Ringtoets/Piping/src/Ringtoets.Piping.IO/Properties/Resources.resx
===================================================================
diff -u -r9fd6d5a7d2289de6a5c6447fe8e0a9019cf75701 -r9b940da26da12706c2b6665959e6de7f1a3dbc52
--- Ringtoets/Piping/src/Ringtoets.Piping.IO/Properties/Resources.resx (.../Resources.resx) (revision 9fd6d5a7d2289de6a5c6447fe8e0a9019cf75701)
+++ Ringtoets/Piping/src/Ringtoets.Piping.IO/Properties/Resources.resx (.../Resources.resx) (revision 9b940da26da12706c2b6665959e6de7f1a3dbc52)
@@ -260,7 +260,7 @@
{0}
Deze ondergrondschematisatie wordt overgeslagen.
-
+
Het XML-document dat de configuratie voor de berekeningen beschrijft is niet geldig.
\ No newline at end of file
Index: Ringtoets/Piping/src/Ringtoets.Piping.IO/Readers/IReadPipingCalculationItem.cs
===================================================================
diff -u -r4ef4e426c0a77d547b58ec56581f292ddb3ed381 -r9b940da26da12706c2b6665959e6de7f1a3dbc52
--- Ringtoets/Piping/src/Ringtoets.Piping.IO/Readers/IReadPipingCalculationItem.cs (.../IReadPipingCalculationItem.cs) (revision 4ef4e426c0a77d547b58ec56581f292ddb3ed381)
+++ Ringtoets/Piping/src/Ringtoets.Piping.IO/Readers/IReadPipingCalculationItem.cs (.../IReadPipingCalculationItem.cs) (revision 9b940da26da12706c2b6665959e6de7f1a3dbc52)
@@ -22,7 +22,7 @@
namespace Ringtoets.Piping.IO.Readers
{
///
- /// Interface for piping calculation items that are read via .
+ /// Interface for piping calculation items that are read via .
///
public interface IReadPipingCalculationItem
{
Fisheye: Tag 9b940da26da12706c2b6665959e6de7f1a3dbc52 refers to a dead (removed) revision in file `Ringtoets/Piping/src/Ringtoets.Piping.IO/Readers/PipingCalculationGroupReader.cs'.
Fisheye: No comparison available. Pass `N' to diff?
Index: Ringtoets/Piping/src/Ringtoets.Piping.IO/Readers/PipingConfigurationReader.cs
===================================================================
diff -u
--- Ringtoets/Piping/src/Ringtoets.Piping.IO/Readers/PipingConfigurationReader.cs (revision 0)
+++ Ringtoets/Piping/src/Ringtoets.Piping.IO/Readers/PipingConfigurationReader.cs (revision 9b940da26da12706c2b6665959e6de7f1a3dbc52)
@@ -0,0 +1,140 @@
+// 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.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Xml;
+using System.Xml.Linq;
+using System.Xml.Schema;
+using Core.Common.IO.Exceptions;
+using Core.Common.Utils;
+using Core.Common.Utils.Builders;
+using Core.Common.Utils.Reflection;
+using Ringtoets.Piping.IO.Properties;
+using CoreCommonUtilsResources = Core.Common.Utils.Properties.Resources;
+
+namespace Ringtoets.Piping.IO.Readers
+{
+ ///
+ /// This class reads a piping configuration from XML and creates a collection of corresponding .
+ ///
+ public class PipingConfigurationReader
+ {
+ ///
+ /// Creates a new instance of .
+ ///
+ /// The file path to the XML file.
+ /// Thrown when is invalid.
+ /// 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.
+ ///
+ ///
+ public PipingConfigurationReader(string xmlFilePath)
+ {
+ IOUtils.ValidateFilePath(xmlFilePath);
+
+ ValidateFileExists(xmlFilePath);
+
+ XDocument xmlDocument = LoadDocument(xmlFilePath);
+
+ ValidateToSchema(xmlDocument);
+ }
+
+ ///
+ /// Reads the piping configuration from the XML and creates a collection of corresponding .
+ ///
+ /// A collection of read .
+ public IEnumerable Read()
+ {
+ return Enumerable.Empty();
+ }
+
+ ///
+ /// Validates whether a file exists at the provided .
+ ///
+ /// The file path to validate.
+ /// Thrown when no existing file is found.
+ private static void ValidateFileExists(string xmlFilePath)
+ {
+ if (!File.Exists(xmlFilePath))
+ {
+ string message = new FileReaderErrorMessageBuilder(xmlFilePath).Build(CoreCommonUtilsResources.Error_File_does_not_exist);
+ throw new CriticalFileReadException(message);
+ }
+ }
+
+ ///
+ /// Loads a XML document from the provided .
+ ///
+ /// The file path to load the XML document from.
+ /// Thrown when the XML document cannot be loaded.
+ private static XDocument LoadDocument(string xmlFilePath)
+ {
+ try
+ {
+ return XDocument.Load(xmlFilePath);
+ }
+ catch (Exception exception)
+ when (exception is ArgumentNullException
+ || exception is XmlException
+ || exception is InvalidOperationException)
+ {
+ string message = new FileReaderErrorMessageBuilder(xmlFilePath).Build(CoreCommonUtilsResources.Error_General_IO_Import_ErrorMessage);
+ throw new CriticalFileReadException(message, exception);
+ }
+ }
+
+ ///
+ /// Validates the provided XML document based on a predefined XML Schema Definition (XSD).
+ ///
+ /// The XML document to validate.
+ /// Thrown when the provided XML document does not match the predefined XML Schema Definition (XSD).
+ private static void ValidateToSchema(XDocument document)
+ {
+ XmlSchemaSet schema = LoadXmlSchema();
+
+ try
+ {
+ document.Validate(schema, null);
+ }
+ catch (XmlSchemaValidationException e)
+ {
+ throw new CriticalFileReadException(Resources.PipingConfigurationReader_Configuration_contains_no_valid_xml, e);
+ }
+ }
+
+ private static XmlSchemaSet LoadXmlSchema()
+ {
+ Stream schemaFile = AssemblyUtils.GetAssemblyResourceStream(typeof(PipingConfigurationReader).Assembly,
+ "Ringtoets.Piping.IO.Readers.XMLPipingConfigurationSchema.xsd");
+
+ var xmlSchema = new XmlSchemaSet();
+ xmlSchema.Add(XmlSchema.Read(schemaFile, null));
+
+ return xmlSchema;
+ }
+ }
+}
\ No newline at end of file
Index: Ringtoets/Piping/src/Ringtoets.Piping.IO/Readers/ReadPipingCalculation.cs
===================================================================
diff -u -r4ef4e426c0a77d547b58ec56581f292ddb3ed381 -r9b940da26da12706c2b6665959e6de7f1a3dbc52
--- Ringtoets/Piping/src/Ringtoets.Piping.IO/Readers/ReadPipingCalculation.cs (.../ReadPipingCalculation.cs) (revision 4ef4e426c0a77d547b58ec56581f292ddb3ed381)
+++ Ringtoets/Piping/src/Ringtoets.Piping.IO/Readers/ReadPipingCalculation.cs (.../ReadPipingCalculation.cs) (revision 9b940da26da12706c2b6665959e6de7f1a3dbc52)
@@ -24,7 +24,7 @@
namespace Ringtoets.Piping.IO.Readers
{
///
- /// Class that represents a piping calculation that is read via .
+ /// Class that represents a piping calculation that is read via .
///
public class ReadPipingCalculation : IReadPipingCalculationItem
{
Index: Ringtoets/Piping/src/Ringtoets.Piping.IO/Readers/ReadPipingCalculationGroup.cs
===================================================================
diff -u -r4ef4e426c0a77d547b58ec56581f292ddb3ed381 -r9b940da26da12706c2b6665959e6de7f1a3dbc52
--- Ringtoets/Piping/src/Ringtoets.Piping.IO/Readers/ReadPipingCalculationGroup.cs (.../ReadPipingCalculationGroup.cs) (revision 4ef4e426c0a77d547b58ec56581f292ddb3ed381)
+++ Ringtoets/Piping/src/Ringtoets.Piping.IO/Readers/ReadPipingCalculationGroup.cs (.../ReadPipingCalculationGroup.cs) (revision 9b940da26da12706c2b6665959e6de7f1a3dbc52)
@@ -24,7 +24,7 @@
namespace Ringtoets.Piping.IO.Readers
{
///
- /// Class that represents a piping calculation group that is read via .
+ /// Class that represents a piping calculation group that is read via .
///
public class ReadPipingCalculationGroup : IReadPipingCalculationItem
{
Index: Ringtoets/Piping/src/Ringtoets.Piping.IO/Ringtoets.Piping.IO.csproj
===================================================================
diff -u -rd8d7d3d24763ec06d36322d9a57996a83a64653b -r9b940da26da12706c2b6665959e6de7f1a3dbc52
--- Ringtoets/Piping/src/Ringtoets.Piping.IO/Ringtoets.Piping.IO.csproj (.../Ringtoets.Piping.IO.csproj) (revision d8d7d3d24763ec06d36322d9a57996a83a64653b)
+++ Ringtoets/Piping/src/Ringtoets.Piping.IO/Ringtoets.Piping.IO.csproj (.../Ringtoets.Piping.IO.csproj) (revision 9b940da26da12706c2b6665959e6de7f1a3dbc52)
@@ -59,7 +59,7 @@
-
+
Fisheye: Tag 9b940da26da12706c2b6665959e6de7f1a3dbc52 refers to a dead (removed) revision in file `Ringtoets/Piping/test/Ringtoets.Piping.IO.Test/Readers/PipingCalculationGroupReaderTest.cs'.
Fisheye: No comparison available. Pass `N' to diff?
Index: Ringtoets/Piping/test/Ringtoets.Piping.IO.Test/Readers/PipingConfigurationReaderTest.cs
===================================================================
diff -u
--- Ringtoets/Piping/test/Ringtoets.Piping.IO.Test/Readers/PipingConfigurationReaderTest.cs (revision 0)
+++ Ringtoets/Piping/test/Ringtoets.Piping.IO.Test/Readers/PipingConfigurationReaderTest.cs (revision 9b940da26da12706c2b6665959e6de7f1a3dbc52)
@@ -0,0 +1,97 @@
+// 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.IO.Exceptions;
+using Core.Common.TestUtil;
+using NUnit.Framework;
+using Ringtoets.Piping.IO.Readers;
+
+namespace Ringtoets.Piping.IO.Test.Readers
+{
+ [TestFixture]
+ public class PipingConfigurationReaderTest
+ {
+ [Test]
+ [TestCase("")]
+ [TestCase(" ")]
+ [TestCase(null)]
+ public void Constructor_NoFilePath_ThrowArgumentException(string invalidFilePath)
+ {
+ // Call
+ TestDelegate call = () => new PipingConfigurationReader(invalidFilePath);
+
+ // Assert
+ var expectedMessage = $"Fout bij het lezen van bestand '{invalidFilePath}': bestandspad mag niet leeg of ongedefinieerd zijn.";
+ TestHelper.AssertThrowsArgumentExceptionAndTestMessage(call, expectedMessage);
+ }
+
+ [Test]
+ public void Constructor_FilePathHasInvalidPathCharacter_ThrowArgumentException()
+ {
+ // Setup
+ char[] invalidFileNameChars = Path.GetInvalidFileNameChars();
+
+ string validFilePath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Piping.IO,
+ "Valid piping configuration.shp");
+ string invalidFilePath = validFilePath.Replace("piping", invalidFileNameChars[3].ToString());
+
+ // Call
+ TestDelegate call = () => new PipingConfigurationReader(invalidFilePath);
+
+ // Assert
+ var expectedMessage = $"Fout bij het lezen van bestand '{invalidFilePath}': bestandspad mag niet de volgende tekens bevatten: {string.Join(", ", invalidFileNameChars)}";
+ TestHelper.AssertThrowsArgumentExceptionAndTestMessage(call, expectedMessage);
+ }
+
+ [Test]
+ public void Constructor_FilePathIsActuallyDirectoryPath_ThrowArgumentException()
+ {
+ // Setup
+ string invalidFilePath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Piping.IO,
+ Path.DirectorySeparatorChar.ToString());
+
+ // Call
+ TestDelegate call = () => new PipingConfigurationReader(invalidFilePath);
+
+ // Assert
+ var expectedMessage = $"Fout bij het lezen van bestand '{invalidFilePath}': bestandspad mag niet verwijzen naar een lege bestandsnaam.";
+ TestHelper.AssertThrowsArgumentExceptionAndTestMessage(call, expectedMessage);
+ }
+
+ [Test]
+ public void Constructor_FileDoesNotExist_ThrowCriticalFileReadException()
+ {
+ // Setup
+ string invalidFilePath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Piping.IO,
+ "I_do_not_exist.shp");
+
+ // Call
+ TestDelegate call = () => new PipingConfigurationReader(invalidFilePath);
+
+ // Assert
+ var expectedMessage = $"Fout bij het lezen van bestand '{invalidFilePath}': het bestand bestaat niet.";
+ var message = Assert.Throws(call).Message;
+ Assert.AreEqual(expectedMessage, message);
+ }
+ }
+}
\ No newline at end of file
Index: Ringtoets/Piping/test/Ringtoets.Piping.IO.Test/Ringtoets.Piping.IO.Test.csproj
===================================================================
diff -u -r9a9a99ad27ee6fdcd22f0df408b868816502647e -r9b940da26da12706c2b6665959e6de7f1a3dbc52
--- Ringtoets/Piping/test/Ringtoets.Piping.IO.Test/Ringtoets.Piping.IO.Test.csproj (.../Ringtoets.Piping.IO.Test.csproj) (revision 9a9a99ad27ee6fdcd22f0df408b868816502647e)
+++ Ringtoets/Piping/test/Ringtoets.Piping.IO.Test/Ringtoets.Piping.IO.Test.csproj (.../Ringtoets.Piping.IO.Test.csproj) (revision 9b940da26da12706c2b6665959e6de7f1a3dbc52)
@@ -75,7 +75,7 @@
-
+