Index: Ringtoets/Common/test/Ringtoets.Common.Data.Test/DikeProfiles/DikeProfileTest.cs =================================================================== diff -u -r1f549a37af503f5da697652b5e5199f8d29ac0fe -r56ac4eb28f5fcc5b20117474e9e4030399d6806a --- Ringtoets/Common/test/Ringtoets.Common.Data.Test/DikeProfiles/DikeProfileTest.cs (.../DikeProfileTest.cs) (revision 1f549a37af503f5da697652b5e5199f8d29ac0fe) +++ Ringtoets/Common/test/Ringtoets.Common.Data.Test/DikeProfiles/DikeProfileTest.cs (.../DikeProfileTest.cs) (revision 56ac4eb28f5fcc5b20117474e9e4030399d6806a) @@ -20,6 +20,7 @@ // All rights reserved. using System; +using Core.Common.Base; using Core.Common.Base.Data; using Core.Common.Base.Geometry; using Core.Common.TestUtil; @@ -35,7 +36,7 @@ public void Constructor_ValidParameters_ExpectedValues() { // Setup - string validId = "id"; + const string validId = "id"; var worldCoordinate = new Point2D(1.1, 2.2); var dikeGeometry = new[] { @@ -57,6 +58,7 @@ }); // Assert + Assert.IsInstanceOf(dikeProfile); Assert.IsInstanceOf(dikeProfile.Orientation); Assert.IsInstanceOf(dikeProfile.DikeHeight); Assert.IsInstanceOf(dikeProfile.X0); @@ -319,10 +321,525 @@ }); // Call - var result = dikeProfile.ToString(); + string result = dikeProfile.ToString(); // Assert Assert.AreEqual(testName, result); } + + [Test] + public void Equals_ToItself_ReturnsTrue() + { + // Setup + DikeProfile dikeProfile = CreateFullyDefinedDikeProfile(); + + // Call + bool isEqualToItself = dikeProfile.Equals(dikeProfile); + + // Assert + Assert.IsTrue(isEqualToItself); + } + + [Test] + public void Equals_ToNull_ReturnsFalse() + { + // Setup + DikeProfile dikeProfile = CreateFullyDefinedDikeProfile(); + + // Call + bool isDikeProfileEqualToNull = dikeProfile.Equals(null); + + // Assert + Assert.IsFalse(isDikeProfileEqualToNull); + } + + [Test] + public void Equal_ToDifferentType_ReturnsFalse() + { + // Setup + DikeProfile dikeProfile = CreateFullyDefinedDikeProfile(); + + var differentType = new object(); + + // Call + bool isDikeProfileEqualToDifferentObject = dikeProfile.Equals(differentType); + + // Assert + Assert.IsFalse(isDikeProfileEqualToDifferentObject); + } + + [Test] + public void Equals_DifferentWorldReferencePoints_ReturnsFalse() + { + // Setup + DikeProfile dikeProfileOne = CreateFullyDefinedDikeProfile(); + + var dikeProfileTwo = new DikeProfile(new Point2D(500, 1000), + dikeProfileOne.DikeGeometry, + dikeProfileOne.ForeshoreGeometry, + dikeProfileOne.BreakWater, + new DikeProfile.ConstructionProperties + { + Name = dikeProfileOne.Name, + Id = dikeProfileOne.Id, + Orientation = dikeProfileOne.Orientation, + DikeHeight = dikeProfileOne.DikeHeight, + X0 = dikeProfileOne.DikeHeight + }); + + // Call + bool isDikeProfileOneEqualToTwo = dikeProfileOne.Equals(dikeProfileTwo); + bool isDikeProfileTwoEqualToOne = dikeProfileTwo.Equals(dikeProfileOne); + + // Assert + Assert.IsFalse(isDikeProfileOneEqualToTwo); + Assert.IsFalse(isDikeProfileTwoEqualToOne); + } + + [Test] + public void Equals_DifferentDikeGeometry_ReturnsFalse() + { + // Setup + DikeProfile dikeProfileOne = CreateFullyDefinedDikeProfile(); + + var dikeGeometry = new[] + { + new RoughnessPoint(new Point2D(1, 0), 1), + new RoughnessPoint(new Point2D(2, 1), 3) + }; + var dikeProfileTwo = new DikeProfile(dikeProfileOne.WorldReferencePoint, + dikeGeometry, + dikeProfileOne.ForeshoreGeometry, + dikeProfileOne.BreakWater, + new DikeProfile.ConstructionProperties + { + Name = dikeProfileOne.Name, + Id = dikeProfileOne.Id, + Orientation = dikeProfileOne.Orientation, + DikeHeight = dikeProfileOne.DikeHeight, + X0 = dikeProfileOne.DikeHeight + }); + + // Call + bool isDikeProfileOneEqualToTwo = dikeProfileOne.Equals(dikeProfileTwo); + bool isDikeProfileTwoEqualToOne = dikeProfileTwo.Equals(dikeProfileOne); + + // Assert + Assert.IsFalse(isDikeProfileOneEqualToTwo); + Assert.IsFalse(isDikeProfileTwoEqualToOne); + } + + [Test] + public void Equals_DifferentForeshoreGeometry_ReturnsFalse() + { + // Setup + DikeProfile dikeProfileOne = CreateFullyDefinedDikeProfile(); + + var foreshoreGeometry = new[] + { + new Point2D(50, 100), + new Point2D(100, 50) + }; + var dikeProfileTwo = new DikeProfile(dikeProfileOne.WorldReferencePoint, + dikeProfileOne.DikeGeometry, + foreshoreGeometry, + dikeProfileOne.BreakWater, + new DikeProfile.ConstructionProperties + { + Name = dikeProfileOne.Name, + Id = dikeProfileOne.Id, + Orientation = dikeProfileOne.Orientation, + DikeHeight = dikeProfileOne.DikeHeight, + X0 = dikeProfileOne.DikeHeight + }); + + // Call + bool isDikeProfileOneEqualToTwo = dikeProfileOne.Equals(dikeProfileTwo); + bool isDikeProfileTwoEqualToOne = dikeProfileTwo.Equals(dikeProfileOne); + + // Assert + Assert.IsFalse(isDikeProfileOneEqualToTwo); + Assert.IsFalse(isDikeProfileTwoEqualToOne); + } + + [Test] + public void Equals_DifferentBreakWater_ReturnsFalse() + { + // Setup + DikeProfile dikeProfileOne = CreateFullyDefinedDikeProfile(); + + var dikeProfileTwo = new DikeProfile(dikeProfileOne.WorldReferencePoint, + dikeProfileOne.DikeGeometry, + dikeProfileOne.ForeshoreGeometry, + null, + new DikeProfile.ConstructionProperties + { + Name = dikeProfileOne.Name, + Id = dikeProfileOne.Id, + Orientation = dikeProfileOne.Orientation, + DikeHeight = dikeProfileOne.DikeHeight, + X0 = dikeProfileOne.DikeHeight + }); + + // Call + bool isDikeProfileOneEqualToTwo = dikeProfileOne.Equals(dikeProfileTwo); + bool isDikeProfileTwoEqualToOne = dikeProfileTwo.Equals(dikeProfileOne); + + // Assert + Assert.IsFalse(isDikeProfileOneEqualToTwo); + Assert.IsFalse(isDikeProfileTwoEqualToOne); + } + + [Test] + public void Equals_DifferentIds_ReturnsFalse() + { + // Setup + DikeProfile dikeProfileOne = CreateFullyDefinedDikeProfile(); + + var dikeProfileTwo = new DikeProfile(dikeProfileOne.WorldReferencePoint, + dikeProfileOne.DikeGeometry, + dikeProfileOne.ForeshoreGeometry, + dikeProfileOne.BreakWater, + new DikeProfile.ConstructionProperties + { + Name = dikeProfileOne.Name, + Id = "Different ID", + Orientation = dikeProfileOne.Orientation, + DikeHeight = dikeProfileOne.DikeHeight, + X0 = dikeProfileOne.DikeHeight + }); + + // Call + bool isDikeProfileOneEqualToTwo = dikeProfileOne.Equals(dikeProfileTwo); + bool isDikeProfileTwoEqualToOne = dikeProfileTwo.Equals(dikeProfileOne); + + // Assert + Assert.IsFalse(isDikeProfileOneEqualToTwo); + Assert.IsFalse(isDikeProfileTwoEqualToOne); + } + + [Test] + public void Equals_DifferentNames_ReturnsFalse() + { + // Setup + DikeProfile dikeProfileOne = CreateFullyDefinedDikeProfile(); + + var dikeProfileTwo = new DikeProfile(dikeProfileOne.WorldReferencePoint, + dikeProfileOne.DikeGeometry, + dikeProfileOne.ForeshoreGeometry, + dikeProfileOne.BreakWater, + new DikeProfile.ConstructionProperties + { + Name = "Different Name", + Id = dikeProfileOne.Id, + Orientation = dikeProfileOne.Orientation, + DikeHeight = dikeProfileOne.DikeHeight, + X0 = dikeProfileOne.DikeHeight + }); + + // Call + bool isDikeProfileOneEqualToTwo = dikeProfileOne.Equals(dikeProfileTwo); + bool isDikeProfileTwoEqualToOne = dikeProfileTwo.Equals(dikeProfileOne); + + // Assert + Assert.IsFalse(isDikeProfileOneEqualToTwo); + Assert.IsFalse(isDikeProfileTwoEqualToOne); + } + + [Test] + public void Equals_DifferentX0_ReturnsFalse() + { + // Setup + const string id = "ID"; + const string name = "Just a name"; + const double orientation = 179; + const double dikeHeight = 0.5; + DikeProfile dikeProfileOne = CreateDikeProfile(new DikeProfile.ConstructionProperties + { + Id = id, + Name = name, + X0 = 10.0, + Orientation = orientation, + DikeHeight = dikeHeight + }); + + DikeProfile dikeProfileTwo = CreateDikeProfile(new DikeProfile.ConstructionProperties + { + Id = id, + Name = name, + X0 = 11.0, + Orientation = orientation, + DikeHeight = dikeHeight + }); + + // Call + bool isDikeProfileOneEqualToTwo = dikeProfileOne.Equals(dikeProfileTwo); + bool isDikeProfileTwoEqualToOne = dikeProfileTwo.Equals(dikeProfileOne); + + // Assert + Assert.IsFalse(isDikeProfileOneEqualToTwo); + Assert.IsFalse(isDikeProfileTwoEqualToOne); + } + + [Test] + public void Equals_DifferentOrientation_ReturnsFalse() + { + // Setup + const string id = "ID"; + const string name = "Just a name"; + const double x0 = 179; + const double dikeHeight = 0.5; + DikeProfile dikeProfileOne = CreateDikeProfile(new DikeProfile.ConstructionProperties + { + Id = id, + Name = name, + X0 = x0, + Orientation = 180, + DikeHeight = dikeHeight + }); + + DikeProfile dikeProfileTwo = CreateDikeProfile(new DikeProfile.ConstructionProperties + { + Id = id, + Name = name, + X0 = x0, + Orientation = 170, + DikeHeight = dikeHeight + }); + + // Call + bool isDikeProfileOneEqualToTwo = dikeProfileOne.Equals(dikeProfileTwo); + bool isDikeProfileTwoEqualToOne = dikeProfileTwo.Equals(dikeProfileOne); + + // Assert + Assert.IsFalse(isDikeProfileOneEqualToTwo); + Assert.IsFalse(isDikeProfileTwoEqualToOne); + } + + [Test] + public void Equals_DifferentDikeHeight_ReturnsFalse() + { + // Setup + const string id = "ID"; + const string name = "Just a name"; + const double orientation = 179; + const double x0 = 0.5; + DikeProfile dikeProfileOne = CreateDikeProfile(new DikeProfile.ConstructionProperties + { + Id = id, + Name = name, + X0 = x0, + Orientation = orientation, + DikeHeight = 0.5 + }); + + DikeProfile dikeProfileTwo = CreateDikeProfile(new DikeProfile.ConstructionProperties + { + Id = id, + Name = name, + X0 = x0, + Orientation = orientation, + DikeHeight = 0.3 + }); + + // Call + bool isDikeProfileOneEqualToTwo = dikeProfileOne.Equals(dikeProfileTwo); + bool isDikeProfileTwoEqualToOne = dikeProfileTwo.Equals(dikeProfileOne); + + // Assert + Assert.IsFalse(isDikeProfileOneEqualToTwo); + Assert.IsFalse(isDikeProfileTwoEqualToOne); + } + + [Test] + public void Equals_AllPropertiesEqual_ReturnsTrue() + { + // Setup + DikeProfile dikeProfileOne = CreateFullyDefinedDikeProfile(); + DikeProfile dikeProfileTwo = CreateFullyDefinedDikeProfile(); + + // Call + bool isDikeProfileOneEqualToTwo = dikeProfileOne.Equals(dikeProfileTwo); + bool isDikeProfileTwoEqualToOne = dikeProfileTwo.Equals(dikeProfileOne); + + // Assert + Assert.IsTrue(isDikeProfileOneEqualToTwo); + Assert.IsTrue(isDikeProfileTwoEqualToOne); + } + + [Test] + public void Equals_TransitivePropertyAllPropertiesEqual_ReturnsTrue() + { + // Setup + DikeProfile dikeProfileOne = CreateFullyDefinedDikeProfile(); + DikeProfile dikeProfileTwo = CreateFullyDefinedDikeProfile(); + DikeProfile dikeProfileThree = CreateFullyDefinedDikeProfile(); + + // Call + bool isDikeProfileOneEqualToTwo = dikeProfileOne.Equals(dikeProfileTwo); + bool isDikeProfileTwoEqualToThree = dikeProfileTwo.Equals(dikeProfileThree); + bool isDikeProfileOneEqualToThree = dikeProfileOne.Equals(dikeProfileThree); + + // Assert + Assert.IsTrue(isDikeProfileOneEqualToTwo); + Assert.IsTrue(isDikeProfileTwoEqualToThree); + Assert.IsTrue(isDikeProfileOneEqualToThree); + } + + [Test] + public void Equals_SameReference_ReturnsTrue() + { + // Setup + DikeProfile dikeProfileOne = CreateFullyDefinedDikeProfile(); + DikeProfile dikeProfileTwo = dikeProfileOne; + + // Call + bool isDikeProfileOneEqualToTwo = dikeProfileOne.Equals(dikeProfileTwo); + bool isDikeProfileTwoEqualToOne = dikeProfileTwo.Equals(dikeProfileOne); + + // Assert + Assert.IsTrue(isDikeProfileOneEqualToTwo); + Assert.IsTrue(isDikeProfileTwoEqualToOne); + } + + [Test] + public void GetHashCode_EqualDikeProfiles_ReturnsSameHashCode() + { + // Setup + DikeProfile dikeProfileOne = CreateFullyDefinedDikeProfile(); + DikeProfile dikeProfileTwo = CreateFullyDefinedDikeProfile(); + + // Call + int hashCodeOne = dikeProfileOne.GetHashCode(); + int hashCodeTwo = dikeProfileTwo.GetHashCode(); + + // Assert + Assert.AreEqual(hashCodeOne, hashCodeTwo); + } + + [Test] + public void CopyProperties_FromDikeProfileNull_ThrowsArgumentNullException() + { + // Setup + DikeProfile dikeProfile = CreateFullyDefinedDikeProfile(); + + // Call + TestDelegate call = () => dikeProfile.CopyProperties(null); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("fromDikeProfile", exception.ParamName); + } + + [Test] + public void CopyProperties_FromDikeProfileAllPropertiesChanged_PropertiesUpdated() + { + // Setup + DikeProfile dikeProfileToUpdate = CreateFullyDefinedDikeProfile(); + + const string expectedId = "new_id"; + const string expectedName = "new_name"; + + var random = new Random(21); + double expectedX0 = dikeProfileToUpdate.X0 + random.NextDouble(); + var expectedOrientation = new RoundedDouble(2, (dikeProfileToUpdate.Orientation + random.NextDouble()) % 360); + var expectedDikeHeight = new RoundedDouble(2, dikeProfileToUpdate.DikeHeight + random.NextDouble()); + + double expectedBreakWaterHeight = dikeProfileToUpdate.BreakWater.Height + random.NextDouble(); + var expectedBreakWater = new BreakWater(random.NextEnumValue(), expectedBreakWaterHeight); + + var expectedForeshoreGeometry = new[] + { + new Point2D(10, 10), + new Point2D(15, 10) + }; + + var expectedDikeGeometry = new[] + { + new RoughnessPoint(new Point2D(10, 10), 1), + new RoughnessPoint(new Point2D(15, 10), 2) + }; + + var expectedWorldReferencePoint = new Point2D(13, 37); + + var dikeProfileToUpdateFrom = new DikeProfile(expectedWorldReferencePoint, + expectedDikeGeometry, + expectedForeshoreGeometry, + expectedBreakWater, + new DikeProfile.ConstructionProperties + { + Id = expectedId, + Name = expectedName, + X0 = expectedX0, + Orientation = expectedOrientation, + DikeHeight = expectedDikeHeight + }); + + // Call + dikeProfileToUpdate.CopyProperties(dikeProfileToUpdateFrom); + + // Assert + Assert.AreEqual(expectedWorldReferencePoint, dikeProfileToUpdate.WorldReferencePoint); + CollectionAssert.AreEqual(expectedForeshoreGeometry, dikeProfileToUpdate.ForeshoreGeometry); + CollectionAssert.AreEqual(expectedDikeGeometry, dikeProfileToUpdate.DikeGeometry); + Assert.AreEqual(expectedBreakWater, dikeProfileToUpdate.BreakWater); + + Assert.AreEqual(expectedId, dikeProfileToUpdate.Id); + Assert.AreEqual(expectedName, dikeProfileToUpdate.Name); + Assert.AreEqual(expectedX0, dikeProfileToUpdate.X0); + Assert.AreEqual(expectedOrientation, dikeProfileToUpdate.Orientation); + Assert.AreEqual(expectedDikeHeight, dikeProfileToUpdate.DikeHeight); + } + + /// + /// Creates a default with all properties set. + /// + /// A fully defined . + private static DikeProfile CreateFullyDefinedDikeProfile() + { + const string id = "id"; + const string name = "What's in a name?"; + + const double x0 = 13.37; + const double orientation = 179; + const double dikeHeight = 10; + + return CreateDikeProfile(new DikeProfile.ConstructionProperties + { + Id = id, + Name = name, + X0 = x0, + Orientation = orientation, + DikeHeight = dikeHeight + }); + } + + /// + /// Creates a with all properties set, except for the + /// parameters related to which + /// are user specified. + /// + /// The construction properties. + /// A with default parameters and + /// specified values of the . + /// Thrown when + /// is null, empty or a whitespace. + private static DikeProfile CreateDikeProfile(DikeProfile.ConstructionProperties properties) + { + var worldCoordinate = new Point2D(0, 0); + var foreshoreGeometry = new[] + { + new Point2D(0, 1), + new Point2D(2, 1) + }; + var dikeGeometry = new[] + { + new RoughnessPoint(new Point2D(0, 1), 1), + new RoughnessPoint(new Point2D(1, 2), 3) + }; + var breakWater = new BreakWater(BreakWaterType.Caisson, 1.3); + + return new DikeProfile(worldCoordinate, dikeGeometry, foreshoreGeometry, breakWater, properties); + } } } \ No newline at end of file