Index: Riskeer/HeightStructures/src/Riskeer.HeightStructures.Plugin/HeightStructuresPlugin.cs =================================================================== diff -u -rfd572b1d0d0be95b5218314d9022665514b68caf -rea1f2528796aea2946f3f8a7bbc28b2c528576d9 --- Riskeer/HeightStructures/src/Riskeer.HeightStructures.Plugin/HeightStructuresPlugin.cs (.../HeightStructuresPlugin.cs) (revision fd572b1d0d0be95b5218314d9022665514b68caf) +++ Riskeer/HeightStructures/src/Riskeer.HeightStructures.Plugin/HeightStructuresPlugin.cs (.../HeightStructuresPlugin.cs) (revision ea1f2528796aea2946f3f8a7bbc28b2c528576d9) @@ -26,6 +26,7 @@ using Core.Common.Base; using Core.Common.Base.IO; using Core.Common.Controls.TreeView; +using Core.Common.Gui.Commands; using Core.Common.Gui.ContextMenu; using Core.Common.Gui.Forms.ProgressDialog; using Core.Common.Gui.Helpers; @@ -406,11 +407,13 @@ object parentData, TreeViewControl treeViewControl) { - IEnumerable> calculations = context.WrappedData - .Calculations - .Cast>(); + StructuresCalculation[] calculations = context.WrappedData + .Calculations + .Cast>() + .ToArray(); IInquiryHelper inquiryHelper = GetInquiryHelper(); + IViewCommands viewCommands = Gui.ViewCommands; var builder = new RiskeerContextMenuBuilder(Gui.Get(context, treeViewControl)); @@ -427,9 +430,13 @@ CalculateAllInFailureMechanism, EnableValidateAndCalculateMenuItemForFailureMechanism) .AddSeparator() - .AddClearAllCalculationOutputInFailureMechanismItem(context.WrappedData) - .AddClearIllustrationPointsOfCalculationsInFailureMechanismItem(() => IllustrationPointsHelper.HasIllustrationPoints(calculations), - CreateChangeHandler(inquiryHelper, calculations)) + .AddClearAllCalculationOutputInFailureMechanismItem( + () => calculations.Any(c => c.HasOutput), + new StructuresClearCalculationOutputChangeHandler( + calculations.Where(c => c.HasOutput), inquiryHelper, viewCommands)) + .AddClearIllustrationPointsOfCalculationsInFailureMechanismItem( + () => IllustrationPointsHelper.HasIllustrationPoints(calculations), + CreateChangeHandler(inquiryHelper, calculations)) .AddSeparator() .AddCollapseAllItem() .AddExpandAllItem() Index: Riskeer/HeightStructures/test/Riskeer.HeightStructures.Plugin.Test/TreeNodeInfos/HeightStructuresFailureMechanismContextTreeNodeInfoTest.cs =================================================================== diff -u -rd1c333df3a55ad8baba0d1cc0c4cff54c69668d7 -rea1f2528796aea2946f3f8a7bbc28b2c528576d9 --- Riskeer/HeightStructures/test/Riskeer.HeightStructures.Plugin.Test/TreeNodeInfos/HeightStructuresFailureMechanismContextTreeNodeInfoTest.cs (.../HeightStructuresFailureMechanismContextTreeNodeInfoTest.cs) (revision d1c333df3a55ad8baba0d1cc0c4cff54c69668d7) +++ Riskeer/HeightStructures/test/Riskeer.HeightStructures.Plugin.Test/TreeNodeInfos/HeightStructuresFailureMechanismContextTreeNodeInfoTest.cs (.../HeightStructuresFailureMechanismContextTreeNodeInfoTest.cs) (revision ea1f2528796aea2946f3f8a7bbc28b2c528576d9) @@ -229,6 +229,7 @@ var gui = mocksRepository.Stub(); gui.Stub(cmp => cmp.Get(failureMechanismContext, treeViewControl)).Return(menuBuilder); gui.Stub(g => g.MainWindow).Return(mocksRepository.Stub()); + gui.Stub(g => g.ViewCommands).Return(mocksRepository.Stub()); mocksRepository.ReplayAll(); plugin.Gui = gui; @@ -297,6 +298,7 @@ gui.Stub(g => g.ProjectOpened += null).IgnoreArguments(); gui.Stub(g => g.ProjectOpened -= null).IgnoreArguments(); gui.Stub(g => g.MainWindow).Return(mocksRepository.Stub()); + gui.Stub(g => g.ViewCommands).Return(mocksRepository.Stub()); mocksRepository.ReplayAll(); plugin.Gui = gui; @@ -447,7 +449,7 @@ public void ContextMenuStrip_HydraulicBoundaryDatabaseNotLinked_ContextMenuItemCalculateAllDisabledAndTooltipSet() { // Setup - var failureMechanism = new TestHeightStructuresFailureMechanism(); + var failureMechanism = new HeightStructuresFailureMechanism(); failureMechanism.CalculationsGroup.Children.Add(new StructuresCalculation()); IAssessmentSection assessmentSection = AssessmentSectionTestHelper.CreateAssessmentSectionStub(mocksRepository); @@ -459,6 +461,7 @@ var gui = mocksRepository.Stub(); gui.Stub(g => g.Get(nodeData, treeViewControl)).Return(menuBuilder); gui.Stub(g => g.MainWindow).Return(mocksRepository.Stub()); + gui.Stub(g => g.ViewCommands).Return(mocksRepository.Stub()); mocksRepository.ReplayAll(); plugin.Gui = gui; @@ -480,7 +483,7 @@ public void ContextMenuStrip_HydraulicBoundaryDatabaseLinkedToInvalidFile_ContextMenuItemCalculateAllDisabledAndTooltipSet() { // Setup - var failureMechanism = new TestHeightStructuresFailureMechanism(); + var failureMechanism = new HeightStructuresFailureMechanism(); failureMechanism.CalculationsGroup.Children.Add(new StructuresCalculation()); IAssessmentSection assessmentSection = AssessmentSectionTestHelper.CreateAssessmentSectionStub(null, mocksRepository, "invalidFilePath"); @@ -493,6 +496,7 @@ var gui = mocksRepository.Stub(); gui.Stub(g => g.Get(nodeData, treeViewControl)).Return(menuBuilder); gui.Stub(g => g.MainWindow).Return(mocksRepository.Stub()); + gui.Stub(g => g.ViewCommands).Return(mocksRepository.Stub()); mocksRepository.ReplayAll(); plugin.Gui = gui; @@ -515,7 +519,7 @@ public void ContextMenuStrip_AllRequiredInputSet_ContextMenuItemCalculateAllEnabled() { // Setup - var failureMechanism = new TestHeightStructuresFailureMechanism(); + var failureMechanism = new HeightStructuresFailureMechanism(); failureMechanism.CalculationsGroup.Children.Add(new StructuresCalculation()); string validFilePath = Path.Combine(testDataPath, "complete.sqlite"); @@ -538,6 +542,7 @@ var gui = mocksRepository.Stub(); gui.Stub(g => g.Get(nodeData, treeViewControl)).Return(menuBuilder); gui.Stub(g => g.MainWindow).Return(mocksRepository.Stub()); + gui.Stub(g => g.ViewCommands).Return(mocksRepository.Stub()); mocksRepository.ReplayAll(); plugin.Gui = gui; @@ -558,7 +563,7 @@ public void ContextMenuStrip_HydraulicBoundaryDatabaseNotLinked_ContextMenuItemValidateAllDisabledAndTooltipSet() { // Setup - var failureMechanism = new TestHeightStructuresFailureMechanism(); + var failureMechanism = new HeightStructuresFailureMechanism(); failureMechanism.CalculationsGroup.Children.Add(new StructuresCalculation()); IAssessmentSection assessmentSection = AssessmentSectionTestHelper.CreateAssessmentSectionStub(mocksRepository); @@ -571,6 +576,7 @@ var gui = mocksRepository.Stub(); gui.Stub(g => g.Get(nodeData, treeViewControl)).Return(menuBuilder); gui.Stub(g => g.MainWindow).Return(mocksRepository.Stub()); + gui.Stub(g => g.ViewCommands).Return(mocksRepository.Stub()); mocksRepository.ReplayAll(); plugin.Gui = gui; @@ -592,7 +598,7 @@ public void ContextMenuStrip_HydraulicBoundaryDatabaseLinkedToInvalidFile_ContextMenuItemValidateAllDisabledAndTooltipSet() { // Setup - var failureMechanism = new TestHeightStructuresFailureMechanism(); + var failureMechanism = new HeightStructuresFailureMechanism(); failureMechanism.CalculationsGroup.Children.Add(new StructuresCalculation()); IAssessmentSection assessmentSection = AssessmentSectionTestHelper.CreateAssessmentSectionStub(null, mocksRepository, "invalidFilePath"); @@ -605,6 +611,7 @@ var gui = mocksRepository.Stub(); gui.Stub(g => g.Get(nodeData, treeViewControl)).Return(menuBuilder); gui.Stub(g => g.MainWindow).Return(mocksRepository.Stub()); + gui.Stub(g => g.ViewCommands).Return(mocksRepository.Stub()); mocksRepository.ReplayAll(); plugin.Gui = gui; @@ -627,7 +634,7 @@ public void ContextMenuStrip_AllRequiredInputSet_ContextMenuItemValidateAllEnabled() { // Setup - var failureMechanism = new TestHeightStructuresFailureMechanism(); + var failureMechanism = new HeightStructuresFailureMechanism(); failureMechanism.CalculationsGroup.Children.Add(new StructuresCalculation()); string validFilePath = Path.Combine(testDataPath, "complete.sqlite"); @@ -650,6 +657,7 @@ var gui = mocksRepository.Stub(); gui.Stub(g => g.Get(nodeData, treeViewControl)).Return(menuBuilder); gui.Stub(g => g.MainWindow).Return(mocksRepository.Stub()); + gui.Stub(g => g.ViewCommands).Return(mocksRepository.Stub()); mocksRepository.ReplayAll(); plugin.Gui = gui; @@ -670,10 +678,9 @@ public void ContextMenuStrip_ClickOnCalculateAllItem_ScheduleAllChildCalculations() { // Setup - var mainWindow = mocksRepository.Stub(); var menuBuilder = new CustomItemsOnlyContextMenuBuilder(); - var failureMechanism = new TestHeightStructuresFailureMechanism(); + var failureMechanism = new HeightStructuresFailureMechanism(); failureMechanism.CalculationsGroup.Children.Add(new TestHeightStructuresCalculationScenario { Name = "A", @@ -708,7 +715,8 @@ { var gui = mocksRepository.Stub(); gui.Stub(g => g.Get(failureMechanismContext, treeViewControl)).Return(menuBuilder); - gui.Stub(g => g.MainWindow).Return(mainWindow); + gui.Stub(g => g.MainWindow).Return(mocksRepository.Stub()); + gui.Stub(g => g.ViewCommands).Return(mocksRepository.Stub()); int nrOfCalculators = failureMechanism.Calculations.Count(); var calculatorFactory = mocksRepository.Stub(); @@ -766,7 +774,7 @@ public void ContextMenuStrip_ClickOnValidateAllItem_ValidateAllChildCalculations() { // Setup - var failureMechanism = new TestHeightStructuresFailureMechanism(); + var failureMechanism = new HeightStructuresFailureMechanism(); failureMechanism.CalculationsGroup.Children.Add(new TestHeightStructuresCalculationScenario { Name = "A", @@ -803,6 +811,7 @@ var gui = mocksRepository.Stub(); gui.Stub(g => g.Get(failureMechanismContext, treeViewControl)).Return(menuBuilder); gui.Stub(g => g.MainWindow).Return(mocksRepository.Stub()); + gui.Stub(g => g.ViewCommands).Return(mocksRepository.Stub()); mocksRepository.ReplayAll(); plugin.Gui = gui; @@ -828,15 +837,233 @@ } [Test] + public void ContextMenuStrip_FailureMechanismWithCalculationsWithoutOutput_ContextMenuItemClearCalculationsOutputEnabled() + { + // Setup + var calculationWithOutput = new StructuresCalculationScenario + { + Output = new TestStructuresOutput() + }; + + var failureMechanism = new HeightStructuresFailureMechanism + { + CalculationsGroup = + { + Children = + { + calculationWithOutput, + new StructuresCalculationScenario() + } + } + }; + + IAssessmentSection assessmentSection = AssessmentSectionTestHelper.CreateAssessmentSectionStub(null, mocksRepository, "invalidFilePath"); + + var nodeData = new HeightStructuresFailureMechanismContext(failureMechanism, assessmentSection); + var menuBuilder = new CustomItemsOnlyContextMenuBuilder(); + + using (var treeViewControl = new TreeViewControl()) + { + var gui = mocksRepository.Stub(); + gui.Stub(g => g.Get(nodeData, treeViewControl)).Return(menuBuilder); + gui.Stub(g => g.MainWindow).Return(mocksRepository.Stub()); + gui.Stub(g => g.ViewCommands).Return(mocksRepository.Stub()); + mocksRepository.ReplayAll(); + + plugin.Gui = gui; + + using (ContextMenuStrip contextMenu = info.ContextMenuStrip(nodeData, null, treeViewControl)) + { + // Call + ToolStripItem toolStripItem = contextMenu.Items[contextMenuClearAllIndex]; + + // Assert + Assert.IsTrue(toolStripItem.Enabled); + } + } + } + + [Test] + public void ContextMenuStrip_FailureMechanismWithCalculationsWithoutOutput_ContextMenuItemClearCalculationsOutputDisabled() + { + // Setup + var failureMechanism = new HeightStructuresFailureMechanism + { + CalculationsGroup = + { + Children = + { + new StructuresCalculationScenario() + } + } + }; + + IAssessmentSection assessmentSection = AssessmentSectionTestHelper.CreateAssessmentSectionStub(null, mocksRepository, "invalidFilePath"); + + var nodeData = new HeightStructuresFailureMechanismContext(failureMechanism, assessmentSection); + var menuBuilder = new CustomItemsOnlyContextMenuBuilder(); + + using (var treeViewControl = new TreeViewControl()) + { + var gui = mocksRepository.Stub(); + gui.Stub(g => g.Get(nodeData, treeViewControl)).Return(menuBuilder); + gui.Stub(g => g.MainWindow).Return(mocksRepository.Stub()); + gui.Stub(g => g.ViewCommands).Return(mocksRepository.Stub()); + mocksRepository.ReplayAll(); + + plugin.Gui = gui; + + using (ContextMenuStrip contextMenu = info.ContextMenuStrip(nodeData, null, treeViewControl)) + { + // Call + ToolStripItem toolStripItem = contextMenu.Items[contextMenuClearAllIndex]; + + // Assert + Assert.IsFalse(toolStripItem.Enabled); + } + } + } + + [Test] + public void GivenCalculationsWithOutput_WhenClearAllCalculationsOutputClickedAndAborted_ThenInquiryAndCalculationsOutputNotCleared() + { + // Given + var calculationWithOutput = new StructuresCalculationScenario + { + Output = new TestStructuresOutput() + }; + + var failureMechanism = new HeightStructuresFailureMechanism + { + CalculationsGroup = + { + Children = + { + calculationWithOutput, + new StructuresCalculationScenario() + } + } + }; + + var calculationObserver = mocksRepository.StrictMock(); + calculationWithOutput.Attach(calculationObserver); + + IAssessmentSection assessmentSection = AssessmentSectionTestHelper.CreateAssessmentSectionStub(null, mocksRepository, "invalidFilePath"); + + var nodeData = new HeightStructuresFailureMechanismContext(failureMechanism, 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 = mocksRepository.Stub(); + gui.Stub(g => g.Get(nodeData, treeViewControl)).Return(menuBuilder); + gui.Stub(g => g.MainWindow).Return(mocksRepository.Stub()); + gui.Stub(g => g.ViewCommands).Return(mocksRepository.StrictMock()); + mocksRepository.ReplayAll(); + + plugin.Gui = gui; + + using (ContextMenuStrip contextMenu = info.ContextMenuStrip(nodeData, null, treeViewControl)) + { + // When + contextMenu.Items[contextMenuClearAllIndex].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 failureMechanism = new HeightStructuresFailureMechanism + { + CalculationsGroup = + { + Children = + { + calculationWithOutput, + calculationWithoutOutput + } + } + }; + + var affectedCalculationObserver = mocksRepository.StrictMock(); + affectedCalculationObserver.Expect(o => o.UpdateObserver()); + calculationWithOutput.Attach(affectedCalculationObserver); + + var unaffectedCalculationObserver = mocksRepository.StrictMock(); + calculationWithoutOutput.Attach(unaffectedCalculationObserver); + + IAssessmentSection assessmentSection = AssessmentSectionTestHelper.CreateAssessmentSectionStub(null, mocksRepository, "invalidFilePath"); + + var nodeData = new HeightStructuresFailureMechanismContext(failureMechanism, 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 = mocksRepository.StrictMock(); + viewCommands.Expect(vc => vc.RemoveAllViewsForItem(calculationWithOutput.Output)); + + var gui = mocksRepository.Stub(); + gui.Stub(g => g.Get(nodeData, treeViewControl)).Return(menuBuilder); + gui.Stub(g => g.MainWindow).Return(mocksRepository.Stub()); + gui.Stub(g => g.ViewCommands).Return(viewCommands); + mocksRepository.ReplayAll(); + + plugin.Gui = gui; + + using (ContextMenuStrip contextMenu = info.ContextMenuStrip(nodeData, null, treeViewControl)) + { + // When + contextMenu.Items[contextMenuClearAllIndex].PerformClick(); + + // Then + Assert.AreEqual("Weet u zeker dat u alle uitvoer wilt wissen?", messageBoxText); + + Assert.IsFalse(calculationWithOutput.HasOutput); + } + } + } + + [Test] public void ContextMenuStrip_FailureMechanismWithCalculationsContainingIllustrationPoints_ContextMenuItemClearIllustrationPointsEnabled() { // Setup - var calculationWithIllustrationPoints = new TestHeightStructuresCalculationScenario + var calculationWithIllustrationPoints = new StructuresCalculationScenario { Output = new TestStructuresOutput(new TestGeneralResultFaultTreeIllustrationPoint()) }; - var calculationWithOutput = new TestHeightStructuresCalculationScenario + var calculationWithOutput = new StructuresCalculationScenario { Output = new TestStructuresOutput() }; @@ -849,7 +1076,7 @@ { calculationWithIllustrationPoints, calculationWithOutput, - new TestHeightStructuresCalculationScenario() + new StructuresCalculationScenario() } } }; @@ -864,6 +1091,7 @@ var gui = mocksRepository.Stub(); gui.Stub(g => g.Get(nodeData, treeViewControl)).Return(menuBuilder); gui.Stub(g => g.MainWindow).Return(mocksRepository.Stub()); + gui.Stub(g => g.ViewCommands).Return(mocksRepository.Stub()); mocksRepository.ReplayAll(); plugin.Gui = gui; @@ -883,7 +1111,7 @@ public void ContextMenuStrip_FailureMechanismWithCalculationsWithoutIllustrationPoints_ContextMenuItemClearIllustrationPointsDisabled() { // Setup - var calculationWithOutput = new TestHeightStructuresCalculationScenario + var calculationWithOutput = new StructuresCalculationScenario { Output = new TestStructuresOutput() }; @@ -895,7 +1123,7 @@ Children = { calculationWithOutput, - new TestHeightStructuresCalculationScenario() + new StructuresCalculationScenario() } } }; @@ -910,6 +1138,7 @@ var gui = mocksRepository.Stub(); gui.Stub(g => g.Get(nodeData, treeViewControl)).Return(menuBuilder); gui.Stub(g => g.MainWindow).Return(mocksRepository.Stub()); + gui.Stub(g => g.ViewCommands).Return(mocksRepository.Stub()); mocksRepository.ReplayAll(); plugin.Gui = gui; @@ -929,25 +1158,25 @@ public void GivenCalculationsWithIllustrationPoints_WhenClearIllustrationPointsClickedAndAborted_ThenInquiryAndIllustrationPointsNotCleared() { // Given - var calculationWithIllustrationPoints = new TestHeightStructuresCalculationScenario + var calculationWithIllustrationPoints = new StructuresCalculationScenario { Output = new TestStructuresOutput(new TestGeneralResultFaultTreeIllustrationPoint()) }; - var calculationWithOutput = new TestHeightStructuresCalculationScenario + var calculationWithOutput = new StructuresCalculationScenario { Output = new TestStructuresOutput() }; - var failureMechanism = new TestHeightStructuresFailureMechanism + var failureMechanism = new HeightStructuresFailureMechanism { CalculationsGroup = { Children = { calculationWithIllustrationPoints, calculationWithOutput, - new TestHeightStructuresCalculationScenario() + new StructuresCalculationScenario() } } }; @@ -974,6 +1203,7 @@ var gui = mocksRepository.Stub(); gui.Stub(g => g.Get(nodeData, treeViewControl)).Return(menuBuilder); gui.Stub(g => g.MainWindow).Return(mocksRepository.Stub()); + gui.Stub(g => g.ViewCommands).Return(mocksRepository.Stub()); mocksRepository.ReplayAll(); plugin.Gui = gui; @@ -996,25 +1226,25 @@ public void GivenCalculationsWithIllustrationPoints_WhenClearIllustrationPointsClickedAndContinued_ThenInquiryAndIllustrationPointsCleared() { // Given - var calculationWithIllustrationPoints = new TestHeightStructuresCalculationScenario + var calculationWithIllustrationPoints = new StructuresCalculationScenario { Output = new TestStructuresOutput(new TestGeneralResultFaultTreeIllustrationPoint()) }; - var calculationWithOutput = new TestHeightStructuresCalculationScenario + var calculationWithOutput = new StructuresCalculationScenario { Output = new TestStructuresOutput() }; - var failureMechanism = new TestHeightStructuresFailureMechanism + var failureMechanism = new HeightStructuresFailureMechanism { CalculationsGroup = { Children = { calculationWithIllustrationPoints, calculationWithOutput, - new TestHeightStructuresCalculationScenario() + new StructuresCalculationScenario() } } }; @@ -1045,6 +1275,7 @@ var gui = mocksRepository.Stub(); gui.Stub(g => g.Get(nodeData, treeViewControl)).Return(menuBuilder); gui.Stub(g => g.MainWindow).Return(mocksRepository.Stub()); + gui.Stub(g => g.ViewCommands).Return(mocksRepository.Stub()); mocksRepository.ReplayAll(); plugin.Gui = gui;