Index: Core/Common/test/Core.Common.TestUtil.Test/TestHelperTest.cs =================================================================== diff -u -rd7a1d3405cbf2ebe2edceb66705e4c7757f2505f -r9ad4c9daea5f2a20f2cc61df9ea79d1144d84b2e --- Core/Common/test/Core.Common.TestUtil.Test/TestHelperTest.cs (.../TestHelperTest.cs) (revision d7a1d3405cbf2ebe2edceb66705e4c7757f2505f) +++ Core/Common/test/Core.Common.TestUtil.Test/TestHelperTest.cs (.../TestHelperTest.cs) (revision 9ad4c9daea5f2a20f2cc61df9ea79d1144d84b2e) @@ -253,6 +253,9 @@ path = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Revetment.IO); Assert.IsTrue(Directory.Exists(path)); + + path = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.AssemblyTool.IO); + Assert.IsTrue(Directory.Exists(path)); } [Test] Index: Core/Common/test/Core.Common.TestUtil/TestDataPath.cs =================================================================== diff -u -r7fef5ada51843b4bfd4cfe03d511fb86051c78a7 -r9ad4c9daea5f2a20f2cc61df9ea79d1144d84b2e --- Core/Common/test/Core.Common.TestUtil/TestDataPath.cs (.../TestDataPath.cs) (revision 7fef5ada51843b4bfd4cfe03d511fb86051c78a7) +++ Core/Common/test/Core.Common.TestUtil/TestDataPath.cs (.../TestDataPath.cs) (revision 9ad4c9daea5f2a20f2cc61df9ea79d1144d84b2e) @@ -55,6 +55,11 @@ public static class Ringtoets { + public static class AssemblyTool + { + public static readonly TestDataPath IO = System.IO.Path.Combine("Ringtoets", "AssemblyTool", "test", "Ringtoets.AssemblyTool.IO.Test"); + } + public static class ClosingStructures { public static readonly TestDataPath IO = System.IO.Path.Combine("Ringtoets", "ClosingStructures", "test", "Ringtoets.ClosingStructures.IO.Test"); Index: Ringtoets/AssemblyTool/src/Ringtoets.AssemblyTool.IO/Model/AssemblyXmlIdentifiers.cs =================================================================== diff -u -r5e2248b589fcb4b39e7ff664cd11a200b08daa28 -r9ad4c9daea5f2a20f2cc61df9ea79d1144d84b2e --- Ringtoets/AssemblyTool/src/Ringtoets.AssemblyTool.IO/Model/AssemblyXmlIdentifiers.cs (.../AssemblyXmlIdentifiers.cs) (revision 5e2248b589fcb4b39e7ff664cd11a200b08daa28) +++ Ringtoets/AssemblyTool/src/Ringtoets.AssemblyTool.IO/Model/AssemblyXmlIdentifiers.cs (.../AssemblyXmlIdentifiers.cs) (revision 9ad4c9daea5f2a20f2cc61df9ea79d1144d84b2e) @@ -58,6 +58,11 @@ public const string AssemblyNamespace = "http://localhost/standaarden/assemblage"; /// + /// The XML namespace identifier for assembly objects. + /// + public const string AssemblyNamespaceIdentifier = "asm"; + + /// /// Identifier for an assessment level element. /// public const string AssessmentLevel = "toets"; @@ -258,6 +263,11 @@ public const string GmlNamespace = "http://www.opengis.net/gml/3.2"; /// + /// The XML namespace identifier for GML objects. + /// + public const string GmlNamespaceIdentifier = "gml"; + + /// /// Identifier for an ID attribute. /// public const string Id = "id"; Index: Ringtoets/AssemblyTool/src/Ringtoets.AssemblyTool.IO/Ringtoets.AssemblyTool.IO.csproj =================================================================== diff -u -r5e2248b589fcb4b39e7ff664cd11a200b08daa28 -r9ad4c9daea5f2a20f2cc61df9ea79d1144d84b2e --- Ringtoets/AssemblyTool/src/Ringtoets.AssemblyTool.IO/Ringtoets.AssemblyTool.IO.csproj (.../Ringtoets.AssemblyTool.IO.csproj) (revision 5e2248b589fcb4b39e7ff664cd11a200b08daa28) +++ Ringtoets/AssemblyTool/src/Ringtoets.AssemblyTool.IO/Ringtoets.AssemblyTool.IO.csproj (.../Ringtoets.AssemblyTool.IO.csproj) (revision 9ad4c9daea5f2a20f2cc61df9ea79d1144d84b2e) @@ -52,13 +52,22 @@ True Resources.resx + {3BBFD65B-B277-4E50-AE6D-BD24C3434609} Core.Common.Base False + + {E344867E-9AC9-44C8-88A5-8185681679A9} + Core.Common.IO + + + {f49bd8b2-332a-4c91-a196-8cce0a2c7d98} + Core.Common.Util + Index: Ringtoets/AssemblyTool/src/Ringtoets.AssemblyTool.IO/SerializableAssemblyWriter.cs =================================================================== diff -u --- Ringtoets/AssemblyTool/src/Ringtoets.AssemblyTool.IO/SerializableAssemblyWriter.cs (revision 0) +++ Ringtoets/AssemblyTool/src/Ringtoets.AssemblyTool.IO/SerializableAssemblyWriter.cs (revision 9ad4c9daea5f2a20f2cc61df9ea79d1144d84b2e) @@ -0,0 +1,75 @@ +// Copyright (C) Stichting Deltares 2017. 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 System.Xml.Serialization; +using Core.Common.IO.Exceptions; +using Ringtoets.AssemblyTool.IO.Model; +using CoreCommonUtilResources = Core.Common.Util.Properties.Resources; + +namespace Ringtoets.AssemblyTool.IO +{ + /// + /// Writer for saving instances of to a file. + /// + public static class SerializableAssemblyWriter + { + /// + /// Writes a to a file. + /// + /// The to be written to the file. + /// The path to the file. + /// Thrown when any parameter is null. + /// Thrown when unable to write to . + public static void WriteAssembly(SerializableAssembly serializableAssembly, string filePath) + { + if (serializableAssembly == null) + { + throw new ArgumentNullException(nameof(serializableAssembly)); + } + + if (filePath == null) + { + throw new ArgumentNullException(nameof(filePath)); + } + + TextWriter writer = null; + try + { + var serializer = new XmlSerializer(typeof(SerializableAssembly)); + writer = new StreamWriter(filePath); + var xmlns = new XmlSerializerNamespaces(); + xmlns.Add(AssemblyXmlIdentifiers.GmlNamespaceIdentifier, AssemblyXmlIdentifiers.GmlNamespace); + xmlns.Add(AssemblyXmlIdentifiers.AssemblyNamespaceIdentifier, AssemblyXmlIdentifiers.AssemblyNamespace); + serializer.Serialize(writer, serializableAssembly, xmlns); + } + catch (SystemException e) + { + throw new CriticalFileWriteException(string.Format(CoreCommonUtilResources.Error_General_output_error_0, filePath), e); + } + finally + { + writer?.Close(); + } + } + } +} \ No newline at end of file Index: Ringtoets/AssemblyTool/test/Ringtoets.AssemblyTool.IO.Test/Model/SerializableAssemblyTest.cs =================================================================== diff -u -r21c37e6d9a366a9a9be9e5f40aa514b9fe8d6e4a -r9ad4c9daea5f2a20f2cc61df9ea79d1144d84b2e --- Ringtoets/AssemblyTool/test/Ringtoets.AssemblyTool.IO.Test/Model/SerializableAssemblyTest.cs (.../SerializableAssemblyTest.cs) (revision 21c37e6d9a366a9a9be9e5f40aa514b9fe8d6e4a) +++ Ringtoets/AssemblyTool/test/Ringtoets.AssemblyTool.IO.Test/Model/SerializableAssemblyTest.cs (.../SerializableAssemblyTest.cs) (revision 9ad4c9daea5f2a20f2cc61df9ea79d1144d84b2e) @@ -30,6 +30,7 @@ using System.Xml.Schema; using System.Xml.Serialization; using Core.Common.Base.Geometry; +using Core.Common.TestUtil; using Core.Common.Util.Reflection; using NUnit.Framework; using Ringtoets.AssemblyTool.IO.Model; @@ -176,14 +177,9 @@ } [Test] - public void GivenAssembly_WhenExported_ReturnsSerializedObject() + [Explicit("XSD validation requires internet connection and takes about 30 seconds to complete.")] + public void GivenAssembly_WhenExported_ReturnsValidSerializedObject() { - var serializer = new XmlSerializer(typeof(SerializableAssembly)); - var xmlns = new XmlSerializerNamespaces(); - xmlns.Add("gml", AssemblyXmlIdentifiers.GmlNamespace); - xmlns.Add("asm", AssemblyXmlIdentifiers.AssemblyNamespace); - - var writer = new StringWriterUtf8(); var assessmentSection = new SerializableAssessmentSection { Id = "section1", @@ -275,30 +271,30 @@ section2 }); + var serializer = new XmlSerializer(typeof(SerializableAssembly)); + var xmlns = new XmlSerializerNamespaces(); + xmlns.Add("gml", AssemblyXmlIdentifiers.GmlNamespace); + xmlns.Add("asm", AssemblyXmlIdentifiers.AssemblyNamespace); + + var writer = new StringWriter(); serializer.Serialize(writer, assembly, xmlns); string xml = writer.ToString(); Console.WriteLine(xml); var schema = new XmlSchemaSet(); - Assembly ass = Assembly.GetExecutingAssembly(); - string path = Path.GetDirectoryName(ass.Location); - schema.Add("http://localhost/standaarden/assemblage", Path.Combine(path, "assemblage.xsd")); + schema.Add("http://localhost/standaarden/assemblage", Path.Combine(TestHelper.GetTestDataPath(TestDataPath.Ringtoets.AssemblyTool.IO), "assemblage.xsd")); XDocument doc = XDocument.Parse(xml); - var msg = ""; + string msg = string.Empty; doc.Validate(schema, (o, e) => { msg += e.Message + Environment.NewLine; }); - Console.WriteLine(msg == "" ? "Document is valid" : "Document invalid: " + msg); - } - - public class StringWriterUtf8 : StringWriter - { - public override Encoding Encoding + if (msg == string.Empty) { - get - { - return Encoding.UTF8; - } + Assert.Pass("Serialized document is valid" + Environment.NewLine); } + else + { + Assert.Fail("Serialized document is invalid:" + Environment.NewLine + msg); + } } private class TestFeatureMember : SerializableFeatureMember {} Index: Ringtoets/AssemblyTool/test/Ringtoets.AssemblyTool.IO.Test/Ringtoets.AssemblyTool.IO.Test.csproj =================================================================== diff -u -r21c37e6d9a366a9a9be9e5f40aa514b9fe8d6e4a -r9ad4c9daea5f2a20f2cc61df9ea79d1144d84b2e --- Ringtoets/AssemblyTool/test/Ringtoets.AssemblyTool.IO.Test/Ringtoets.AssemblyTool.IO.Test.csproj (.../Ringtoets.AssemblyTool.IO.Test.csproj) (revision 21c37e6d9a366a9a9be9e5f40aa514b9fe8d6e4a) +++ Ringtoets/AssemblyTool/test/Ringtoets.AssemblyTool.IO.Test/Ringtoets.AssemblyTool.IO.Test.csproj (.../Ringtoets.AssemblyTool.IO.Test.csproj) (revision 9ad4c9daea5f2a20f2cc61df9ea79d1144d84b2e) @@ -44,21 +44,22 @@ + Copying.licenseheader - - Designer - Always - {3BBFD65B-B277-4E50-AE6D-BD24C3434609} Core.Common.Base + + {E344867E-9AC9-44C8-88A5-8185681679A9} + Core.Common.IO + {F49BD8B2-332A-4C91-A196-8CCE0A2C7D98} Core.Common.Util Index: Ringtoets/AssemblyTool/test/Ringtoets.AssemblyTool.IO.Test/SerializableAssemblyWriterTest.cs =================================================================== diff -u --- Ringtoets/AssemblyTool/test/Ringtoets.AssemblyTool.IO.Test/SerializableAssemblyWriterTest.cs (revision 0) +++ Ringtoets/AssemblyTool/test/Ringtoets.AssemblyTool.IO.Test/SerializableAssemblyWriterTest.cs (revision 9ad4c9daea5f2a20f2cc61df9ea79d1144d84b2e) @@ -0,0 +1,220 @@ +// Copyright (C) Stichting Deltares 2017. 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 System.Security.AccessControl; +using System.Text; +using System.Xml.Serialization; +using Core.Common.Base.Geometry; +using Core.Common.IO.Exceptions; +using Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.AssemblyTool.IO.Model; + +namespace Ringtoets.AssemblyTool.IO.Test +{ + [TestFixture] + public class SerializableAssemblyWriterTest + { + [Test] + public void WriteAssembly_SerializableAssemblyNull_ThrowsArgumentNullException() + { + // Call + TestDelegate test = () => SerializableAssemblyWriter.WriteAssembly(null, string.Empty); + + // Assert + var exception = Assert.Throws(test); + Assert.AreEqual("serializableAssembly", exception.ParamName); + } + + [Test] + public void WriteAssembly_FilePathNull_ThrowsArgumentNullException() + { + // Call + TestDelegate test = () => SerializableAssemblyWriter.WriteAssembly(new SerializableAssembly(), null); + + // Assert + var exception = Assert.Throws(test); + Assert.AreEqual("filePath", exception.ParamName); + } + + [Test] + public void WriteAssembly_InvalidData_ThrowsCriticalFileWriteException() + { + // Setup + string directoryPath = TestHelper.GetScratchPadPath("WriteAssembly_ValidData_ValidFile"); + Directory.CreateDirectory(directoryPath); + string filePath = Path.Combine(directoryPath, "test_assembly.gml"); + + var assembly = new SerializableAssembly( + "id", + new Point2D(0.0, 10.0), + new Point2D(10.0, 20.0), + new SerializableFeatureMember[] + { + new SerializableFailureMechanism() + }); + + try + { + // Call + TestDelegate call = () => SerializableAssemblyWriter.WriteAssembly(assembly, filePath); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual($"Er is een onverwachte fout opgetreden tijdens het schrijven van het bestand '{filePath}'.", exception.Message); + Assert.IsInstanceOf(exception.InnerException); + } + finally + { + Directory.Delete(directoryPath, true); + } + } + + [Test] + [TestCase("")] + [TestCase(" ")] + [TestCase("c:\\>")] + public void WriteAssembly_FilePathInvalid_ThrowsCriticalFileWriteException(string filePath) + { + // Call + TestDelegate call = () => SerializableAssemblyWriter.WriteAssembly(new SerializableAssembly(), filePath); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual($"Er is een onverwachte fout opgetreden tijdens het schrijven van het bestand '{filePath}'.", exception.Message); + Assert.IsInstanceOf(exception.InnerException); + } + + [Test] + public void WriteAssembly_FilePathTooLong_ThrowsCriticalFileWriteException() + { + // Setup + var filePath = new string('a', 249); + + // Call + TestDelegate call = () => SerializableAssemblyWriter.WriteAssembly(new SerializableAssembly(), filePath); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual($"Er is een onverwachte fout opgetreden tijdens het schrijven van het bestand '{filePath}'.", exception.Message); + Assert.IsInstanceOf(exception.InnerException); + } + + [Test] + public void WriteAssembly_InvalidDirectoryRights_ThrowsCriticalFileWriteException() + { + // Setup + string directoryPath = TestHelper.GetScratchPadPath(nameof(WriteAssembly_InvalidDirectoryRights_ThrowsCriticalFileWriteException)); + using (var disposeHelper = new DirectoryDisposeHelper(TestHelper.GetScratchPadPath(), nameof(WriteAssembly_InvalidDirectoryRights_ThrowsCriticalFileWriteException))) + { + string filePath = Path.Combine(directoryPath, "test.bnd"); + disposeHelper.LockDirectory(FileSystemRights.Write); + + // Call + TestDelegate call = () => SerializableAssemblyWriter.WriteAssembly(new SerializableAssembly(), filePath); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual($"Er is een onverwachte fout opgetreden tijdens het schrijven van het bestand '{filePath}'.", exception.Message); + Assert.IsInstanceOf(exception.InnerException); + } + } + + [Test] + public void WriteAssembly_FileInUse_ThrowsCriticalFileWriteException() + { + // Setup + string filePath = TestHelper.GetScratchPadPath(nameof(WriteAssembly_FileInUse_ThrowsCriticalFileWriteException)); + + using (var fileDisposeHelper = new FileDisposeHelper(filePath)) + { + fileDisposeHelper.LockFiles(); + + // Call + TestDelegate call = () => SerializableAssemblyWriter.WriteAssembly(new SerializableAssembly(), filePath); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual($"Er is een onverwachte fout opgetreden tijdens het schrijven van het bestand '{filePath}'.", exception.Message); + Assert.IsInstanceOf(exception.InnerException); + } + } + + [Test] + public void WriteAssembly_ValidData_ValidFile() + { + // Setup + string directoryPath = TestHelper.GetScratchPadPath("WriteAssembly_ValidData_ValidFile"); + Directory.CreateDirectory(directoryPath); + string filePath = Path.Combine(directoryPath, "test_assembly.gml"); + + var assembly = new SerializableAssembly( + "id", + new Point2D(0.0, 10.0), + new Point2D(10.0, 20.0), + new SerializableFeatureMember[] + { + new SerializableAssessmentSection(), + new SerializableAssessmentProcess() + }); + + try + { + // Call + SerializableAssemblyWriter.WriteAssembly(assembly, filePath); + + // Assert + Assert.IsTrue(File.Exists(filePath)); + string fileContent = File.ReadAllText(filePath); + Assert.AreEqual(GetSerializedAssembly(assembly), fileContent); + } + finally + { + Directory.Delete(directoryPath, true); + } + } + + private static string GetSerializedAssembly(SerializableAssembly assembly) + { + var serializer = new XmlSerializer(typeof(SerializableAssembly)); + var xmlns = new XmlSerializerNamespaces(); + xmlns.Add("gml", "http://www.opengis.net/gml/3.2"); + xmlns.Add("asm", "http://localhost/standaarden/assemblage"); + + var writer = new StringWriterUtf8(); + serializer.Serialize(writer, assembly, xmlns); + return writer.ToString(); + } + + private class StringWriterUtf8 : StringWriter + { + public override Encoding Encoding + { + get + { + return Encoding.UTF8; + } + } + } + } +} \ No newline at end of file Fisheye: Tag 9ad4c9daea5f2a20f2cc61df9ea79d1144d84b2e refers to a dead (removed) revision in file `Ringtoets/AssemblyTool/test/Ringtoets.AssemblyTool.IO.Test/assemblage.xsd'. Fisheye: No comparison available. Pass `N' to diff? Index: Ringtoets/AssemblyTool/test/Ringtoets.AssemblyTool.IO.Test/test-data/assemblage.xsd =================================================================== diff -u --- Ringtoets/AssemblyTool/test/Ringtoets.AssemblyTool.IO.Test/test-data/assemblage.xsd (revision 0) +++ Ringtoets/AssemblyTool/test/Ringtoets.AssemblyTool.IO.Test/test-data/assemblage.xsd (revision 9ad4c9daea5f2a20f2cc61df9ea79d1144d84b2e) @@ -0,0 +1,422 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Geüniformeerd oordeel over het dijktraject rekening houdend met alle + toetssporen. + + + + + + + + + + + + Resultaat van de veiligheidstoetsing. - voldoet aan de norm - + voldoet niet aan de norm - nader onderzoek nodig + + + + + + + + + + + + + + + + + + + + + + + + + + De wijze waarop een mechanisme of een onderdeel van de waterkering wordt + beoordeeld. + + + + + + + + + Naam/code van het toetsspoor, zoals STPH (piping) + etc. + + + + + + + Groep van toetssporen gebaseerd op een onderverdeling op grond + van de beschikbare berekeningswijze en of betrekking hebben op directe of + indirecte mechanismen (FO Assemblagetool) + + + + + + + Aanduiding van het type faalmechanimse: + direct/indirect. + + + + + + + Aanduiding van het type oordeel: tussentijds / + volledig + + + + + + + + + + + + Geheel van activiteiten gericht op het (periodiek) beoordelen of de + momentane toestand van een object voldoet aan de vigerende functionele en/of + wettelijke eisen. + + + + + + + + Jaartal begin van de beoordelingsronde. Toelichting: een + waterkeringstelsel wordt in meerdere beoordelingsrondes beoordeeld (in de + tijd). Bijvoorbeeld de beoordelingsronde die loopt van 2017 tot en met + 2023. + + + + + + + Jaartal einde van de beoordelingsronde. Toelichting: een + waterkeringstelsel wordt in meerdere beoordelingsrondes beoordeeld (in de + tijd). Bijvoorbeeld de beoordelingsronde die loopt van 2017 tot en met + 2023. + + + + + + + + + + + + + Geen definitie in Aquo-lex Domein: goed, voldoende, onvoldoende, geen + oordeel + + + + + + + + + + + + + + + + + + + + + + + + Gecombineerd oordeel van de toetsoordelen van de verschillende + toetssporen op (deel)vakniveau. + + + + + + + + + + + + + + + + + + + + + + + + Deel van een waterkeringstelsel met min of meer gelijke eigenschappen (Aquo, + 'Toetsvak'). Voorbeelden: toetssectie, inspectievak, onderhoudsvak. + + + + + + + + + + + Afstand (in meters) van het begin van de sectie t.o.v. + het nulpunt van het referentiestelsel van de + waterkeringstelsel. + + + + + + + Afstand (in meters) van het einde van de sectie t.o.v. + het nulpunt van het referentiestelsel van de + waterkeringstelsel. + + + + + + Geometrische representatie van het object als lijn. + + + + + + + WaterkeringsectieType: Nadere aanduiding van het type + waterkeringsectie. + + + + + + + + + + + + + + + + + + + + + + Een logisch samenhangend stelsel van waterkeringen. + + + + + + + + + Naam van het waterkeringstelsel. + + + + + + Geometrische representatie van het object als lijn of + vlak. + + + + + + + + WaterkeringstelselType: Nadere aanduiding van het type + waterkeringstelsel. + + + + + + + +