Index: Ringtoets/Common/test/Ringtoets.Common.Forms.Test/PresentationObjects/StructuresCalculationContextTest.cs =================================================================== diff -u -r1c7761edbc39ac04842ad34decd0b7230036f89d -r3a9daab3a208eb7bb29a44ad6d5646fe7cf85e11 --- Ringtoets/Common/test/Ringtoets.Common.Forms.Test/PresentationObjects/StructuresCalculationContextTest.cs (.../StructuresCalculationContextTest.cs) (revision 1c7761edbc39ac04842ad34decd0b7230036f89d) +++ Ringtoets/Common/test/Ringtoets.Common.Forms.Test/PresentationObjects/StructuresCalculationContextTest.cs (.../StructuresCalculationContextTest.cs) (revision 3a9daab3a208eb7bb29a44ad6d5646fe7cf85e11) @@ -77,14 +77,190 @@ Assert.AreEqual("parent", exception.ParamName); mockRepository.VerifyAll(); } - } - public class TestStructuresCalculationContext : StructuresCalculationContext - { - public TestStructuresCalculationContext(StructuresCalculation calculation, - CalculationGroup parent, - TestFailureMechanism failureMechanism, - IAssessmentSection assessmentSection) - : base(calculation, parent, failureMechanism, assessmentSection) {} + [Test] + public void Equals_ToNull_ReturnFalse() + { + // Setup + var mocksRepository = new MockRepository(); + var assessmentSection = mocksRepository.Stub(); + mocksRepository.ReplayAll(); + + var calculation = new TestStructuresCalculation(); + var failureMechanism = new TestFailureMechanism(); + var parent = new CalculationGroup(); + var context = new TestStructuresCalculationContext(calculation, parent, failureMechanism, assessmentSection); + + // Call + bool isEqual = context.Equals(null); + + // Assert + Assert.IsFalse(isEqual); + + mocksRepository.VerifyAll(); + } + + [Test] + public void Equals_ToItself_ReturnTrue() + { + // Setup + var mocksRepository = new MockRepository(); + var assessmentSection = mocksRepository.Stub(); + mocksRepository.ReplayAll(); + + var calculation = new TestStructuresCalculation(); + var failureMechanism = new TestFailureMechanism(); + var parent = new CalculationGroup(); + var context = new TestStructuresCalculationContext(calculation, parent, failureMechanism, assessmentSection); + + // Call + bool isEqual = context.Equals(context); + + // Assert + Assert.IsTrue(isEqual); + + mocksRepository.VerifyAll(); + } + + [Test] + public void Equals_ToOtherWithDifferentType_ReturnFalse() + { + // Setup + var mocksRepository = new MockRepository(); + var assessmentSection = mocksRepository.Stub(); + mocksRepository.ReplayAll(); + + var calculation = new TestStructuresCalculation(); + var failureMechanism = new TestFailureMechanism(); + var parent = new CalculationGroup(); + var context = new TestStructuresCalculationContext(calculation, parent, failureMechanism, assessmentSection); + + // Call + bool isEqual = context.Equals(new object()); + + // Assert + Assert.IsFalse(isEqual); + + mocksRepository.VerifyAll(); + } + + [Test] + public void Equals_ToOtherWithDifferentWrappedData_ReturnFalse() + { + // Setup + var mocksRepository = new MockRepository(); + var assessmentSection = mocksRepository.Stub(); + mocksRepository.ReplayAll(); + + var calculation1 = new TestStructuresCalculation(); + var calculation2 = new TestStructuresCalculation(); + var failureMechanism = new TestFailureMechanism(); + var parent = new CalculationGroup(); + var context1 = new TestStructuresCalculationContext(calculation1, parent, failureMechanism, assessmentSection); + var context2 = new TestStructuresCalculationContext(calculation2, parent, failureMechanism, assessmentSection); + + // Precondition: + Assert.IsFalse(calculation1.Equals(calculation2)); + + // Call + bool isEqual1 = context1.Equals(context2); + bool isEqual2 = context2.Equals(context1); + + // Assert + Assert.IsFalse(isEqual1); + Assert.IsFalse(isEqual2); + + mocksRepository.VerifyAll(); + } + + [Test] + public void Equals_ToOtherWithDifferentParent_ReturnFalse() + { + // Setup + var mocksRepository = new MockRepository(); + var assessmentSection = mocksRepository.Stub(); + mocksRepository.ReplayAll(); + + var calculation = new TestStructuresCalculation(); + var failureMechanism = new TestFailureMechanism(); + var parent1 = new CalculationGroup(); + var parent2 = new CalculationGroup(); + var context1 = new TestStructuresCalculationContext(calculation, parent1, failureMechanism, assessmentSection); + var context2 = new TestStructuresCalculationContext(calculation, parent2, failureMechanism, assessmentSection); + + // Precondition: + Assert.IsFalse(parent1.Equals(parent2)); + + // Call + bool isEqual1 = context1.Equals(context2); + bool isEqual2 = context2.Equals(context1); + + // Assert + Assert.IsFalse(isEqual1); + Assert.IsFalse(isEqual2); + + mocksRepository.VerifyAll(); + } + + [Test] + public void Equals_ToOtherWithSameWrappedDataAndParent_ReturnTrue() + { + // Setup + var mocksRepository = new MockRepository(); + var assessmentSection = mocksRepository.Stub(); + mocksRepository.ReplayAll(); + + var calculation = new TestStructuresCalculation(); + var failureMechanism = new TestFailureMechanism(); + var parent = new CalculationGroup(); + var context1 = new TestStructuresCalculationContext(calculation, parent, failureMechanism, assessmentSection); + var context2 = new TestStructuresCalculationContext(calculation, parent, failureMechanism, assessmentSection); + + // Call + bool isEqual1 = context1.Equals(context2); + bool isEqual2 = context2.Equals(context1); + + // Assert + Assert.IsTrue(isEqual1); + Assert.IsTrue(isEqual2); + + mocksRepository.VerifyAll(); + } + + [Test] + public void GetHashCode_EqualObjects_ReturnSameHashCode() + { + // Setup + var mocksRepository = new MockRepository(); + var assessmentSection = mocksRepository.Stub(); + mocksRepository.ReplayAll(); + + var calculation = new TestStructuresCalculation(); + var failureMechanism = new TestFailureMechanism(); + var parent = new CalculationGroup(); + var context1 = new TestStructuresCalculationContext(calculation, parent, failureMechanism, assessmentSection); + var context2 = new TestStructuresCalculationContext(calculation, parent, failureMechanism, assessmentSection); + + // Precondition: + Assert.AreEqual(context1, context2); + + // Call + int hashCode1 = context1.GetHashCode(); + int hashCode2 = context2.GetHashCode(); + + // Assert + Assert.AreEqual(hashCode1, hashCode2); + + mocksRepository.VerifyAll(); + } + + private class TestStructuresCalculationContext : StructuresCalculationContext + { + public TestStructuresCalculationContext(StructuresCalculation calculation, + CalculationGroup parent, + TestFailureMechanism failureMechanism, + IAssessmentSection assessmentSection) + : base(calculation, parent, failureMechanism, assessmentSection) {} + } } } \ No newline at end of file