Index: Ringtoets/Common/src/Ringtoets.Common.Data/Calculation/CalculationGroup.cs
===================================================================
diff -u -r17b11c850b35c3ea99150ba25098b5b769b58f4f -rfb83f35cff901948b621ab14c2064590b33f17a0
--- Ringtoets/Common/src/Ringtoets.Common.Data/Calculation/CalculationGroup.cs (.../CalculationGroup.cs) (revision 17b11c850b35c3ea99150ba25098b5b769b58f4f)
+++ Ringtoets/Common/src/Ringtoets.Common.Data/Calculation/CalculationGroup.cs (.../CalculationGroup.cs) (revision fb83f35cff901948b621ab14c2064590b33f17a0)
@@ -21,6 +21,7 @@
using System;
using System.Collections.Generic;
+using System.Linq;
using Core.Common.Base;
using Ringtoets.Common.Data.Properties;
@@ -59,7 +60,7 @@
///
/// Gets the children that define this group.
///
- public IList Children { get; }
+ public IList Children { get; private set; }
public string Name
{
@@ -79,7 +80,11 @@
public object Clone()
{
- throw new NotImplementedException();
+ var clone = (CalculationGroup) MemberwiseClone();
+
+ clone.Children = Children.Select(c => (ICalculationBase) c.Clone()).ToArray();
+
+ return clone;
}
}
}
\ No newline at end of file
Index: Ringtoets/Common/test/Ringtoets.Common.Data.Test/Calculation/CalculationGroupTest.cs
===================================================================
diff -u -r3178e116f5e59e03078d465efeb303c5e232c7bf -rfb83f35cff901948b621ab14c2064590b33f17a0
--- Ringtoets/Common/test/Ringtoets.Common.Data.Test/Calculation/CalculationGroupTest.cs (.../CalculationGroupTest.cs) (revision 3178e116f5e59e03078d465efeb303c5e232c7bf)
+++ Ringtoets/Common/test/Ringtoets.Common.Data.Test/Calculation/CalculationGroupTest.cs (.../CalculationGroupTest.cs) (revision fb83f35cff901948b621ab14c2064590b33f17a0)
@@ -21,9 +21,12 @@
using System;
using Core.Common.Base;
+using Core.Common.Data.TestUtil;
+using Core.Common.TestUtil;
using NUnit.Framework;
using Rhino.Mocks;
using Ringtoets.Common.Data.Calculation;
+using Ringtoets.Common.Data.TestUtil;
namespace Ringtoets.Common.Data.Test.Calculation
{
@@ -222,5 +225,42 @@
}, group.Children,
"Already existing items should have remained in collection and new item should be added.");
}
+
+ [Test]
+ public void Clone_Always_ReturnNewInstanceWithCopiedValues()
+ {
+ // Setup
+ var random = new Random(21);
+ var original = new CalculationGroup("Random group name", random.NextBoolean())
+ {
+ Children =
+ {
+ new TestCalculationBase
+ {
+ Name = "Random item name 1"
+ },
+ new TestCalculationBase
+ {
+ Name = "Random item name 2"
+ }
+ }
+ };
+
+ // Call
+ object clone = original.Clone();
+
+ // Assert
+ CoreCloneAssert.AreObjectClones(original, clone, CommonCloneAssert.AreEqual);
+ }
+
+ private class TestCalculationBase : Observable, ICalculationBase
+ {
+ public string Name { get; set; }
+
+ public object Clone()
+ {
+ return MemberwiseClone();
+ }
+ }
}
}
\ No newline at end of file
Index: Ringtoets/Common/test/Ringtoets.Common.Data.TestUtil/CommonCloneAssert.cs
===================================================================
diff -u -r268c1647f0094f6c43aeceaa5793437562cffe5a -rfb83f35cff901948b621ab14c2064590b33f17a0
--- Ringtoets/Common/test/Ringtoets.Common.Data.TestUtil/CommonCloneAssert.cs (.../CommonCloneAssert.cs) (revision 268c1647f0094f6c43aeceaa5793437562cffe5a)
+++ Ringtoets/Common/test/Ringtoets.Common.Data.TestUtil/CommonCloneAssert.cs (.../CommonCloneAssert.cs) (revision fb83f35cff901948b621ab14c2064590b33f17a0)
@@ -21,6 +21,7 @@
using Core.Common.Data.TestUtil;
using NUnit.Framework;
+using Ringtoets.Common.Data.Calculation;
using Ringtoets.Common.Data.DikeProfiles;
using Ringtoets.Common.Data.IllustrationPoints;
using Ringtoets.Common.Data.Probability;
@@ -326,5 +327,34 @@
CoreCloneAssert.AreObjectClones(original.InputParameters, clone.InputParameters, AreClones);
CoreCloneAssert.AreObjectClones(original.Output, clone.Output, AreClones);
}
+
+ ///
+ /// Method that asserts whether and
+ /// are clones.
+ ///
+ /// The original object.
+ /// The cloned object.
+ /// Thrown when and
+ /// are not clones.
+ public static void AreEqual(CalculationGroup original, CalculationGroup clone)
+ {
+ Assert.AreEqual(original.Name, clone.Name);
+ Assert.AreEqual(original.IsNameEditable, clone.IsNameEditable);
+
+ CoreCloneAssert.AreEnumerationClones(original.Children, clone.Children, AreClones);
+ }
+
+ ///
+ /// Method that asserts whether and
+ /// are clones.
+ ///
+ /// The original object.
+ /// The cloned object.
+ /// Thrown when and
+ /// are not clones.
+ private static void AreClones(ICalculationBase original, ICalculationBase clone)
+ {
+ Assert.AreEqual(original.Name, clone.Name);
+ }
}
}
\ No newline at end of file