Index: Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/PresentationObjects/RingtoetsPipingSurfaceLineContextTest.cs =================================================================== diff -u -r6a1df79cc36617a42d0016f9b7a9271020a2196e -rf03b38fb7ef00a60db346246b2fb738f960841c9 --- Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/PresentationObjects/RingtoetsPipingSurfaceLineContextTest.cs (.../RingtoetsPipingSurfaceLineContextTest.cs) (revision 6a1df79cc36617a42d0016f9b7a9271020a2196e) +++ Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/PresentationObjects/RingtoetsPipingSurfaceLineContextTest.cs (.../RingtoetsPipingSurfaceLineContextTest.cs) (revision f03b38fb7ef00a60db346246b2fb738f960841c9) @@ -103,5 +103,113 @@ // Assert mocks.VerifyAll(); // Expect detach from failure mechanism } + + [Test] + public void Equals_ToItself_ReturnTrue() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.StrictMock(); + var failureMechanism = new PipingFailureMechanism(); + mocks.ReplayAll(); + + var context = new RingtoetsPipingSurfaceLineContext(failureMechanism, assessmentSection); + + // Call + bool isEqual = context.Equals(context); + + // Assert + Assert.IsTrue(isEqual); + mocks.VerifyAll(); + } + + [Test] + public void Equals_ToNull_ReturnFalse() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.StrictMock(); + var failureMechanism = new PipingFailureMechanism(); + mocks.ReplayAll(); + + var context = new RingtoetsPipingSurfaceLineContext(failureMechanism, assessmentSection); + // Call + bool isEqual = context.Equals(null); + + // Assert + Assert.IsFalse(isEqual); + mocks.VerifyAll(); + } + + [Test] + public void Equals_ToEqualOtherInstance_ReturnTrue() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.StrictMock(); + var failureMechanism = new PipingFailureMechanism(); + mocks.ReplayAll(); + + var context = new RingtoetsPipingSurfaceLineContext(failureMechanism, assessmentSection); + + var otherContext = new RingtoetsPipingSurfaceLineContext(failureMechanism, assessmentSection); + + // Call + bool isEqual = context.Equals(otherContext); + bool isEqual2 = otherContext.Equals(context); + + // Assert + Assert.IsTrue(isEqual); + Assert.IsTrue(isEqual2); + mocks.VerifyAll(); + } + + [Test] + public void Equals_ToInequalOtherInstance_ReturnFalse() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.StrictMock(); + var failureMechanism = new PipingFailureMechanism(); + var otherFailureMechanism = new PipingFailureMechanism(); + mocks.ReplayAll(); + + var context = new RingtoetsPipingSurfaceLineContext(failureMechanism, assessmentSection); + + var otherContext = new RingtoetsPipingSurfaceLineContext(otherFailureMechanism, assessmentSection); + + // Call + bool isEqual = context.Equals(otherContext); + bool isEqual2 = otherContext.Equals(context); + + // Assert + Assert.IsFalse(isEqual); + Assert.IsFalse(isEqual2); + mocks.VerifyAll(); + } + + [Test] + public void GetHashCode_TwoContextInstancesEqualToEachOther_ReturnIdenticalHashes() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.StrictMock(); + var failureMechanism = new PipingFailureMechanism(); + mocks.ReplayAll(); + + var context = new RingtoetsPipingSurfaceLineContext(failureMechanism, assessmentSection); + + var otherContext = new RingtoetsPipingSurfaceLineContext(failureMechanism, assessmentSection); + // Precondition + Assert.True(context.Equals(otherContext)); + + // Call + int contextHashCode = context.GetHashCode(); + int otherContextHashCode = otherContext.GetHashCode(); + + // Assert + Assert.AreEqual(contextHashCode, otherContextHashCode); + mocks.VerifyAll(); + } } }