Index: Ringtoets/Common/test/Ringtoets.Common.Data.Test/Structures/StructuresCalculationTest.cs =================================================================== diff -u -rc59d5c2acab71a0a5f1a179e1a1d394d935ef14b -r3126832223e21f55afdd473dc3c7bfac8b42fb66 --- Ringtoets/Common/test/Ringtoets.Common.Data.Test/Structures/StructuresCalculationTest.cs (.../StructuresCalculationTest.cs) (revision c59d5c2acab71a0a5f1a179e1a1d394d935ef14b) +++ Ringtoets/Common/test/Ringtoets.Common.Data.Test/Structures/StructuresCalculationTest.cs (.../StructuresCalculationTest.cs) (revision 3126832223e21f55afdd473dc3c7bfac8b42fb66) @@ -24,6 +24,8 @@ using Ringtoets.Common.Data.Calculation; using Ringtoets.Common.Data.Structures; using Ringtoets.Common.Data.TestUtil; +using CoreCloneAssert = Core.Common.Data.TestUtil.CloneAssert; +using CommonCloneAssert = Ringtoets.Common.Data.TestUtil.CloneAssert; namespace Ringtoets.Common.Data.Test.Structures { @@ -128,20 +130,62 @@ Assert.AreEqual(comments, calculation.Comments.Body); } - private class TestStructuresCalculation : StructuresCalculation {} + [Test] + public void Clone_AllPropertiesSet_ReturnNewInstanceWithCopiedValues() + { + // Setup + TestStructuresCalculation original = CreateRandomCalculationWithoutOutput(); - private class TestStructuresInput : IStructuresCalculationInput + original.Output = new TestStructuresOutput(); + + // Call + object clone = original.Clone(); + + // Assert + CoreCloneAssert.AreObjectClones(original, clone, CommonCloneAssert.AreClones); + } + + [Test] + public void Clone_NotAllPropertiesSet_ReturnNewInstanceWithCopiedValues() { - public void Attach(IObserver observer) {} + // Setup + TestStructuresCalculation original = CreateRandomCalculationWithoutOutput(); - public void Detach(IObserver observer) {} + // Call + object clone = original.Clone(); - public void NotifyObservers() {} + // Assert + CoreCloneAssert.AreObjectClones(original, clone, CommonCloneAssert.AreClones); + } - public object Clone() + private static TestStructuresCalculation CreateRandomCalculationWithoutOutput() + { + var calculation = new TestStructuresCalculation { - return MemberwiseClone(); + Comments = + { + Body = "Random body" + } + }; + + CommonTestDataGenerator.SetRandomDataToStructuresInput(calculation.InputParameters); + + return calculation; + } + + private class TestStructuresCalculation : StructuresCalculation {} + + private class TestStructuresInput : StructuresInputBase + { + public override bool IsStructureInputSynchronized + { + get + { + return true; + } } + + public override void SynchronizeStructureInput() {} } } } \ No newline at end of file Index: Ringtoets/Common/test/Ringtoets.Common.Data.TestUtil/CloneAssert.cs =================================================================== diff -u -r0f827ea0e06ceae9e35fa54e42abed8796111539 -r3126832223e21f55afdd473dc3c7bfac8b42fb66 --- Ringtoets/Common/test/Ringtoets.Common.Data.TestUtil/CloneAssert.cs (.../CloneAssert.cs) (revision 0f827ea0e06ceae9e35fa54e42abed8796111539) +++ Ringtoets/Common/test/Ringtoets.Common.Data.TestUtil/CloneAssert.cs (.../CloneAssert.cs) (revision 3126832223e21f55afdd473dc3c7bfac8b42fb66) @@ -268,6 +268,7 @@ /// Method that asserts whether and /// are clones. /// + /// The type of the structure contained by the structures input. /// The original object. /// The cloned object. /// Thrown when and @@ -305,5 +306,25 @@ CoreCloneAssert.AreObjectClones(original.ProbabilityAssessmentOutput, clone.ProbabilityAssessmentOutput, AreClones); CoreCloneAssert.AreObjectClones(original.GeneralResult, clone.GeneralResult, AreClones); } + + /// + /// Method that asserts whether and + /// are clones. + /// + /// The type of structures input. + /// The type of the structure contained by the structures input. + /// The original object. + /// The cloned object. + /// Thrown when and + /// are not clones. + public static void AreClones(StructuresCalculation original, StructuresCalculation clone) + where TInput : StructuresInputBase, new() + where TStructure : StructureBase, new() + { + Assert.AreEqual(original.Name, clone.Name); + CoreCloneAssert.AreObjectClones(original.Comments, clone.Comments, AreClones); + CoreCloneAssert.AreObjectClones(original.InputParameters, clone.InputParameters, AreClones); + CoreCloneAssert.AreObjectClones(original.Output, clone.Output, AreClones); + } } } \ No newline at end of file