Index: Ringtoets/Common/src/Ringtoets.Common.Data/DikeProfiles/ForeshoreProfile.cs =================================================================== diff -u -rb3b6c13cf736c134476b3db34281332d01ca86b1 -r76c82f11791024d9a22f40d0f918cd2b9b13d2ef --- Ringtoets/Common/src/Ringtoets.Common.Data/DikeProfiles/ForeshoreProfile.cs (.../ForeshoreProfile.cs) (revision b3b6c13cf736c134476b3db34281332d01ca86b1) +++ Ringtoets/Common/src/Ringtoets.Common.Data/DikeProfiles/ForeshoreProfile.cs (.../ForeshoreProfile.cs) (revision 76c82f11791024d9a22f40d0f918cd2b9b13d2ef) @@ -82,28 +82,28 @@ /// /// Gets the ID of the foreshore profile. /// - public string Id { get; } + public string Id { get; private set; } /// /// Gets the name of the foreshore profile. /// - public string Name { get; } + public string Name { get; private set; } /// /// Gets the reference point in world coordinates corresponding to the local coordinate . /// - public Point2D WorldReferencePoint { get; } + public Point2D WorldReferencePoint { get; private set; } /// /// Gets the local x-coordinate corresponding to the world reference point . /// - public double X0 { get; } + public double X0 { get; private set; } /// /// Gets the orientation of the foreshore profile geometry with respect to North /// in degrees. A positive value equals a clockwise rotation. /// - public RoundedDouble Orientation { get; } + public RoundedDouble Orientation { get; private set; } /// /// Gets a value indicating if there is a break water object available. @@ -119,13 +119,38 @@ /// /// Gets the break water object of the foreshore profile, if any. /// - public BreakWater BreakWater { get; } + public BreakWater BreakWater { get; private set; } /// /// Gets the geometry of the foreshore profile. /// public RoundedPoint2DCollection Geometry { get; private set; } + /// + /// Copies all the properties of + /// to the current instance. + /// + /// The foreshore profile to copy the + /// properties from. + /// Thrown when + /// is null. + public void CopyProperties(ForeshoreProfile fromForeshoreProfile) + { + if (fromForeshoreProfile == null) + { + throw new ArgumentNullException(nameof(fromForeshoreProfile)); + } + + Id = fromForeshoreProfile.Id; + Name = fromForeshoreProfile.Name; + X0 = fromForeshoreProfile.X0; + Orientation = fromForeshoreProfile.Orientation; + + BreakWater = fromForeshoreProfile.BreakWater; + WorldReferencePoint = fromForeshoreProfile.WorldReferencePoint; + SetGeometry(fromForeshoreProfile.Geometry); + } + public override string ToString() { return Name; @@ -178,6 +203,13 @@ && EqualGeometry(other.Geometry.ToArray()); } + /// + /// Sets the geometry of the foreshore profile. + /// + /// The points corresponding to the geometry of + /// the foreshore profile. + /// Thrown when an element in + /// is null. private void SetGeometry(IEnumerable points) { Point2D[] foreshorePoints = points.ToArray(); Index: Ringtoets/Common/test/Ringtoets.Common.Data.Test/DikeProfiles/ForeshoreProfileTest.cs =================================================================== diff -u -rb3b6c13cf736c134476b3db34281332d01ca86b1 -r76c82f11791024d9a22f40d0f918cd2b9b13d2ef --- Ringtoets/Common/test/Ringtoets.Common.Data.Test/DikeProfiles/ForeshoreProfileTest.cs (.../ForeshoreProfileTest.cs) (revision b3b6c13cf736c134476b3db34281332d01ca86b1) +++ Ringtoets/Common/test/Ringtoets.Common.Data.Test/DikeProfiles/ForeshoreProfileTest.cs (.../ForeshoreProfileTest.cs) (revision 76c82f11791024d9a22f40d0f918cd2b9b13d2ef) @@ -594,6 +594,71 @@ Assert.AreEqual(hashCodeOne, hashCodeTwo); } + [Test] + public void CopyProperties_FromForeshoreProfileNull_ThrowsArgumentNullException() + { + // Setup + ForeshoreProfile foreshoreProfile = CreateFullyDefinedForeshoreProfile(); + + // Call + TestDelegate call = () => foreshoreProfile.CopyProperties(null); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("fromForeshoreProfile", exception.ParamName); + } + + [Test] + public void CopyProperties_FromForeshoreProfileAllPropertiesChanged_PropertiesChanged() + { + // Setup + ForeshoreProfile foreshoreProfileToUpdate = CreateFullyDefinedForeshoreProfile(); + + const string expectedId = "new_id"; + const string expectedName = "new_name"; + + var random = new Random(21); + double expectedX0 = foreshoreProfileToUpdate.X0 + random.NextDouble(); + var expectedOrientation = new RoundedDouble(2, (foreshoreProfileToUpdate.Orientation + random.NextDouble()) % 360); + + double expectedBreakWaterHeight = foreshoreProfileToUpdate.BreakWater.Height + random.NextDouble(); + var expectedBreakWater = new BreakWater(random.NextEnumValue(), expectedBreakWaterHeight); + + Point2D originalPoint = foreshoreProfileToUpdate.WorldReferencePoint; + var expectedWorldReferencePoint = new Point2D(originalPoint.X + random.NextDouble(), + originalPoint.Y + random.NextDouble()); + + var expectedForeshoreGeometry = new[] + { + new Point2D(10, 10), + new Point2D(15, 10) + }; + + var foreshoreProfileToUpdateFrom = new ForeshoreProfile(expectedWorldReferencePoint, + expectedForeshoreGeometry, + expectedBreakWater, + new ForeshoreProfile.ConstructionProperties + { + Id = expectedId, + Name = expectedName, + Orientation = expectedOrientation, + X0 = expectedX0 + }); + + // Call + foreshoreProfileToUpdate.CopyProperties(foreshoreProfileToUpdateFrom); + + // Assert + Assert.AreEqual(expectedWorldReferencePoint, foreshoreProfileToUpdate.WorldReferencePoint); + CollectionAssert.AreEqual(expectedForeshoreGeometry, foreshoreProfileToUpdate.Geometry); + Assert.AreEqual(expectedBreakWater, foreshoreProfileToUpdate.BreakWater); + + Assert.AreEqual(expectedId, foreshoreProfileToUpdate.Id); + Assert.AreEqual(expectedName, foreshoreProfileToUpdate.Name); + Assert.AreEqual(expectedX0, foreshoreProfileToUpdate.X0); + Assert.AreEqual(expectedOrientation, foreshoreProfileToUpdate.Orientation); + } + /// /// Creates a default with all properties set. /// @@ -627,15 +692,15 @@ /// is null, empty or a whitespace. private static ForeshoreProfile CreateForeshoreProfile(ForeshoreProfile.ConstructionProperties properties) { - var worldCoordinate = new Point2D(0, 0); + var worldReferencePoint = new Point2D(0, 0); var geometry = new[] { new Point2D(0, 1), new Point2D(2, 1) }; var breakWater = new BreakWater(BreakWaterType.Caisson, 1.3); - return new ForeshoreProfile(worldCoordinate, geometry, breakWater, properties); + return new ForeshoreProfile(worldReferencePoint, geometry, breakWater, properties); } } } \ No newline at end of file