Index: Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Forms.Test/TreeNodeInfos/GrassCoverErosionInwardsCalculationContextTreeNodeInfoTest.cs =================================================================== diff -u -r3bd79dc878fa0b81b1ebb5c35dd5612f2bfed356 -r9643d7e5bbb27a7782b5d939b029a70a1c023138 --- Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Forms.Test/TreeNodeInfos/GrassCoverErosionInwardsCalculationContextTreeNodeInfoTest.cs (.../GrassCoverErosionInwardsCalculationContextTreeNodeInfoTest.cs) (revision 3bd79dc878fa0b81b1ebb5c35dd5612f2bfed356) +++ Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Forms.Test/TreeNodeInfos/GrassCoverErosionInwardsCalculationContextTreeNodeInfoTest.cs (.../GrassCoverErosionInwardsCalculationContextTreeNodeInfoTest.cs) (revision 9643d7e5bbb27a7782b5d939b029a70a1c023138) @@ -23,6 +23,7 @@ using Core.Common.Controls.TreeView; using Core.Common.Gui; using Core.Common.Gui.ContextMenu; +using Core.Common.Gui.TestUtil.ContextMenu; using Core.Common.TestUtil; using NUnit.Framework; using Rhino.Mocks; @@ -33,6 +34,7 @@ using Ringtoets.GrassCoverErosionInwards.Forms.PresentationObjects; using Ringtoets.GrassCoverErosionInwards.Plugin; using GrassCoverErosionInwardsFormsResources = Ringtoets.GrassCoverErosionInwards.Forms.Properties.Resources; +using RingtoetsCommonFormsResources = Ringtoets.Common.Forms.Properties.Resources; namespace Ringtoets.GrassCoverErosionInwards.Forms.Test.TreeNodeInfos { @@ -77,11 +79,12 @@ [Test] public void ChildNodeObjects_WithOutputData_ReturnOutputChildNode() - { - var calculation = mocks.StrictMock(new GeneralGrassCoverErosionInwardsInput()); + { var assessmentSectionMock = mocks.StrictMock(); mocks.ReplayAll(); + var calculation = new GrassCoverErosionInwardsCalculation(new GeneralGrassCoverErosionInwardsInput()); + var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); var calculationContext = new GrassCoverErosionInwardsCalculationContext(calculation, failureMechanism, assessmentSectionMock); @@ -99,6 +102,7 @@ var emptyOutput = (EmptyGrassCoverErosionInwardsOutput) children[2]; Assert.IsNotNull(emptyOutput); + mocks.VerifyAll(); } [Test] @@ -110,6 +114,7 @@ var menuBuilderMock = mocks.Stub(); menuBuilderMock.Expect(mb => mb.AddCustomItem(null)).IgnoreArguments().Return(menuBuilderMock); + menuBuilderMock.Expect(mb => mb.AddCustomItem(null)).IgnoreArguments().Return(menuBuilderMock); menuBuilderMock.Expect(mb => mb.AddSeparator()).Return(menuBuilderMock); menuBuilderMock.Expect(mb => mb.AddRenameItem()).Return(menuBuilderMock); menuBuilderMock.Expect(mb => mb.AddDeleteItem()).Return(menuBuilderMock); @@ -125,7 +130,7 @@ var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); var assessmentSectionMock = mocks.StrictMock(); - var calculation = mocks.StrictMock(new GeneralGrassCoverErosionInwardsInput()); + var calculation = new GrassCoverErosionInwardsCalculation(new GeneralGrassCoverErosionInwardsInput()); var nodeData = new GrassCoverErosionInwardsCalculationContext(calculation, failureMechanism, assessmentSectionMock); @@ -141,5 +146,65 @@ // Assert mocks.VerifyAll(); // Expect no calls on arguments } + + [Test] + public void ContextMenuStrip_PipingCalculationWithoutOutput_ContextMenuItemClearOutputDisabled() + { + // Setup + var gui = mocks.StrictMock(); + var treeViewControlMock = mocks.StrictMock(); + + var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); + var assessmentSectionMock = mocks.StrictMock(); + var calculation = new GrassCoverErosionInwardsCalculation(new GeneralGrassCoverErosionInwardsInput()); + + var nodeData = new GrassCoverErosionInwardsCalculationContext(calculation, failureMechanism, assessmentSectionMock); + + gui.Expect(cmp => cmp.Get(nodeData, treeViewControlMock)).Return(new CustomItemsOnlyContextMenuBuilder()); + + mocks.ReplayAll(); + + plugin.Gui = gui; + + // Call + var contextMenu = info.ContextMenuStrip(nodeData, null, treeViewControlMock); + + // Assert + mocks.VerifyAll(); // Expect no calls on arguments + + TestHelper.AssertContextMenuStripContainsItem(contextMenu, 0, RingtoetsCommonFormsResources.Calculate, RingtoetsCommonFormsResources.Calculate_ToolTip, RingtoetsCommonFormsResources.CalculateIcon); + TestHelper.AssertContextMenuStripContainsItem(contextMenu, 1, RingtoetsCommonFormsResources.Clear_output, RingtoetsCommonFormsResources.ClearOutput_No_output_to_clear, RingtoetsCommonFormsResources.ClearIcon, false); + } + + [Test] + public void ContextMenuStrip_PipingCalculationWithOutput_ContextMenuItemClearOutputEnabled() + { + var gui = mocks.StrictMock(); + var treeViewControlMock = mocks.StrictMock(); + + var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); + var assessmentSectionMock = mocks.StrictMock(); + var calculation = new GrassCoverErosionInwardsCalculation(new GeneralGrassCoverErosionInwardsInput()) + { + Output = new GrassCoverErosionInwardsOutput(0, 0, 0, 0, 0) + }; + + var nodeData = new GrassCoverErosionInwardsCalculationContext(calculation, failureMechanism, assessmentSectionMock); + + gui.Expect(cmp => cmp.Get(nodeData, treeViewControlMock)).Return(new CustomItemsOnlyContextMenuBuilder()); + + mocks.ReplayAll(); + + plugin.Gui = gui; + + // Call + var contextMenu = info.ContextMenuStrip(nodeData, null, treeViewControlMock); + + // Assert + mocks.VerifyAll(); // Expect no calls on arguments + + TestHelper.AssertContextMenuStripContainsItem(contextMenu, 0, RingtoetsCommonFormsResources.Calculate, RingtoetsCommonFormsResources.Calculate_ToolTip, RingtoetsCommonFormsResources.CalculateIcon); + TestHelper.AssertContextMenuStripContainsItem(contextMenu, 1, RingtoetsCommonFormsResources.Clear_output, RingtoetsCommonFormsResources.Clear_output_ToolTip, RingtoetsCommonFormsResources.ClearIcon); + } } } \ No newline at end of file