Index: Ringtoets/Common/test/Ringtoets.Common.Forms.Test/PresentationObjects/StructuresCalculationContextTest.cs =================================================================== diff -u -rb8fc9e68ddf41b3a07a7ef7b74d5ed7e98a42794 -r68a818233c83cb62a31ba4e99c6786c7597324ea --- Ringtoets/Common/test/Ringtoets.Common.Forms.Test/PresentationObjects/StructuresCalculationContextTest.cs (.../StructuresCalculationContextTest.cs) (revision b8fc9e68ddf41b3a07a7ef7b74d5ed7e98a42794) +++ Ringtoets/Common/test/Ringtoets.Common.Forms.Test/PresentationObjects/StructuresCalculationContextTest.cs (.../StructuresCalculationContextTest.cs) (revision 68a818233c83cb62a31ba4e99c6786c7597324ea) @@ -83,22 +83,16 @@ [TestFixture] private class StructuresCalculationContextEqualsTest : EqualsGuidelinesTestFixture { - private MockRepository mocks; + private static readonly MockRepository mocks = new MockRepository(); - private IAssessmentSection assessmentSection; - private TestStructuresCalculation calculation; - private TestFailureMechanism failureMechanism; - private CalculationGroup parent; + private static readonly IAssessmentSection assessmentSection = mocks.Stub(); + private static readonly TestStructuresCalculation calculation = new TestStructuresCalculation(); + private static readonly TestFailureMechanism failureMechanism = new TestFailureMechanism(); + private static readonly CalculationGroup parent = new CalculationGroup(); [SetUp] public void SetUp() { - calculation = new TestStructuresCalculation(); - failureMechanism = new TestFailureMechanism(); - parent = new CalculationGroup(); - - mocks = new MockRepository(); - assessmentSection = mocks.Stub(); mocks.ReplayAll(); } @@ -108,46 +102,6 @@ mocks.VerifyAll(); } - [Test] - public void Equals_ToOtherWithDifferentWrappedData_ReturnFalse() - { - // Setup - var differentCalculation = new TestStructuresCalculation(); - var context1 = new TestStructuresCalculationContext(calculation, parent, failureMechanism, assessmentSection); - var context2 = new TestStructuresCalculationContext(differentCalculation, parent, failureMechanism, assessmentSection); - - // Precondition: - Assert.IsFalse(calculation.Equals(differentCalculation)); - - // Call - bool isEqual1 = context1.Equals(context2); - bool isEqual2 = context2.Equals(context1); - - // Assert - Assert.IsFalse(isEqual1); - Assert.IsFalse(isEqual2); - } - - [Test] - public void Equals_ToOtherWithDifferentParent_ReturnFalse() - { - // Setup - var differentParent = new CalculationGroup(); - var context1 = new TestStructuresCalculationContext(calculation, parent, failureMechanism, assessmentSection); - var context2 = new TestStructuresCalculationContext(calculation, differentParent, failureMechanism, assessmentSection); - - // Precondition: - Assert.IsFalse(parent.Equals(differentParent)); - - // Call - bool isEqual1 = context1.Equals(context2); - bool isEqual2 = context2.Equals(context1); - - // Assert - Assert.IsFalse(isEqual1); - Assert.IsFalse(isEqual2); - } - protected override TestStructuresCalculationContext CreateObject() { return new TestStructuresCalculationContext(calculation, parent, failureMechanism, assessmentSection); @@ -160,7 +114,16 @@ private static IEnumerable GetUnequalTestCases() { - yield break; + yield return new TestCaseData(new TestStructuresCalculationContext(new TestStructuresCalculation(), + parent, + failureMechanism, + assessmentSection)) + .SetName("Calculation"); + yield return new TestCaseData(new TestStructuresCalculationContext(calculation, + new CalculationGroup(), + failureMechanism, + assessmentSection)) + .SetName("Parent"); } } Index: Ringtoets/DuneErosion/test/Ringtoets.DuneErosion.Forms.Test/PresentationObjects/DuneLocationContextTest.cs =================================================================== diff -u -r330f2e86f2fb575c436cdbb46b6d31bc246ef6fc -r68a818233c83cb62a31ba4e99c6786c7597324ea --- Ringtoets/DuneErosion/test/Ringtoets.DuneErosion.Forms.Test/PresentationObjects/DuneLocationContextTest.cs (.../DuneLocationContextTest.cs) (revision 330f2e86f2fb575c436cdbb46b6d31bc246ef6fc) +++ Ringtoets/DuneErosion/test/Ringtoets.DuneErosion.Forms.Test/PresentationObjects/DuneLocationContextTest.cs (.../DuneLocationContextTest.cs) (revision 68a818233c83cb62a31ba4e99c6786c7597324ea) @@ -20,8 +20,11 @@ // All rights reserved. using System; +using System.Collections.Generic; using Core.Common.Base; using Core.Common.Controls.PresentationObjects; +using Core.Common.Gui.Forms.MessageWindow; +using Core.Common.TestUtil; using NUnit.Framework; using Ringtoets.DuneErosion.Data; using Ringtoets.DuneErosion.Data.TestUtil; @@ -62,112 +65,34 @@ Assert.AreSame(location, context.DuneLocation); } - [Test] - public void Equals_ToNull_ReturnFalse() + [TestFixture] + private class DuneLocationContextEqualsTest : EqualsGuidelinesTestFixture { - // Setup - var duneLocations = new ObservableList(); - var duneLocation = new TestDuneLocation(); + private static readonly ObservableList duneLocations = new ObservableList(); + private static readonly DuneLocation duneLocation = new TestDuneLocation(); - var context = new DuneLocationContext(duneLocations, duneLocation); + protected override DuneLocationContext CreateObject() + { + return new DuneLocationContext(duneLocations, duneLocation); + } - // Call - bool isEqual = context.Equals(null); + protected override DerivedDuneLocationContext CreateDerivedObject() + { + return new DerivedDuneLocationContext(duneLocations, duneLocation); + } - // Assert - Assert.IsFalse(isEqual); + private static IEnumerable GetUnequalTestCases() + { + yield return new TestCaseData(new DuneLocationContext(new ObservableList(), duneLocation)) + .SetName("LocationsList"); + yield return new TestCaseData(new DuneLocationContext(duneLocations, new TestDuneLocation())) + .SetName("Locations"); + } } - [Test] - public void Equals_ToItself_ReturnTrue() + private class DerivedDuneLocationContext : DuneLocationContext { - // Setup - var duneLocations = new ObservableList(); - var duneLocation = new TestDuneLocation(); - - var context = new DuneLocationContext(duneLocations, duneLocation); - - // Call - bool isEqual = context.Equals(context); - - // Assert - Assert.IsTrue(isEqual); + public DerivedDuneLocationContext(ObservableList wrappedList, DuneLocation duneLocation) : base(wrappedList, duneLocation) {} } - - [Test] - public void Equals_ToOtherWithDifferentLocationListAndSameLocation_ReturnFalse() - { - // Setup - var duneLocations1 = new ObservableList(); - var duneLocations2 = new ObservableList(); - var duneLocation = new TestDuneLocation(); - var context1 = new DuneLocationContext(duneLocations1, duneLocation); - var context2 = new DuneLocationContext(duneLocations2, duneLocation); - - // Call - bool isEqual1 = context1.Equals(context2); - bool isEqual2 = context2.Equals(context1); - - // Assert - Assert.IsFalse(isEqual1); - Assert.IsFalse(isEqual2); - } - - [Test] - public void Equals_ToOtherWithSameLocationListAndDifferentLocation_ReturnFalse() - { - // Setup - var duneLocations = new ObservableList(); - var duneLocation1 = new TestDuneLocation(); - var duneLocation2 = new TestDuneLocation(); - var context1 = new DuneLocationContext(duneLocations, duneLocation1); - var context2 = new DuneLocationContext(duneLocations, duneLocation2); - - // Call - bool isEqual1 = context1.Equals(context2); - bool isEqual2 = context2.Equals(context1); - - // Assert - Assert.IsFalse(isEqual1); - Assert.IsFalse(isEqual2); - } - - [Test] - public void Equals_ToOtherWithSameLocationListAndSameLocation_ReturnTrue() - { - // Setup - var duneLocations = new ObservableList(); - var duneLocation = new TestDuneLocation(); - var context1 = new DuneLocationContext(duneLocations, duneLocation); - var context2 = new DuneLocationContext(duneLocations, duneLocation); - - // Call - bool isEqual1 = context1.Equals(context2); - bool isEqual2 = context2.Equals(context1); - - // Assert - Assert.IsTrue(isEqual1); - Assert.IsTrue(isEqual2); - } - - [Test] - public void GetHashCode_EqualObjects_ReturnSameHashCode() - { - // Setup - var duneLocations = new ObservableList(); - var duneLocation = new TestDuneLocation(); - var context1 = new DuneLocationContext(duneLocations, duneLocation); - var context2 = new DuneLocationContext(duneLocations, duneLocation); - - // Precondition - Assert.AreEqual(context1, context2); - - // Call - int hashCode1 = context1.GetHashCode(); - int hashCode2 = context2.GetHashCode(); - - // Assert - Assert.AreEqual(hashCode1, hashCode2); - } } } \ No newline at end of file