Index: Riskeer/HeightStructures/src/Riskeer.HeightStructures.Plugin/HeightStructuresPlugin.cs =================================================================== diff -u -r8a21e60e9474fe20f665b1a41cc14c778d99d572 -r8b7fa9b31132e2e73edfec3202289852c40fbfeb --- Riskeer/HeightStructures/src/Riskeer.HeightStructures.Plugin/HeightStructuresPlugin.cs (.../HeightStructuresPlugin.cs) (revision 8a21e60e9474fe20f665b1a41cc14c778d99d572) +++ Riskeer/HeightStructures/src/Riskeer.HeightStructures.Plugin/HeightStructuresPlugin.cs (.../HeightStructuresPlugin.cs) (revision 8b7fa9b31132e2e73edfec3202289852c40fbfeb) @@ -432,11 +432,10 @@ .AddSeparator() .AddClearAllCalculationOutputInFailureMechanismItem( () => calculations.Any(c => c.HasOutput), - new ClearStructuresCalculationOutputChangeHandler( - calculations.Where(c => c.HasOutput), inquiryHelper, viewCommands)) + CreateClearCalculationOutputChangeHandler(calculations, inquiryHelper, viewCommands)) .AddClearIllustrationPointsOfCalculationsInFailureMechanismItem( () => IllustrationPointsHelper.HasIllustrationPoints(calculations), - CreateChangeHandler(inquiryHelper, calculations)) + CreateIllustrationPointsChangeHandler(inquiryHelper, calculations)) .AddSeparator() .AddCollapseAllItem() .AddExpandAllItem() @@ -521,15 +520,18 @@ TreeViewControl treeViewControl) { CalculationGroup group = context.WrappedData; - IInquiryHelper inquiryHelper = GetInquiryHelper(); + var builder = new RiskeerContextMenuBuilder(Gui.Get(context, treeViewControl)); bool isNestedGroup = parentData is HeightStructuresCalculationGroupContext; - StructuresCalculation[] calculations = group - .GetCalculations() - .OfType>() - .ToArray(); + StructuresCalculationScenario[] calculations = group + .GetCalculations() + .OfType>() + .ToArray(); + IInquiryHelper inquiryHelper = GetInquiryHelper(); + IViewCommands viewCommands = Gui.ViewCommands; + if (!isNestedGroup) { builder.AddOpenItem() @@ -560,8 +562,9 @@ builder.AddRenameItem(); } - builder.AddUpdateForeshoreProfileOfCalculationsItem(calculations, inquiryHelper, - SynchronizeCalculationWithForeshoreProfileHelper.UpdateForeshoreProfileDerivedCalculationInput) + builder.AddUpdateForeshoreProfileOfCalculationsItem( + calculations, inquiryHelper, + SynchronizeCalculationWithForeshoreProfileHelper.UpdateForeshoreProfileDerivedCalculationInput) .AddCustomItem(CreateUpdateAllStructuresItem(calculations)) .AddSeparator() .AddValidateAllCalculationsInGroupItem( @@ -573,9 +576,12 @@ CalculateAllInCalculationGroup, EnableValidateAndCalculateMenuItemForCalculationGroup) .AddSeparator() - .AddClearAllCalculationOutputInGroupItem(group) - .AddClearIllustrationPointsOfCalculationsInGroupItem(() => IllustrationPointsHelper.HasIllustrationPoints(calculations), - CreateChangeHandler(inquiryHelper, calculations)); + .AddClearAllCalculationOutputInGroupItem( + () => calculations.Any(c => c.HasOutput), + CreateClearCalculationOutputChangeHandler(calculations, inquiryHelper, viewCommands)) + .AddClearIllustrationPointsOfCalculationsInGroupItem( + () => IllustrationPointsHelper.HasIllustrationPoints(calculations), + CreateIllustrationPointsChangeHandler(inquiryHelper, calculations)); if (isNestedGroup) { @@ -848,12 +854,19 @@ #endregion - private ClearIllustrationPointsOfStructureCalculationCollectionChangeHandler CreateChangeHandler( + private ClearIllustrationPointsOfStructureCalculationCollectionChangeHandler CreateIllustrationPointsChangeHandler( IInquiryHelper inquiryHelper, IEnumerable> calculations) { return new ClearIllustrationPointsOfStructureCalculationCollectionChangeHandler(inquiryHelper, calculations); } + private static ClearStructuresCalculationOutputChangeHandler CreateClearCalculationOutputChangeHandler( + IEnumerable> calculations, IInquiryHelper inquiryHelper, IViewCommands viewCommands) + { + return new ClearStructuresCalculationOutputChangeHandler( + calculations.Where(c => c.HasOutput), inquiryHelper, viewCommands); + } + private static void ValidateAll(IEnumerable> heightStructuresCalculations, IAssessmentSection assessmentSection) { Index: Riskeer/HeightStructures/test/Riskeer.HeightStructures.Plugin.Test/TreeNodeInfos/HeightStructuresCalculationGroupContextTreeNodeInfoTest.cs =================================================================== diff -u -r389868939500c397bb8f18faee20ad540a19a1fe -r8b7fa9b31132e2e73edfec3202289852c40fbfeb --- Riskeer/HeightStructures/test/Riskeer.HeightStructures.Plugin.Test/TreeNodeInfos/HeightStructuresCalculationGroupContextTreeNodeInfoTest.cs (.../HeightStructuresCalculationGroupContextTreeNodeInfoTest.cs) (revision 389868939500c397bb8f18faee20ad540a19a1fe) +++ Riskeer/HeightStructures/test/Riskeer.HeightStructures.Plugin.Test/TreeNodeInfos/HeightStructuresCalculationGroupContextTreeNodeInfoTest.cs (.../HeightStructuresCalculationGroupContextTreeNodeInfoTest.cs) (revision 8b7fa9b31132e2e73edfec3202289852c40fbfeb) @@ -390,6 +390,7 @@ { gui.Stub(g => g.Get(groupContext, treeViewControl)).Return(menuBuilder); gui.Stub(g => g.MainWindow).Return(mocks.Stub()); + gui.Stub(g => g.ViewCommands).Return(mocks.StrictMock()); mocks.ReplayAll(); // Call @@ -422,6 +423,7 @@ { gui.Stub(g => g.Get(groupContext, treeViewControl)).Return(menuBuilder); gui.Stub(g => g.MainWindow).Return(mocks.Stub()); + gui.Stub(g => g.ViewCommands).Return(mocks.StrictMock()); mocks.ReplayAll(); // Call @@ -790,6 +792,7 @@ { 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.StrictMock()); mocks.ReplayAll(); plugin.Gui = gui; @@ -847,6 +850,7 @@ { 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.StrictMock()); mocks.ReplayAll(); plugin.Gui = gui; @@ -865,6 +869,218 @@ } [Test] + public void ContextMenuStrip_CalculationGroupWithCalculationsWithoutOutput_ContextMenuItemClearCalculationsOutputEnabled() + { + // Setup + var calculationGroup = new CalculationGroup + { + Children = + { + new StructuresCalculationScenario(), + new CalculationGroup + { + Children = + { + new StructuresCalculationScenario + { + Output = new TestStructuresOutput() + } + } + } + } + }; + + IAssessmentSection assessmentSection = AssessmentSectionTestHelper.CreateAssessmentSectionStub(null, mocks, "invalidFilePath"); + + var nodeData = new HeightStructuresCalculationGroupContext( + calculationGroup, null, new HeightStructuresFailureMechanism(), assessmentSection); + + var menuBuilder = new CustomItemsOnlyContextMenuBuilder(); + + using (var treeViewControl = new TreeViewControl()) + { + 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[contextMenuClearAllIndexRootGroup]; + + // Assert + Assert.IsTrue(toolStripItem.Enabled); + } + } + } + + [Test] + public void ContextMenuStrip_CalculationGroupWithCalculationsWithoutOutput_ContextMenuItemClearCalculationsOutputDisabled() + { + // Setup + var calculationGroup = new CalculationGroup + { + Children = + { + new StructuresCalculationScenario() + } + }; + + IAssessmentSection assessmentSection = AssessmentSectionTestHelper.CreateAssessmentSectionStub(null, mocks, "invalidFilePath"); + + var nodeData = new HeightStructuresCalculationGroupContext( + calculationGroup, null, new HeightStructuresFailureMechanism(), assessmentSection); + + var menuBuilder = new CustomItemsOnlyContextMenuBuilder(); + + using (var treeViewControl = new TreeViewControl()) + { + 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[contextMenuClearAllIndexRootGroup]; + + // Assert + Assert.IsFalse(toolStripItem.Enabled); + } + } + } + + [Test] + public void GivenCalculationsWithOutput_WhenClearAllCalculationsOutputClickedAndAborted_ThenInquiryAndCalculationsOutputNotCleared() + { + // Given + var calculationWithOutput = new StructuresCalculationScenario + { + Output = new TestStructuresOutput() + }; + + var calculationGroup = new CalculationGroup + { + Children = + { + calculationWithOutput, + new StructuresCalculationScenario() + } + }; + + var calculationObserver = mocks.StrictMock(); + calculationWithOutput.Attach(calculationObserver); + + IAssessmentSection assessmentSection = AssessmentSectionTestHelper.CreateAssessmentSectionStub(null, mocks, "invalidFilePath"); + + var nodeData = new HeightStructuresCalculationGroupContext( + calculationGroup, null, new HeightStructuresFailureMechanism(), 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()) + { + 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[contextMenuClearAllIndexRootGroup].PerformClick(); + + // Then + Assert.AreEqual("Weet u zeker dat u alle uitvoer wilt wissen?", messageBoxText); + + Assert.IsTrue(calculationWithOutput.HasOutput); + } + } + } + + [Test] + public void GivenCalculationsWithOutput_WhenClearAllCalculationsOutputClickedAndContinued_ThenInquiryAndOutputViewsClosedAndCalculationsOutputCleared() + { + // Given + var calculationWithOutput = new StructuresCalculationScenario + { + Output = new TestStructuresOutput() + }; + + var calculationWithoutOutput = new StructuresCalculationScenario(); + var calculationGroup = new CalculationGroup + { + Children = + { + calculationWithOutput, + calculationWithoutOutput + } + }; + + var affectedCalculationObserver = mocks.StrictMock(); + affectedCalculationObserver.Expect(o => o.UpdateObserver()); + calculationWithOutput.Attach(affectedCalculationObserver); + + var unaffectedCalculationObserver = mocks.StrictMock(); + calculationWithoutOutput.Attach(unaffectedCalculationObserver); + + IAssessmentSection assessmentSection = AssessmentSectionTestHelper.CreateAssessmentSectionStub(null, mocks, "invalidFilePath"); + + var nodeData = new HeightStructuresCalculationGroupContext( + calculationGroup, null, new HeightStructuresFailureMechanism(), 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(calculationWithOutput.Output)); + + 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[contextMenuClearAllIndexRootGroup].PerformClick(); + + // Then + Assert.AreEqual("Weet u zeker dat u alle uitvoer wilt wissen?", messageBoxText); + + Assert.IsFalse(calculationWithOutput.HasOutput); + } + } + } + + [Test] public void ContextMenuStrip_CalculationGroupWithCalculationsContainingIllustrationPoints_ContextMenuItemClearIllustrationPointsEnabled() { // Setup @@ -898,6 +1114,7 @@ { 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; @@ -941,6 +1158,7 @@ { 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; @@ -1001,6 +1219,7 @@ { 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.StrictMock()); mocks.ReplayAll(); plugin.Gui = gui; @@ -1068,6 +1287,7 @@ { 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.StrictMock()); mocks.ReplayAll(); plugin.Gui = gui; @@ -1090,7 +1310,6 @@ public void ContextMenuStrip_ClickOnCalculateAllItem_ScheduleAllChildCalculations() { // Setup - var mainWindow = mocks.Stub(); var menuBuilder = new CustomItemsOnlyContextMenuBuilder(); var failureMechanism = new TestHeightStructuresFailureMechanism(); @@ -1130,7 +1349,7 @@ using (var treeViewControl = new TreeViewControl()) { gui.Stub(g => g.Get(groupContext, treeViewControl)).Return(menuBuilder); - gui.Stub(g => g.MainWindow).Return(mainWindow); + gui.Stub(g => g.MainWindow).Return(mocks.Stub()); gui.Stub(g => g.ViewCommands).Return(mocks.Stub()); int nrOfCalculators = failureMechanism.Calculations.Count(); @@ -1359,6 +1578,7 @@ { 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.StrictMock()); mocks.ReplayAll(); // Call @@ -1397,6 +1617,7 @@ { 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.StrictMock()); mocks.ReplayAll(); // Call @@ -1439,8 +1660,9 @@ using (var treeViewControl = new TreeViewControl()) { - gui.Stub(cmp => cmp.Get(nodeData, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder()); + 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.StrictMock()); mocks.ReplayAll(); // Call @@ -1484,8 +1706,9 @@ using (var treeViewControl = new TreeViewControl()) { - gui.Stub(cmp => cmp.Get(nodeData, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder()); + 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.StrictMock()); mocks.ReplayAll(); ChangeStructure(testHeightStructure); @@ -1530,8 +1753,9 @@ using (var treeViewControl = new TreeViewControl()) { var mainWindow = mocks.Stub(); - gui.Stub(cmp => cmp.Get(nodeData, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder()); + gui.Stub(g => g.Get(nodeData, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder()); gui.Stub(g => g.MainWindow).Return(mainWindow); + gui.Stub(g => g.ViewCommands).Return(mocks.StrictMock()); mocks.ReplayAll(); ChangeStructure(structure); @@ -1586,8 +1810,9 @@ using (var treeViewControl = new TreeViewControl()) { var mainWindow = mocks.Stub(); - gui.Stub(cmp => cmp.Get(nodeData, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder()); + gui.Stub(g => g.Get(nodeData, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder()); gui.Stub(g => g.MainWindow).Return(mainWindow); + gui.Stub(g => g.ViewCommands).Return(mocks.StrictMock()); mocks.ReplayAll(); ChangeStructure(structure); @@ -1648,8 +1873,9 @@ using (var treeViewControl = new TreeViewControl()) { var mainWindow = mocks.Stub(); - gui.Stub(cmp => cmp.Get(nodeData, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder()); + gui.Stub(g => g.Get(nodeData, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder()); gui.Stub(g => g.MainWindow).Return(mainWindow); + gui.Stub(g => g.ViewCommands).Return(mocks.StrictMock()); mocks.ReplayAll(); ChangeStructure(structure); @@ -1709,9 +1935,9 @@ var menuBuilder = new CustomItemsOnlyContextMenuBuilder(); var mainWindow = mocks.Stub(); - gui.Stub(cmp => cmp.Get(nodeData, treeViewControl)).Return(menuBuilder); + gui.Stub(g => g.Get(nodeData, treeViewControl)).Return(menuBuilder); gui.Stub(g => g.MainWindow).Return(mainWindow); - gui.Stub(cmp => cmp.ViewCommands).Return(mocks.Stub()); + gui.Stub(g => g.ViewCommands).Return(mocks.Stub()); mocks.ReplayAll(); @@ -1766,9 +1992,9 @@ var menuBuilder = new CustomItemsOnlyContextMenuBuilder(); var mainWindow = mocks.Stub(); - gui.Stub(cmp => cmp.Get(nodeData, treeViewControl)).Return(menuBuilder); + gui.Stub(g => g.Get(nodeData, treeViewControl)).Return(menuBuilder); gui.Stub(g => g.MainWindow).Return(mainWindow); - gui.Stub(cmp => cmp.ViewCommands).Return(mocks.Stub()); + gui.Stub(g => g.ViewCommands).Return(mocks.Stub()); mocks.ReplayAll(); @@ -1831,9 +2057,9 @@ var menuBuilder = new CustomItemsOnlyContextMenuBuilder(); var mainWindow = mocks.Stub(); - gui.Stub(cmp => cmp.Get(nodeData, treeViewControl)).Return(menuBuilder); + gui.Stub(g => g.Get(nodeData, treeViewControl)).Return(menuBuilder); gui.Stub(g => g.MainWindow).Return(mainWindow); - gui.Stub(cmp => cmp.ViewCommands).Return(mocks.Stub()); + gui.Stub(g => g.ViewCommands).Return(mocks.Stub()); mocks.ReplayAll();