Index: Core/Components/src/Core.Components.Gis.IO/Readers/PolylineShapeFileReader.cs
===================================================================
diff -u -raf83c5308c30a462589f45eecd5ba0dfac0cda00 -r8e91f29f35b5f93ea1d9dfc7dcd79edfdd1b4e53
--- Core/Components/src/Core.Components.Gis.IO/Readers/PolylineShapeFileReader.cs (.../PolylineShapeFileReader.cs) (revision af83c5308c30a462589f45eecd5ba0dfac0cda00)
+++ Core/Components/src/Core.Components.Gis.IO/Readers/PolylineShapeFileReader.cs (.../PolylineShapeFileReader.cs) (revision 8e91f29f35b5f93ea1d9dfc7dcd79edfdd1b4e53)
@@ -30,7 +30,6 @@
using Core.Components.Gis.Geometries;
using DotSpatial.Data;
using DotSpatial.Topology;
-
using CoreCommonUtilsResources = Core.Common.Utils.Properties.Resources;
using GisIOResources = Core.Components.Gis.IO.Properties.Resources;
@@ -102,6 +101,16 @@
return ConvertMultiLineFeatureToMapLineData(featureList, !string.IsNullOrWhiteSpace(name) ? name : GisIOResources.PolylineShapeFileReader_ReadLine_Line);
}
+ ///
+ /// Gets the single line feature at the given index.
+ ///
+ /// The index of which feature to retrieve.
+ /// The feature that consists out of 1 whole polyline.
+ public override IFeature GetFeature(int index)
+ {
+ return ShapeFile.Features[index];
+ }
+
private IFeature ReadFeatureLine()
{
try
@@ -114,22 +123,15 @@
}
}
- ///
- /// Gets the single line feature at the given index.
- ///
- /// The index of which feature to retrieve.
- /// The feature that consists out of 1 whole polyline.
- public override IFeature GetFeature(int index)
- {
- return ShapeFile.Features[index];
- }
-
private MapLineData ConvertSingleLineFeatureToMapLineData(IFeature lineFeature, string name)
{
MapFeature feature = CreateMapFeatureForLineFeature(lineFeature);
CopyMetaDataIntoFeature(feature, readIndex);
- IEnumerable mapFeatures = new[] { feature };
+ IEnumerable mapFeatures = new[]
+ {
+ feature
+ };
return new MapLineData(mapFeatures, name);
}
Index: Core/Components/test/Core.Components.Gis.IO.Test/Readers/PolylineShapeFileReaderTest.cs
===================================================================
diff -u -r151bab16a7ebc1bffc0621ab56c6dc219db1e90f -r8e91f29f35b5f93ea1d9dfc7dcd79edfdd1b4e53
--- Core/Components/test/Core.Components.Gis.IO.Test/Readers/PolylineShapeFileReaderTest.cs (.../PolylineShapeFileReaderTest.cs) (revision 151bab16a7ebc1bffc0621ab56c6dc219db1e90f)
+++ Core/Components/test/Core.Components.Gis.IO.Test/Readers/PolylineShapeFileReaderTest.cs (.../PolylineShapeFileReaderTest.cs) (revision 8e91f29f35b5f93ea1d9dfc7dcd79edfdd1b4e53)
@@ -21,7 +21,6 @@
using System.Collections.Generic;
using System.Linq;
-
using Core.Common.Base.Geometry;
using Core.Common.IO.Exceptions;
using Core.Common.TestUtil;
@@ -132,7 +131,7 @@
using (var reader = new PolylineShapeFileReader(shapeWithOneLine))
{
// Call
- MapLineData line = (MapLineData)reader.ReadLine(name);
+ MapLineData line = (MapLineData) reader.ReadLine(name);
// Assert
Assert.AreEqual(name, line.Name);
@@ -151,7 +150,7 @@
using (var reader = new PolylineShapeFileReader(shapeWithOneLine))
{
// Call
- MapLineData line = (MapLineData)reader.ReadLine(name);
+ MapLineData line = (MapLineData) reader.ReadLine(name);
// Assert
Assert.AreEqual("Lijn", line.Name);
@@ -167,11 +166,11 @@
using (var reader = new PolylineShapeFileReader(shapeWithOneLine))
{
// Call
- MapLineData line = (MapLineData)reader.ReadLine();
+ MapLineData line = (MapLineData) reader.ReadLine();
// Assert
Assert.IsNotNull(line);
-
+
MapFeature[] features = line.Features.ToArray();
Assert.AreEqual(1, features.Length);
@@ -208,10 +207,10 @@
Assert.AreEqual(4, reader.GetNumberOfLines());
// Call
- MapLineData line1 = (MapLineData)reader.ReadLine();
- MapLineData line2 = (MapLineData)reader.ReadLine();
- MapLineData line3 = (MapLineData)reader.ReadLine();
- MapLineData line4 = (MapLineData)reader.ReadLine();
+ MapLineData line1 = (MapLineData) reader.ReadLine();
+ MapLineData line2 = (MapLineData) reader.ReadLine();
+ MapLineData line3 = (MapLineData) reader.ReadLine();
+ MapLineData line4 = (MapLineData) reader.ReadLine();
// Assert
@@ -312,7 +311,7 @@
using (var reader = new PolylineShapeFileReader(shapeWithOneLine))
{
// Call
- MapLineData line = (MapLineData)reader.ReadShapeFile(name);
+ MapLineData line = (MapLineData) reader.ReadShapeFile(name);
// Assert
Assert.AreEqual(name, line.Name);
@@ -331,7 +330,7 @@
using (var reader = new PolylineShapeFileReader(shapeWithOneLine))
{
// Call
- MapLineData line = (MapLineData)reader.ReadShapeFile(name);
+ MapLineData line = (MapLineData) reader.ReadShapeFile(name);
// Assert
Assert.AreEqual("Lijn", line.Name);
@@ -347,7 +346,7 @@
using (var reader = new PolylineShapeFileReader(shapeWithOneLine))
{
// Call
- MapLineData line = (MapLineData)reader.ReadShapeFile();
+ MapLineData line = (MapLineData) reader.ReadShapeFile();
// Assert
Assert.IsNotNull(line);
@@ -388,7 +387,7 @@
Assert.AreEqual(4, reader.GetNumberOfLines());
// Call
- MapLineData lines = (MapLineData)reader.ReadShapeFile();
+ MapLineData lines = (MapLineData) reader.ReadShapeFile();
// Assert
MapFeature[] features = lines.Features.ToArray();
@@ -497,7 +496,7 @@
{
// Setup
string shapefileFilePath = TestHelper.GetTestDataPath(TestDataPath.Core.Components.Gis.IO,
- "Multiple_PolyLine_with_ID.shp");
+ "Multiple_PolyLine_with_ID.shp");
using (var reader = new PolylineShapeFileReader(shapefileFilePath))
{
// Call
@@ -518,7 +517,7 @@
{
// Setup
string shapefileFilePath = TestHelper.GetTestDataPath(TestDataPath.Core.Components.Gis.IO,
- "Multiple_PolyLine_with_ID.shp");
+ "Multiple_PolyLine_with_ID.shp");
using (var reader = new PolylineShapeFileReader(shapefileFilePath))
{
// Call
Index: Ringtoets/Common/src/Ringtoets.Common.Data/AssessmentSection/ReferenceLineMeta.cs
===================================================================
diff -u -r8ab20e71c86b0a20f269eb7122efee529011136b -r8e91f29f35b5f93ea1d9dfc7dcd79edfdd1b4e53
--- Ringtoets/Common/src/Ringtoets.Common.Data/AssessmentSection/ReferenceLineMeta.cs (.../ReferenceLineMeta.cs) (revision 8ab20e71c86b0a20f269eb7122efee529011136b)
+++ Ringtoets/Common/src/Ringtoets.Common.Data/AssessmentSection/ReferenceLineMeta.cs (.../ReferenceLineMeta.cs) (revision 8e91f29f35b5f93ea1d9dfc7dcd79edfdd1b4e53)
@@ -29,7 +29,7 @@
///
/// Gets or sets the unique identifier within a registration.
///
- public string ReferenceLineId { get; set; }
+ public string AssessmentSectionId { get; set; }
///
/// Gets or sets the signaling value for the assessment section.
Index: Ringtoets/Common/src/Ringtoets.Common.IO/ReferenceLineMetaImporter.cs
===================================================================
diff -u
--- Ringtoets/Common/src/Ringtoets.Common.IO/ReferenceLineMetaImporter.cs (revision 0)
+++ Ringtoets/Common/src/Ringtoets.Common.IO/ReferenceLineMetaImporter.cs (revision 8e91f29f35b5f93ea1d9dfc7dcd79edfdd1b4e53)
@@ -0,0 +1,164 @@
+// 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.Security;
+using Core.Common.IO.Exceptions;
+using Core.Common.Utils.Builders;
+using Core.Common.Utils.Properties;
+using log4net;
+using Ringtoets.Common.Data.AssessmentSection;
+using Ringtoets.Common.Forms.PresentationObjects;
+
+namespace Ringtoets.Common.IO
+{
+ ///
+ /// Imports a and stores in on a ,
+ /// taking data from a shapefile containing a polylines.
+ ///
+ public class ReferenceLineMetaImporter
+ {
+ private static readonly ILog log = LogManager.GetLogger(typeof(ReferenceLineMetaImporter));
+ private readonly List referenceLineMetas = new List();
+ private string shapeFilePath;
+
+ ///
+ /// Initializes a new instance of the class and reads the file.
+ /// Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonDocuments), "WTI", "NBPW");
+ ///
+ /// The path to the folder where a shape file should be read.
+ public ReferenceLineMetaImporter(string folderpath)
+ {
+ ValidateAndConnectTo(folderpath);
+
+ ReadReferenceLineMetas();
+ }
+
+ ///
+ /// This method imports the data to an item from a file at the given location.
+ ///
+ /// The item to perform the import on.
+ ///
+ ///
+ public bool Import(ReferenceLineContext targetItem, string assessmentSectionId)
+ {
+ var selectedReferenceLineMeta = referenceLineMetas.FirstOrDefault(rlm => rlm.AssessmentSectionId == assessmentSectionId);
+ if (selectedReferenceLineMeta == null)
+ {
+ var message = new FileReaderErrorMessageBuilder(shapeFilePath)
+ .Build(string.Format("De geselecteerde referentielijn '{0}' is niet gevonden.", assessmentSectionId));
+ log.Error(message);
+ return false;
+ }
+
+ targetItem.WrappedData.ReferenceLine = selectedReferenceLineMeta;
+
+ return true;
+ }
+
+ ///
+ /// Gets all the assessment section ids from the shape file.
+ ///
+ /// A list of all assessment section ids read.
+ public IEnumerable GetAssessmentSectionIds()
+ {
+ return referenceLineMetas.Select(rlm => rlm.AssessmentSectionId);
+ }
+
+ private void ValidateAndConnectTo(string folderpath)
+ {
+ ValidateDirectory(folderpath);
+
+ var files = Directory.GetFiles(folderpath, "*.shp");
+ if (files.Length == 0)
+ {
+ var message = new FileReaderErrorMessageBuilder(
+ Path.Combine(folderpath, "*.shp"))
+ .Build(@"Er is geen shape file gevonden.");
+ throw new CriticalFileReadException(message);
+ }
+
+ shapeFilePath = files.First();
+ if (files.Length > 1)
+ {
+ log.Warn(string.Format(@"Er zijn meerdere shape files gevonden in '{0}'. '{1}' is gekozen.",
+ Path.GetDirectoryName(shapeFilePath), Path.GetFileName(shapeFilePath)));
+ }
+ }
+
+ private static void ValidateDirectory(string path)
+ {
+ if (String.IsNullOrWhiteSpace(path))
+ {
+ var message = new FileReaderErrorMessageBuilder(path).Build(Resources.Error_Path_must_be_specified);
+ throw new ArgumentException(message);
+ }
+
+ try
+ {
+ Path.GetFullPath(path);
+ }
+ catch (ArgumentException e)
+ {
+ var message = new FileReaderErrorMessageBuilder(path)
+ .Build(String.Format(Resources.Error_Path_cannot_contain_Characters_0_,
+ String.Join(", ", Path.GetInvalidFileNameChars())));
+ throw new ArgumentException(message, e);
+ }
+ catch (Exception e)
+ {
+ if (e is IOException || e is SecurityException)
+ {
+ HandleException(e);
+ var message = new FileReaderErrorMessageBuilder(path)
+ .Build("Ongeldig pad.");
+ throw new CriticalFileReadException(message, e);
+ }
+ throw;
+ }
+ }
+
+ private static void HandleException(Exception e)
+ {
+ var message = string.Format("{0} Het bestand wordt overgeslagen.", e.Message);
+ log.Error(message);
+ }
+
+ private void ReadReferenceLineMetas()
+ {
+ using (var reader = new ReferenceLinesMetaReader(shapeFilePath))
+ {
+ ReferenceLineMeta referenceLinesMeta;
+ do
+ {
+ referenceLinesMeta = reader.ReadReferenceLinesMeta();
+ if (referenceLinesMeta != null)
+ {
+ referenceLineMetas.Add(referenceLinesMeta);
+ }
+ } while (referenceLinesMeta != null);
+ }
+ }
+ }
+}
\ No newline at end of file
Index: Ringtoets/Common/src/Ringtoets.Common.IO/ReferenceLinesMetaReader.cs
===================================================================
diff -u -r8ab20e71c86b0a20f269eb7122efee529011136b -r8e91f29f35b5f93ea1d9dfc7dcd79edfdd1b4e53
--- Ringtoets/Common/src/Ringtoets.Common.IO/ReferenceLinesMetaReader.cs (.../ReferenceLinesMetaReader.cs) (revision 8ab20e71c86b0a20f269eb7122efee529011136b)
+++ Ringtoets/Common/src/Ringtoets.Common.IO/ReferenceLinesMetaReader.cs (.../ReferenceLinesMetaReader.cs) (revision 8e91f29f35b5f93ea1d9dfc7dcd79edfdd1b4e53)
@@ -41,7 +41,7 @@
///
public class ReferenceLinesMetaReader : IDisposable
{
- private const string referenceLineIdAttributeKey = "TRAJECT_ID";
+ private const string assessmentsectionIdAttributeKey = "TRAJECT_ID";
private const string signalingValueAttributeKey = "NORM_SW";
private const string lowerLimitValueAttributeKey = "NORM_OG";
private readonly PolylineShapeFileReader polylineShapeFileReader;
@@ -71,14 +71,6 @@
}
///
- /// Gets the number of reference lines in the shape file.
- ///
- public int GetReferenceLinesCount()
- {
- return polylineShapeFileReader.GetNumberOfLines();
- }
-
- ///
/// Reads the current feature in the shape file into a .
///
/// The created .
@@ -101,7 +93,7 @@
private void ValidateExistenceOfRequiredAttributes()
{
- var hasAssessmentSectionIdAttribute = polylineShapeFileReader.HasAttribute(referenceLineIdAttributeKey);
+ var hasAssessmentSectionIdAttribute = polylineShapeFileReader.HasAttribute(assessmentsectionIdAttributeKey);
var hasSignalingValueAttribute = polylineShapeFileReader.HasAttribute(signalingValueAttributeKey);
var hasLowerLimitValueAttribute = polylineShapeFileReader.HasAttribute(lowerLimitValueAttributeKey);
@@ -110,7 +102,7 @@
return;
}
- var message = "";
+ string message;
if (hasAssessmentSectionIdAttribute && hasSignalingValueAttribute)
{
// No low limit
@@ -131,15 +123,15 @@
{
// No Assessment Section Id
message = string.Format(RingtoetsCommonIOResources.ReferenceLinesMetaReader_File_lacks_required_Attribute_0_,
- referenceLineIdAttributeKey);
+ assessmentsectionIdAttributeKey);
throw new CriticalFileReadException(message);
}
// Multiple attributes not found
var missingAttributes = new List();
if (!hasAssessmentSectionIdAttribute)
{
- missingAttributes.Add(referenceLineIdAttributeKey);
+ missingAttributes.Add(assessmentsectionIdAttributeKey);
}
if (!hasSignalingValueAttribute)
{
@@ -176,14 +168,14 @@
var feature = features[0];
- var referenceLineId = GetReferenceLineId(feature);
+ var assessmentSectionId = GetAssessmentSectionId(feature);
var signalingValue = GetSignalingValueAttributeKey(feature);
var lowerLimitValue = GetLowerLimitValueAttribute(feature);
IEnumerable geometryPoints = GetSectionGeometry(feature);
var referenceLineMeta = new ReferenceLineMeta
{
- ReferenceLineId = referenceLineId
+ AssessmentSectionId = assessmentSectionId
};
if (lowerLimitValue != null)
{
@@ -209,9 +201,9 @@
return mapGeometries[0].PointCollections.First().Select(p => new Point2D(p.X, p.Y));
}
- private static string GetReferenceLineId(MapFeature lineFeature)
+ private static string GetAssessmentSectionId(MapFeature lineFeature)
{
- var referenceLineId = Convert.ToString(lineFeature.MetaData[referenceLineIdAttributeKey]);
+ var referenceLineId = Convert.ToString(lineFeature.MetaData[assessmentsectionIdAttributeKey]);
if (String.IsNullOrEmpty(referenceLineId))
{
throw new CriticalFileReadException(RingtoetsCommonIOResources.ReferenceLinesMetaReader_TrajectId_is_empty);
Index: Ringtoets/Common/src/Ringtoets.Common.IO/Ringtoets.Common.IO.csproj
===================================================================
diff -u -r5253591e2ead1fb1e5e23dc0506f62c661be023c -r8e91f29f35b5f93ea1d9dfc7dcd79edfdd1b4e53
--- Ringtoets/Common/src/Ringtoets.Common.IO/Ringtoets.Common.IO.csproj (.../Ringtoets.Common.IO.csproj) (revision 5253591e2ead1fb1e5e23dc0506f62c661be023c)
+++ Ringtoets/Common/src/Ringtoets.Common.IO/Ringtoets.Common.IO.csproj (.../Ringtoets.Common.IO.csproj) (revision 8e91f29f35b5f93ea1d9dfc7dcd79edfdd1b4e53)
@@ -49,6 +49,7 @@
+
Index: Ringtoets/Common/test/Ringtoets.Common.IO.Test/ReferenceLineMetaImporterTest.cs
===================================================================
diff -u
--- Ringtoets/Common/test/Ringtoets.Common.IO.Test/ReferenceLineMetaImporterTest.cs (revision 0)
+++ Ringtoets/Common/test/Ringtoets.Common.IO.Test/ReferenceLineMetaImporterTest.cs (revision 8e91f29f35b5f93ea1d9dfc7dcd79edfdd1b4e53)
@@ -0,0 +1,200 @@
+// 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 Core.Common.IO.Exceptions;
+using Core.Common.TestUtil;
+using NUnit.Framework;
+using Rhino.Mocks;
+using Ringtoets.Common.Data.AssessmentSection;
+using Ringtoets.Common.Forms.PresentationObjects;
+
+namespace Ringtoets.Common.IO.Test
+{
+ [TestFixture]
+ public class ReferenceLineMetaImporterTest
+ {
+ private readonly string testDataPath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Common.IO, "ReferenceLineMetaImporter");
+
+ [Test]
+ [TestCase("")]
+ [TestCase(" ")]
+ [TestCase(null)]
+ public void Constructor_NoFilePath_ThrowArgumentException(string invalidFilePath)
+ {
+ // Call
+ TestDelegate call = () => new ReferenceLineMetaImporter(invalidFilePath);
+
+ // Assert
+ var expectedMessage = string.Format("Fout bij het lezen van bestand '{0}': Bestandspad mag niet leeg of ongedefinieerd zijn.",
+ invalidFilePath);
+ TestHelper.AssertThrowsArgumentExceptionAndTestMessage(call, expectedMessage);
+ }
+
+ [Test]
+ public void Constructor_FilePathHasInvalidPathCharacter_ThrowArgumentException()
+ {
+ // Setup
+ char[] invalidFileNameChars = Path.GetInvalidFileNameChars();
+
+ string validFilePath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Common.IO,
+ "SomeFolder");
+ string invalidFilePath = validFilePath.Replace("F", invalidFileNameChars[1].ToString());
+
+ // Call
+ TestDelegate call = () => new ReferenceLineMetaImporter(invalidFilePath);
+
+ // Assert
+ var expectedMessage = string.Format("Fout bij het lezen van bestand '{0}': Bestandspad mag niet de volgende tekens bevatten: {1}",
+ invalidFilePath, String.Join(", ", invalidFileNameChars));
+ TestHelper.AssertThrowsArgumentExceptionAndTestMessage(call, expectedMessage);
+ }
+
+ [Test]
+ public void Constructor_FilePathTooLong_ThrowsCriticalFileReadException()
+ {
+ // Setup
+ string pathToEmptyFolder = Path.Combine(testDataPath, new string('A', 260));
+
+ // Call
+ TestDelegate call = () => new ReferenceLineMetaImporter(pathToEmptyFolder);
+
+ // Assert
+ var expectedExceptionMessage = string.Format("Fout bij het lezen van bestand '{0}': Ongeldig pad.",
+ pathToEmptyFolder);
+ CriticalFileReadException exception = Assert.Throws(call);
+ Assert.AreEqual(expectedExceptionMessage, exception.Message);
+ }
+
+ [Test]
+ public void Constructor_EmptyFolder_ThrowsCriticalFileReadException()
+ {
+ // Setup
+ string pathToEmptyFolder = Path.Combine(testDataPath, "EmptyFolder");
+
+ // Call
+ TestDelegate call = () => new ReferenceLineMetaImporter(pathToEmptyFolder);
+
+ // Assert
+ var expectedExceptionMessage = string.Format("Fout bij het lezen van bestand '{0}\\*.shp': Er is geen shape file gevonden.",
+ pathToEmptyFolder);
+ CriticalFileReadException exception = Assert.Throws(call);
+ Assert.AreEqual(expectedExceptionMessage, exception.Message);
+ }
+
+ [Test]
+ public void Constructor_FolderWithTwoShapeFiles_LogsWarningAndTakesFirstShapeFile()
+ {
+ // Setup
+ string pathToFolder = Path.Combine(testDataPath, "TwoShapeFiles");
+
+ // Call
+ var referenceIds = new List();
+ Action call = () =>
+ {
+ var importer = new ReferenceLineMetaImporter(pathToFolder);
+ referenceIds.AddRange(importer.GetAssessmentSectionIds());
+ };
+
+ // Assert
+ var expectedMessage = string.Format("Er zijn meerdere shape files gevonden in '{0}'. 'NBPW_A.shp' is gekozen.", pathToFolder);
+ TestHelper.AssertLogMessageIsGenerated(call, expectedMessage);
+ Assert.AreEqual(1, referenceIds.Count);
+ Assert.AreEqual("A", referenceIds.First());
+ }
+
+ [Test]
+ public void GetReferenceLineIds_ValidDirectoryWithOneShapeFile_ReturnsReadReferenceIds()
+ {
+ // Setup
+ string pathValidFolder = Path.Combine(testDataPath, "ValidShapeFile");
+ var importer = new ReferenceLineMetaImporter(pathValidFolder);
+
+ // Call
+ var referenceIds = importer.GetAssessmentSectionIds().ToArray();
+
+ // Assert
+ Assert.AreEqual(10, referenceIds.Length);
+ var expectedReferenceIds = new[]
+ {
+ "1-1",
+ "2-2",
+ "3-3",
+ "4-4",
+ "5-5",
+ "6-6",
+ "7-7",
+ "8-8",
+ "9-9",
+ "10-10",
+ };
+ Assert.AreEqual(expectedReferenceIds, referenceIds);
+ }
+
+ [Test]
+ public void Import_IncorrectReferenceId_LogsWarningAndReturnsFalse()
+ {
+ // Setup
+ MockRepository mockRepository = new MockRepository();
+ var assessmentSectionMock = mockRepository.StrictMock();
+ mockRepository.ReplayAll();
+
+ string pathToValidFolder = Path.Combine(testDataPath, "ValidShapeFile");
+ var importer = new ReferenceLineMetaImporter(pathToValidFolder);
+ const string invalidReferenceId = "B";
+ var referecenLineContext = new ReferenceLineContext(assessmentSectionMock);
+
+ // Call
+ Action call = () => importer.Import(referecenLineContext, invalidReferenceId);
+
+ // Assert
+ var expectedMessage = string.Format("Fout bij het lezen van bestand '{0}': De geselecteerde referentielijn '{1}' is niet gevonden.",
+ Path.Combine(pathToValidFolder, "validShapeFile.shp")
+ , invalidReferenceId);
+ TestHelper.AssertLogMessageIsGenerated(call, expectedMessage);
+ mockRepository.VerifyAll();
+ }
+
+ [Test]
+ public void Import_ValidReferenceId_ImportsReferenceLineAndRetunsTrue()
+ {
+ // Setup
+ MockRepository mockRepository = new MockRepository();
+ var assessmentSectionMock = mockRepository.Stub();
+ mockRepository.ReplayAll();
+
+ string pathToValidFolder = Path.Combine(testDataPath, "ValidShapeFile");
+ var importer = new ReferenceLineMetaImporter(pathToValidFolder);
+ const string validReferenceId = "1-1";
+ var referecenLineContext = new ReferenceLineContext(assessmentSectionMock);
+
+ // Call
+ bool importsuccesful = importer.Import(referecenLineContext, validReferenceId);
+
+ // Assert
+ Assert.True(importsuccesful); //TODO add assert for trackid if moved to referenceLine
+ mockRepository.VerifyAll();
+ }
+ }
+}
\ No newline at end of file
Index: Ringtoets/Common/test/Ringtoets.Common.IO.Test/ReferenceLinesMetaReaderTest.cs
===================================================================
diff -u -r16d6d5ad38a45e4e0e8b3a9b41b3383d31595a36 -r8e91f29f35b5f93ea1d9dfc7dcd79edfdd1b4e53
--- Ringtoets/Common/test/Ringtoets.Common.IO.Test/ReferenceLinesMetaReaderTest.cs (.../ReferenceLinesMetaReaderTest.cs) (revision 16d6d5ad38a45e4e0e8b3a9b41b3383d31595a36)
+++ Ringtoets/Common/test/Ringtoets.Common.IO.Test/ReferenceLinesMetaReaderTest.cs (.../ReferenceLinesMetaReaderTest.cs) (revision 8e91f29f35b5f93ea1d9dfc7dcd79edfdd1b4e53)
@@ -159,24 +159,6 @@
}
[Test]
- [TestCase("NBPW.shp", 20)]
- public void GetReferenceLinesCount_ValidFilePath_ReturnElementCount(string shapeFileName, int expectedElementCount)
- {
- // Setup
- string validFilePath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Common.IO,
- shapeFileName);
-
- using (var reader = new ReferenceLinesMetaReader(validFilePath))
- {
- // Call
- int count = reader.GetReferenceLinesCount();
-
- // Assert
- Assert.AreEqual(expectedElementCount, count);
- }
- }
-
- [Test]
[TestCase("NBPW_missingTrajectId.shp", "TRAJECT_ID")]
[TestCase("NBPW_missingNORM_SW.shp", "NORM_SW")]
[TestCase("NBPW_missingNORM_OG.shp", "NORM_OG")]
@@ -214,7 +196,7 @@
}
[Test]
- public void ReadReferenceLinesMeta_ValidFilePath1_ReturnsElement()
+ public void ReadReferenceLinesMeta_ValidFilePath_ReturnsElement()
{
// Setup
var validFilePath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Common.IO,
@@ -226,7 +208,7 @@
ReferenceLineMeta referenceLineMeta = reader.ReadReferenceLinesMeta();
// Assert
- Assert.AreEqual("205", referenceLineMeta.ReferenceLineId);
+ Assert.AreEqual("205", referenceLineMeta.AssessmentSectionId);
Assert.AreEqual(3000, referenceLineMeta.SignalingValue);
Assert.AreEqual(1000, referenceLineMeta.LowerLimitValue);
Point2D[] geometryPoints = referenceLineMeta.Points.ToArray();
@@ -235,7 +217,7 @@
Assert.AreEqual(160892.075100, geometryPoints[1].X, 1e-6);
ReferenceLineMeta referenceLineMeta2 = reader.ReadReferenceLinesMeta();
- Assert.AreEqual("11-1", referenceLineMeta2.ReferenceLineId);
+ Assert.AreEqual("11-1", referenceLineMeta2.AssessmentSectionId);
}
}
@@ -252,7 +234,7 @@
ReferenceLineMeta referenceLineMeta = reader.ReadReferenceLinesMeta();
// Assert
- Assert.AreEqual("46-1", referenceLineMeta.ReferenceLineId);
+ Assert.AreEqual("46-1", referenceLineMeta.AssessmentSectionId);
Assert.IsNull(referenceLineMeta.SignalingValue);
Assert.IsNull(referenceLineMeta.LowerLimitValue);
}
@@ -286,11 +268,11 @@
using (var reader = new ReferenceLinesMetaReader(validFilePath))
{
- int count = reader.GetReferenceLinesCount();
- for (int i = 0; i < count; i++)
+ ReferenceLineMeta line;
+ do
{
- reader.ReadReferenceLinesMeta();
- }
+ line = reader.ReadReferenceLinesMeta();
+ } while (line != null);
// Call
var resultBeyondEndOfFile = reader.ReadReferenceLinesMeta();
Index: Ringtoets/Common/test/Ringtoets.Common.IO.Test/Ringtoets.Common.IO.Test.csproj
===================================================================
diff -u -r5253591e2ead1fb1e5e23dc0506f62c661be023c -r8e91f29f35b5f93ea1d9dfc7dcd79edfdd1b4e53
--- Ringtoets/Common/test/Ringtoets.Common.IO.Test/Ringtoets.Common.IO.Test.csproj (.../Ringtoets.Common.IO.Test.csproj) (revision 5253591e2ead1fb1e5e23dc0506f62c661be023c)
+++ Ringtoets/Common/test/Ringtoets.Common.IO.Test/Ringtoets.Common.IO.Test.csproj (.../Ringtoets.Common.IO.Test.csproj) (revision 8e91f29f35b5f93ea1d9dfc7dcd79edfdd1b4e53)
@@ -51,6 +51,7 @@
+
Index: Ringtoets/Common/test/Ringtoets.Common.IO.Test/test-data/ReferenceLineMetaImporter/TwoShapeFiles/NBPW_A.dbf
===================================================================
diff -u
Binary files differ
Index: Ringtoets/Common/test/Ringtoets.Common.IO.Test/test-data/ReferenceLineMetaImporter/TwoShapeFiles/NBPW_A.prj
===================================================================
diff -u
--- Ringtoets/Common/test/Ringtoets.Common.IO.Test/test-data/ReferenceLineMetaImporter/TwoShapeFiles/NBPW_A.prj (revision 0)
+++ Ringtoets/Common/test/Ringtoets.Common.IO.Test/test-data/ReferenceLineMetaImporter/TwoShapeFiles/NBPW_A.prj (revision 8e91f29f35b5f93ea1d9dfc7dcd79edfdd1b4e53)
@@ -0,0 +1 @@
+PROJCS["Amersfoort_RD_New",GEOGCS["GCS_Amersfoort",DATUM["D_Amersfoort",SPHEROID["Bessel_1841",6377397.155,299.1528128]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]],PROJECTION["Double_Stereographic"],PARAMETER["latitude_of_origin",52.15616055555555],PARAMETER["central_meridian",5.38763888888889],PARAMETER["scale_factor",0.9999079],PARAMETER["false_easting",155000],PARAMETER["false_northing",463000],UNIT["Meter",1]]
\ No newline at end of file
Index: Ringtoets/Common/test/Ringtoets.Common.IO.Test/test-data/ReferenceLineMetaImporter/TwoShapeFiles/NBPW_A.qpj
===================================================================
diff -u
--- Ringtoets/Common/test/Ringtoets.Common.IO.Test/test-data/ReferenceLineMetaImporter/TwoShapeFiles/NBPW_A.qpj (revision 0)
+++ Ringtoets/Common/test/Ringtoets.Common.IO.Test/test-data/ReferenceLineMetaImporter/TwoShapeFiles/NBPW_A.qpj (revision 8e91f29f35b5f93ea1d9dfc7dcd79edfdd1b4e53)
@@ -0,0 +1 @@
+PROJCS["Amersfoort / RD New",GEOGCS["Amersfoort",DATUM["Amersfoort",SPHEROID["Bessel 1841",6377397.155,299.1528128,AUTHORITY["EPSG","7004"]],TOWGS84[565.4171,50.3319,465.5524,-0.398957388243134,0.343987817378283,-1.87740163998045,4.0725],AUTHORITY["EPSG","6289"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4289"]],PROJECTION["Oblique_Stereographic"],PARAMETER["latitude_of_origin",52.15616055555555],PARAMETER["central_meridian",5.38763888888889],PARAMETER["scale_factor",0.9999079],PARAMETER["false_easting",155000],PARAMETER["false_northing",463000],UNIT["metre",1,AUTHORITY["EPSG","9001"]],AXIS["X",EAST],AXIS["Y",NORTH],AUTHORITY["EPSG","28992"]]
Index: Ringtoets/Common/test/Ringtoets.Common.IO.Test/test-data/ReferenceLineMetaImporter/TwoShapeFiles/NBPW_A.shp
===================================================================
diff -u
Binary files differ
Index: Ringtoets/Common/test/Ringtoets.Common.IO.Test/test-data/ReferenceLineMetaImporter/TwoShapeFiles/NBPW_A.shx
===================================================================
diff -u
Binary files differ
Index: Ringtoets/Common/test/Ringtoets.Common.IO.Test/test-data/ReferenceLineMetaImporter/TwoShapeFiles/NBPW_B.dbf
===================================================================
diff -u
Binary files differ
Index: Ringtoets/Common/test/Ringtoets.Common.IO.Test/test-data/ReferenceLineMetaImporter/TwoShapeFiles/NBPW_B.prj
===================================================================
diff -u
--- Ringtoets/Common/test/Ringtoets.Common.IO.Test/test-data/ReferenceLineMetaImporter/TwoShapeFiles/NBPW_B.prj (revision 0)
+++ Ringtoets/Common/test/Ringtoets.Common.IO.Test/test-data/ReferenceLineMetaImporter/TwoShapeFiles/NBPW_B.prj (revision 8e91f29f35b5f93ea1d9dfc7dcd79edfdd1b4e53)
@@ -0,0 +1 @@
+PROJCS["Amersfoort_RD_New",GEOGCS["GCS_Amersfoort",DATUM["D_Amersfoort",SPHEROID["Bessel_1841",6377397.155,299.1528128]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]],PROJECTION["Double_Stereographic"],PARAMETER["latitude_of_origin",52.15616055555555],PARAMETER["central_meridian",5.38763888888889],PARAMETER["scale_factor",0.9999079],PARAMETER["false_easting",155000],PARAMETER["false_northing",463000],UNIT["Meter",1]]
\ No newline at end of file
Index: Ringtoets/Common/test/Ringtoets.Common.IO.Test/test-data/ReferenceLineMetaImporter/TwoShapeFiles/NBPW_B.qpj
===================================================================
diff -u
--- Ringtoets/Common/test/Ringtoets.Common.IO.Test/test-data/ReferenceLineMetaImporter/TwoShapeFiles/NBPW_B.qpj (revision 0)
+++ Ringtoets/Common/test/Ringtoets.Common.IO.Test/test-data/ReferenceLineMetaImporter/TwoShapeFiles/NBPW_B.qpj (revision 8e91f29f35b5f93ea1d9dfc7dcd79edfdd1b4e53)
@@ -0,0 +1 @@
+PROJCS["Amersfoort / RD New",GEOGCS["Amersfoort",DATUM["Amersfoort",SPHEROID["Bessel 1841",6377397.155,299.1528128,AUTHORITY["EPSG","7004"]],TOWGS84[565.4171,50.3319,465.5524,-0.398957388243134,0.343987817378283,-1.87740163998045,4.0725],AUTHORITY["EPSG","6289"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4289"]],PROJECTION["Oblique_Stereographic"],PARAMETER["latitude_of_origin",52.15616055555555],PARAMETER["central_meridian",5.38763888888889],PARAMETER["scale_factor",0.9999079],PARAMETER["false_easting",155000],PARAMETER["false_northing",463000],UNIT["metre",1,AUTHORITY["EPSG","9001"]],AXIS["X",EAST],AXIS["Y",NORTH],AUTHORITY["EPSG","28992"]]
Index: Ringtoets/Common/test/Ringtoets.Common.IO.Test/test-data/ReferenceLineMetaImporter/TwoShapeFiles/NBPW_B.shp
===================================================================
diff -u
Binary files differ
Index: Ringtoets/Common/test/Ringtoets.Common.IO.Test/test-data/ReferenceLineMetaImporter/TwoShapeFiles/NBPW_B.shx
===================================================================
diff -u
Binary files differ
Index: Ringtoets/Common/test/Ringtoets.Common.IO.Test/test-data/ReferenceLineMetaImporter/ValidShapeFile/validShapeFile.dbf
===================================================================
diff -u
Binary files differ
Index: Ringtoets/Common/test/Ringtoets.Common.IO.Test/test-data/ReferenceLineMetaImporter/ValidShapeFile/validShapeFile.prj
===================================================================
diff -u
--- Ringtoets/Common/test/Ringtoets.Common.IO.Test/test-data/ReferenceLineMetaImporter/ValidShapeFile/validShapeFile.prj (revision 0)
+++ Ringtoets/Common/test/Ringtoets.Common.IO.Test/test-data/ReferenceLineMetaImporter/ValidShapeFile/validShapeFile.prj (revision 8e91f29f35b5f93ea1d9dfc7dcd79edfdd1b4e53)
@@ -0,0 +1 @@
+PROJCS["Amersfoort_RD_New",GEOGCS["GCS_Amersfoort",DATUM["D_Amersfoort",SPHEROID["Bessel_1841",6377397.155,299.1528128]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]],PROJECTION["Double_Stereographic"],PARAMETER["latitude_of_origin",52.15616055555555],PARAMETER["central_meridian",5.38763888888889],PARAMETER["scale_factor",0.9999079],PARAMETER["false_easting",155000],PARAMETER["false_northing",463000],UNIT["Meter",1]]
\ No newline at end of file
Index: Ringtoets/Common/test/Ringtoets.Common.IO.Test/test-data/ReferenceLineMetaImporter/ValidShapeFile/validShapeFile.qpj
===================================================================
diff -u
--- Ringtoets/Common/test/Ringtoets.Common.IO.Test/test-data/ReferenceLineMetaImporter/ValidShapeFile/validShapeFile.qpj (revision 0)
+++ Ringtoets/Common/test/Ringtoets.Common.IO.Test/test-data/ReferenceLineMetaImporter/ValidShapeFile/validShapeFile.qpj (revision 8e91f29f35b5f93ea1d9dfc7dcd79edfdd1b4e53)
@@ -0,0 +1 @@
+PROJCS["Amersfoort / RD New",GEOGCS["Amersfoort",DATUM["Amersfoort",SPHEROID["Bessel 1841",6377397.155,299.1528128,AUTHORITY["EPSG","7004"]],TOWGS84[565.4171,50.3319,465.5524,-0.398957388243134,0.343987817378283,-1.87740163998045,4.0725],AUTHORITY["EPSG","6289"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4289"]],PROJECTION["Oblique_Stereographic"],PARAMETER["latitude_of_origin",52.15616055555555],PARAMETER["central_meridian",5.38763888888889],PARAMETER["scale_factor",0.9999079],PARAMETER["false_easting",155000],PARAMETER["false_northing",463000],UNIT["metre",1,AUTHORITY["EPSG","9001"]],AXIS["X",EAST],AXIS["Y",NORTH],AUTHORITY["EPSG","28992"]]
Index: Ringtoets/Common/test/Ringtoets.Common.IO.Test/test-data/ReferenceLineMetaImporter/ValidShapeFile/validShapeFile.shp
===================================================================
diff -u
Binary files differ
Index: Ringtoets/Common/test/Ringtoets.Common.IO.Test/test-data/ReferenceLineMetaImporter/ValidShapeFile/validShapeFile.shx
===================================================================
diff -u
Binary files differ