Index: Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.IO/DikeProfiles/DikeProfileLocation.cs =================================================================== diff -u -re71f7a8977226f7bdbc146c4e5aac1f13c39e3eb -r5a421e7bb0b0c52d5d1d9ca20d495cd11bfa10e8 --- Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.IO/DikeProfiles/DikeProfileLocation.cs (.../DikeProfileLocation.cs) (revision e71f7a8977226f7bdbc146c4e5aac1f13c39e3eb) +++ Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.IO/DikeProfiles/DikeProfileLocation.cs (.../DikeProfileLocation.cs) (revision 5a421e7bb0b0c52d5d1d9ca20d495cd11bfa10e8) @@ -19,7 +19,10 @@ // Stichting Deltares and remain full property of Stichting Deltares at all times. // All rights reserved. +using System; +using System.Linq; using Core.Common.Base.Geometry; +using GrasCoverErosionInwardsIoResources = Ringtoets.GrassCoverErosionInwards.IO.Properties.Resources; namespace Ringtoets.GrassCoverErosionInwards.IO.DikeProfiles { @@ -35,8 +38,29 @@ /// The name of this /// The coordinate offset in the local coordinate system for this /// The coordinates of the location as a . + /// + /// The Id parameter is null. + /// The Id parameter contains illegal characters. + /// The Point parameter is null. + /// public DikeProfileLocation(string id, string name, double offset, Point2D point) { + if (id == null) + { + throw new ArgumentException(GrasCoverErosionInwardsIoResources.DikeProfileLocation_DikeProfileLocation_Id_is_null); + } + if (!id.All(char.IsLetterOrDigit)) + { + throw new ArgumentException(GrasCoverErosionInwardsIoResources.DikeProfileLocation_DikeProfileLocation_Id_is_invalid); + } + if (double.IsNaN(offset) || double.IsInfinity(offset)) + { + throw new ArgumentException(GrasCoverErosionInwardsIoResources.DikeProfileLocation_DikeProfileLocation_X0_is_invalid); + } + if (point == null) + { + throw new ArgumentException(GrasCoverErosionInwardsIoResources.DikeProfileLocation_DikeProfileLocation_Point_is_null); + } Id = id; Name = name; Offset = offset; Index: Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.IO/DikeProfiles/DikeProfileLocationReader.cs =================================================================== diff -u -re71f7a8977226f7bdbc146c4e5aac1f13c39e3eb -r5a421e7bb0b0c52d5d1d9ca20d495cd11bfa10e8 --- Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.IO/DikeProfiles/DikeProfileLocationReader.cs (.../DikeProfileLocationReader.cs) (revision e71f7a8977226f7bdbc146c4e5aac1f13c39e3eb) +++ Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.IO/DikeProfiles/DikeProfileLocationReader.cs (.../DikeProfileLocationReader.cs) (revision 5a421e7bb0b0c52d5d1d9ca20d495cd11bfa10e8) @@ -92,7 +92,14 @@ var attributeX0Value = GetOffsetAttributeValue(attributes); Point2D point = mapPointData.Features.First().MapGeometries.First().PointCollections.First().First(); - dikeProfileLocations.Add(new DikeProfileLocation(attributeIdValue, attributeNameValue, attributeX0Value, point)); + try + { + dikeProfileLocations.Add(new DikeProfileLocation(attributeIdValue, attributeNameValue, attributeX0Value, point)); + } + catch (ArgumentException exception) + { + throw new CriticalFileReadException(exception.Message); + } } return dikeProfileLocations; @@ -142,14 +149,6 @@ private static string GetIdAttributeValue(IDictionary attributes) { var attributeIdValue = attributes[idAttributeName] as string; - if (attributeIdValue == null) - { - throw new CriticalFileReadException(GrasCoverErosionInwardsIoResources.DikeProfileLocationReader_GetDikeProfileLocations_Invalid_Id); - } - if (!attributeIdValue.All(char.IsLetterOrDigit)) - { - throw new CriticalFileReadException(GrasCoverErosionInwardsIoResources.DikeProfileLocationReader_GetDikeProfileLocations_Illegal_Id); - } return attributeIdValue; } Index: Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.IO/Properties/Resources.Designer.cs =================================================================== diff -u -ra27dce61d57406a3f528e8970018c9c35b8c29cf -r5a421e7bb0b0c52d5d1d9ca20d495cd11bfa10e8 --- Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.IO/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision a27dce61d57406a3f528e8970018c9c35b8c29cf) +++ Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.IO/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision 5a421e7bb0b0c52d5d1d9ca20d495cd11bfa10e8) @@ -268,33 +268,60 @@ } /// - /// Looks up a localized string similar to Het bestand heeft geen attribuut '{0}' welke vereist is om de locaties van de dijkprofielen in te lezen.. + /// Looks up a localized string similar to De locatie parameter 'Id' bevat meer dan letters en cijfers.. /// - internal static string DikeProfileLocationReader_CheckRequiredAttributePresence_Missing_attribute_0_ { + internal static string DikeProfileLocation_DikeProfileLocation_Id_is_invalid { get { - return ResourceManager.GetString("DikeProfileLocationReader_CheckRequiredAttributePresence_Missing_attribute_0_", resourceCulture); + return ResourceManager.GetString("DikeProfileLocation_DikeProfileLocation_Id_is_invalid", resourceCulture); } } /// - /// 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.. + /// Looks up a localized string similar to De locatie parameter 'Id' heeft geen waarde.. /// - internal static string DikeProfileLocationReader_GetDikeProfileLocations_Illegal_Id { + internal static string DikeProfileLocation_DikeProfileLocation_Id_is_null { get { - return ResourceManager.GetString("DikeProfileLocationReader_GetDikeProfileLocations_Illegal_Id", resourceCulture); + return ResourceManager.GetString("DikeProfileLocation_DikeProfileLocation_Id_is_null", resourceCulture); } } /// - /// 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 een ongeldig punt als locatie.. /// - internal static string DikeProfileLocationReader_GetDikeProfileLocations_Invalid_Id { + internal static string DikeProfileLocation_DikeProfileLocation_Invalid_point { get { - return ResourceManager.GetString("DikeProfileLocationReader_GetDikeProfileLocations_Invalid_Id", resourceCulture); + return ResourceManager.GetString("DikeProfileLocation_DikeProfileLocation_Invalid_point", resourceCulture); } } /// + /// Looks up a localized string similar to De locatie heeft geen coördinaten.. + /// + internal static string DikeProfileLocation_DikeProfileLocation_Point_is_null { + get { + return ResourceManager.GetString("DikeProfileLocation_DikeProfileLocation_Point_is_null", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to De locatie parameter 'X0' bevat een ongeldig getal.. + /// + internal static string DikeProfileLocation_DikeProfileLocation_X0_is_invalid { + get { + return ResourceManager.GetString("DikeProfileLocation_DikeProfileLocation_X0_is_invalid", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Het bestand heeft geen attribuut '{0}' welke vereist is om de locaties van de dijkprofielen in te lezen.. + /// + internal static string DikeProfileLocationReader_CheckRequiredAttributePresence_Missing_attribute_0_ { + get { + return ResourceManager.GetString("DikeProfileLocationReader_CheckRequiredAttributePresence_Missing_attribute_0_", resourceCulture); + } + } + + /// /// Looks up a localized string similar to Het bestand heeft een attribuut 'X0' zonder geldige waarde, welke vereist is om de locaties van de dijkprofielen in te lezen.. /// internal static string DikeProfileLocationReader_GetDikeProfileLocations_Invalid_X0 { Index: Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.IO/Properties/Resources.resx =================================================================== diff -u -ra27dce61d57406a3f528e8970018c9c35b8c29cf -r5a421e7bb0b0c52d5d1d9ca20d495cd11bfa10e8 --- Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.IO/Properties/Resources.resx (.../Resources.resx) (revision a27dce61d57406a3f528e8970018c9c35b8c29cf) +++ Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.IO/Properties/Resources.resx (.../Resources.resx) (revision 5a421e7bb0b0c52d5d1d9ca20d495cd11bfa10e8) @@ -129,15 +129,9 @@ Fout bij het aanmaken van een dijk profiel locatie: offset is ongeldig. - - 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 '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. @@ -201,4 +195,19 @@ De ingelezen kruinhoogte ({0}) is te groot of te klein om ingelezen te worden. + + Het bestand bevat een ongeldig punt als locatie. + + + De locatie parameter 'Id' heeft geen waarde. + + + De locatie parameter 'Id' bevat meer dan letters en cijfers. + + + De locatie heeft geen coördinaten. + + + De locatie parameter 'X0' bevat een ongeldig getal. + \ No newline at end of file Index: Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.IO.Test/DikeProfiles/DikeProfileLocationReaderTest.cs =================================================================== diff -u -re71f7a8977226f7bdbc146c4e5aac1f13c39e3eb -r5a421e7bb0b0c52d5d1d9ca20d495cd11bfa10e8 --- Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.IO.Test/DikeProfiles/DikeProfileLocationReaderTest.cs (.../DikeProfileLocationReaderTest.cs) (revision e71f7a8977226f7bdbc146c4e5aac1f13c39e3eb) +++ Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.IO.Test/DikeProfiles/DikeProfileLocationReaderTest.cs (.../DikeProfileLocationReaderTest.cs) (revision 5a421e7bb0b0c52d5d1d9ca20d495cd11bfa10e8) @@ -164,29 +164,44 @@ } [Test] - [TestCase("Voorlanden_12-2_EmptyId.shp", "ID")] - [TestCase("Voorlanden_12-2_EmptyX0.shp", "X0")] - public void GetDikeProfileLocations_FileWithEmptyEntryInColumn_ThrowCriticalFileReadException( - string fileName, string offendingColumnName) + public void GetDikeProfileLocations_FileWithNullId_ThrowCriticalFileReadException() { // Setup string invalidFilePath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.GrassCoverErosionInwards.IO, - Path.Combine("DikeProfiles", fileName)); + Path.Combine("DikeProfiles", "Voorlanden_12-2_EmptyId.shp")); using (var reader = new DikeProfileLocationReader(invalidFilePath)) { // Call TestDelegate call = () => reader.GetDikeProfileLocations(); // Assert - var expectedMessage = string.Format("Het bestand heeft een attribuut '{0}' zonder geldige waarde, welke vereist is om de locaties van de dijkprofielen in te lezen.", - offendingColumnName); + var expectedMessage = "De locatie parameter 'Id' heeft geen waarde."; string message = Assert.Throws(call).Message; Assert.AreEqual(expectedMessage, message); } } [Test] + public void GetDikeProfileLocations_FileWithNullX0_ThrowCriticalFileReadException() + { + // Setup + string invalidFilePath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.GrassCoverErosionInwards.IO, + Path.Combine("DikeProfiles", "Voorlanden_12-2_EmptyX0.shp")); + + using (var reader = new DikeProfileLocationReader(invalidFilePath)) + { + // Call + TestDelegate call = () => reader.GetDikeProfileLocations(); + + // Assert + var expectedMessage = "Het bestand heeft een attribuut 'X0' zonder geldige waarde, welke vereist is om de locaties van de dijkprofielen in te lezen."; + string message = Assert.Throws(call).Message; + Assert.AreEqual(expectedMessage, message); + } + } + + [Test] [TestCase("Voorlanden_12-2_IdWithSymbol.shp")] [TestCase("Voorlanden_12-2_IdWithWhitespace.shp")] public void GetDikeProfileLocations_FileWithIllegalCharactersInId_ThrowCriticalFileReadException(string fileName) @@ -201,7 +216,7 @@ 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."; + var expectedMessage = "De locatie parameter 'Id' bevat meer dan letters en cijfers."; string message = Assert.Throws(call).Message; Assert.AreEqual(expectedMessage, message); } Index: Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.IO.Test/DikeProfiles/DikeProfileLocationTest.cs =================================================================== diff -u -re71f7a8977226f7bdbc146c4e5aac1f13c39e3eb -r5a421e7bb0b0c52d5d1d9ca20d495cd11bfa10e8 --- Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.IO.Test/DikeProfiles/DikeProfileLocationTest.cs (.../DikeProfileLocationTest.cs) (revision e71f7a8977226f7bdbc146c4e5aac1f13c39e3eb) +++ Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.IO.Test/DikeProfiles/DikeProfileLocationTest.cs (.../DikeProfileLocationTest.cs) (revision 5a421e7bb0b0c52d5d1d9ca20d495cd11bfa10e8) @@ -19,6 +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 NUnit.Framework; using Ringtoets.GrassCoverErosionInwards.IO.DikeProfiles; @@ -55,5 +56,69 @@ Assert.IsInstanceOf(typeof(double), dikeProfileLocation.Offset); Assert.IsInstanceOf(typeof(Point2D), dikeProfileLocation.Point); } + + [Test] + public void Constructor_InitializedWithNullId_ThrownArgumentException() + { + // Setup + var referencePoint = new Point2D(2.2, 3.3); + + // Call + TestDelegate call = () => new DikeProfileLocation(null, "aNAME", 1.1, referencePoint); + + // Assert + var expectedMessage = "De locatie parameter 'Id' heeft geen waarde."; + string message = Assert.Throws(call).Message; + Assert.AreEqual(expectedMessage, message); + } + + [Test] + public void Constructor_InitializedWithNullPoint_ThrownArgumentException() + { + // Call + TestDelegate call = () => new DikeProfileLocation("anID", "aNAME", 1.1, null); + + // Assert + var expectedMessage = "De locatie heeft geen coördinaten."; + string message = Assert.Throws(call).Message; + Assert.AreEqual(expectedMessage, message); + } + + [Test] + [TestCase("a 1")] + [TestCase("a#1")] + [TestCase(" ")] + [TestCase("*&(%&$")] + public void Constructor_InitializedWithInvalidId_ThrownArgumentException(string id) + { + // Setup + var referencePoint = new Point2D(2.2, 3.3); + + // Call + TestDelegate call = () => new DikeProfileLocation(id, "aNAME", 1.1, referencePoint); + + // Assert + var expectedMessage = "De locatie parameter 'Id' bevat meer dan letters en cijfers."; + string message = Assert.Throws(call).Message; + Assert.AreEqual(expectedMessage, message); + } + + [Test] + [TestCase(double.NaN)] + [TestCase(double.PositiveInfinity)] + [TestCase(double.NegativeInfinity)] + public void Constructor_InitializedWithInvalidId_ThrownArgumentException(double x0) + { + // Setup + var referencePoint = new Point2D(2.2, 3.3); + + // Call + TestDelegate call = () => new DikeProfileLocation("anID", "aNAME", x0, referencePoint); + + // Assert + var expectedMessage = "De locatie parameter 'X0' bevat een ongeldig getal."; + string message = Assert.Throws(call).Message; + Assert.AreEqual(expectedMessage, message); + } } } \ No newline at end of file