Index: Ringtoets/Common/src/Ringtoets.Common.Data/IllustrationPoints/IllustrationPointNode.cs =================================================================== diff -u -rf288f9ccb9ac465f017170a59279909d8431fdc7 -rdbb1f44e19506308219de5f8800bcbd2fc0df929 --- Ringtoets/Common/src/Ringtoets.Common.Data/IllustrationPoints/IllustrationPointNode.cs (.../IllustrationPointNode.cs) (revision f288f9ccb9ac465f017170a59279909d8431fdc7) +++ Ringtoets/Common/src/Ringtoets.Common.Data/IllustrationPoints/IllustrationPointNode.cs (.../IllustrationPointNode.cs) (revision dbb1f44e19506308219de5f8800bcbd2fc0df929) @@ -30,7 +30,7 @@ /// A node with attached illustration point data that is part of a tree. Multiple /// nodes form the tree structure describing how the illustration points are related. /// - public class IllustrationPointNode + public class IllustrationPointNode : ICloneable { /// /// Creates a new instance of . @@ -53,7 +53,7 @@ /// /// Gets the attached illustration point data to this node. /// - public IllustrationPointBase Data { get; } + public IllustrationPointBase Data { get; private set; } /// /// Gets the attached child nodes of this node. @@ -81,5 +81,15 @@ } Children = children; } + + public object Clone() + { + var clone = (IllustrationPointNode) MemberwiseClone(); + + clone.Data = (IllustrationPointBase) Data.Clone(); + clone.Children = Children.Select(c => (IllustrationPointNode) c.Clone()); + + return clone; + } } } \ No newline at end of file Index: Ringtoets/Common/test/Ringtoets.Common.Data.Test/IllustrationPoints/IllustrationPointNodeTest.cs =================================================================== diff -u -rfe90a6d174a01975381e6cda55ed1f7f4e831a51 -rdbb1f44e19506308219de5f8800bcbd2fc0df929 --- Ringtoets/Common/test/Ringtoets.Common.Data.Test/IllustrationPoints/IllustrationPointNodeTest.cs (.../IllustrationPointNodeTest.cs) (revision fe90a6d174a01975381e6cda55ed1f7f4e831a51) +++ Ringtoets/Common/test/Ringtoets.Common.Data.Test/IllustrationPoints/IllustrationPointNodeTest.cs (.../IllustrationPointNodeTest.cs) (revision dbb1f44e19506308219de5f8800bcbd2fc0df929) @@ -26,6 +26,8 @@ using NUnit.Framework; using Ringtoets.Common.Data.IllustrationPoints; using Ringtoets.Common.Data.TestUtil.IllustrationPoints; +using CoreCloneAssert = Core.Common.Data.TestUtil.CloneAssert; +using CommonCloneAssert = Ringtoets.Common.Data.TestUtil.CloneAssert; namespace Ringtoets.Common.Data.Test.IllustrationPoints { @@ -50,21 +52,22 @@ var data = new TestIllustrationPoint(); // Call - var treeNode = new IllustrationPointNode(data); + var illustrationPointNode = new IllustrationPointNode(data); // Assert - Assert.AreSame(data, treeNode.Data); - CollectionAssert.IsEmpty(treeNode.Children); + Assert.IsInstanceOf(illustrationPointNode); + Assert.AreSame(data, illustrationPointNode.Data); + CollectionAssert.IsEmpty(illustrationPointNode.Children); } [Test] public void SetChildren_ChildrenNull_ThrowsArgumentNullException() { // Setup - var treeNode = new IllustrationPointNode(new TestIllustrationPoint()); + var illustrationPointNode = new IllustrationPointNode(new TestIllustrationPoint()); // Call - TestDelegate call = () => treeNode.SetChildren(null); + TestDelegate call = () => illustrationPointNode.SetChildren(null); // Assert var exception = Assert.Throws(call); @@ -77,17 +80,17 @@ public void SetChildren_InvalidNrOfChildren_ThrowsInvalidArgumentException(int nrOfChildren) { // Setup - var treeNode = new IllustrationPointNode(new TestIllustrationPoint()); + var illustrationPointNode = new IllustrationPointNode(new TestIllustrationPoint()); var childrenToBeAttached = new IllustrationPointNode[nrOfChildren]; // Call - TestDelegate call = () => treeNode.SetChildren(childrenToBeAttached); + TestDelegate call = () => illustrationPointNode.SetChildren(childrenToBeAttached); // Assert const string expectedMessage = "Een illustratiepunt node in de foutenboom moet 0 of 2 onderliggende nodes hebben."; var exception = TestHelper.AssertThrowsArgumentExceptionAndTestMessage(call, expectedMessage); Assert.AreEqual("children", exception.ParamName); - CollectionAssert.IsEmpty(treeNode.Children); + CollectionAssert.IsEmpty(illustrationPointNode.Children); } [Test] @@ -96,16 +99,35 @@ public void SetChildren_ValidNrOfChildren_ReturnsExpectedProperties(int nrOfChildren) { // Setup - var treeNode = new IllustrationPointNode(new TestIllustrationPoint()); + var illustrationPointNode = new IllustrationPointNode(new TestIllustrationPoint()); var childrenToBeAdded = new IllustrationPointNode[nrOfChildren]; // Call - treeNode.SetChildren(childrenToBeAdded); + illustrationPointNode.SetChildren(childrenToBeAdded); // Assert - IEnumerable addedChildren = treeNode.Children; + IEnumerable addedChildren = illustrationPointNode.Children; Assert.AreSame(childrenToBeAdded, addedChildren); Assert.AreEqual(nrOfChildren, addedChildren.Count()); } + + [Test] + public void Clone_Always_ReturnNewInstanceWithCopiedValues() + { + // Setup + var original = new IllustrationPointNode(new TestIllustrationPoint()); + + original.SetChildren(new[] + { + new IllustrationPointNode(new TestIllustrationPoint()), + new IllustrationPointNode(new TestIllustrationPoint()) + }); + + // Call + object clone = original.Clone(); + + // Assert + CoreCloneAssert.AreClones(original, clone, CommonCloneAssert.AreClones); + } } } \ No newline at end of file Index: Ringtoets/Common/test/Ringtoets.Common.Data.TestUtil/CloneAssert.cs =================================================================== diff -u -r2a88a3e4469b6b59db4ca9ff874cf69804c9393e -rdbb1f44e19506308219de5f8800bcbd2fc0df929 --- Ringtoets/Common/test/Ringtoets.Common.Data.TestUtil/CloneAssert.cs (.../CloneAssert.cs) (revision 2a88a3e4469b6b59db4ca9ff874cf69804c9393e) +++ Ringtoets/Common/test/Ringtoets.Common.Data.TestUtil/CloneAssert.cs (.../CloneAssert.cs) (revision dbb1f44e19506308219de5f8800bcbd2fc0df929) @@ -204,5 +204,19 @@ CoreCloneAssert.AreClones(original.Stochasts, clone.Stochasts, AreClones); Assert.AreEqual(original.CombinationType, clone.CombinationType); } + + /// + /// Method that asserts whether and + /// are clones. + /// + /// The original object. + /// The cloned object. + /// Thrown when and + /// are not clones. + public static void AreClones(IllustrationPointNode original, IllustrationPointNode clone) + { + CoreCloneAssert.AreClones(original.Data, clone.Data, AreClones); + CoreCloneAssert.AreClones(original.Children, clone.Children, AreClones); + } } } \ No newline at end of file