public void GetNextProfileLocation_FileWithBinaryX0_GetLocations() { // Setup string validFilePath = TestHelper.GetTestDataPath(TestDataPath.Riskeer.Common.IO, Path.Combine("DikeProfiles", "BinaryX0", "PROF63_GE_D0.shp")); var dikeProfileLocations = new List <ProfileLocation>(); using (var reader = new ProfileLocationReader(validFilePath)) { int count = reader.GetLocationCount; for (var i = 0; i < count; i++) { // Call dikeProfileLocations.Add(reader.GetNextProfileLocation()); } // Assert Assert.AreEqual(160089.54199999946, dikeProfileLocations[0].Point.X); Assert.AreEqual(160618.05799999836, dikeProfileLocations[1].Point.X); Assert.AreEqual(582257.47199999972, dikeProfileLocations[0].Point.Y); Assert.AreEqual(582857.71500000195, dikeProfileLocations[1].Point.Y); Assert.AreEqual(42.0, dikeProfileLocations[0].Offset); Assert.AreEqual(44.420000000000002, dikeProfileLocations[1].Offset); } }
public void GetNextProfileLocation_FileWithFivePoints_GetFivePoint2DsWithCorrectCoordinates() { // Setup string validFilePath = TestHelper.GetTestDataPath(TestDataPath.Riskeer.Common.IO, Path.Combine("DikeProfiles", "Voorlanden 12-2.shp")); var dikeProfileLocations = new List <ProfileLocation>(); using (var reader = new ProfileLocationReader(validFilePath)) { int count = reader.GetLocationCount; for (var i = 0; i < count; i++) { // Call dikeProfileLocations.Add(reader.GetNextProfileLocation()); } // Assert Assert.AreEqual(131223.21400000341, dikeProfileLocations[0].Point.X); Assert.AreEqual(133854.31200000079, dikeProfileLocations[1].Point.X); Assert.AreEqual(135561.0960000027, dikeProfileLocations[2].Point.X); Assert.AreEqual(136432.12250000238, dikeProfileLocations[3].Point.X); Assert.AreEqual(136039.49100000039, dikeProfileLocations[4].Point.X); Assert.AreEqual(548393.43800000288, dikeProfileLocations[0].Point.Y); Assert.AreEqual(545323.13749999879, dikeProfileLocations[1].Point.Y); Assert.AreEqual(541920.34149999847, dikeProfileLocations[2].Point.Y); Assert.AreEqual(538235.26300000318, dikeProfileLocations[3].Point.Y); Assert.AreEqual(533920.28050000477, dikeProfileLocations[4].Point.Y); } }
public void Constructor_ValidFilePath_ExpectedValues() { // Setup string validFilePath = TestHelper.GetTestDataPath(TestDataPath.Riskeer.Common.IO, Path.Combine("DikeProfiles", "Voorlanden 12-2.shp")); // Call using (var reader = new ProfileLocationReader(validFilePath)) { // Assert Assert.IsInstanceOf <IDisposable>(reader); } }
public void GetLocationCount_FileWithFivePoints_GetFive() { // Setup string validFilePath = TestHelper.GetTestDataPath(TestDataPath.Riskeer.Common.IO, Path.Combine("DikeProfiles", "Voorlanden 12-2.shp")); using (var reader = new ProfileLocationReader(validFilePath)) { // Call int count = reader.GetLocationCount; // Assert Assert.AreEqual(5, count); } }
public void GetNextProfileLocation_FileWithInvalidFormattedBinaryX0_ThrowLineParseException() { // Setup string validFilePath = TestHelper.GetTestDataPath(TestDataPath.Riskeer.Common.IO, Path.Combine("DikeProfiles", "InvalidBinaryX0_InvalidFormat", "PROF63_GE_D0.shp")); using (var reader = new ProfileLocationReader(validFilePath)) { // Call TestDelegate call = () => reader.GetNextProfileLocation(); // Assert var exception = Assert.Throws <LineParseException>(call); Assert.AreEqual("Het profiel heeft geen geldige waarde voor attribuut 'X0'.", exception.Message); Assert.IsInstanceOf <FormatException>(exception.InnerException); } }
public void GetNextProfileLocation_FileWithIllegalCharactersInId_ThrowCriticalFileReadException(string fileName) { // Setup string invalidFilePath = TestHelper.GetTestDataPath(TestDataPath.Riskeer.Common.IO, Path.Combine("DikeProfiles", fileName)); using (var reader = new ProfileLocationReader(invalidFilePath)) { // Call TestDelegate call = () => reader.GetNextProfileLocation(); // Assert const string expectedMessage = "De locatie parameter 'ID' mag uitsluitend uit letters en cijfers bestaan."; string message = Assert.Throws <LineParseException>(call).Message; Assert.AreEqual(expectedMessage, message); } }
public void GetNextProfileLocation_FileWithNullX0_ThrowCriticalFileReadException() { // Setup string invalidFilePath = TestHelper.GetTestDataPath(TestDataPath.Riskeer.Common.IO, Path.Combine("DikeProfiles", "Voorlanden_12-2_EmptyX0.shp")); using (var reader = new ProfileLocationReader(invalidFilePath)) { // Call TestDelegate call = () => reader.GetNextProfileLocation(); // Assert const string expectedMessage = "Het profiel heeft geen geldige waarde voor attribuut 'X0'."; string message = Assert.Throws <LineParseException>(call).Message; Assert.AreEqual(expectedMessage, message); } }
/// <summary> /// Get the next <see cref="ProfileLocation"/> from <paramref name="profileLocationReader"/> /// and add to <paramref name="profileLocations"/> in case it is close enough to the <see cref="ReferenceLine"/>. /// </summary> /// <param name="profileLocationReader">Reader reading <see cref="ProfileLocation"/> objects from a shapefile.</param> /// <param name="profileLocations">Collection of <see cref="ProfileLocation"/> objects /// to which the new <see cref="ProfileLocation"/> is to be added.</param> /// <exception cref="CriticalFileReadException">Thrown when the <paramref name="profileLocationReader"/> reads /// multiple locations for a profile.</exception> /// <exception cref="LineParseException">Thrown when either: /// <list type="bullet"> /// <item>The shapefile misses a value for a required attribute.</item> /// <item>The shapefile has an attribute whose type is incorrect.</item> /// <item>The read <see cref="ProfileLocation"/> is outside the reference line.</item> /// </list></exception> private void AddNextProfileLocation(ProfileLocationReader profileLocationReader, Collection <ProfileLocation> profileLocations) { ProfileLocation profileLocation = profileLocationReader.GetNextProfileLocation(); double distanceToReferenceLine = GetDistanceToReferenceLine(profileLocation.Point); if (distanceToReferenceLine > 1.0) { throw new LineParseException(string.Format(Resources.ProfilesImporter_AddNextProfileLocation_Location_with_id_0_outside_referenceline, profileLocation.Id)); } if (profileLocations.Any(dpl => dpl.Id.Equals(profileLocation.Id))) { string message = string.Format(Resources.ProfilesImporter_AddNextProfileLocation_Location_with_id_0_already_read, profileLocation.Id); throw new CriticalFileReadException(message); } profileLocations.Add(profileLocation); }
public void GetNextProfileLocation_FileWithNullAsNameAttribute_GetLocations() { // Setup string invalidFilePath = TestHelper.GetTestDataPath(TestDataPath.Riskeer.Common.IO, Path.Combine("DikeProfiles", "Voorlanden_12-2_EmptyName.shp")); var dikeProfileLocations = new List <ProfileLocation>(); using (var reader = new ProfileLocationReader(invalidFilePath)) { int count = reader.GetLocationCount; for (var i = 0; i < count; i++) { // Call dikeProfileLocations.Add(reader.GetNextProfileLocation()); } // Assert Assert.AreEqual(5, dikeProfileLocations.Count); } }
private ReadResult <ProfileLocation> ReadProfileLocations() { NotifyProgress(Resources.ProfilesImporter_ReadProfileLocations_reading_profilelocations, 1, 1); try { using (var profileLocationReader = new ProfileLocationReader(FilePath)) { return(GetProfileLocationReadResult(profileLocationReader)); } } catch (CriticalFileReadException exception) { Log.Error(exception.Message); } catch (ArgumentException exception) { Log.Error(exception.Message); } return(new ReadResult <ProfileLocation>(true)); }
public void GetNextProfileLocation_FileWithNLocations_GetNDikeProfileLocations( string fileName, int expectedNumberOfDikeProfileLocations) { // Setup string validFilePath = TestHelper.GetTestDataPath(TestDataPath.Riskeer.Common.IO, Path.Combine("DikeProfiles", fileName)); var dikeProfileLocations = new List <ProfileLocation>(); using (var reader = new ProfileLocationReader(validFilePath)) { // Call int count = reader.GetLocationCount; for (var i = 0; i < count; i++) { dikeProfileLocations.Add(reader.GetNextProfileLocation()); } // Assert Assert.AreEqual(expectedNumberOfDikeProfileLocations, dikeProfileLocations.Count); } }
private ReadResult <ProfileLocation> GetProfileLocationReadResult(ProfileLocationReader profileLocationReader) { var profileLocations = new Collection <ProfileLocation>(); int totalNumberOfSteps = profileLocationReader.GetLocationCount; for (var i = 0; i < totalNumberOfSteps; i++) { if (Canceled) { return(new ReadResult <ProfileLocation>(false)); } try { NotifyProgress(Resources.ProfilesImporter_GetProfileLocationReadResult_reading_profilelocation, i + 1, totalNumberOfSteps); AddNextProfileLocation(profileLocationReader, profileLocations); } catch (LineParseException exception) { string message = string.Format( Resources.ProfilesImporter_GetProfileLocationReadResult_Error_reading_Profile_LineNumber_0_Error_1, i + 1, exception.Message); Log.Error(message, exception); return(new ReadResult <ProfileLocation>(true)); } catch (CriticalFileReadException exception) { Log.Error(exception.Message); return(new ReadResult <ProfileLocation>(true)); } } return(new ReadResult <ProfileLocation>(false) { Items = profileLocations }); }
public void GetNextProfileLocation_FileWithFivePoints_GetFiveLocationsWithPoint2D() { // Setup string validFilePath = TestHelper.GetTestDataPath(TestDataPath.Riskeer.Common.IO, Path.Combine("DikeProfiles", "Voorlanden 12-2.shp")); var dikeProfileLocations = new List <ProfileLocation>(); using (var reader = new ProfileLocationReader(validFilePath)) { int count = reader.GetLocationCount; for (var i = 0; i < count; i++) { // Call dikeProfileLocations.Add(reader.GetNextProfileLocation()); } // Assert Assert.IsInstanceOf(typeof(Point2D), dikeProfileLocations[0].Point); Assert.IsInstanceOf(typeof(Point2D), dikeProfileLocations[1].Point); Assert.IsInstanceOf(typeof(Point2D), dikeProfileLocations[2].Point); Assert.IsInstanceOf(typeof(Point2D), dikeProfileLocations[3].Point); Assert.IsInstanceOf(typeof(Point2D), dikeProfileLocations[4].Point); } }
public void GetNextProfileLocation_FileWithFivePoints_GetFiveLocationsWithCorrectAtrributes() { // Setup string validFilePath = TestHelper.GetTestDataPath(TestDataPath.Riskeer.Common.IO, Path.Combine("DikeProfiles", "Voorlanden 12-2.shp")); var dikeProfileLocations = new List <ProfileLocation>(); using (var reader = new ProfileLocationReader(validFilePath)) { int count = reader.GetLocationCount; for (var i = 0; i < count; i++) { // Call dikeProfileLocations.Add(reader.GetNextProfileLocation()); } // Assert Assert.AreEqual("profiel001", dikeProfileLocations[0].Id); Assert.AreEqual("profiel002", dikeProfileLocations[1].Id); Assert.AreEqual("profiel003", dikeProfileLocations[2].Id); Assert.AreEqual("profiel004", dikeProfileLocations[3].Id); Assert.AreEqual("profiel005", dikeProfileLocations[4].Id); Assert.AreEqual("profiel001", dikeProfileLocations[0].Name); Assert.AreEqual("profiel002", dikeProfileLocations[1].Name); Assert.AreEqual("profiel003", dikeProfileLocations[2].Name); Assert.AreEqual("profiel004", dikeProfileLocations[3].Name); Assert.AreEqual("profiel005", dikeProfileLocations[4].Name); Assert.AreEqual(-10.61273321, dikeProfileLocations[0].Offset); Assert.AreEqual(-9.4408575, dikeProfileLocations[1].Offset); Assert.AreEqual(8.25860742, dikeProfileLocations[2].Offset); Assert.AreEqual(-17.93475471, dikeProfileLocations[3].Offset); Assert.AreEqual(15.56165507, dikeProfileLocations[4].Offset); } }