Index: Riskeer/MacroStabilityInwards/src/Riskeer.MacroStabilityInwards.Plugin/MacroStabilityInwardsPlugin.cs =================================================================== diff -u -r2e2312ddb122b6eb64709975570cd373441e507b -r5f4204ee0aaefc7d889e00d3c6bea809c704a3eb --- Riskeer/MacroStabilityInwards/src/Riskeer.MacroStabilityInwards.Plugin/MacroStabilityInwardsPlugin.cs (.../MacroStabilityInwardsPlugin.cs) (revision 2e2312ddb122b6eb64709975570cd373441e507b) +++ Riskeer/MacroStabilityInwards/src/Riskeer.MacroStabilityInwards.Plugin/MacroStabilityInwardsPlugin.cs (.../MacroStabilityInwardsPlugin.cs) (revision 5f4204ee0aaefc7d889e00d3c6bea809c704a3eb) @@ -675,8 +675,7 @@ .AddSeparator() .AddClearAllCalculationOutputInFailureMechanismItem( () => calculations.Any(c => c.HasOutput), - new ClearMacroStabilityInwardsCalculationOutputChangeHandler( - calculations.Where(c => c.HasOutput), inquiryHelper, viewCommands)) + CreateClearCalculationOutputChangeHandler(calculations, inquiryHelper, viewCommands)) .AddSeparator() .AddCollapseAllItem() .AddExpandAllItem() @@ -764,6 +763,13 @@ StrictContextMenuItem generateCalculationsItem = CreateGenerateMacroStabilityInwardsCalculationsItem(nodeData); + MacroStabilityInwardsCalculationScenario[] calculations = group.GetCalculations() + .Cast() + .ToArray(); + + IInquiryHelper inquiryHelper = GetInquiryHelper(); + IViewCommands viewCommands = Gui.ViewCommands; + if (!isNestedGroup) { builder.AddOpenItem() @@ -802,7 +808,9 @@ nodeData, CalculateAllInCalculationGroup) .AddSeparator() - .AddClearAllCalculationOutputInGroupItem(group); + .AddClearAllCalculationOutputInGroupItem( + () => calculations.Any(c => c.HasOutput), + CreateClearCalculationOutputChangeHandler(calculations, inquiryHelper, viewCommands)); if (isNestedGroup) { @@ -974,6 +982,13 @@ #endregion + private static ClearMacroStabilityInwardsCalculationOutputChangeHandler CreateClearCalculationOutputChangeHandler( + IEnumerable calculations, IInquiryHelper inquiryHelper, IViewCommands viewCommands) + { + return new ClearMacroStabilityInwardsCalculationOutputChangeHandler( + calculations.Where(c => c.HasOutput), inquiryHelper, viewCommands); + } + #endregion #region ImportInfos Index: Riskeer/MacroStabilityInwards/test/Riskeer.MacroStabilityInwards.Plugin.Test/TreeNodeInfos/MacroStabilityInwardsCalculationGroupContextTreeNodeInfoTest.cs =================================================================== diff -u -rc6e95a768f3d8e9e8309c2b68a3d8272904e79ab -r5f4204ee0aaefc7d889e00d3c6bea809c704a3eb --- Riskeer/MacroStabilityInwards/test/Riskeer.MacroStabilityInwards.Plugin.Test/TreeNodeInfos/MacroStabilityInwardsCalculationGroupContextTreeNodeInfoTest.cs (.../MacroStabilityInwardsCalculationGroupContextTreeNodeInfoTest.cs) (revision c6e95a768f3d8e9e8309c2b68a3d8272904e79ab) +++ Riskeer/MacroStabilityInwards/test/Riskeer.MacroStabilityInwards.Plugin.Test/TreeNodeInfos/MacroStabilityInwardsCalculationGroupContextTreeNodeInfoTest.cs (.../MacroStabilityInwardsCalculationGroupContextTreeNodeInfoTest.cs) (revision 5f4204ee0aaefc7d889e00d3c6bea809c704a3eb) @@ -230,6 +230,8 @@ 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()); treeViewControl.Expect(tvc => tvc.CanRemoveNodeForData(nodeData)).Return(true); treeViewControl.Expect(tvc => tvc.CanRenameNodeForData(nodeData)).Return(true); @@ -358,7 +360,8 @@ var gui = mocks.Stub(); gui.Stub(g => g.Get(nodeData, treeViewControl)).Return(menuBuilder); - gui.Stub(cmp => cmp.ViewCommands).Return(mocks.Stub()); + gui.Stub(g => g.MainWindow).Return(mocks.Stub()); + gui.Stub(g => g.ViewCommands).Return(mocks.Stub()); mocks.ReplayAll(); @@ -455,7 +458,8 @@ var gui = mocks.Stub(); gui.Stub(g => g.Get(nodeData, treeViewControl)).Return(menuBuilder); - gui.Stub(cmp => cmp.ViewCommands).Return(mocks.Stub()); + gui.Stub(g => g.MainWindow).Return(mocks.Stub()); + gui.Stub(g => g.ViewCommands).Return(mocks.Stub()); mocks.ReplayAll(); plugin.Gui = gui; @@ -498,7 +502,8 @@ var gui = mocks.Stub(); gui.Stub(g => g.Get(nodeData, treeViewControl)).Return(menuBuilder); - gui.Stub(cmp => cmp.ViewCommands).Return(mocks.Stub()); + gui.Stub(g => g.MainWindow).Return(mocks.Stub()); + gui.Stub(g => g.ViewCommands).Return(mocks.Stub()); mocks.ReplayAll(); plugin.Gui = gui; @@ -544,7 +549,8 @@ var gui = mocks.Stub(); gui.Stub(g => g.Get(nodeData, treeViewControl)).Return(menuBuilder); - gui.Stub(cmp => cmp.ViewCommands).Return(mocks.Stub()); + gui.Stub(g => g.MainWindow).Return(mocks.Stub()); + gui.Stub(g => g.ViewCommands).Return(mocks.Stub()); mocks.ReplayAll(); plugin.Gui = gui; @@ -594,7 +600,9 @@ var menuBuilder = new CustomItemsOnlyContextMenuBuilder(); var gui = 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(mocks.Stub()); + gui.Stub(g => g.ViewCommands).Return(mocks.Stub()); mocks.ReplayAll(); plugin.Gui = gui; @@ -642,7 +650,9 @@ var menuBuilder = new CustomItemsOnlyContextMenuBuilder(); var gui = 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(mocks.Stub()); + gui.Stub(g => g.ViewCommands).Return(mocks.Stub()); var observer = mocks.StrictMock(); observer.Expect(o => o.UpdateObserver()); @@ -702,8 +712,10 @@ var menuBuilder = new CustomItemsOnlyContextMenuBuilder(); var gui = 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(mocks.Stub()); + gui.Stub(g => g.ViewCommands).Return(mocks.Stub()); + var observer = mocks.StrictMock(); observer.Expect(o => o.UpdateObserver()); mocks.ReplayAll(); @@ -784,7 +796,9 @@ var menuBuilder = new CustomItemsOnlyContextMenuBuilder(); var gui = 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(mocks.Stub()); + gui.Stub(g => g.ViewCommands).Return(mocks.Stub()); mocks.ReplayAll(); plugin.Gui = gui; @@ -817,8 +831,6 @@ // Setup using (var treeViewControl = new TreeViewControl()) { - var mainWindow = mocks.Stub(); - var assessmentSection = new AssessmentSectionStub(); var hydraulicBoundaryLocation = new TestHydraulicBoundaryLocation(); @@ -862,7 +874,8 @@ var gui = mocks.Stub(); gui.Stub(g => g.Get(nodeData, 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()); mocks.ReplayAll(); plugin.Gui = gui; @@ -906,101 +919,233 @@ } [Test] - [TestCase(false, TestName = "ContextMenuStrip_ClearOutput_ClearOutputCalculationsAndNotifyObservers(false)")] - [TestCase(true, TestName = "ContextMenuStrip_ClearOutput_ClearOutputCalculationsAndNotifyObservers(true)")] - public void ContextMenuStrip_ClickOnClearOutputItem_ClearOutputAllChildCalculationsAndNotifyCalculationObservers(bool confirm) + public void ContextMenuStrip_CalculationGroupWithCalculationsWithoutOutput_ContextMenuItemClearCalculationsOutputEnabled() { // Setup + var calculationGroup = new CalculationGroup + { + Children = + { + new MacroStabilityInwardsCalculationScenario(), + new CalculationGroup + { + Children = + { + new MacroStabilityInwardsCalculationScenario + { + Output = MacroStabilityInwardsOutputTestFactory.CreateRandomOutput() + } + } + } + } + }; + + IAssessmentSection assessmentSection = AssessmentSectionTestHelper.CreateAssessmentSectionStub(null, mocks, "invalidFilePath"); + + var nodeData = new MacroStabilityInwardsCalculationGroupContext(calculationGroup, + null, + Enumerable.Empty(), + Enumerable.Empty(), + new MacroStabilityInwardsFailureMechanism(), + assessmentSection); + + var menuBuilder = new CustomItemsOnlyContextMenuBuilder(); + using (var treeViewControl = new TreeViewControl()) { - var calculation1Observer = mocks.StrictMock(); - var calculation2Observer = mocks.StrictMock(); - if (confirm) + 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)) { - calculation1Observer.Expect(o => o.UpdateObserver()); - calculation2Observer.Expect(o => o.UpdateObserver()); + // Call + ToolStripItem toolStripItem = contextMenu.Items[contextMenuClearOutputIndexRootGroup]; + + // Assert + Assert.IsTrue(toolStripItem.Enabled); } + } + } - var assessmentSection = new AssessmentSectionStub(); - var hydraulicBoundaryLocation = new TestHydraulicBoundaryLocation(); + [Test] + public void ContextMenuStrip_CalculationGroupWithCalculationsWithoutOutput_ContextMenuItemClearCalculationsOutputDisabled() + { + // Setup + var calculationGroup = new CalculationGroup + { + Children = + { + new MacroStabilityInwardsCalculationScenario() + } + }; - assessmentSection.SetHydraulicBoundaryLocationCalculations(new[] + IAssessmentSection assessmentSection = AssessmentSectionTestHelper.CreateAssessmentSectionStub(null, mocks, "invalidFilePath"); + + var nodeData = new MacroStabilityInwardsCalculationGroupContext(calculationGroup, + null, + Enumerable.Empty(), + Enumerable.Empty(), + new MacroStabilityInwardsFailureMechanism(), + 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)) { - hydraulicBoundaryLocation - }, true); + // Call + ToolStripItem toolStripItem = contextMenu.Items[contextMenuClearOutputIndexRootGroup]; - MacroStabilityInwardsCalculationScenario calculation1 = MacroStabilityInwardsCalculationScenarioTestFactory.CreateMacroStabilityInwardsCalculationScenarioWithValidInput(hydraulicBoundaryLocation); - calculation1.Name = "A"; - calculation1.Output = MacroStabilityInwardsOutputTestFactory.CreateOutput(); - calculation1.Attach(calculation1Observer); - MacroStabilityInwardsCalculationScenario calculation2 = MacroStabilityInwardsCalculationScenarioTestFactory.CreateMacroStabilityInwardsCalculationScenarioWithValidInput(hydraulicBoundaryLocation); - calculation2.Name = "B"; - calculation2.Output = MacroStabilityInwardsOutputTestFactory.CreateOutput(); - calculation2.Attach(calculation2Observer); + // Assert + Assert.IsFalse(toolStripItem.Enabled); + } + } + } - var childGroup = new CalculationGroup(); - childGroup.Children.Add(calculation1); + [Test] + public void GivenCalculationsWithOutput_WhenClearAllCalculationsOutputClickedAndAborted_ThenInquiryAndCalculationsOutputNotCleared() + { + // Given + var calculationWithOutput = new MacroStabilityInwardsCalculationScenario + { + Output = MacroStabilityInwardsOutputTestFactory.CreateRandomOutput() + }; - var emptyChildGroup = new CalculationGroup(); - var group = new CalculationGroup(); - var parentGroup = new CalculationGroup(); + var calculationGroup = new CalculationGroup + { + Children = + { + calculationWithOutput, + new MacroStabilityInwardsCalculationScenario() + } + }; - group.Children.Add(childGroup); - group.Children.Add(emptyChildGroup); - group.Children.Add(calculation2); + var calculationObserver = mocks.StrictMock(); + calculationWithOutput.Attach(calculationObserver); - var failureMechanism = new MacroStabilityInwardsFailureMechanism(); + IAssessmentSection assessmentSection = AssessmentSectionTestHelper.CreateAssessmentSectionStub(null, mocks, "invalidFilePath"); - var nodeData = new MacroStabilityInwardsCalculationGroupContext(group, - parentGroup, - Enumerable.Empty(), - Enumerable.Empty(), - failureMechanism, - assessmentSection); - var parentNodeData = new MacroStabilityInwardsCalculationGroupContext(parentGroup, - null, - Enumerable.Empty(), - Enumerable.Empty(), - failureMechanism, - assessmentSection); + var nodeData = new MacroStabilityInwardsCalculationGroupContext(calculationGroup, + null, + Enumerable.Empty(), + Enumerable.Empty(), + new MacroStabilityInwardsFailureMechanism(), + assessmentSection); + var menuBuilder = new CustomItemsOnlyContextMenuBuilder(); - 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(cmp => cmp.Get(nodeData, treeViewControl)).Return(menuBuilder); + 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; - string messageBoxTitle = null, messageBoxText = null; - DialogBoxHandler = (name, wnd) => + using (ContextMenuStrip contextMenu = info.ContextMenuStrip(nodeData, null, treeViewControl)) { - var messageBox = new MessageBoxTester(wnd); + // When + contextMenu.Items[contextMenuClearOutputIndexRootGroup].PerformClick(); - messageBoxText = messageBox.Text; - messageBoxTitle = messageBox.Title; + // Then + Assert.AreEqual("Weet u zeker dat u alle uitvoer wilt wissen?", messageBoxText); - if (confirm) - { - messageBox.ClickOk(); - } - else - { - messageBox.ClickCancel(); - } - }; + Assert.IsTrue(calculationWithOutput.HasOutput); + } + } + } - using (ContextMenuStrip contextMenu = info.ContextMenuStrip(nodeData, parentNodeData, treeViewControl)) + [Test] + public void GivenCalculationsWithOutput_WhenClearAllCalculationsOutputClickedAndContinued_ThenInquiryAndOutputViewsClosedAndCalculationsOutputCleared() + { + // Given + var calculationWithOutput = new MacroStabilityInwardsCalculationScenario + { + Output = MacroStabilityInwardsOutputTestFactory.CreateRandomOutput() + }; + + var calculationWithoutOutput = new MacroStabilityInwardsCalculationScenario(); + var calculationGroup = new CalculationGroup + { + Children = { - // Call - contextMenu.Items[contextMenuClearOutputIndexNestedGroup].PerformClick(); + calculationWithOutput, + calculationWithoutOutput + } + }; - // Assert - Assert.AreNotEqual(confirm, calculation1.HasOutput); - Assert.AreNotEqual(confirm, calculation2.HasOutput); + var affectedCalculationObserver = mocks.StrictMock(); + affectedCalculationObserver.Expect(o => o.UpdateObserver()); + calculationWithOutput.Attach(affectedCalculationObserver); - Assert.AreEqual("Bevestigen", messageBoxTitle); + var unaffectedCalculationObserver = mocks.StrictMock(); + calculationWithoutOutput.Attach(unaffectedCalculationObserver); + + IAssessmentSection assessmentSection = AssessmentSectionTestHelper.CreateAssessmentSectionStub(null, mocks, "invalidFilePath"); + + var nodeData = new MacroStabilityInwardsCalculationGroupContext(calculationGroup, + null, + Enumerable.Empty(), + Enumerable.Empty(), + new MacroStabilityInwardsFailureMechanism(), + 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)); + + 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[contextMenuClearOutputIndexRootGroup].PerformClick(); + + // Then Assert.AreEqual("Weet u zeker dat u alle uitvoer wilt wissen?", messageBoxText); + + Assert.IsFalse(calculationWithOutput.HasOutput); } } } @@ -1034,9 +1179,9 @@ var mainWindow = mocks.Stub(); var gui = 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(); plugin.Gui = gui; @@ -1135,9 +1280,9 @@ var mainWindow = mocks.Stub(); var gui = 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(); plugin.Gui = gui; @@ -1246,9 +1391,9 @@ var mainWindow = mocks.Stub(); var gui = 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(); plugin.Gui = gui;