Index: Riskeer/GrassCoverErosionInwards/src/Riskeer.GrassCoverErosionInwards.Plugin/GrassCoverErosionInwardsPlugin.cs =================================================================== diff -u -r0b69db9fa07e6bf41d1c6e5aa47bb7b7b9ec71d1 -r580c7cbe418a856f8e61ece99303e31eeea4475a --- Riskeer/GrassCoverErosionInwards/src/Riskeer.GrassCoverErosionInwards.Plugin/GrassCoverErosionInwardsPlugin.cs (.../GrassCoverErosionInwardsPlugin.cs) (revision 0b69db9fa07e6bf41d1c6e5aa47bb7b7b9ec71d1) +++ Riskeer/GrassCoverErosionInwards/src/Riskeer.GrassCoverErosionInwards.Plugin/GrassCoverErosionInwardsPlugin.cs (.../GrassCoverErosionInwardsPlugin.cs) (revision 580c7cbe418a856f8e61ece99303e31eeea4475a) @@ -900,12 +900,13 @@ private ContextMenuStrip CalculationContextContextMenuStrip(GrassCoverErosionInwardsCalculationScenarioContext context, object parentData, TreeViewControl treeViewControl) { - GrassCoverErosionInwardsCalculation calculation = context.WrappedData; - var changeHandler = new ClearIllustrationPointsOfGrassCoverErosionInwardsCalculationChangeHandler(GetInquiryHelper(), - calculation); + GrassCoverErosionInwardsCalculationScenario calculation = context.WrappedData; StrictContextMenuItem updateDikeProfile = CreateUpdateDikeProfileItem(context); + IInquiryHelper inquiryHelper = GetInquiryHelper(); + IViewCommands viewCommands = Gui.ViewCommands; + var builder = new RiskeerContextMenuBuilder(Gui.Get(context, treeViewControl)); return builder.AddExportItem() .AddSeparator() @@ -923,9 +924,16 @@ Calculate, EnableValidateAndCalculateMenuItemForCalculation) .AddSeparator() - .AddClearCalculationOutputItem(calculation) - .AddClearIllustrationPointsOfCalculationItem(() => GrassCoverErosionInwardsIllustrationPointsHelper.HasIllustrationPoints(calculation), - changeHandler) + .AddClearCalculationOutputItem( + () => calculation.HasOutput, + CreateClearCalculationOutputChangeHandler(new[] + { + calculation + }, inquiryHelper, viewCommands)) + .AddClearIllustrationPointsOfCalculationItem( + () => GrassCoverErosionInwardsIllustrationPointsHelper.HasIllustrationPoints(calculation), + new ClearIllustrationPointsOfGrassCoverErosionInwardsCalculationChangeHandler( + inquiryHelper, calculation)) .AddDeleteItem() .AddSeparator() .AddCollapseAllItem() Index: Riskeer/GrassCoverErosionInwards/test/Riskeer.GrassCoverErosionInwards.Plugin.Test/TreeNodeInfos/GrassCoverErosionInwardsCalculationContextTreeNodeInfoTest.cs =================================================================== diff -u -rf4359dde195c85255ac1aa2373710dc709f65a56 -r580c7cbe418a856f8e61ece99303e31eeea4475a --- Riskeer/GrassCoverErosionInwards/test/Riskeer.GrassCoverErosionInwards.Plugin.Test/TreeNodeInfos/GrassCoverErosionInwardsCalculationContextTreeNodeInfoTest.cs (.../GrassCoverErosionInwardsCalculationContextTreeNodeInfoTest.cs) (revision f4359dde195c85255ac1aa2373710dc709f65a56) +++ Riskeer/GrassCoverErosionInwards/test/Riskeer.GrassCoverErosionInwards.Plugin.Test/TreeNodeInfos/GrassCoverErosionInwardsCalculationContextTreeNodeInfoTest.cs (.../GrassCoverErosionInwardsCalculationContextTreeNodeInfoTest.cs) (revision 580c7cbe418a856f8e61ece99303e31eeea4475a) @@ -29,6 +29,7 @@ using Core.Common.Base.Geometry; using Core.Common.Controls.TreeView; using Core.Common.Gui; +using Core.Common.Gui.Commands; using Core.Common.Gui.ContextMenu; using Core.Common.Gui.Forms.MainWindow; using Core.Common.Gui.TestUtil.ContextMenu; @@ -185,8 +186,9 @@ using (var treeViewControl = new TreeViewControl()) { var gui = mocks.Stub(); - gui.Stub(cmp => cmp.Get(nodeData, treeViewControl)).Return(menuBuilder); - gui.Stub(cmp => cmp.MainWindow).Return(mocks.Stub()); + gui.Stub(g => g.Get(nodeData, treeViewControl)).Return(menuBuilder); + gui.Stub(g => g.MainWindow).Return(mocks.Stub()); + gui.Stub(g => g.ViewCommands).Return(mocks.Stub()); mocks.ReplayAll(); plugin.Gui = gui; @@ -224,8 +226,9 @@ using (var treeViewControl = new TreeViewControl()) { var gui = mocks.Stub(); - gui.Stub(cmp => cmp.Get(nodeData, treeViewControl)).Return(menuBuilder); - gui.Stub(cmp => cmp.MainWindow).Return(mocks.Stub()); + gui.Stub(g => g.Get(nodeData, treeViewControl)).Return(menuBuilder); + gui.Stub(g => g.MainWindow).Return(mocks.Stub()); + gui.Stub(g => g.ViewCommands).Return(mocks.Stub()); mocks.ReplayAll(); plugin.Gui = gui; @@ -287,8 +290,9 @@ using (var treeViewControl = new TreeViewControl()) { var gui = mocks.Stub(); - gui.Stub(cmp => cmp.Get(nodeData, treeViewControl)).Return(menuBuilder); - gui.Stub(cmp => cmp.MainWindow).Return(mocks.Stub()); + gui.Stub(g => g.Get(nodeData, treeViewControl)).Return(menuBuilder); + gui.Stub(g => g.MainWindow).Return(mocks.Stub()); + gui.Stub(g => g.ViewCommands).Return(mocks.Stub()); mocks.ReplayAll(); plugin.Gui = gui; @@ -328,8 +332,9 @@ using (var treeViewControl = new TreeViewControl()) { var gui = mocks.Stub(); - gui.Stub(cmp => cmp.Get(nodeData, treeViewControl)).Return(menuBuilder); - gui.Stub(cmp => cmp.MainWindow).Return(mocks.Stub()); + gui.Stub(g => g.Get(nodeData, treeViewControl)).Return(menuBuilder); + gui.Stub(g => g.MainWindow).Return(mocks.Stub()); + gui.Stub(g => g.ViewCommands).Return(mocks.Stub()); mocks.ReplayAll(); plugin.Gui = gui; @@ -370,8 +375,9 @@ using (var treeViewControl = new TreeViewControl()) { var gui = mocks.Stub(); - gui.Stub(cmp => cmp.Get(nodeData, treeViewControl)).Return(menuBuilder); - gui.Stub(cmp => cmp.MainWindow).Return(mocks.Stub()); + gui.Stub(g => g.Get(nodeData, treeViewControl)).Return(menuBuilder); + gui.Stub(g => g.MainWindow).Return(mocks.Stub()); + gui.Stub(g => g.ViewCommands).Return(mocks.Stub()); mocks.ReplayAll(); plugin.Gui = gui; @@ -417,10 +423,10 @@ using (var treeViewControl = new TreeViewControl()) { - var mainWindow = mocks.Stub(); var gui = mocks.Stub(); - gui.Stub(cmp => cmp.Get(nodeData, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder()); - gui.Stub(g => g.MainWindow).Return(mainWindow); + gui.Stub(g => g.Get(nodeData, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder()); + gui.Stub(g => g.MainWindow).Return(mocks.Stub()); + gui.Stub(g => g.ViewCommands).Return(mocks.Stub()); mocks.ReplayAll(); plugin.Gui = gui; @@ -475,10 +481,10 @@ using (var treeViewControl = new TreeViewControl()) { - var mainWindow = mocks.Stub(); var gui = mocks.Stub(); - gui.Stub(cmp => cmp.Get(nodeData, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder()); - gui.Stub(g => g.MainWindow).Return(mainWindow); + gui.Stub(g => g.Get(nodeData, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder()); + gui.Stub(g => g.MainWindow).Return(mocks.Stub()); + gui.Stub(g => g.ViewCommands).Return(mocks.Stub()); mocks.ReplayAll(); plugin.Gui = gui; @@ -540,10 +546,10 @@ using (var treeViewControl = new TreeViewControl()) { - var mainWindow = mocks.Stub(); var gui = mocks.Stub(); - gui.Stub(cmp => cmp.Get(nodeData, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder()); - gui.Stub(g => g.MainWindow).Return(mainWindow); + gui.Stub(g => g.Get(nodeData, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder()); + gui.Stub(g => g.MainWindow).Return(mocks.Stub()); + gui.Stub(g => g.ViewCommands).Return(mocks.Stub()); mocks.ReplayAll(); plugin.Gui = gui; @@ -581,8 +587,9 @@ using (var treeViewControl = new TreeViewControl()) { var gui = mocks.Stub(); - gui.Stub(cmp => cmp.Get(nodeData, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder()); - gui.Stub(cmp => cmp.MainWindow).Return(mocks.Stub()); + gui.Stub(g => g.Get(nodeData, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder()); + gui.Stub(g => g.MainWindow).Return(mocks.Stub()); + gui.Stub(g => g.ViewCommands).Return(mocks.Stub()); mocks.ReplayAll(); plugin.Gui = gui; @@ -613,8 +620,9 @@ using (var treeViewControl = new TreeViewControl()) { var gui = mocks.Stub(); - gui.Stub(cmp => cmp.Get(nodeData, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder()); - gui.Stub(cmp => cmp.MainWindow).Return(mocks.Stub()); + gui.Stub(g => g.Get(nodeData, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder()); + gui.Stub(g => g.MainWindow).Return(mocks.Stub()); + gui.Stub(g => g.ViewCommands).Return(mocks.Stub()); mocks.ReplayAll(); plugin.Gui = gui; @@ -657,8 +665,9 @@ using (var treeViewControl = new TreeViewControl()) { var gui = mocks.Stub(); - gui.Stub(cmp => cmp.Get(nodeData, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder()); - gui.Stub(cmp => cmp.MainWindow).Return(mocks.Stub()); + gui.Stub(g => g.Get(nodeData, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder()); + gui.Stub(g => g.MainWindow).Return(mocks.Stub()); + gui.Stub(g => g.ViewCommands).Return(mocks.Stub()); mocks.ReplayAll(); plugin.Gui = gui; @@ -688,8 +697,9 @@ using (var treeViewControl = new TreeViewControl()) { var gui = mocks.Stub(); - gui.Stub(cmp => cmp.Get(nodeData, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder()); - gui.Stub(cmp => cmp.MainWindow).Return(mocks.Stub()); + gui.Stub(g => g.Get(nodeData, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder()); + gui.Stub(g => g.MainWindow).Return(mocks.Stub()); + gui.Stub(g => g.ViewCommands).Return(mocks.Stub()); mocks.ReplayAll(); plugin.Gui = gui; @@ -720,8 +730,9 @@ using (var treeViewControl = new TreeViewControl()) { var gui = mocks.Stub(); - gui.Stub(cmp => cmp.Get(nodeData, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder()); - gui.Stub(cmp => cmp.MainWindow).Return(mocks.Stub()); + gui.Stub(g => g.Get(nodeData, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder()); + gui.Stub(g => g.MainWindow).Return(mocks.Stub()); + gui.Stub(g => g.ViewCommands).Return(mocks.Stub()); mocks.ReplayAll(); plugin.Gui = gui; @@ -763,8 +774,9 @@ using (var treeViewControl = new TreeViewControl()) { var gui = mocks.Stub(); - gui.Stub(cmp => cmp.Get(nodeData, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder()); - gui.Stub(cmp => cmp.MainWindow).Return(mocks.Stub()); + gui.Stub(g => g.Get(nodeData, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder()); + gui.Stub(g => g.MainWindow).Return(mocks.Stub()); + gui.Stub(g => g.ViewCommands).Return(mocks.Stub()); mocks.ReplayAll(); plugin.Gui = gui; @@ -785,7 +797,6 @@ public void GivenValidCalculation_WhenCalculatingFromContextMenu_ThenOutputSetLogMessagesAddedAndUpdateObserver() { // Given - var mainWindow = mocks.DynamicMock(); var observer = mocks.StrictMock(); observer.Expect(o => o.UpdateObserver()); @@ -826,7 +837,8 @@ { var gui = mocks.Stub(); gui.Stub(g => g.Get(calculationContext, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder()); - gui.Stub(g => g.MainWindow).Return(mainWindow); + gui.Stub(g => g.MainWindow).Return(mocks.DynamicMock()); + gui.Stub(g => g.ViewCommands).Return(mocks.Stub()); var calculatorFactory = mocks.Stub(); calculatorFactory.Expect(cf => cf.CreateOvertoppingCalculator(Arg.Is.NotNull)) @@ -914,7 +926,8 @@ { var gui = mocks.Stub(); gui.Stub(g => g.Get(calculationContext, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder()); - gui.Stub(cmp => cmp.MainWindow).Return(mocks.Stub()); + gui.Stub(g => g.MainWindow).Return(mocks.Stub()); + gui.Stub(g => g.ViewCommands).Return(mocks.Stub()); mocks.ReplayAll(); plugin.Gui = gui; @@ -938,6 +951,183 @@ } [Test] + public void ContextMenuStrip_CalculationGroupWithCalculationsWithoutOutput_ContextMenuItemClearCalculationsOutputEnabled() + { + // Setup + var calculation = new GrassCoverErosionInwardsCalculationScenario + { + Output = new TestGrassCoverErosionInwardsOutput() + }; + + IAssessmentSection assessmentSection = AssessmentSectionTestHelper.CreateAssessmentSectionStub(null, mocks, "invalidFilePath"); + + var nodeData = new GrassCoverErosionInwardsCalculationScenarioContext( + calculation, new CalculationGroup(), new GrassCoverErosionInwardsFailureMechanism(), assessmentSection); + + var menuBuilder = new CustomItemsOnlyContextMenuBuilder(); + + using (var treeViewControl = new TreeViewControl()) + { + var gui = mocks.Stub(); + gui.Stub(g => g.Get(nodeData, treeViewControl)).Return(menuBuilder); + gui.Stub(g => g.MainWindow).Return(mocks.Stub()); + gui.Stub(g => g.ViewCommands).Return(mocks.Stub()); + mocks.ReplayAll(); + + plugin.Gui = gui; + + using (ContextMenuStrip contextMenu = info.ContextMenuStrip(nodeData, null, treeViewControl)) + { + // Call + ToolStripItem toolStripItem = contextMenu.Items[contextMenuClearIndex]; + + // Assert + Assert.IsTrue(toolStripItem.Enabled); + } + } + } + + [Test] + public void ContextMenuStrip_CalculationGroupWithCalculationsWithoutOutput_ContextMenuItemClearCalculationsOutputDisabled() + { + // Setup + var calculation = new GrassCoverErosionInwardsCalculationScenario(); + + IAssessmentSection assessmentSection = AssessmentSectionTestHelper.CreateAssessmentSectionStub(null, mocks, "invalidFilePath"); + + var nodeData = new GrassCoverErosionInwardsCalculationScenarioContext( + calculation, new CalculationGroup(), new GrassCoverErosionInwardsFailureMechanism(), assessmentSection); + + var menuBuilder = new CustomItemsOnlyContextMenuBuilder(); + + using (var treeViewControl = new TreeViewControl()) + { + var gui = mocks.Stub(); + gui.Stub(g => g.Get(nodeData, treeViewControl)).Return(menuBuilder); + gui.Stub(g => g.MainWindow).Return(mocks.Stub()); + gui.Stub(g => g.ViewCommands).Return(mocks.Stub()); + mocks.ReplayAll(); + + plugin.Gui = gui; + + using (ContextMenuStrip contextMenu = info.ContextMenuStrip(nodeData, null, treeViewControl)) + { + // Call + ToolStripItem toolStripItem = contextMenu.Items[contextMenuClearIndex]; + + // Assert + Assert.IsFalse(toolStripItem.Enabled); + } + } + } + + [Test] + public void GivenCalculationsWithOutput_WhenClearAllCalculationsOutputClickedAndAborted_ThenInquiryAndCalculationsOutputNotCleared() + { + // Given + var calculation = new GrassCoverErosionInwardsCalculationScenario + { + Output = new TestGrassCoverErosionInwardsOutput() + }; + + var calculationObserver = mocks.StrictMock(); + calculation.Attach(calculationObserver); + + IAssessmentSection assessmentSection = AssessmentSectionTestHelper.CreateAssessmentSectionStub(null, mocks, "invalidFilePath"); + + var nodeData = new GrassCoverErosionInwardsCalculationScenarioContext( + calculation, new CalculationGroup(), new GrassCoverErosionInwardsFailureMechanism(), assessmentSection); + + var menuBuilder = new CustomItemsOnlyContextMenuBuilder(); + + var messageBoxText = ""; + DialogBoxHandler = (name, wnd) => + { + var helper = new MessageBoxTester(wnd); + messageBoxText = helper.Text; + + helper.ClickCancel(); + }; + + using (var treeViewControl = new TreeViewControl()) + { + var gui = mocks.Stub(); + gui.Stub(g => g.Get(nodeData, treeViewControl)).Return(menuBuilder); + gui.Stub(g => g.MainWindow).Return(mocks.Stub()); + gui.Stub(g => g.ViewCommands).Return(mocks.StrictMock()); + mocks.ReplayAll(); + + plugin.Gui = gui; + + using (ContextMenuStrip contextMenu = info.ContextMenuStrip(nodeData, null, treeViewControl)) + { + // When + contextMenu.Items[contextMenuClearIndex].PerformClick(); + + // Then + Assert.AreEqual("Weet u zeker dat u de uitvoer van deze berekening wilt wissen?", messageBoxText); + + Assert.IsTrue(calculation.HasOutput); + } + } + } + + [Test] + public void GivenCalculationsWithOutput_WhenClearAllCalculationsOutputClickedAndContinued_ThenInquiryAndOutputViewsClosedAndCalculationsOutputCleared() + { + // Given + var calculation = new GrassCoverErosionInwardsCalculationScenario + { + Output = new TestGrassCoverErosionInwardsOutput() + }; + + var calculationObserver = mocks.StrictMock(); + calculationObserver.Expect(o => o.UpdateObserver()); + calculation.Attach(calculationObserver); + + IAssessmentSection assessmentSection = AssessmentSectionTestHelper.CreateAssessmentSectionStub(null, mocks, "invalidFilePath"); + + var nodeData = new GrassCoverErosionInwardsCalculationScenarioContext( + calculation, new CalculationGroup(), new GrassCoverErosionInwardsFailureMechanism(), assessmentSection); + + var menuBuilder = new CustomItemsOnlyContextMenuBuilder(); + + var messageBoxText = ""; + DialogBoxHandler = (name, wnd) => + { + var helper = new MessageBoxTester(wnd); + messageBoxText = helper.Text; + + helper.ClickOk(); + }; + + using (var treeViewControl = new TreeViewControl()) + { + var viewCommands = mocks.StrictMock(); + viewCommands.Expect(vc => vc.RemoveAllViewsForItem(calculation.Output)); + + var gui = mocks.Stub(); + gui.Stub(g => g.Get(nodeData, treeViewControl)).Return(menuBuilder); + gui.Stub(g => g.MainWindow).Return(mocks.Stub()); + gui.Stub(g => g.ViewCommands).Return(viewCommands); + mocks.ReplayAll(); + + plugin.Gui = gui; + + using (ContextMenuStrip contextMenu = info.ContextMenuStrip(nodeData, null, treeViewControl)) + { + // When + contextMenu.Items[contextMenuClearIndex].PerformClick(); + + // Then + Assert.AreEqual("Weet u zeker dat u de uitvoer van deze berekening wilt wissen?", messageBoxText); + + Assert.IsFalse(calculation.HasOutput); + } + } + } + + [Test] [TestCaseSource(nameof(GetCalculationConfigurationsWithIllustrationPoints))] public void ContextMenuStrip_CalculationWithIllustrationPoints_ContextMenuItemClearIllustrationPointsEnabled( GrassCoverErosionInwardsCalculationScenario calculation) @@ -953,8 +1143,9 @@ using (var treeViewControl = new TreeViewControl()) { var gui = mocks.Stub(); - gui.Stub(cmp => cmp.Get(nodeData, treeViewControl)).Return(menuBuilder); - gui.Stub(cmp => cmp.MainWindow).Return(mocks.Stub()); + gui.Stub(g => g.Get(nodeData, treeViewControl)).Return(menuBuilder); + gui.Stub(g => g.MainWindow).Return(mocks.Stub()); + gui.Stub(g => g.ViewCommands).Return(mocks.Stub()); mocks.ReplayAll(); plugin.Gui = gui; @@ -988,8 +1179,9 @@ using (var treeViewControl = new TreeViewControl()) { var gui = mocks.Stub(); - gui.Stub(cmp => cmp.Get(nodeData, treeViewControl)).Return(menuBuilder); - gui.Stub(cmp => cmp.MainWindow).Return(mocks.Stub()); + gui.Stub(g => g.Get(nodeData, treeViewControl)).Return(menuBuilder); + gui.Stub(g => g.MainWindow).Return(mocks.Stub()); + gui.Stub(g => g.ViewCommands).Return(mocks.Stub()); mocks.ReplayAll(); plugin.Gui = gui; @@ -1035,8 +1227,9 @@ using (var treeViewControl = new TreeViewControl()) { var gui = mocks.Stub(); - gui.Stub(cmp => cmp.Get(nodeData, treeViewControl)).Return(menuBuilder); - gui.Stub(cmp => cmp.MainWindow).Return(mocks.Stub()); + gui.Stub(g => g.Get(nodeData, treeViewControl)).Return(menuBuilder); + gui.Stub(g => g.MainWindow).Return(mocks.Stub()); + gui.Stub(g => g.ViewCommands).Return(mocks.Stub()); mocks.ReplayAll(); plugin.Gui = gui; @@ -1088,8 +1281,9 @@ using (var treeViewControl = new TreeViewControl()) { var gui = mocks.Stub(); - gui.Stub(cmp => cmp.Get(nodeData, treeViewControl)).Return(menuBuilder); - gui.Stub(cmp => cmp.MainWindow).Return(mocks.Stub()); + gui.Stub(g => g.Get(nodeData, treeViewControl)).Return(menuBuilder); + gui.Stub(g => g.MainWindow).Return(mocks.Stub()); + gui.Stub(g => g.ViewCommands).Return(mocks.Stub()); mocks.ReplayAll(); plugin.Gui = gui;