Index: Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.IO/DikeProfiles/DikeProfileLocation.cs =================================================================== diff -u -raf83c5308c30a462589f45eecd5ba0dfac0cda00 -r0eafbd198165fdfb8a3f9fabfa29919dd573d274 --- Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.IO/DikeProfiles/DikeProfileLocation.cs (.../DikeProfileLocation.cs) (revision af83c5308c30a462589f45eecd5ba0dfac0cda00) +++ Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.IO/DikeProfiles/DikeProfileLocation.cs (.../DikeProfileLocation.cs) (revision 0eafbd198165fdfb8a3f9fabfa29919dd573d274) @@ -39,23 +39,6 @@ /// The actual location. public DikeProfileLocation(string idValue, string nameValue, double x0Value, Point2D pointValue) { - if (idValue == null) - { - throw new ArgumentException(Resources.DikeProfileLocation_Constructor_Invalid_Id); - } - if (nameValue == null) - { - throw new ArgumentException(Resources.DikeProfileLocation_Constructor_Invalid_Name); - } - if (double.IsNaN(x0Value)) - { - throw new ArgumentException(Resources.DikeProfileLocation_Constructor_Invalid_X0); - } - if (pointValue == null) - { - throw new ArgumentException(Resources.DikeProfileLocation_Constructor_Invalid_Point); - } - Id = idValue; Name = nameValue; X0 = x0Value; Index: Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.IO/DikeProfiles/DikeProfileLocationReader.cs =================================================================== diff -u -raf83c5308c30a462589f45eecd5ba0dfac0cda00 -r0eafbd198165fdfb8a3f9fabfa29919dd573d274 --- Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.IO/DikeProfiles/DikeProfileLocationReader.cs (.../DikeProfileLocationReader.cs) (revision af83c5308c30a462589f45eecd5ba0dfac0cda00) +++ Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.IO/DikeProfiles/DikeProfileLocationReader.cs (.../DikeProfileLocationReader.cs) (revision 0eafbd198165fdfb8a3f9fabfa29919dd573d274) @@ -75,7 +75,7 @@ /// /// Filepath of the shapefile containing dike locations. /// Shapefile does not only contain point features. - /// + /// Return an instance of . private PointShapeFileReader OpenPointsShapeFile(string shapeFilePath) { try @@ -91,51 +91,43 @@ } /// - /// Get the number of point features in the shapefile. + /// Retrieve a for each point feature in the shapefile. /// - /// Shapefile does not contain the required attributes. - /// - private int GetDikeProfileLocationCount() + /// Shapefile does not contain the required attributes, + /// or misses values for required attributes, or an attribute's type is incorrect. + /// A of objects. + public IList GetDikeProfileLocations() { - foreach (string attribute in new[]{"ID", "Naam", "X0"}) + List dikeProfileLocations = new List(); + + foreach (string attribute in new[] { "ID", "Naam", "X0" }) { if (!pointsShapeFileReader.HasAttribute(attribute)) { throw new CriticalFileReadException( string.Format("Het bestand heeft geen attribuut '{0}' welke vereist is om de locaties van de dijkprofielen in te lezen.", attribute)); } } - return pointsShapeFileReader.GetNumberOfLines(); - } - /// - /// Retrieve a for each point feature in the shapefile. - /// - /// Shapefile does not contain values for all required attributes. - /// A of objects. - public IList GetDikeProfileLocations() - { - List dikeProfileLocations = new List(); - - int dikeProfileLocationCount = GetDikeProfileLocationCount(); + int dikeProfileLocationCount = pointsShapeFileReader.GetNumberOfLines(); for (int i = 0; i < dikeProfileLocationCount; i++) { MapPointData mapPointData = (MapPointData)pointsShapeFileReader.ReadLine(); IDictionary attributes = mapPointData.Features.First().MetaData; var attributeIdValue = attributes["ID"] as string; - if (string.IsNullOrWhiteSpace(attributeIdValue)) + if (attributeIdValue == null) { throw new CriticalFileReadException(GrasCoverErosionInwardsIoResources.DikeProfileLocationReader_GetDikeProfileLocations_Invalid_Id); } - - var attributeNameValue = attributes["Naam"] as string; - if (string.IsNullOrWhiteSpace(attributeNameValue)) + if (!attributeIdValue.All(char.IsLetterOrDigit)) { - throw new CriticalFileReadException(GrasCoverErosionInwardsIoResources.DikeProfileLocationReader_GetDikeProfileLocations_Invalid_Name); + throw new CriticalFileReadException(GrasCoverErosionInwardsIoResources.DikeProfileLocationReader_GetDikeProfileLocations_Illegal_Id); } + var attributeNameValue = attributes["Naam"] as string; + var attributeX0Value = attributes["X0"] as double?; if (attributeX0Value == null) { Index: Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.IO/Properties/Resources.Designer.cs =================================================================== diff -u -r4339c599a8e0bc1265e7a07cb4d6ce3665562e76 -r0eafbd198165fdfb8a3f9fabfa29919dd573d274 --- Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.IO/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision 4339c599a8e0bc1265e7a07cb4d6ce3665562e76) +++ Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.IO/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision 0eafbd198165fdfb8a3f9fabfa29919dd573d274) @@ -142,15 +142,6 @@ } /// - /// Looks up a localized string similar to Fout bij het aanmaken van een dijk profiel locatie: Naam is ongeldig.. - /// - internal static string DikeProfileLocation_Constructor_Invalid_Name { - get { - return ResourceManager.GetString("DikeProfileLocation_Constructor_Invalid_Name", resourceCulture); - } - } - - /// /// Looks up a localized string similar to Fout bij het aanmaken van een dijk profiel locatie: Punt is ongeldig.. /// internal static string DikeProfileLocation_Constructor_Invalid_Point { @@ -169,20 +160,20 @@ } /// - /// Looks up a localized string similar to Het bestand heeft een attribuut 'ID' zonder geldige waarde, welke vereist is om de locaties van de dijkprofielen in te lezen.. + /// Looks up a localized string similar to Het bestand bevat het attribuut Id met een waarde welke uit meer dan alleen letters en cijfers bestaat.. /// - internal static string DikeProfileLocationReader_GetDikeProfileLocations_Invalid_Id { + internal static string DikeProfileLocationReader_GetDikeProfileLocations_Illegal_Id { get { - return ResourceManager.GetString("DikeProfileLocationReader_GetDikeProfileLocations_Invalid_Id", resourceCulture); + return ResourceManager.GetString("DikeProfileLocationReader_GetDikeProfileLocations_Illegal_Id", resourceCulture); } } /// - /// Looks up a localized string similar to Het bestand heeft een attribuut 'Naam' zonder geldige waarde, welke vereist is om de locaties van de dijkprofielen in te lezen.. + /// Looks up a localized string similar to Het bestand heeft een attribuut 'ID' zonder geldige waarde, welke vereist is om de locaties van de dijkprofielen in te lezen.. /// - internal static string DikeProfileLocationReader_GetDikeProfileLocations_Invalid_Name { + internal static string DikeProfileLocationReader_GetDikeProfileLocations_Invalid_Id { get { - return ResourceManager.GetString("DikeProfileLocationReader_GetDikeProfileLocations_Invalid_Name", resourceCulture); + return ResourceManager.GetString("DikeProfileLocationReader_GetDikeProfileLocations_Invalid_Id", resourceCulture); } } Index: Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.IO/Properties/Resources.resx =================================================================== diff -u -r4339c599a8e0bc1265e7a07cb4d6ce3665562e76 -r0eafbd198165fdfb8a3f9fabfa29919dd573d274 --- Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.IO/Properties/Resources.resx (.../Resources.resx) (revision 4339c599a8e0bc1265e7a07cb4d6ce3665562e76) +++ Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.IO/Properties/Resources.resx (.../Resources.resx) (revision 0eafbd198165fdfb8a3f9fabfa29919dd573d274) @@ -123,9 +123,6 @@ Fout bij het aanmaken van een dijk profiel locatie: Id is ongeldig. - - Fout bij het aanmaken van een dijk profiel locatie: Naam is ongeldig. - Fout bij het aanmaken van een dijk profiel locatie: Punt is ongeldig. @@ -135,12 +132,12 @@ Het bestand heeft een attribuut 'ID' zonder geldige waarde, welke vereist is om de locaties van de dijkprofielen in te lezen. - - Het bestand heeft een attribuut 'Naam' zonder geldige waarde, welke vereist is om de locaties van de dijkprofielen in te lezen. - Het bestand heeft een attribuut 'X0' zonder geldige waarde, welke vereist is om de locaties van de dijkprofielen in te lezen. + + Het bestand bevat het attribuut Id met een waarde welke uit meer dan alleen letters en cijfers bestaat. + De ingelezen dam-type waarde ({0}) moet binnen het bereik [0, 3] vallen. Index: Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.IO/Ringtoets.GrassCoverErosionInwards.IO.csproj =================================================================== diff -u -raf83c5308c30a462589f45eecd5ba0dfac0cda00 -r0eafbd198165fdfb8a3f9fabfa29919dd573d274 --- Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.IO/Ringtoets.GrassCoverErosionInwards.IO.csproj (.../Ringtoets.GrassCoverErosionInwards.IO.csproj) (revision af83c5308c30a462589f45eecd5ba0dfac0cda00) +++ Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.IO/Ringtoets.GrassCoverErosionInwards.IO.csproj (.../Ringtoets.GrassCoverErosionInwards.IO.csproj) (revision 0eafbd198165fdfb8a3f9fabfa29919dd573d274) @@ -94,6 +94,7 @@ ResXFileCodeGenerator Resources.Designer.cs + Designer Index: Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.IO.Test/DikeProfiles/DikeProfileLocationReaderTest.cs =================================================================== diff -u -raf83c5308c30a462589f45eecd5ba0dfac0cda00 -r0eafbd198165fdfb8a3f9fabfa29919dd573d274 --- Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.IO.Test/DikeProfiles/DikeProfileLocationReaderTest.cs (.../DikeProfileLocationReaderTest.cs) (revision af83c5308c30a462589f45eecd5ba0dfac0cda00) +++ Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.IO.Test/DikeProfiles/DikeProfileLocationReaderTest.cs (.../DikeProfileLocationReaderTest.cs) (revision 0eafbd198165fdfb8a3f9fabfa29919dd573d274) @@ -122,8 +122,8 @@ [Test] [TestCase("Voorlanden 12-2.shp", 5)] [TestCase("Voorlanden_12-2_Alternative.shp", 9)] - public void GetDikeProfileLocationCount_FileWithFiveElements_ReturnFive( - string fileName, int expectedNumberOfElements) + public void GetDikeProfileLocations_FileWithNLocations_ReturnNDikeProfileLocations( + string fileName, int expectedNumberOfDikeProfileLocations) { // Setup string validFilePath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.GrassCoverErosionInwards.IO, @@ -132,18 +132,18 @@ using (var reader = new DikeProfileLocationReader(validFilePath)) { // Call - int count = reader.GetDikeProfileLocations().Count; + IList dikeProfileLocations = reader.GetDikeProfileLocations(); // Assert - Assert.AreEqual(expectedNumberOfElements, count); + Assert.AreEqual(expectedNumberOfDikeProfileLocations, dikeProfileLocations.Count); } } [Test] [TestCase("Voorlanden_12-2_WithoutId.shp", "ID")] [TestCase("Voorlanden_12-2_WithoutName.shp", "Naam")] [TestCase("Voorlanden_12-2_WithoutX0.shp", "X0")] - public void GetDikeProfileLocationCount_FileWithoutIdColumn_ThrowCriticalFileReadException( + public void GetDikeProfileLocations_FileMissingAttributeColumn_ThrowCriticalFileReadException( string fileName, string missingColumnName) { // Setup @@ -165,7 +165,6 @@ [Test] [TestCase("Voorlanden_12-2_EmptyId.shp", "ID")] - [TestCase("Voorlanden_12-2_EmptyName.shp", "Naam")] [TestCase("Voorlanden_12-2_EmptyX0.shp", "X0")] public void GetDikeProfileLocations_FileWithEmptyEntryInColumn_ThrowCriticalFileReadException( string fileName, string offendingColumnName) @@ -188,6 +187,44 @@ } [Test] + [TestCase("Voorlanden_12-2_IdWithSymbol.shp")] + [TestCase("Voorlanden_12-2_IdWithWhitespace.shp")] + public void GetDikeProfileLocations_FileWithIllegalCharactersInId_ThrowCriticalFileReadException(string fileName) + { + // Setup + string invalidFilePath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.GrassCoverErosionInwards.IO, + Path.Combine("DikeProfiles", fileName)); + + using (var reader = new DikeProfileLocationReader(invalidFilePath)) + { + // Call + TestDelegate call = () => reader.GetDikeProfileLocations(); + + // Assert + var expectedMessage = "Het bestand bevat het attribuut Id met een waarde welke uit meer dan alleen letters en cijfers bestaat."; + string message = Assert.Throws(call).Message; + Assert.AreEqual(expectedMessage, message); + } + } + + [Test] + public void GetDikeProfileLocations_FileWithNullAsNameAttribute_GetLocations() + { + // Setup + string invalidFilePath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.GrassCoverErosionInwards.IO, + Path.Combine("DikeProfiles", "Voorlanden_12-2_EmptyName.shp")); + + using (var reader = new DikeProfileLocationReader(invalidFilePath)) + { + // Call + IEnumerable locations = reader.GetDikeProfileLocations(); + + // Assert + Assert.AreEqual(5, locations.Count()); + } + } + + [Test] public void GetDikeProfileLocations_FileWithFivePoints_GetFiveLocations() { // Setup Index: Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.IO.Test/DikeProfiles/DikeProfileLocationTest.cs =================================================================== diff -u -raf83c5308c30a462589f45eecd5ba0dfac0cda00 -r0eafbd198165fdfb8a3f9fabfa29919dd573d274 --- Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.IO.Test/DikeProfiles/DikeProfileLocationTest.cs (.../DikeProfileLocationTest.cs) (revision af83c5308c30a462589f45eecd5ba0dfac0cda00) +++ Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.IO.Test/DikeProfiles/DikeProfileLocationTest.cs (.../DikeProfileLocationTest.cs) (revision 0eafbd198165fdfb8a3f9fabfa29919dd573d274) @@ -19,9 +19,7 @@ // Stichting Deltares and remain full property of Stichting Deltares at all times. // All rights reserved. -using System; using Core.Common.Base.Geometry; -using Core.Common.TestUtil; using NUnit.Framework; using Ringtoets.GrassCoverErosionInwards.IO.DikeProfiles; @@ -31,41 +29,6 @@ public class DikeProfileLocationTest { [Test] - [TestCase("Id", null, "name", 0.0)] - [TestCase("Naam", "id", null, 0.0)] - public void Constructor_InitializedWithNullParameter_ThrownArgumentException(string parameterName, string idValue, string nameValue, double x0Value) - { - // Call - TestDelegate call = () => new DikeProfileLocation(idValue, nameValue, x0Value, new Point2D(0.0, 0.0)); - - // Assert - var expectedMessage = string.Format("Fout bij het aanmaken van een dijk profiel locatie: {0} is ongeldig.", parameterName); - TestHelper.AssertThrowsArgumentExceptionAndTestMessage(call, expectedMessage); - } - - [Test] - public void Constructor_InitializedWithNullPoint_ThrownArgumentException() - { - // Call - TestDelegate call = () => new DikeProfileLocation("anID", "aNAME", 0.0, null); - - // Assert - var expectedMessage = "Fout bij het aanmaken van een dijk profiel locatie: Punt is ongeldig."; - TestHelper.AssertThrowsArgumentExceptionAndTestMessage(call, expectedMessage); - } - - [Test] - public void Constructor_InitializedWithInvalidX0_ThrownArgumentException() - { - // Call - TestDelegate call = () => new DikeProfileLocation("id", "name", double.NaN, new Point2D(0.0, 0.0)); - - // Assert - var expectedMessage = "Fout bij het aanmaken van een dijk profiel locatie: X0 is ongeldig."; - TestHelper.AssertThrowsArgumentExceptionAndTestMessage(call, expectedMessage); - } - - [Test] public void Constructor_InitializedWithValidValues_CorrectProperties() { // Setup @@ -78,5 +41,19 @@ Assert.AreEqual(1.1, dikeProfileLocation.X0); Assert.AreEqual(referencePoint, dikeProfileLocation.Point); } + + [Test] + public void Constructor_InitializedWithValidValues_CorrectPropertyTypes() + { + // Setup + var referencePoint = new Point2D(2.2, 3.3); + DikeProfileLocation dikeProfileLocation = new DikeProfileLocation("id", null, 1.1, referencePoint); + + // Assert + Assert.IsInstanceOf(typeof(string), dikeProfileLocation.Id); + Assert.IsNull(dikeProfileLocation.Name); + Assert.IsInstanceOf(typeof(double), dikeProfileLocation.X0); + Assert.IsInstanceOf(typeof(Point2D), dikeProfileLocation.Point); + } } } \ No newline at end of file Index: Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.IO.Test/test-data/DikeProfiles/Voorlanden_12-2_IdWithSymbol.dbf =================================================================== diff -u Binary files differ Index: Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.IO.Test/test-data/DikeProfiles/Voorlanden_12-2_IdWithSymbol.prj =================================================================== diff -u --- Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.IO.Test/test-data/DikeProfiles/Voorlanden_12-2_IdWithSymbol.prj (revision 0) +++ Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.IO.Test/test-data/DikeProfiles/Voorlanden_12-2_IdWithSymbol.prj (revision 0eafbd198165fdfb8a3f9fabfa29919dd573d274) @@ -0,0 +1 @@ +PROJCS["RD_New",GEOGCS["GCS_Amersfoort",DATUM["D_Amersfoort",SPHEROID["Bessel_1841",6377397.155,299.1528128]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]],PROJECTION["Double_Stereographic"],PARAMETER["False_Easting",155000.0],PARAMETER["False_Northing",463000.0],PARAMETER["Central_Meridian",5.38763888888889],PARAMETER["Scale_Factor",0.9999079],PARAMETER["Latitude_Of_Origin",52.15616055555555],UNIT["Meter",1.0]] \ No newline at end of file Index: Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.IO.Test/test-data/DikeProfiles/Voorlanden_12-2_IdWithSymbol.shp =================================================================== diff -u Binary files differ Index: Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.IO.Test/test-data/DikeProfiles/Voorlanden_12-2_IdWithSymbol.shx =================================================================== diff -u Binary files differ Index: Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.IO.Test/test-data/DikeProfiles/Voorlanden_12-2_IdWithWhitespace.dbf =================================================================== diff -u Binary files differ Index: Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.IO.Test/test-data/DikeProfiles/Voorlanden_12-2_IdWithWhitespace.prj =================================================================== diff -u --- Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.IO.Test/test-data/DikeProfiles/Voorlanden_12-2_IdWithWhitespace.prj (revision 0) +++ Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.IO.Test/test-data/DikeProfiles/Voorlanden_12-2_IdWithWhitespace.prj (revision 0eafbd198165fdfb8a3f9fabfa29919dd573d274) @@ -0,0 +1 @@ +PROJCS["RD_New",GEOGCS["GCS_Amersfoort",DATUM["D_Amersfoort",SPHEROID["Bessel_1841",6377397.155,299.1528128]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]],PROJECTION["Double_Stereographic"],PARAMETER["False_Easting",155000.0],PARAMETER["False_Northing",463000.0],PARAMETER["Central_Meridian",5.38763888888889],PARAMETER["Scale_Factor",0.9999079],PARAMETER["Latitude_Of_Origin",52.15616055555555],UNIT["Meter",1.0]] \ No newline at end of file Index: Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.IO.Test/test-data/DikeProfiles/Voorlanden_12-2_IdWithWhitespace.shp =================================================================== diff -u Binary files differ Index: Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.IO.Test/test-data/DikeProfiles/Voorlanden_12-2_IdWithWhitespace.shx =================================================================== diff -u Binary files differ