Index: Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.Data/MacroStabilityInwardsLocationInputBase.cs =================================================================== diff -u -rd485f27eb5a6d688406882dce60c3229e22f2ac2 -r6e6d78be2b5fb41a3425ceff72182a8fe5abb445 --- Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.Data/MacroStabilityInwardsLocationInputBase.cs (.../MacroStabilityInwardsLocationInputBase.cs) (revision d485f27eb5a6d688406882dce60c3229e22f2ac2) +++ Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.Data/MacroStabilityInwardsLocationInputBase.cs (.../MacroStabilityInwardsLocationInputBase.cs) (revision 6e6d78be2b5fb41a3425ceff72182a8fe5abb445) @@ -19,6 +19,7 @@ // Stichting Deltares and remain full property of Stichting Deltares at all times. // All rights reserved. +using System; using Core.Common.Base.Data; using Ringtoets.MacroStabilityInwards.Primitives; @@ -28,7 +29,7 @@ /// Base class that holds all locations input for either daily or /// extreme conditions for the macro stability inwards calculation. /// - public abstract class MacroStabilityInwardsLocationInputBase : IMacroStabilityInwardsLocationInput + public abstract class MacroStabilityInwardsLocationInputBase : IMacroStabilityInwardsLocationInput, ICloneable { private RoundedDouble waterLevelPolder; private RoundedDouble phreaticLineOffsetBelowDikeTopAtRiver; @@ -112,5 +113,10 @@ phreaticLineOffsetBelowDikeToeAtPolder = value.ToPrecision(phreaticLineOffsetBelowDikeToeAtPolder.NumberOfDecimalPlaces); } } + + public object Clone() + { + return MemberwiseClone(); + } } } \ No newline at end of file Index: Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Data.Test/MacroStabilityInwardsLocationInputBaseTest.cs =================================================================== diff -u -rd485f27eb5a6d688406882dce60c3229e22f2ac2 -r6e6d78be2b5fb41a3425ceff72182a8fe5abb445 --- Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Data.Test/MacroStabilityInwardsLocationInputBaseTest.cs (.../MacroStabilityInwardsLocationInputBaseTest.cs) (revision d485f27eb5a6d688406882dce60c3229e22f2ac2) +++ Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Data.Test/MacroStabilityInwardsLocationInputBaseTest.cs (.../MacroStabilityInwardsLocationInputBaseTest.cs) (revision 6e6d78be2b5fb41a3425ceff72182a8fe5abb445) @@ -21,8 +21,11 @@ using System; using Core.Common.Base.Data; +using Core.Common.Data.TestUtil; +using Core.Common.TestUtil; using NUnit.Framework; using Ringtoets.Common.Data.TestUtil; +using Ringtoets.MacroStabilityInwards.Data.TestUtil; using Ringtoets.MacroStabilityInwards.Primitives; namespace Ringtoets.MacroStabilityInwards.Data.Test @@ -37,6 +40,8 @@ // Assert Assert.IsInstanceOf(locationInput); + Assert.IsInstanceOf(locationInput); + Assert.IsTrue(locationInput.UseDefaultOffsets); Assert.IsNaN(locationInput.PhreaticLineOffsetBelowDikeTopAtRiver); @@ -89,6 +94,26 @@ locationInput.PhreaticLineOffsetBelowShoulderBaseInside.GetAccuracy()); } + [Test] + public void Clone_Always_ReturnNewInstanceWithCopiedValues() + { + // Setup + var random = new Random(21); + MacroStabilityInwardsLocationInputBase original = new TestMacroStabilityInwardsLocationInput + { + PhreaticLineOffsetBelowDikeTopAtPolder = random.NextRoundedDouble(), + PhreaticLineOffsetBelowDikeToeAtPolder = random.NextRoundedDouble(), + PhreaticLineOffsetBelowDikeTopAtRiver = random.NextRoundedDouble(), + PhreaticLineOffsetBelowShoulderBaseInside = random.NextRoundedDouble() + }; + + // Call + object clone = original.Clone(); + + // Assert + CoreCloneAssert.AreObjectClones(original, clone, MacroStabilityInwardsCloneAssert.AreClones); + } + private class TestMacroStabilityInwardsLocationInput : MacroStabilityInwardsLocationInputBase {} } } \ No newline at end of file Index: Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Data.Test/MacroStabilityInwardsLocationInputDailyTest.cs =================================================================== diff -u -rd485f27eb5a6d688406882dce60c3229e22f2ac2 -r6e6d78be2b5fb41a3425ceff72182a8fe5abb445 --- Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Data.Test/MacroStabilityInwardsLocationInputDailyTest.cs (.../MacroStabilityInwardsLocationInputDailyTest.cs) (revision d485f27eb5a6d688406882dce60c3229e22f2ac2) +++ Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Data.Test/MacroStabilityInwardsLocationInputDailyTest.cs (.../MacroStabilityInwardsLocationInputDailyTest.cs) (revision 6e6d78be2b5fb41a3425ceff72182a8fe5abb445) @@ -19,7 +19,9 @@ // Stichting Deltares and remain full property of Stichting Deltares at all times. // All rights reserved. +using Core.Common.Data.TestUtil; using NUnit.Framework; +using Ringtoets.MacroStabilityInwards.Data.TestUtil; using Ringtoets.MacroStabilityInwards.Primitives; namespace Ringtoets.MacroStabilityInwards.Data.Test @@ -39,5 +41,18 @@ Assert.AreEqual(0.0, locationInput.PenetrationLength); Assert.AreEqual(2, locationInput.PhreaticLineOffsetBelowDikeToeAtPolder.NumberOfDecimalPlaces); } + + [Test] + public void Clone_Always_ReturnNewInstanceWithCopiedValues() + { + // Setup + var original = new MacroStabilityInwardsLocationInputDaily(); + + // Call + object clone = original.Clone(); + + // Assert + CoreCloneAssert.AreObjectClones(original, clone, MacroStabilityInwardsCloneAssert.AreClones); + } } } \ No newline at end of file Index: Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Data.Test/MacroStabilityInwardsLocationInputExtremeTest.cs =================================================================== diff -u -rd485f27eb5a6d688406882dce60c3229e22f2ac2 -r6e6d78be2b5fb41a3425ceff72182a8fe5abb445 --- Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Data.Test/MacroStabilityInwardsLocationInputExtremeTest.cs (.../MacroStabilityInwardsLocationInputExtremeTest.cs) (revision d485f27eb5a6d688406882dce60c3229e22f2ac2) +++ Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Data.Test/MacroStabilityInwardsLocationInputExtremeTest.cs (.../MacroStabilityInwardsLocationInputExtremeTest.cs) (revision 6e6d78be2b5fb41a3425ceff72182a8fe5abb445) @@ -21,8 +21,11 @@ using System; using Core.Common.Base.Data; +using Core.Common.Data.TestUtil; +using Core.Common.TestUtil; using NUnit.Framework; using Ringtoets.Common.Data.TestUtil; +using Ringtoets.MacroStabilityInwards.Data.TestUtil; using Ringtoets.MacroStabilityInwards.Primitives; namespace Ringtoets.MacroStabilityInwards.Data.Test @@ -60,5 +63,22 @@ Assert.AreEqual(2, locationInput.PenetrationLength.NumberOfDecimalPlaces); Assert.AreEqual(penetrationLength, locationInput.PenetrationLength, locationInput.PenetrationLength.GetAccuracy()); } + + [Test] + public void Clone_Always_ReturnNewInstanceWithCopiedValues() + { + // Setup + var random = new Random(21); + var original = new MacroStabilityInwardsLocationInputExtreme + { + PenetrationLength = random.NextRoundedDouble() + }; + + // Call + object clone = original.Clone(); + + // Assert + CoreCloneAssert.AreObjectClones(original, clone, MacroStabilityInwardsCloneAssert.AreClones); + } } } \ No newline at end of file Index: Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Data.TestUtil/MacroStabilityInwardsCloneAssert.cs =================================================================== diff -u -rd44a51e1d18e1e0c4c8e322174687304fd15e8fb -r6e6d78be2b5fb41a3425ceff72182a8fe5abb445 --- Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Data.TestUtil/MacroStabilityInwardsCloneAssert.cs (.../MacroStabilityInwardsCloneAssert.cs) (revision d44a51e1d18e1e0c4c8e322174687304fd15e8fb) +++ Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Data.TestUtil/MacroStabilityInwardsCloneAssert.cs (.../MacroStabilityInwardsCloneAssert.cs) (revision 6e6d78be2b5fb41a3425ceff72182a8fe5abb445) @@ -38,6 +38,55 @@ /// The cloned object. /// Thrown when and /// are not clones. + public static void AreClones(MacroStabilityInwardsLocationInputBase original, + MacroStabilityInwardsLocationInputBase clone) + { + Assert.AreEqual(original.WaterLevelPolder, clone.WaterLevelPolder); + Assert.AreEqual(original.UseDefaultOffsets, clone.UseDefaultOffsets); + Assert.AreEqual(original.PhreaticLineOffsetBelowDikeTopAtPolder, clone.PhreaticLineOffsetBelowDikeTopAtPolder); + Assert.AreEqual(original.PhreaticLineOffsetBelowDikeTopAtRiver, clone.PhreaticLineOffsetBelowDikeTopAtRiver); + Assert.AreEqual(original.PhreaticLineOffsetBelowShoulderBaseInside, clone.PhreaticLineOffsetBelowShoulderBaseInside); + Assert.AreEqual(original.PhreaticLineOffsetBelowDikeToeAtPolder, clone.PhreaticLineOffsetBelowDikeToeAtPolder); + } + + /// + /// Method that asserts whether and + /// are clones. + /// + /// The original object. + /// The cloned object. + /// Thrown when and + /// are not clones. + public static void AreClones(MacroStabilityInwardsLocationInputExtreme original, + MacroStabilityInwardsLocationInputExtreme clone) + { + AreClones((MacroStabilityInwardsLocationInputBase)original, clone); + Assert.AreEqual(original.PenetrationLength, clone.PenetrationLength); + } + + /// + /// Method that asserts whether and + /// are clones. + /// + /// The original object. + /// The cloned object. + /// Thrown when and + /// are not clones. + public static void AreClones(MacroStabilityInwardsLocationInputDaily original, + MacroStabilityInwardsLocationInputDaily clone) + { + AreClones((MacroStabilityInwardsLocationInputBase)original, clone); + Assert.AreEqual(original.PenetrationLength, clone.PenetrationLength); + } + + /// + /// Method that asserts whether and + /// are clones. + /// + /// The original object. + /// The cloned object. + /// Thrown when and + /// are not clones. public static void AreClones(MacroStabilityInwardsGrid original, MacroStabilityInwardsGrid clone) {