Index: Core/Common/test/Core.Common.TestUtil/EqualsGuidelinesTestFixture.cs =================================================================== diff -u -r0a41ca42fbbb5d63d8711f5f6d6a704480e289ee -re318f8ad1ae9ff8fabdb362d27e3db320af91ac0 --- Core/Common/test/Core.Common.TestUtil/EqualsGuidelinesTestFixture.cs (.../EqualsGuidelinesTestFixture.cs) (revision 0a41ca42fbbb5d63d8711f5f6d6a704480e289ee) +++ Core/Common/test/Core.Common.TestUtil/EqualsGuidelinesTestFixture.cs (.../EqualsGuidelinesTestFixture.cs) (revision e318f8ad1ae9ff8fabdb362d27e3db320af91ac0) @@ -24,7 +24,7 @@ namespace Core.Common.TestUtil { /// - /// Testfixture that asserts overrides of the Equals() function + /// Testfixture that asserts overrides of the function /// which follows the guidelines specified at /// https://msdn.microsoft.com/en-us/library/ms173147(v=vs.90).aspx /// Index: Ringtoets/Piping/src/Ringtoets.Piping.Primitives/PipingSoilProfile.cs =================================================================== diff -u -r53d2734c780c83d29b435303f9d82bcbaac94fe7 -re318f8ad1ae9ff8fabdb362d27e3db320af91ac0 --- Ringtoets/Piping/src/Ringtoets.Piping.Primitives/PipingSoilProfile.cs (.../PipingSoilProfile.cs) (revision 53d2734c780c83d29b435303f9d82bcbaac94fe7) +++ Ringtoets/Piping/src/Ringtoets.Piping.Primitives/PipingSoilProfile.cs (.../PipingSoilProfile.cs) (revision e318f8ad1ae9ff8fabdb362d27e3db320af91ac0) @@ -130,8 +130,11 @@ { return true; } - var other = obj as PipingSoilProfile; - return other != null && Equals(other); + if (GetType() != obj.GetType()) + { + return false; + } + return Equals((PipingSoilProfile) obj); } public override int GetHashCode() Index: Ringtoets/Piping/test/Ringtoets.Piping.Primitives.Test/PipingSoilProfileTest.cs =================================================================== diff -u -r4d2b702d8a5e4570ee53fa499f8f5fa196acdb98 -re318f8ad1ae9ff8fabdb362d27e3db320af91ac0 --- Ringtoets/Piping/test/Ringtoets.Piping.Primitives.Test/PipingSoilProfileTest.cs (.../PipingSoilProfileTest.cs) (revision 4d2b702d8a5e4570ee53fa499f8f5fa196acdb98) +++ Ringtoets/Piping/test/Ringtoets.Piping.Primitives.Test/PipingSoilProfileTest.cs (.../PipingSoilProfileTest.cs) (revision e318f8ad1ae9ff8fabdb362d27e3db320af91ac0) @@ -22,7 +22,6 @@ using System; using System.Collections.Generic; using System.Collections.ObjectModel; -using System.Drawing; using System.Linq; using Core.Common.TestUtil; using NUnit.Framework; @@ -200,145 +199,54 @@ Assert.AreEqual(name, text); } - [Test] - public void GetHashCode_EqualProfiles_AreEqual() + [TestFixture] + private class PipingSoilProfileEqualsGuideLines : EqualsGuidelinesTestFixture { - // Setup - PipingSoilProfile profileA = CreateRandomProfile(21); - PipingSoilProfile profileB = CreateRandomProfile(21); + private const string name = "Profile name"; + private const double bottom = 3.14; + private const SoilProfileType type = SoilProfileType.SoilProfile1D; - // Precondition - Assert.AreEqual(profileA, profileB); - Assert.AreEqual(profileB, profileA); + protected override PipingSoilProfile CreateObject() + { + return CreateSingleLayerProfile(name, bottom, type); + } - // Call & Assert - Assert.AreEqual(profileA.GetHashCode(), profileB.GetHashCode()); - Assert.AreEqual(profileB.GetHashCode(), profileA.GetHashCode()); - } + protected override TestProfile CreateDerivedObject() + { + PipingSoilProfile baseProfile = CreateSingleLayerProfile(name, bottom, type); + return new TestProfile(baseProfile); + } - [Test] - public void Equals_DerivedClassWithEqualProperties_ReturnsTrue() - { - // Setup - PipingSoilProfile profile = CreateRandomProfile(2); - var derivedProfile = new TestProfile(profile); - - // Call - bool areEqual = profile.Equals(derivedProfile); - - // Assert - Assert.IsTrue(areEqual); - } - - [Test] - public void Equals_DifferentType_ReturnsFalse() - { - // Setup - PipingSoilProfile profile = CreateRandomProfile(2); - - // Call - bool areEqual = profile.Equals(new object()); - - // Assert - Assert.IsFalse(areEqual); - } - - [Test] - public void Equals_Null_ReturnsFalse() - { - // Setup - var profile = new PipingSoilProfile("name", 0, new[] + private static IEnumerable GetUnequalTestCases() { - CreateRandomLayer(new Random(21)) - }, SoilProfileType.SoilProfile1D); + PipingSoilProfile baseProfile = CreateSingleLayerProfile(name, bottom, type); - // Call - bool areEqual = profile.Equals(null); + yield return new TestCaseData(CreateSingleLayerProfile("Different name", + baseProfile.Bottom, + baseProfile.SoilProfileSourceType)) + .SetName("Name"); - // Assert - Assert.IsFalse(areEqual); - } + yield return new TestCaseData(CreateSingleLayerProfile(baseProfile.Name, + baseProfile.Bottom + 10, + baseProfile.SoilProfileSourceType)) + .SetName("Bottom"); - [Test] - [TestCaseSource(nameof(ProfileCombinations))] - public void Equals_DifferentScenarios_ReturnsExpectedResult(PipingSoilProfile profile, PipingSoilProfile otherProfile, bool expectedEqual) - { - // Call - bool areEqualOne = profile.Equals(otherProfile); - bool areEqualTwo = otherProfile.Equals(profile); + yield return new TestCaseData(CreateSingleLayerProfile(baseProfile.Name, + baseProfile.Bottom, + SoilProfileType.SoilProfile2D)) + .SetName("SoilProfileType"); - // Assert - Assert.AreEqual(expectedEqual, areEqualOne); - Assert.AreEqual(expectedEqual, areEqualTwo); + yield return new TestCaseData(new PipingSoilProfile(baseProfile.Name, + baseProfile.Bottom, + new[] + { + new PipingSoilLayer(baseProfile.Bottom + 10) + }, + baseProfile.SoilProfileSourceType)) + .SetName("Layers"); + } } - private static TestCaseData[] ProfileCombinations() - { - PipingSoilProfile profileA = CreateRandomProfile(21); - PipingSoilProfile profileB = CreateRandomProfile(21); - PipingSoilProfile profileC = CreateRandomProfile(73); - - PipingSoilProfile profileD = CreateSingleLayerProfile("A", -3, SoilProfileType.SoilProfile1D); - PipingSoilProfile profileE = CreateSingleLayerProfile("A", -3, SoilProfileType.SoilProfile2D); - PipingSoilProfile profileF = CreateSingleLayerProfile("A", -2, SoilProfileType.SoilProfile1D); - PipingSoilProfile profileG = CreateSingleLayerProfile("B", -3, SoilProfileType.SoilProfile1D); - - const int seed = 78; - var random = new Random(seed); - var profileH = new PipingSoilProfile(GetRandomName(random), -random.NextDouble(), new[] - { - CreateRandomLayer(random) - }, random.NextEnumValue()); - - random = new Random(seed); - var profileI = new PipingSoilProfile(GetRandomName(random), -random.NextDouble(), new[] - { - CreateRandomLayer(random), - CreateRandomLayer(random) - }, random.NextEnumValue()); - - var profileJ = new PipingSoilProfile("A", -3, new[] - { - new PipingSoilLayer(-2) - }, SoilProfileType.SoilProfile1D); - var profileK = new PipingSoilProfile("A", -3, new[] - { - new PipingSoilLayer(-2) - }, SoilProfileType.SoilProfile1D); - - return new[] - { - new TestCaseData(profileA, profileB, true) - { - TestName = "Equals_ProfileAProfileB_True" - }, - new TestCaseData(profileB, profileC, false) - { - TestName = "Equals_ProfileBProfileC_False" - }, - new TestCaseData(profileD, profileE, false) - { - TestName = "Equals_ProfileDProfileE_False" - }, - new TestCaseData(profileD, profileF, false) - { - TestName = "Equals_ProfileDProfileF_False" - }, - new TestCaseData(profileD, profileG, false) - { - TestName = "Equals_ProfileDProfileG_False" - }, - new TestCaseData(profileH, profileI, false) - { - TestName = "Equals_ProfileHProfileI_False" - }, - new TestCaseData(profileJ, profileK, true) - { - TestName = "Equals_DifferentIds_True" - } - }; - } - private static PipingSoilProfile CreateSingleLayerProfile(string name, double bottom, SoilProfileType type) { return new PipingSoilProfile(name, bottom, new[] @@ -347,39 +255,6 @@ }, type); } - private static PipingSoilProfile CreateRandomProfile(int randomSeed) - { - var random = new Random(randomSeed); - var layers = new Collection(); - for (var i = 0; i < random.Next(2, 6); i++) - { - layers.Add(CreateRandomLayer(random)); - } - return new PipingSoilProfile(GetRandomName(random), -1.0 - random.NextDouble(), layers, random.NextEnumValue()); - } - - private static PipingSoilLayer CreateRandomLayer(Random random) - { - return new PipingSoilLayer(random.NextDouble()) - { - MaterialName = GetRandomName(random), - Color = Color.FromKnownColor(random.NextEnumValue()), - IsAquifer = random.NextBoolean(), - BelowPhreaticLevelDeviation = random.NextDouble(), - BelowPhreaticLevelMean = random.NextDouble(), - BelowPhreaticLevelShift = random.NextDouble(), - DiameterD70CoefficientOfVariation = random.NextDouble(), - DiameterD70Mean = random.NextDouble(), - PermeabilityCoefficientOfVariation = random.NextDouble(), - PermeabilityMean = random.NextDouble() - }; - } - - private static string GetRandomName(Random random) - { - return new string('x', random.Next(0, 40)); - } - private class TestProfile : PipingSoilProfile { public TestProfile(PipingSoilProfile profile)