public void SetCharacteristicPoints_DikeToesReversed_ThrowsImportedDataTransformException() { // Setup const string name = "Reversed dike toes"; var points = new CharacteristicPoints(name) { DikeToeAtPolder = new Point3D(3, 2, 5), DikeToeAtRiver = new Point3D(3.4, 3, 8), DitchDikeSide = new Point3D(4.4, 6, 8), BottomDitchDikeSide = new Point3D(5.1, 6, 6.5), BottomDitchPolderSide = new Point3D(8.5, 7.2, 4.2), DitchPolderSide = new Point3D(9.6, 7.5, 3.9) }; var surfaceLine = new PipingSurfaceLine(string.Empty); surfaceLine.SetGeometry(CharacteristicPointsToGeometry(points)); // Call TestDelegate test = () => surfaceLine.SetCharacteristicPoints(points); // Assert var exception = Assert.Throws <ImportedDataTransformException>(test); Assert.AreEqual($"Het uittredepunt moet landwaarts van het intredepunt liggen voor locatie '{name}'.", exception.Message); }
public void SetCharacteristicPoints_MandatoryPointNotOnSurfaceLine_ThrowsImportedDataTransformException( CharacteristicPoints points, Action <CharacteristicPoints, Point3D> setPoint, string pointDescription) { // Setup var surfaceLine = new MacroStabilityInwardsSurfaceLine(points.Name); surfaceLine.SetGeometry(CharacteristicPointsToGeometry(points)); var changedPoint = new Point3D(-1, -1, -1); setPoint(points, changedPoint); // Call TestDelegate test = () => surfaceLine.SetCharacteristicPoints(points); // Assert var exception = Assert.Throws <ImportedDataTransformException>(test); string message = $"Profielschematisatie '{points.Name}' kan niet gebruikt worden. " + $"De geometrie bevat geen punt op locatie {changedPoint} om als \'{pointDescription}\' in te stellen. " + "Dit karakteristieke punt is verplicht."; Assert.AreEqual(message, exception.Message); }
public void Constructor_WithName_ValuesAsExpected(string name) { // Call var location = new CharacteristicPoints(name); // Assert Assert.AreEqual(name, location.Name); }
private static IEnumerable <Point3D> CharacteristicPointsToGeometry(CharacteristicPoints points) { return(new[] { points.DikeToeAtRiver, points.DikeToeAtPolder, points.DitchDikeSide, points.BottomDitchDikeSide, points.BottomDitchPolderSide, points.DitchPolderSide }.Where(p => p != null)); }
public PipingSurfaceLine Transform(SurfaceLine surfaceLine, CharacteristicPoints characteristicPoints) { Point2D intersectionPoint = surfaceLine.GetSingleReferenceLineIntersection(referenceLine); var pipingSurfaceLine = new PipingSurfaceLine(surfaceLine.Name ?? string.Empty); pipingSurfaceLine.SetGeometry(surfaceLine.Points); pipingSurfaceLine.SetCharacteristicPoints(characteristicPoints); pipingSurfaceLine.ReferenceLineIntersectionWorldPoint = intersectionPoint; return(pipingSurfaceLine); }
public MacroStabilityInwardsSurfaceLine Transform(SurfaceLine surfaceLine, CharacteristicPoints characteristicPoints) { Point2D intersectionPoint = surfaceLine.GetSingleReferenceLineIntersection(referenceLine); var macroStabilityInwardsSurfaceLine = new MacroStabilityInwardsSurfaceLine(surfaceLine.Name); macroStabilityInwardsSurfaceLine.SetGeometry(surfaceLine.Points); macroStabilityInwardsSurfaceLine.SetCharacteristicPoints(characteristicPoints); macroStabilityInwardsSurfaceLine.ReferenceLineIntersectionWorldPoint = intersectionPoint; return(macroStabilityInwardsSurfaceLine); }
private static IEnumerable <Point3D> CharacteristicPointsToGeometry(CharacteristicPoints points) { return(new[] { points.DikeTopAtPolder, points.DikeTopAtRiver, points.ShoulderBaseInside, points.ShoulderTopInside, points.SurfaceLevelOutside, points.SurfaceLevelInside, points.DikeToeAtRiver, points.DikeToeAtPolder, points.DitchDikeSide, points.BottomDitchDikeSide, points.BottomDitchPolderSide, points.DitchPolderSide }.Where(p => p != null)); }
public void SetCharacteristicPoints_ValidSituations_PointsAreSet(CharacteristicPoints points) { // Setup var surfaceLine = new PipingSurfaceLine(string.Empty); surfaceLine.SetGeometry(CharacteristicPointsToGeometry(points)); // Call surfaceLine.SetCharacteristicPoints(points); // Assert Assert.AreEqual(points.DikeToeAtRiver, surfaceLine.DikeToeAtRiver); Assert.AreEqual(points.DikeToeAtPolder, surfaceLine.DikeToeAtPolder); Assert.AreEqual(points.DitchDikeSide, surfaceLine.DitchDikeSide); Assert.AreEqual(points.BottomDitchDikeSide, surfaceLine.BottomDitchDikeSide); Assert.AreEqual(points.BottomDitchPolderSide, surfaceLine.BottomDitchPolderSide); Assert.AreEqual(points.DitchPolderSide, surfaceLine.DitchPolderSide); }
public void Transform_DikeToePolderOnOrBeforeDikeToeRiver_ThrowsImportedDataTransformException(double xDikeToePolder) { // Setup var referenceLine = new ReferenceLine(); var transformer = new PipingSurfaceLineTransformer(referenceLine); const string locationName = "a location"; var random = new Random(21); double randomY = random.NextDouble(); double randomZ = random.NextDouble(); var surfaceLine = new SurfaceLine(); surfaceLine.SetGeometry(new[] { new Point3D(2.0, randomY, randomZ), new Point3D(3.0, randomY, randomZ), new Point3D(3.5, randomY, randomZ), new Point3D(4.0, randomY, randomZ) }); var characteristicPoints = new CharacteristicPoints(locationName) { DikeToeAtRiver = new Point3D(3.5, 4, randomZ), DikeToeAtPolder = new Point3D(xDikeToePolder, 4, randomZ) }; referenceLine.SetGeometry(new[] { new Point2D(3.2, randomY - 1), new Point2D(3.2, randomY + 1) }); // Call TestDelegate test = () => transformer.Transform(surfaceLine, characteristicPoints); // Assert string message = $"Het uittredepunt moet landwaarts van het intredepunt liggen voor locatie '{locationName}'."; var exception = Assert.Throws <ImportedDataTransformException>(test); Assert.AreEqual(message, exception.Message); }
public void ReadCharacteristicPointsLocation_OpenedValidFileWithHeaderAndTwoLocationsWhileAtTheEndOfFile_ReturnNull() { // Setup string path = Path.Combine(testDataPath, "2locations.krp.csv"); using (var reader = new CharacteristicPointsCsvReader(path)) { int locationsCount = reader.GetLocationsCount(); for (var i = 0; i < locationsCount; i++) { CharacteristicPoints characteristicPointsLocation = reader.ReadCharacteristicPointsLocation(); Assert.IsNotInstanceOf <IDisposable>(characteristicPointsLocation, "Fail Fast: Disposal logic required to be implemented in test."); Assert.IsNotNull(characteristicPointsLocation); } // Call CharacteristicPoints result = reader.ReadCharacteristicPointsLocation(); // Assert Assert.IsNull(result); } }
public void SetCharacteristicPoints_ValidSituations_PointsAreSet(CharacteristicPoints points) { // Setup var surfaceLine = new MacroStabilityInwardsSurfaceLine(string.Empty); surfaceLine.SetGeometry(CharacteristicPointsToGeometry(points)); // Call surfaceLine.SetCharacteristicPoints(points); // Assert Assert.AreEqual(points.DikeTopAtPolder, surfaceLine.DikeTopAtPolder); Assert.AreEqual(points.DikeTopAtRiver, surfaceLine.DikeTopAtRiver); Assert.AreEqual(points.ShoulderBaseInside, surfaceLine.ShoulderBaseInside); Assert.AreEqual(points.ShoulderTopInside, surfaceLine.ShoulderTopInside); Assert.AreEqual(points.SurfaceLevelOutside, surfaceLine.SurfaceLevelOutside); Assert.AreEqual(points.SurfaceLevelInside, surfaceLine.SurfaceLevelInside); Assert.AreEqual(points.DikeToeAtRiver, surfaceLine.DikeToeAtRiver); Assert.AreEqual(points.DikeToeAtPolder, surfaceLine.DikeToeAtPolder); Assert.AreEqual(points.DitchDikeSide, surfaceLine.DitchDikeSide); Assert.AreEqual(points.BottomDitchDikeSide, surfaceLine.BottomDitchDikeSide); Assert.AreEqual(points.BottomDitchPolderSide, surfaceLine.BottomDitchPolderSide); Assert.AreEqual(points.DitchPolderSide, surfaceLine.DitchPolderSide); }
private void ReadCharacteristicPointsLocation_OpenedValidFileWithHeaderAndTwoCharacteristicPointsLocations_ReturnCreatedCharacteristicPointsLocation(string fileName) { // Setup string path = Path.Combine(testDataPath, fileName); // Precondition: Assert.IsTrue(File.Exists(path)); using (var reader = new CharacteristicPointsCsvReader(path)) { // Call CharacteristicPoints location1 = reader.ReadCharacteristicPointsLocation(); CharacteristicPoints location2 = reader.ReadCharacteristicPointsLocation(); // Assert #region 1st location Assert.AreEqual("Rotterdam1", location1.Name); Assert.AreEqual(new Point3D(100, 0, -0.63), location1.SurfaceLevelInside); Assert.AreEqual(new Point3D(60.83, 0, -0.57), location1.DitchPolderSide); Assert.AreEqual(new Point3D(59.36, 0, -1.87), location1.BottomDitchPolderSide); Assert.AreEqual(new Point3D(57.99, 0, -1.9), location1.BottomDitchDikeSide); Assert.AreEqual(new Point3D(55.37, 0, -0.31), location1.DitchDikeSide); Assert.AreEqual(new Point3D(55.37, 0, -0.31), location1.DikeToeAtPolder); Assert.IsNull(location1.ShoulderTopInside); Assert.IsNull(location1.ShoulderBaseInside); Assert.AreEqual(new Point3D(40.17, 0, 2.63), location1.DikeTopAtPolder); Assert.AreEqual(new Point3D(40.85, 0, 2.44), location1.TrafficLoadInside); Assert.AreEqual(new Point3D(38.35, 0, 2.623), location1.TrafficLoadOutside); Assert.AreEqual(new Point3D(35.95, 0, 2.61), location1.DikeTopAtRiver); Assert.IsNull(location1.ShoulderBaseOutside); Assert.IsNull(location1.ShoulderTopOutside); Assert.AreEqual(new Point3D(29.1, 0, -0.2), location1.DikeToeAtRiver); Assert.AreEqual(new Point3D(0, 0, -0.71), location1.SurfaceLevelOutside); Assert.AreEqual(new Point3D(23.703, 0, -1.5), location1.DikeTableHeight); Assert.IsNull(location1.InsertRiverChannel); Assert.IsNull(location1.BottomRiverChannel); #endregion #region 2nd location Assert.AreEqual("Amsterdam1", location2.Name); Assert.AreEqual(new Point3D(100, 0, -0.47), location2.SurfaceLevelInside); Assert.AreEqual(new Point3D(58.42, 0, -0.6), location2.DitchPolderSide); Assert.IsNull(location2.BottomDitchPolderSide); Assert.IsNull(location2.BottomDitchDikeSide); Assert.AreEqual(new Point3D(56.2, 0, -1.98), location2.DitchDikeSide); Assert.AreEqual(new Point3D(56.2, 0, -1.98), location2.DikeToeAtPolder); Assert.AreEqual(new Point3D(53.48, 0, -0.49), location2.ShoulderTopInside); Assert.AreEqual(new Point3D(53.48, 0, -0.49), location2.ShoulderBaseInside); Assert.AreEqual(new Point3D(38.17, 0, 3.04), location2.DikeTopAtPolder); Assert.AreEqual(new Point3D(37.73, 0, 3.13), location2.TrafficLoadInside); Assert.AreEqual(new Point3D(35.23, 0, 3.253), location2.TrafficLoadOutside); Assert.AreEqual(new Point3D(32.77, 0, 3.11), location2.DikeTopAtRiver); Assert.AreEqual(new Point3D(19.61, 0, -0.05), location2.ShoulderBaseOutside); Assert.AreEqual(new Point3D(0, 0, -0.33), location2.ShoulderTopOutside); Assert.IsNull(location2.DikeToeAtRiver); Assert.IsNull(location2.SurfaceLevelOutside); Assert.AreEqual(new Point3D(17.32, 0, -1.52), location2.DikeTableHeight); Assert.IsNull(location2.InsertRiverChannel); Assert.IsNull(location2.BottomRiverChannel); #endregion } }
public void Transform_MandatoryCharacteristicPointNotOnSurfaceLine_ThrowsImportedDataTransformException( Action <CharacteristicPoints, Point3D> pointChange, Func <MacroStabilityInwardsSurfaceLine, Point3D> pointWhichIsNull, string changedCharacteristicPointName) { // Setup var referenceLine = new ReferenceLine(); var transformer = new MacroStabilityInwardsSurfaceLineTransformer(referenceLine); const string locationName = "a location"; var random = new Random(21); double randomZ = random.NextDouble(); var surfaceLine = new SurfaceLine { Name = locationName }; var point1 = new Point3D(3.5, 4.8, randomZ); var point2 = new Point3D(7.2, 9.3, randomZ); var point3 = new Point3D(12.0, 5.6, randomZ); var notOnSurfaceLinePoint = new Point3D(7.3, 9.3, randomZ); surfaceLine.SetGeometry(new[] { point1, point2, point3 }); var characteristicPoints = new CharacteristicPoints(locationName) { SurfaceLevelOutside = point2, DikeToeAtRiver = point2, DikeTopAtPolder = point2, DikeTopAtRiver = point2, ShoulderBaseInside = point3, ShoulderTopInside = point3, BottomDitchDikeSide = point3, BottomDitchPolderSide = point3, DitchPolderSide = point3, DitchDikeSide = point3, DikeToeAtPolder = point3, SurfaceLevelInside = point3 }; pointChange(characteristicPoints, notOnSurfaceLinePoint); referenceLine.SetGeometry(new[] { new Point2D(5.6, 2.5), new Point2D(6.8, 15) }); // Call TestDelegate test = () => transformer.Transform(surfaceLine, characteristicPoints); // Assert var exception = Assert.Throws <ImportedDataTransformException>(test); string message = $"Profielschematisatie '{locationName}' kan niet gebruikt worden. " + $"De geometrie bevat geen punt op locatie {notOnSurfaceLinePoint} om als \'{changedCharacteristicPointName}\' in te stellen. " + "Dit karakteristieke punt is verplicht."; Assert.AreEqual(message, exception.Message); }
/// <summary> /// Tries to set the relevant characteristic points from the <paramref name="characteristicPoints"/> /// on the <paramref name="surfaceLine"/>. /// </summary> /// <param name="surfaceLine">The surface line to set the characteristic points for.</param> /// <param name="characteristicPoints">The characteristic points to set, if the collection is valid.</param> /// <exception cref="ArgumentNullException">Thrown when <paramref name="surfaceLine"/> is <c>null</c>.</exception> /// <exception cref="ImportedDataTransformException">Thrown when <paramref name="characteristicPoints"/> defines /// a dike toe at polder side in front of the dike toe at river side.</exception> public static void SetCharacteristicPoints(this PipingSurfaceLine surfaceLine, CharacteristicPoints characteristicPoints) { if (surfaceLine == null) { throw new ArgumentNullException(nameof(surfaceLine)); } if (characteristicPoints == null) { return; } surfaceLine.ValidateDikeToesInOrder(characteristicPoints); surfaceLine.TrySetDikeToeAtRiver(characteristicPoints.DikeToeAtRiver); surfaceLine.TrySetDitchDikeSide(characteristicPoints.DitchDikeSide); surfaceLine.TrySetBottomDitchDikeSide(characteristicPoints.BottomDitchDikeSide); surfaceLine.TrySetBottomDitchPolderSide(characteristicPoints.BottomDitchPolderSide); surfaceLine.TrySetDitchPolderSide(characteristicPoints.DitchPolderSide); surfaceLine.TrySetDikeToeAtPolder(characteristicPoints.DikeToeAtPolder); }
/// <summary> /// Validates whether or not the dike toes are in the right order. /// </summary> /// <param name="surfaceLine">The surface line.</param> /// <param name="characteristicPoints">The characteristic points (possibly) containing the dike toes.</param> /// <exception cref="ImportedDataTransformException">Thrown when the dike toes are not in the right order.</exception> private static void ValidateDikeToesInOrder(this PipingSurfaceLine surfaceLine, CharacteristicPoints characteristicPoints) { if (characteristicPoints.DikeToeAtRiver != null && characteristicPoints.DikeToeAtPolder != null) { Point2D localDikeToeAtRiver = surfaceLine.GetLocalPointFromGeometry(characteristicPoints.DikeToeAtRiver); Point2D localDikeToeAtPolder = surfaceLine.GetLocalPointFromGeometry(characteristicPoints.DikeToeAtPolder); if (localDikeToeAtPolder.X <= localDikeToeAtRiver.X) { string message = string.Format(Resources.SurfaceLinesCsvImporter_CheckCharacteristicPoints_EntryPointL_greater_or_equal_to_ExitPointL_for_0_, characteristicPoints.Name); throw new ImportedDataTransformException(message); } } }
public void SetCharacteristicPoints_UndefinedMandatoryPoint_ThrowsImportedDataTransformException(CharacteristicPoints points, string pointDescription) { // Setup var surfaceLine = new MacroStabilityInwardsSurfaceLine(points.Name); surfaceLine.SetGeometry(CharacteristicPointsToGeometry(points)); // Call TestDelegate test = () => surfaceLine.SetCharacteristicPoints(points); // Assert var exception = Assert.Throws <ImportedDataTransformException>(test); string message = $"Profielschematisatie '{points.Name}' kan niet gebruikt worden. Karakteristiek punt \'{pointDescription}\' is niet gedefiniëerd. Dit karakteristieke punt is verplicht."; Assert.AreEqual(message, exception.Message); }
/// <summary> /// Tries to set the relevant characteristic points from the <paramref name="characteristicPoints"/> /// on the <paramref name="surfaceLine"/>. /// </summary> /// <param name="surfaceLine">The surface line to set the characteristic points for.</param> /// <param name="characteristicPoints">The characteristic points to set, if the collection is valid.</param> /// <exception cref="ArgumentNullException">Thrown when <paramref name="surfaceLine"/> is <c>null</c>.</exception> /// <exception cref="ImportedDataTransformException">Thrown when a mandatory characteristic point is not /// present or not on the given <paramref name="surfaceLine"/>.</exception> public static void SetCharacteristicPoints(this MacroStabilityInwardsSurfaceLine surfaceLine, CharacteristicPoints characteristicPoints) { if (surfaceLine == null) { throw new ArgumentNullException(nameof(surfaceLine)); } if (characteristicPoints == null) { throw new ImportedDataTransformException($"Karakteristieke punten definitie voor profielschematisatie '{surfaceLine.Name}' is verplicht."); } surfaceLine.TrySetSurfaceLevelOutside(characteristicPoints.SurfaceLevelOutside); surfaceLine.TrySetDikeToeAtRiver(characteristicPoints.DikeToeAtRiver); surfaceLine.TrySetDikeTopAtPolder(characteristicPoints.DikeTopAtPolder); surfaceLine.TrySetDikeTopAtRiver(characteristicPoints.DikeTopAtRiver); surfaceLine.TrySetDikeToeAtPolder(characteristicPoints.DikeToeAtPolder); surfaceLine.TrySetSurfaceLevelInside(characteristicPoints.SurfaceLevelInside); surfaceLine.TrySetShoulderBaseInside(characteristicPoints.ShoulderBaseInside); surfaceLine.TrySetShoulderTopInside(characteristicPoints.ShoulderTopInside); surfaceLine.TrySetDitchDikeSide(characteristicPoints.DitchDikeSide); surfaceLine.TrySetBottomDitchDikeSide(characteristicPoints.BottomDitchDikeSide); surfaceLine.TrySetBottomDitchPolderSide(characteristicPoints.BottomDitchPolderSide); surfaceLine.TrySetDitchPolderSide(characteristicPoints.DitchPolderSide); }
public void Transform_CharacteristicPointNotOnSurfaceLine_LogErrorAndReturnSurfaceLineWithoutCharacteristicPointSet(Action <CharacteristicPoints, Point3D> pointChange, Func <PipingSurfaceLine, Point3D> pointWhichIsNull, string changedCharacteristicPointName) { // Setup var referenceLine = new ReferenceLine(); var transformer = new PipingSurfaceLineTransformer(referenceLine); const string locationName = "a location"; var random = new Random(21); double randomZ = random.NextDouble(); var surfaceLine = new SurfaceLine { Name = locationName }; var point1 = new Point3D(3.5, 4.8, randomZ); var point2 = new Point3D(7.2, 9.3, randomZ); var point3 = new Point3D(12.0, 5.6, randomZ); var notOnSurfaceLinePoint = new Point3D(7.3, 9.3, randomZ); surfaceLine.SetGeometry(new[] { point1, point2, point3 }); var characteristicPoints = new CharacteristicPoints(locationName) { DikeToeAtRiver = point2, BottomDitchDikeSide = point2, BottomDitchPolderSide = point2, DitchPolderSide = point2, DitchDikeSide = point3, DikeToeAtPolder = point3 }; pointChange(characteristicPoints, notOnSurfaceLinePoint); referenceLine.SetGeometry(new[] { new Point2D(5.6, 2.5), new Point2D(6.8, 15) }); PipingSurfaceLine result = null; // Call Action call = () => result = transformer.Transform(surfaceLine, characteristicPoints); // Assert string message = $"Karakteristiek punt van profielschematisatie '{locationName}' is overgeslagen. De geometrie bevat geen punt op locatie {notOnSurfaceLinePoint} om als '{changedCharacteristicPointName}' in te stellen."; TestHelper.AssertLogMessageWithLevelIsGenerated(call, Tuple.Create(message, LogLevelConstant.Error)); CollectionAssert.AreEqual(new[] { point1, point2, point3 }, result.Points); Assert.IsNull(pointWhichIsNull(result)); Assert.AreEqual(1, new Collection <Point3D> { result.DikeToeAtRiver, result.BottomDitchDikeSide, result.BottomDitchPolderSide, result.DitchPolderSide, result.DitchDikeSide, result.DikeToeAtPolder }.Count(p => p == null)); }