Index: Ringtoets/Common/test/Ringtoets.Common.Forms.Test/PresentationObjects/FailureMechanismSectionsContextTest.cs =================================================================== diff -u -rc6a3cd9e25138d35bf0881f3ff6df9dfe1776fd2 -rf03b38fb7ef00a60db346246b2fb738f960841c9 --- Ringtoets/Common/test/Ringtoets.Common.Forms.Test/PresentationObjects/FailureMechanismSectionsContextTest.cs (.../FailureMechanismSectionsContextTest.cs) (revision c6a3cd9e25138d35bf0881f3ff6df9dfe1776fd2) +++ Ringtoets/Common/test/Ringtoets.Common.Forms.Test/PresentationObjects/FailureMechanismSectionsContextTest.cs (.../FailureMechanismSectionsContextTest.cs) (revision f03b38fb7ef00a60db346246b2fb738f960841c9) @@ -128,5 +128,114 @@ // 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 = mocks.Stub(); + mocks.ReplayAll(); + + var context = new FailureMechanismSectionsContext(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 = mocks.Stub(); + mocks.ReplayAll(); + + var context = new FailureMechanismSectionsContext(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 = mocks.Stub(); + mocks.ReplayAll(); + + var context = new FailureMechanismSectionsContext(failureMechanism, assessmentSection); + + var otherContext = new FailureMechanismSectionsContext(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 = mocks.Stub(); + var otherFailureMechanism = mocks.Stub(); + mocks.ReplayAll(); + + var context = new FailureMechanismSectionsContext(failureMechanism, assessmentSection); + + var otherContext = new FailureMechanismSectionsContext(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 = mocks.Stub(); + mocks.ReplayAll(); + + var context = new FailureMechanismSectionsContext(failureMechanism, assessmentSection); + + var otherContext = new FailureMechanismSectionsContext(failureMechanism, assessmentSection); + // Precondition + Assert.True(context.Equals(otherContext)); + + // Call + int contextHashCode = context.GetHashCode(); + int otherContextHashCode = otherContext.GetHashCode(); + + // Assert + Assert.AreEqual(contextHashCode, otherContextHashCode); + mocks.VerifyAll(); + } } } \ No newline at end of file