Index: Ringtoets/Common/src/Ringtoets.Common.Data/AssessmentSection/IAssessmentSection.cs =================================================================== diff -u -ra3de4991e513b548eabc760f084132e936b42cb9 -r2715f4b30426f7295453b30cd7c1af97f060bcaa --- Ringtoets/Common/src/Ringtoets.Common.Data/AssessmentSection/IAssessmentSection.cs (.../IAssessmentSection.cs) (revision a3de4991e513b548eabc760f084132e936b42cb9) +++ Ringtoets/Common/src/Ringtoets.Common.Data/AssessmentSection/IAssessmentSection.cs (.../IAssessmentSection.cs) (revision 2715f4b30426f7295453b30cd7c1af97f060bcaa) @@ -34,7 +34,7 @@ public interface IAssessmentSection : ICommentable, IObservable, IStorable { /// - /// Gets or sets the name of the assessment section. + /// Gets or sets the identifier of the assessment section. /// string Id { get; } Index: Ringtoets/Common/src/Ringtoets.Common.IO/ReferenceLineMetaImporter.cs =================================================================== diff -u -r1537ed6c8364e79f9b4c869c95e3d9398a55a572 -r2715f4b30426f7295453b30cd7c1af97f060bcaa --- Ringtoets/Common/src/Ringtoets.Common.IO/ReferenceLineMetaImporter.cs (.../ReferenceLineMetaImporter.cs) (revision 1537ed6c8364e79f9b4c869c95e3d9398a55a572) +++ Ringtoets/Common/src/Ringtoets.Common.IO/ReferenceLineMetaImporter.cs (.../ReferenceLineMetaImporter.cs) (revision 2715f4b30426f7295453b30cd7c1af97f060bcaa) @@ -75,7 +75,7 @@ /// public IEnumerable GetReferenceLineMetas() { - var referenceLineMetas = ReadReferenceLineMetas(); + ICollection referenceLineMetas = ReadReferenceLineMetas(); ValidateReferenceLineMetas(referenceLineMetas); @@ -87,8 +87,7 @@ var files = GetShapeFilesInFolder(folderpath); if (files.Length == 0) { - var message = new FileReaderErrorMessageBuilder( - Path.Combine(folderpath, "*.shp")) + var message = new FileReaderErrorMessageBuilder(folderpath) .Build(RingtoetsCommonIOResources.ReferenceLineMetaImporter_ValidateAndConnectTo_No_shape_file_found); throw new CriticalFileReadException(message); } @@ -132,8 +131,9 @@ } } - private IEnumerable ReadReferenceLineMetas() + private ICollection ReadReferenceLineMetas() { + var referenceLinesMetas = new List(); using (var reader = new ReferenceLinesMetaReader(shapeFilePath)) { ReferenceLineMeta referenceLinesMeta; @@ -142,15 +142,16 @@ referenceLinesMeta = reader.ReadReferenceLinesMeta(); if (referenceLinesMeta != null) { - yield return referenceLinesMeta; + referenceLinesMetas.Add(referenceLinesMeta); } } while (referenceLinesMeta != null); } + return referenceLinesMetas; } - private void ValidateReferenceLineMetas(IEnumerable referenceLineMetas) + private void ValidateReferenceLineMetas(ICollection referenceLineMetas) { - var referenceLineMetasCount = referenceLineMetas.Select(rlm => rlm.AssessmentSectionId).Count(); + var referenceLineMetasCount = referenceLineMetas.Count; var referenceLineMetasDistinctCount = referenceLineMetas.Select(rlm => rlm.AssessmentSectionId).Distinct().Count(); if (referenceLineMetasCount != referenceLineMetasDistinctCount) Index: Ringtoets/Common/src/Ringtoets.Common.IO/ReferenceLinesMetaReader.cs =================================================================== diff -u -r1de82b61e03283a14d380a48cd718ec65a98432d -r2715f4b30426f7295453b30cd7c1af97f060bcaa --- Ringtoets/Common/src/Ringtoets.Common.IO/ReferenceLinesMetaReader.cs (.../ReferenceLinesMetaReader.cs) (revision 1de82b61e03283a14d380a48cd718ec65a98432d) +++ Ringtoets/Common/src/Ringtoets.Common.IO/ReferenceLinesMetaReader.cs (.../ReferenceLinesMetaReader.cs) (revision 2715f4b30426f7295453b30cd7c1af97f060bcaa) @@ -50,6 +50,7 @@ /// Initializes a new instance of the class and validates the file. /// /// The file path to the shape file. + /// When is invalid. /// Thrown when: /// /// points to a file that does not exist. @@ -93,73 +94,47 @@ private void ValidateExistenceOfRequiredAttributes() { - var hasAssessmentSectionIdAttribute = polylineShapeFileReader.HasAttribute(assessmentsectionIdAttributeKey); - var hasSignalingValueAttribute = polylineShapeFileReader.HasAttribute(signalingValueAttributeKey); - var hasLowerLimitValueAttribute = polylineShapeFileReader.HasAttribute(lowerLimitValueAttributeKey); - - if (hasAssessmentSectionIdAttribute && hasSignalingValueAttribute && hasLowerLimitValueAttribute) + IList missingAttributes = GetMissingAttributes(); + if (missingAttributes.Count == 1) { - return; - } - - string message; - if (hasAssessmentSectionIdAttribute && hasSignalingValueAttribute) - { - // No low limit - message = string.Format(RingtoetsCommonIOResources.ReferenceLinesMetaReader_File_lacks_required_Attribute_0_, - lowerLimitValueAttributeKey); + var message = string.Format(RingtoetsCommonIOResources.ReferenceLinesMetaReader_File_lacks_required_Attribute_0_, + missingAttributes[0]); throw new CriticalFileReadException(message); } - - if (hasAssessmentSectionIdAttribute && hasLowerLimitValueAttribute) + if (missingAttributes.Count > 1) { - // No signaling value - message = string.Format(RingtoetsCommonIOResources.ReferenceLinesMetaReader_File_lacks_required_Attribute_0_, - signalingValueAttributeKey); + var message = string.Format(RingtoetsCommonIOResources.ReferenceLinesMetaReader_File_lacks_required_Attributes_0_, + string.Join("', '", missingAttributes)); throw new CriticalFileReadException(message); } + } - if (hasSignalingValueAttribute && hasLowerLimitValueAttribute) + private IList GetMissingAttributes() + { + var list = new List(3); + if (!polylineShapeFileReader.HasAttribute(assessmentsectionIdAttributeKey)) { - // No Assessment Section Id - message = string.Format(RingtoetsCommonIOResources.ReferenceLinesMetaReader_File_lacks_required_Attribute_0_, - assessmentsectionIdAttributeKey); - throw new CriticalFileReadException(message); + list.Add(assessmentsectionIdAttributeKey); } - - // Multiple attributes not found - var missingAttributes = new List(); - if (!hasAssessmentSectionIdAttribute) + if (!polylineShapeFileReader.HasAttribute(signalingValueAttributeKey)) { - missingAttributes.Add(assessmentsectionIdAttributeKey); + list.Add(signalingValueAttributeKey); } - if (!hasSignalingValueAttribute) + if (!polylineShapeFileReader.HasAttribute(lowerLimitValueAttributeKey)) { - missingAttributes.Add(signalingValueAttributeKey); + list.Add(lowerLimitValueAttributeKey); } - if (!hasLowerLimitValueAttribute) - { - missingAttributes.Add(lowerLimitValueAttributeKey); - } - - message = string.Format(RingtoetsCommonIOResources.ReferenceLinesMetaReader_File_lacks_required_Attributes_0_, - string.Join("', '", missingAttributes)); - - throw new CriticalFileReadException(message); + return list; } private static PolylineShapeFileReader OpenPolyLineShapeFile(string shapeFilePath) { return new PolylineShapeFileReader(shapeFilePath); } - /// - /// Reads a new from the file. - /// - /// private MapLineData ReadMapLineData() { - return polylineShapeFileReader.ReadLine() as MapLineData; + return (MapLineData) polylineShapeFileReader.ReadLine(); } private static ReferenceLineMeta CreateReferenceLineMeta(MapLineData lineData) @@ -168,9 +143,9 @@ var feature = features[0]; - var assessmentSectionId = GetAssessmentSectionId(feature); - var signalingValue = GetSignalingValueAttributeKey(feature); - var lowerLimitValue = GetLowerLimitValueAttribute(feature); + string assessmentSectionId = GetAssessmentSectionId(feature); + int? signalingValue = GetSignalingValueAttributeKey(feature); + int? lowerLimitValue = GetLowerLimitValueAttribute(feature); IEnumerable geometryPoints = GetSectionGeometry(feature); var referenceLineMeta = new ReferenceLineMeta Index: Ringtoets/Common/test/Ringtoets.Common.Data.Test/AssessmentSection/ReferenceLineMetaTest.cs =================================================================== diff -u -r1de82b61e03283a14d380a48cd718ec65a98432d -r2715f4b30426f7295453b30cd7c1af97f060bcaa --- Ringtoets/Common/test/Ringtoets.Common.Data.Test/AssessmentSection/ReferenceLineMetaTest.cs (.../ReferenceLineMetaTest.cs) (revision 1de82b61e03283a14d380a48cd718ec65a98432d) +++ Ringtoets/Common/test/Ringtoets.Common.Data.Test/AssessmentSection/ReferenceLineMetaTest.cs (.../ReferenceLineMetaTest.cs) (revision 2715f4b30426f7295453b30cd7c1af97f060bcaa) @@ -37,5 +37,49 @@ Assert.IsInstanceOf(referenceLine.ReferenceLine); CollectionAssert.IsEmpty(referenceLine.ReferenceLine.Points); } + + [Test] + public void SetAssessmentSectionId_ExpectedValue() + { + // Setup + const string assessmentSectionId = "SomeStringValue"; + var referenceLine = new ReferenceLineMeta(); + + // Call + referenceLine.AssessmentSectionId = assessmentSectionId; + + // Assert + Assert.AreEqual(assessmentSectionId, referenceLine.AssessmentSectionId); + } + + [Test] + [TestCase(1234)] + [TestCase(null)] + public void SetSignalingValue_ExpectedValue(int? signalingValue) + { + // Setup + var referenceLine = new ReferenceLineMeta(); + + // Call + referenceLine.SignalingValue = signalingValue; + + // Assert + Assert.AreEqual(signalingValue, referenceLine.SignalingValue); + } + + [Test] + [TestCase(1234)] + [TestCase(null)] + public void SetLowerLimitValue_ExpectedValue(int? lowerLimitValue) + { + // Setup + var referenceLine = new ReferenceLineMeta(); + + // Call + referenceLine.LowerLimitValue = lowerLimitValue; + + // Assert + Assert.AreEqual(lowerLimitValue, referenceLine.LowerLimitValue); + } } } \ No newline at end of file Index: Ringtoets/Common/test/Ringtoets.Common.IO.Test/ReferenceLineMetaImporterTest.cs =================================================================== diff -u -r1537ed6c8364e79f9b4c869c95e3d9398a55a572 -r2715f4b30426f7295453b30cd7c1af97f060bcaa --- Ringtoets/Common/test/Ringtoets.Common.IO.Test/ReferenceLineMetaImporterTest.cs (.../ReferenceLineMetaImporterTest.cs) (revision 1537ed6c8364e79f9b4c869c95e3d9398a55a572) +++ Ringtoets/Common/test/Ringtoets.Common.IO.Test/ReferenceLineMetaImporterTest.cs (.../ReferenceLineMetaImporterTest.cs) (revision 2715f4b30426f7295453b30cd7c1af97f060bcaa) @@ -23,6 +23,7 @@ using System.Collections.Generic; using System.IO; using System.Linq; +using Core.Common.Base.Geometry; using Core.Common.IO.Exceptions; using Core.Common.TestUtil; using NUnit.Extensions.Forms; @@ -115,7 +116,7 @@ TestDelegate call = () => new ReferenceLineMetaImporter(pathToEmptyFolder); // Assert - var expectedExceptionMessage = string.Format("Fout bij het lezen van bestand '{0}\\*.shp': Er is geen shape file gevonden.", + var expectedExceptionMessage = string.Format("Fout bij het lezen van bestand '{0}': Er is geen shape file gevonden.", pathToEmptyFolder); CriticalFileReadException exception = Assert.Throws(call); Assert.AreEqual(expectedExceptionMessage, exception.Message); @@ -208,22 +209,46 @@ var referenceLineMetas = importer.GetReferenceLineMetas().ToArray(); // Assert - Assert.AreEqual(10, referenceLineMetas.Length); - var expectedAssessmentSectionIds = new[] + Assert.AreEqual(3, referenceLineMetas.Length); + + var expectedReferenceLineMeta1 = new ReferenceLineMeta { - "1-1", - "2-2", - "3-3", - "4-4", - "5-5", - "6-6", - "7-7", - "8-8", - "9-9", - "10-10", + AssessmentSectionId = "1-1", + LowerLimitValue = 1000, + SignalingValue = 3000 }; - var assessmentSectionIds = referenceLineMetas.Select(rlm => rlm.AssessmentSectionId); - Assert.AreEqual(expectedAssessmentSectionIds, assessmentSectionIds); + expectedReferenceLineMeta1.ReferenceLine.SetGeometry(new[] + { + new Point2D(160679.9250, 475072.583), + new Point2D(160892.0751, 474315.4917) + }); + AssertReferenceLineMetas(expectedReferenceLineMeta1, referenceLineMetas[0]); + + var expectedReferenceLineMeta2 = new ReferenceLineMeta + { + AssessmentSectionId = "2-2", + LowerLimitValue = 100, + SignalingValue = 300 + }; + expectedReferenceLineMeta2.ReferenceLine.SetGeometry(new[] + { + new Point2D(155556.9191, 464341.1281), + new Point2D(155521.4761, 464360.7401) + }); + AssertReferenceLineMetas(expectedReferenceLineMeta2, referenceLineMetas[1]); + + var expectedReferenceLineMeta3 = new ReferenceLineMeta + { + AssessmentSectionId = "3-3", + LowerLimitValue = 100, + SignalingValue = 300 + }; + expectedReferenceLineMeta3.ReferenceLine.SetGeometry(new[] + { + new Point2D(147367.321899, 476902.915710), + new Point2D(147410.0515, 476938.9447) + }); + AssertReferenceLineMetas(expectedReferenceLineMeta3, referenceLineMetas[2]); } [Test] @@ -234,10 +259,28 @@ var importer = new ReferenceLineMetaImporter(pathValidFolder); // Call - IEnumerable referenceIds = importer.GetReferenceLineMetas(); + IEnumerable referenceLineMetas = importer.GetReferenceLineMetas(); // Assert - Assert.AreEqual(0, referenceIds.Count()); + Assert.AreEqual(0, referenceLineMetas.Count()); } + + private static void AssertReferenceLineMetas(ReferenceLineMeta expectedReferenceLineMeta, ReferenceLineMeta actualReferenceLineMeta) + { + Assert.AreEqual(expectedReferenceLineMeta.AssessmentSectionId, actualReferenceLineMeta.AssessmentSectionId); + Assert.AreEqual(expectedReferenceLineMeta.SignalingValue, actualReferenceLineMeta.SignalingValue); + Assert.AreEqual(expectedReferenceLineMeta.LowerLimitValue, actualReferenceLineMeta.LowerLimitValue); + + var expectedPoints = expectedReferenceLineMeta.ReferenceLine.Points.ToArray(); + var actualPoints = actualReferenceLineMeta.ReferenceLine.Points.ToArray(); + var errorMessage = String.Format("Unexpected geometry found in ReferenceLineMeta with id '{0}'", actualReferenceLineMeta.AssessmentSectionId); + Assert.AreEqual(expectedPoints.Length, actualPoints.Length, errorMessage); + + for (var i = 0; i < expectedPoints.Length; i++) + { + Assert.AreEqual(expectedPoints[i].X, actualPoints[i].X, 1e-6, errorMessage); + Assert.AreEqual(expectedPoints[i].Y, actualPoints[i].Y, 1e-6, errorMessage); + } + } } } \ No newline at end of file Index: Ringtoets/Common/test/Ringtoets.Common.IO.Test/test-data/ReferenceLineMetaImporter/ValidShapeFile/validShapeFile.dbf =================================================================== diff -u -r8e91f29f35b5f93ea1d9dfc7dcd79edfdd1b4e53 -r2715f4b30426f7295453b30cd7c1af97f060bcaa Binary files differ Index: Ringtoets/Common/test/Ringtoets.Common.IO.Test/test-data/ReferenceLineMetaImporter/ValidShapeFile/validShapeFile.shp =================================================================== diff -u -r8e91f29f35b5f93ea1d9dfc7dcd79edfdd1b4e53 -r2715f4b30426f7295453b30cd7c1af97f060bcaa Binary files differ Index: Ringtoets/Common/test/Ringtoets.Common.IO.Test/test-data/ReferenceLineMetaImporter/ValidShapeFile/validShapeFile.shx =================================================================== diff -u -r8e91f29f35b5f93ea1d9dfc7dcd79edfdd1b4e53 -r2715f4b30426f7295453b30cd7c1af97f060bcaa Binary files differ Index: Ringtoets/Piping/test/Ringtoets.Piping.Data.Test/RingtoetsPipingSurfaceLineTest.cs =================================================================== diff -u -rfd3f53993a2113c76da7d305a0e80621605bfe3f -r2715f4b30426f7295453b30cd7c1af97f060bcaa --- Ringtoets/Piping/test/Ringtoets.Piping.Data.Test/RingtoetsPipingSurfaceLineTest.cs (.../RingtoetsPipingSurfaceLineTest.cs) (revision fd3f53993a2113c76da7d305a0e80621605bfe3f) +++ Ringtoets/Piping/test/Ringtoets.Piping.Data.Test/RingtoetsPipingSurfaceLineTest.cs (.../RingtoetsPipingSurfaceLineTest.cs) (revision 2715f4b30426f7295453b30cd7c1af97f060bcaa) @@ -30,7 +30,6 @@ using Ringtoets.Piping.Data.Properties; using Ringtoets.Piping.Primitives; using Ringtoets.Piping.Primitives.Exceptions; - using PipingPrimitivesResources = Ringtoets.Piping.Primitives.Properties.Resources; namespace Ringtoets.Piping.Data.Test