public void GetNextStructure_ShapefileAttributeKWKNAAMSometimesNullOrWhitespace_GetSixStructuresWithCorrectAttributes() { // Setup string validFilePath = TestHelper.GetTestDataPath(TestDataPath.Riskeer.Common.IO, Path.Combine("Structures", "StructuresSomeWithEmptyKWKNAAM", "Kunstwerken.shp")); var structures = new List <StructureLocation>(); using (var reader = new StructureLocationReader(validFilePath)) { // Call int count = reader.GetStructureCount; for (var i = 0; i < count; i++) { structures.Add(reader.GetNextStructureLocation()); } // Assert Assert.AreEqual(6, structures.Count); Assert.AreEqual("Coupure Den Oever (90k1)", structures[0].Name); Assert.AreEqual("KUNST2", structures[1].Name); Assert.AreEqual("Gemaal Lely (93k4)", structures[2].Name); Assert.AreEqual("Gemaal de Stontele (94k1)", structures[3].Name); Assert.AreEqual("KUNST5", structures[4].Name); Assert.AreEqual("KUNST6", structures[5].Name); } }
public void GetNextStructure_ShapefileWithoutAttributeKWKNAAM_NamesEqualAttributeKWKIDENT() { // Setup string validFilePath = TestHelper.GetTestDataPath(TestDataPath.Riskeer.Common.IO, Path.Combine("Structures", "StructuresWithoutKWKNAAM", "Kunstwerken.shp")); var structures = new List <StructureLocation>(); using (var reader = new StructureLocationReader(validFilePath)) { // Call int count = reader.GetStructureCount; for (var i = 0; i < count; i++) { structures.Add(reader.GetNextStructureLocation()); } // Assert Assert.AreEqual(structures[0].Id, structures[0].Name); Assert.AreEqual(structures[1].Id, structures[1].Name); Assert.AreEqual(structures[2].Id, structures[2].Name); Assert.AreEqual(structures[3].Id, structures[3].Name); Assert.AreEqual(structures[4].Id, structures[4].Name); Assert.AreEqual(structures[5].Id, structures[5].Name); } }
public void GetNextStructure_FileWithSixStructures_GetSixStructuresWithCorrectAttributes() { // Setup string validFilePath = TestHelper.GetTestDataPath(TestDataPath.Riskeer.Common.IO, Path.Combine("Structures", "CorrectFiles", "Kunstwerken.shp")); var structures = new List <StructureLocation>(); using (var reader = new StructureLocationReader(validFilePath)) { // Call int count = reader.GetStructureCount; for (var i = 0; i < count; i++) { structures.Add(reader.GetNextStructureLocation()); } // Assert Assert.AreEqual(6, structures.Count); Assert.AreEqual("KUNST1", structures[0].Id); Assert.AreEqual("KUNST2", structures[1].Id); Assert.AreEqual("KUNST3", structures[2].Id); Assert.AreEqual("KUNST4", structures[3].Id); Assert.AreEqual("KUNST5", structures[4].Id); Assert.AreEqual("KUNST6", structures[5].Id); Assert.AreEqual("Coupure Den Oever (90k1)", structures[0].Name); Assert.AreEqual("Gemaal Leemans (93k3)", structures[1].Name); Assert.AreEqual("Gemaal Lely (93k4)", structures[2].Name); Assert.AreEqual("Gemaal de Stontele (94k1)", structures[3].Name); Assert.AreEqual("Stontelerkeersluis (93k1)", structures[4].Name); Assert.AreEqual("Stontelerschutsluis (93k2)", structures[5].Name); Assert.IsInstanceOf(typeof(Point2D), structures[0].Point); Assert.IsInstanceOf(typeof(Point2D), structures[1].Point); Assert.IsInstanceOf(typeof(Point2D), structures[2].Point); Assert.IsInstanceOf(typeof(Point2D), structures[3].Point); Assert.IsInstanceOf(typeof(Point2D), structures[4].Point); Assert.IsInstanceOf(typeof(Point2D), structures[5].Point); Assert.AreEqual(131144.094, structures[0].Point.X); Assert.AreEqual(131538.705, structures[1].Point.X); Assert.AreEqual(135878.442, structures[2].Point.X); Assert.AreEqual(131225.017, structures[3].Point.X); Assert.AreEqual(131270.38, structures[4].Point.X); Assert.AreEqual(131507.119, structures[5].Point.X); Assert.AreEqual(549979.893, structures[0].Point.Y); Assert.AreEqual(548316.752, structures[1].Point.Y); Assert.AreEqual(532149.859, structures[2].Point.Y); Assert.AreEqual(548395.948, structures[3].Point.Y); Assert.AreEqual(548367.462, structures[4].Point.Y); Assert.AreEqual(548322.951, structures[5].Point.Y); } }
public void GetNextStructure_ShapefileAttributeKWKIDENTValuesAreNull_ThrowLineParseException() { // Setup string validFilePath = TestHelper.GetTestDataPath(TestDataPath.Riskeer.Common.IO, Path.Combine("Structures", "StructuresWithNullKWKIDENT", "Kunstwerken.shp")); using (var reader = new StructureLocationReader(validFilePath)) { // Call TestDelegate call = () => reader.GetNextStructureLocation(); // Assert var exception = Assert.Throws <LineParseException>(call); Assert.AreEqual("Het kunstwerk heeft geen geldige waarde voor attribuut 'KWKIDENT'.", exception.Message); } }
/// <summary> /// Get the next <see cref="StructureLocation"/> from <paramref name="structureLocationReader"/> /// and add to <paramref name="structureLocations"/> in case it is close enough to the <see cref="ReferenceLine"/>. /// </summary> /// <param name="structureLocationReader">Reader reading <see cref="StructureLocation"/> objects from a shapefile.</param> /// <param name="structureLocations">Collection of <see cref="StructureLocation"/> objects /// to which the new <see cref="StructureLocation"/> is to be added.</param> /// <exception cref="CriticalFileReadException">Thrown when either: /// <list type="bullet"> /// <item>The <paramref name="structureLocationReader"/> reads multiple structures for a structure.</item> /// <item>A structure read from the <paramref name="structureLocationReader"/> is not on the reference line.</item> /// </list></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> /// </list></exception> private void AddNextStructureLocation(StructureLocationReader structureLocationReader, Collection <StructureLocation> structureLocations) { StructureLocation structureLocation = structureLocationReader.GetNextStructureLocation(); double distanceToReferenceLine = GetDistanceToReferenceLine(structureLocation.Point); if (distanceToReferenceLine > 1.0) { string message = string.Format(Resources.StructuresImporter_AddNextStructureLocation_Location_0_outside_referenceline, structureLocation.Id); throw new CriticalFileReadException(message); } if (structureLocations.Any(dpl => dpl.Id.Equals(structureLocation.Id))) { string message = string.Format(Resources.StructuresImporter_AddNextStructureLocation_Location_with_kwkident_0_already_read, structureLocation.Id); throw new CriticalFileReadException(message); } structureLocations.Add(structureLocation); }