Index: Ringtoets/Common/src/Ringtoets.Common.Forms/TreeNodeInfos/RingtoetsContextMenuBuilder.cs =================================================================== diff -u -r836d03bd77cc7848d686b59c61fd63ef711c7b32 -red4051ed5a4979fcc002c2d2100ac1c80007dd1b --- Ringtoets/Common/src/Ringtoets.Common.Forms/TreeNodeInfos/RingtoetsContextMenuBuilder.cs (.../RingtoetsContextMenuBuilder.cs) (revision 836d03bd77cc7848d686b59c61fd63ef711c7b32) +++ Ringtoets/Common/src/Ringtoets.Common.Forms/TreeNodeInfos/RingtoetsContextMenuBuilder.cs (.../RingtoetsContextMenuBuilder.cs) (revision ed4051ed5a4979fcc002c2d2100ac1c80007dd1b) @@ -133,6 +133,8 @@ /// The type of the calculation item context. /// The calculation item to duplicate. /// The calculation item context belonging to the calculation item. + /// Thrown when the parent calculation group of + /// equals null. /// The itself. public RingtoetsContextMenuBuilder AddDuplicateCalculationItem( TCalculationItem calculationItem, Index: Ringtoets/Common/src/Ringtoets.Common.Forms/TreeNodeInfos/RingtoetsContextMenuItemFactory.cs =================================================================== diff -u -r836d03bd77cc7848d686b59c61fd63ef711c7b32 -red4051ed5a4979fcc002c2d2100ac1c80007dd1b --- Ringtoets/Common/src/Ringtoets.Common.Forms/TreeNodeInfos/RingtoetsContextMenuItemFactory.cs (.../RingtoetsContextMenuItemFactory.cs) (revision 836d03bd77cc7848d686b59c61fd63ef711c7b32) +++ Ringtoets/Common/src/Ringtoets.Common.Forms/TreeNodeInfos/RingtoetsContextMenuItemFactory.cs (.../RingtoetsContextMenuItemFactory.cs) (revision ed4051ed5a4979fcc002c2d2100ac1c80007dd1b) @@ -21,6 +21,7 @@ using System; using System.Collections.Generic; +using System.ComponentModel; using System.Drawing; using System.Linq; using System.Windows.Forms; @@ -180,13 +181,20 @@ /// The type of the calculation item context. /// The calculation item to duplicate. /// The calculation item context belonging to the calculation item. + /// Thrown when the parent calculation group of + /// equals null. /// The created . public static StrictContextMenuItem CreateDuplicateCalculationItem( TCalculationItem calculationItem, TCalculationItemContext calculationItemContext) where TCalculationItemContext : ICalculationContext where TCalculationItem : ICalculationBase { + if (calculationItemContext.Parent == null) + { + throw new ArgumentException($"{nameof(calculationItemContext.Parent)} should be set."); + } + return new StrictContextMenuItem( Resources.Duplicate, Resources.Duplicate_ToolTip, Index: Ringtoets/Common/test/Ringtoets.Common.Forms.Test/TreeNodeInfos/RingtoetsContextMenuItemFactoryTest.cs =================================================================== diff -u -r836d03bd77cc7848d686b59c61fd63ef711c7b32 -red4051ed5a4979fcc002c2d2100ac1c80007dd1b --- Ringtoets/Common/test/Ringtoets.Common.Forms.Test/TreeNodeInfos/RingtoetsContextMenuItemFactoryTest.cs (.../RingtoetsContextMenuItemFactoryTest.cs) (revision 836d03bd77cc7848d686b59c61fd63ef711c7b32) +++ Ringtoets/Common/test/Ringtoets.Common.Forms.Test/TreeNodeInfos/RingtoetsContextMenuItemFactoryTest.cs (.../RingtoetsContextMenuItemFactoryTest.cs) (revision ed4051ed5a4979fcc002c2d2100ac1c80007dd1b) @@ -651,12 +651,13 @@ } [Test] - public void CreateDuplicateCalculationItem_Always_CreatesDecoratedAndEnabledItem() + public void CreateDuplicateCalculationItem_CalculationItemWithParent_CreatesDecoratedAndEnabledItem() { // Setup var mocks = new MockRepository(); var calculationItem = mocks.Stub(); var calculationItemContext = mocks.Stub>(); + calculationItemContext.Stub(ic => ic.Parent).Return(new CalculationGroup()); mocks.ReplayAll(); // Call @@ -672,6 +673,25 @@ } [Test] + public void CreateDuplicateCalculationItem_CalculationItemWithoutParent_ThrowsArgumentException() + { + // Setup + var mocks = new MockRepository(); + var calculationItem = mocks.Stub(); + var calculationItemContext = mocks.Stub>(); + mocks.ReplayAll(); + + // Call + TestDelegate call = () => RingtoetsContextMenuItemFactory.CreateDuplicateCalculationItem(calculationItem, calculationItemContext); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual($"{nameof(calculationItemContext.Parent)} should be set.", exception.Message); + + mocks.VerifyAll(); + } + + [Test] [TestCaseSource(nameof(CalculationGroupConfigurations))] public void CreateDuplicateCalculationItem_PerformClickOnCreatedItem_DuplicatesCalculationItemWithExpectedNameAndPosition(ICalculationBase calculationItem, CalculationGroup calculationGroup,