Index: Ringtoets/Common/src/Ringtoets.Common.Forms/PresentationObjects/StructuresCalculationContext.cs
===================================================================
diff -u -r9fe25ebfb1f70f00d66564ef2a89f6e22c27dce4 -r3a9daab3a208eb7bb29a44ad6d5646fe7cf85e11
--- Ringtoets/Common/src/Ringtoets.Common.Forms/PresentationObjects/StructuresCalculationContext.cs (.../StructuresCalculationContext.cs) (revision 9fe25ebfb1f70f00d66564ef2a89f6e22c27dce4)
+++ Ringtoets/Common/src/Ringtoets.Common.Forms/PresentationObjects/StructuresCalculationContext.cs (.../StructuresCalculationContext.cs) (revision 3a9daab3a208eb7bb29a44ad6d5646fe7cf85e11)
@@ -20,6 +20,7 @@
// All rights reserved.
using System;
+using Core.Common.Controls.PresentationObjects;
using Ringtoets.Common.Data.AssessmentSection;
using Ringtoets.Common.Data.Calculation;
using Ringtoets.Common.Data.FailureMechanism;
@@ -44,10 +45,10 @@
/// The failure mechanism which the context belongs to.
/// The assessment section which the calculation belongs to.
/// Thrown when any input argument is null.
- public StructuresCalculationContext(StructuresCalculation calculation,
- CalculationGroup parent,
- TFailureMechanism failureMechanism,
- IAssessmentSection assessmentSection)
+ protected StructuresCalculationContext(StructuresCalculation calculation,
+ CalculationGroup parent,
+ TFailureMechanism failureMechanism,
+ IAssessmentSection assessmentSection)
: base(calculation, failureMechanism, assessmentSection)
{
if (parent == null)
@@ -59,5 +60,22 @@
}
public CalculationGroup Parent { get; }
+
+ public override bool Equals(WrappedObjectContextBase> other)
+ {
+ return base.Equals(other)
+ && other is StructuresCalculationContext
+ && ReferenceEquals(Parent, ((StructuresCalculationContext) other).Parent);
+ }
+
+ public override bool Equals(object obj)
+ {
+ return Equals(obj as StructuresCalculationContext);
+ }
+
+ public override int GetHashCode()
+ {
+ return base.GetHashCode() ^ Parent.GetHashCode();
+ }
}
}
\ No newline at end of file
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