Index: Riskeer/WaveImpactAsphaltCover/src/Riskeer.WaveImpactAsphaltCover.Plugin/WaveImpactAsphaltCoverPlugin.cs =================================================================== diff -u -r52760c1ed98083bbd196a248ecd8e827c11d5841 -rf199c4cf16f21217422a67e938c19839712cd6e4 --- Riskeer/WaveImpactAsphaltCover/src/Riskeer.WaveImpactAsphaltCover.Plugin/WaveImpactAsphaltCoverPlugin.cs (.../WaveImpactAsphaltCoverPlugin.cs) (revision 52760c1ed98083bbd196a248ecd8e827c11d5841) +++ Riskeer/WaveImpactAsphaltCover/src/Riskeer.WaveImpactAsphaltCover.Plugin/WaveImpactAsphaltCoverPlugin.cs (.../WaveImpactAsphaltCoverPlugin.cs) (revision f199c4cf16f21217422a67e938c19839712cd6e4) @@ -470,8 +470,7 @@ .AddSeparator() .AddClearAllCalculationOutputInGroupItem( () => calculations.Any(c => c.HasOutput), - new WaveConditionsCalculationOutputChangeHandler( - calculations.Where(c => c.HasOutput), inquiryHelper)); + CreateClearWaveConditionsCalculationOutputChangeHandler(calculations, inquiryHelper)); if (isNestedGroup) { @@ -618,21 +617,29 @@ WaveImpactAsphaltCoverWaveConditionsCalculation calculation = nodeData.WrappedData; + IInquiryHelper inquiryHelper = GetInquiryHelper(); + return builder.AddExportItem() .AddSeparator() .AddDuplicateCalculationItem(calculation, nodeData) .AddSeparator() .AddRenameItem() - .AddUpdateForeshoreProfileOfCalculationItem(calculation, GetInquiryHelper(), - SynchronizeCalculationWithForeshoreProfileHelper.UpdateForeshoreProfileDerivedCalculationInput) + .AddUpdateForeshoreProfileOfCalculationItem( + calculation, inquiryHelper, + SynchronizeCalculationWithForeshoreProfileHelper.UpdateForeshoreProfileDerivedCalculationInput) .AddSeparator() - .AddValidateCalculationItem(nodeData, - Validate, - EnableValidateAndCalculateMenuItemForCalculation) + .AddValidateCalculationItem( + nodeData, Validate, + EnableValidateAndCalculateMenuItemForCalculation) .AddPerformCalculationItem( nodeData, Calculate, EnableValidateAndCalculateMenuItemForCalculation) .AddSeparator() - .AddClearCalculationOutputItem(calculation) + .AddClearCalculationOutputItem( + () => calculation.HasOutput, + CreateClearWaveConditionsCalculationOutputChangeHandler(new[] + { + calculation + }, inquiryHelper)) .AddDeleteItem() .AddSeparator() .AddCollapseAllItem() @@ -686,6 +693,13 @@ return HydraulicBoundaryDatabaseConnectionValidator.Validate(assessmentSection.HydraulicBoundaryDatabase); } + private static WaveConditionsCalculationOutputChangeHandler CreateClearWaveConditionsCalculationOutputChangeHandler( + IEnumerable calculations, IInquiryHelper inquiryHelper) + { + return new WaveConditionsCalculationOutputChangeHandler( + calculations.Where(c => c.HasOutput), inquiryHelper); + } + #endregion } } \ No newline at end of file Index: Riskeer/WaveImpactAsphaltCover/test/Riskeer.WaveImpactAsphaltCover.Plugin.Test/TreeNodeInfos/WaveImpactAsphaltCoverWaveConditionsCalculationContextTreeNodeInfoTest.cs =================================================================== diff -u -r2e5b444e91e9bd39e83725489f1c01505df84f76 -rf199c4cf16f21217422a67e938c19839712cd6e4 --- Riskeer/WaveImpactAsphaltCover/test/Riskeer.WaveImpactAsphaltCover.Plugin.Test/TreeNodeInfos/WaveImpactAsphaltCoverWaveConditionsCalculationContextTreeNodeInfoTest.cs (.../WaveImpactAsphaltCoverWaveConditionsCalculationContextTreeNodeInfoTest.cs) (revision 2e5b444e91e9bd39e83725489f1c01505df84f76) +++ Riskeer/WaveImpactAsphaltCover/test/Riskeer.WaveImpactAsphaltCover.Plugin.Test/TreeNodeInfos/WaveImpactAsphaltCoverWaveConditionsCalculationContextTreeNodeInfoTest.cs (.../WaveImpactAsphaltCoverWaveConditionsCalculationContextTreeNodeInfoTest.cs) (revision f199c4cf16f21217422a67e938c19839712cd6e4) @@ -49,6 +49,7 @@ using Riskeer.HydraRing.Calculation.TestUtil.Calculator; using Riskeer.Revetment.Data; using Riskeer.WaveImpactAsphaltCover.Data; +using Riskeer.WaveImpactAsphaltCover.Data.TestUtil; using Riskeer.WaveImpactAsphaltCover.Forms.PresentationObjects; using RiskeerCommonFormsResources = Riskeer.Common.Forms.Properties.Resources; @@ -1534,169 +1535,171 @@ } [Test] - public void GivenCalculationWithoutOutput_ThenClearOutputItemDisabled() + public void ContextMenuStrip_CalculationWithoutOutput_ContextMenuItemClearCalculationsOutputEnabled() { - // Given - var failureMechanism = new WaveImpactAsphaltCoverFailureMechanism(); - IAssessmentSection assessmentSection = AssessmentSectionTestHelper.CreateAssessmentSectionStub(mocks); - - var parent = new CalculationGroup(); + // Setup var calculation = new WaveImpactAsphaltCoverWaveConditionsCalculation { - Name = "A", - Output = null + Output = WaveImpactAsphaltCoverTestDataGenerator.GetRandomWaveImpactAsphaltCoverWaveConditionsOutput() }; - var context = new WaveImpactAsphaltCoverWaveConditionsCalculationContext(calculation, - parent, - failureMechanism, - assessmentSection); + IAssessmentSection assessmentSection = AssessmentSectionTestHelper.CreateAssessmentSectionStub(null, mocks, "invalidFilePath"); + + var nodeData = new WaveImpactAsphaltCoverWaveConditionsCalculationContext( + calculation, new CalculationGroup(), new WaveImpactAsphaltCoverFailureMechanism(), assessmentSection); + + var menuBuilder = new CustomItemsOnlyContextMenuBuilder(); + using (var treeViewControl = new TreeViewControl()) { - var appFeatureCommandHandler = mocks.Stub(); - var importHandler = mocks.Stub(); - var exportHandler = mocks.Stub(); - var updateHandler = mocks.Stub(); - var viewCommands = mocks.Stub(); - var menuBuilder = new ContextMenuBuilder(appFeatureCommandHandler, - importHandler, - exportHandler, - updateHandler, - viewCommands, - context, - treeViewControl); + var gui = mocks.Stub(); + gui.Stub(g => g.Get(nodeData, treeViewControl)).Return(menuBuilder); + gui.Stub(g => g.MainWindow).Return(mocks.Stub()); + mocks.ReplayAll(); + plugin.Gui = gui; + + using (ContextMenuStrip contextMenu = info.ContextMenuStrip(nodeData, null, treeViewControl)) + { + // Call + ToolStripItem toolStripItem = contextMenu.Items[clearOutputMenuItemIndex]; + + // Assert + Assert.IsTrue(toolStripItem.Enabled); + } + } + } + + [Test] + public void ContextMenuStrip_CalculationWithoutOutput_ContextMenuItemClearCalculationsOutputDisabled() + { + // Setup + var calculation = new WaveImpactAsphaltCoverWaveConditionsCalculation(); + + IAssessmentSection assessmentSection = AssessmentSectionTestHelper.CreateAssessmentSectionStub(null, mocks, "invalidFilePath"); + + var nodeData = new WaveImpactAsphaltCoverWaveConditionsCalculationContext( + calculation, new CalculationGroup(), new WaveImpactAsphaltCoverFailureMechanism(), assessmentSection); + + var menuBuilder = new CustomItemsOnlyContextMenuBuilder(); + + using (var treeViewControl = new TreeViewControl()) + { var gui = mocks.Stub(); - gui.Stub(g => g.Get(context, 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()); mocks.ReplayAll(); plugin.Gui = gui; - using (ContextMenuStrip contextMenu = info.ContextMenuStrip(context, null, treeViewControl)) + using (ContextMenuStrip contextMenu = info.ContextMenuStrip(nodeData, null, treeViewControl)) { - // Then - TestHelper.AssertContextMenuStripContainsItem(contextMenu, - clearOutputMenuItemIndex, - "&Wis uitvoer...", - "Deze berekening heeft geen uitvoer om te wissen.", - RiskeerCommonFormsResources.ClearIcon, - false); + // Call + ToolStripItem toolStripItem = contextMenu.Items[clearOutputMenuItemIndex]; + + // Assert + Assert.IsFalse(toolStripItem.Enabled); } } } [Test] - public void GivenCalculationWithOutput_ThenClearOutputItemEnabled() + public void GivenCalculationsWithOutput_WhenClearCalculationOutputClickedAndAborted_ThenInquiryAndCalculationOutputNotCleared() { // Given - var failureMechanism = new WaveImpactAsphaltCoverFailureMechanism(); - IAssessmentSection assessmentSection = AssessmentSectionTestHelper.CreateAssessmentSectionStub(mocks); - - var parent = new CalculationGroup(); var calculation = new WaveImpactAsphaltCoverWaveConditionsCalculation { - Name = "A", - Output = new WaveImpactAsphaltCoverWaveConditionsOutput(Enumerable.Empty()) + Output = WaveImpactAsphaltCoverTestDataGenerator.GetRandomWaveImpactAsphaltCoverWaveConditionsOutput() }; - var context = new WaveImpactAsphaltCoverWaveConditionsCalculationContext(calculation, - parent, - failureMechanism, - assessmentSection); - using (var treeViewControl = new TreeViewControl()) + var calculationObserver = mocks.StrictMock(); + calculation.Attach(calculationObserver); + + IAssessmentSection assessmentSection = AssessmentSectionTestHelper.CreateAssessmentSectionStub(null, mocks, "invalidFilePath"); + + var nodeData = new WaveImpactAsphaltCoverWaveConditionsCalculationContext( + calculation, new CalculationGroup(), new WaveImpactAsphaltCoverFailureMechanism(), assessmentSection); + + var menuBuilder = new CustomItemsOnlyContextMenuBuilder(); + + var messageBoxText = ""; + DialogBoxHandler = (name, wnd) => { - var appFeatureCommandHandler = mocks.Stub(); - var importHandler = mocks.Stub(); - var exportHandler = mocks.Stub(); - var updateHandler = mocks.Stub(); - var viewCommands = mocks.Stub(); - var menuBuilder = new ContextMenuBuilder(appFeatureCommandHandler, - importHandler, - exportHandler, - updateHandler, - viewCommands, - context, - treeViewControl); + var helper = new MessageBoxTester(wnd); + messageBoxText = helper.Text; + helper.ClickCancel(); + }; + + using (var treeViewControl = new TreeViewControl()) + { var gui = mocks.Stub(); - gui.Stub(g => g.Get(context, 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()); mocks.ReplayAll(); plugin.Gui = gui; - using (ContextMenuStrip contextMenu = info.ContextMenuStrip(context, null, treeViewControl)) + using (ContextMenuStrip contextMenu = info.ContextMenuStrip(nodeData, null, treeViewControl)) { + // When + contextMenu.Items[clearOutputMenuItemIndex].PerformClick(); + // Then - TestHelper.AssertContextMenuStripContainsItem(contextMenu, - clearOutputMenuItemIndex, - "&Wis uitvoer...", - "Wis de uitvoer van deze berekening.", - RiskeerCommonFormsResources.ClearIcon); + Assert.AreEqual("Weet u zeker dat u de uitvoer van deze berekening wilt wissen?", messageBoxText); + + Assert.IsTrue(calculation.HasOutput); } } } [Test] - public void GivenCalculationWithOutput_WhenClearingOutput_ThenClearOutput() + public void GivenCalculationsWithOutput_WhenClearCalculationOutputClickedAndContinued_ThenInquiryAndCalculationOutputCleared() { // Given - var failureMechanism = new WaveImpactAsphaltCoverFailureMechanism(); - IAssessmentSection assessmentSection = AssessmentSectionTestHelper.CreateAssessmentSectionStub(mocks); + var calculation = new WaveImpactAsphaltCoverWaveConditionsCalculation + { + Output = WaveImpactAsphaltCoverTestDataGenerator.GetRandomWaveImpactAsphaltCoverWaveConditionsOutput() + }; - var observer = mocks.Stub(); - observer.Expect(o => o.UpdateObserver()); + var calculationObserver = mocks.StrictMock(); + calculationObserver.Expect(o => o.UpdateObserver()); + calculation.Attach(calculationObserver); - var parent = new CalculationGroup(); - var calculation = new WaveImpactAsphaltCoverWaveConditionsCalculation + IAssessmentSection assessmentSection = AssessmentSectionTestHelper.CreateAssessmentSectionStub(null, mocks, "invalidFilePath"); + + var nodeData = new WaveImpactAsphaltCoverWaveConditionsCalculationContext( + calculation, new CalculationGroup(), new WaveImpactAsphaltCoverFailureMechanism(), assessmentSection); + + var menuBuilder = new CustomItemsOnlyContextMenuBuilder(); + + var messageBoxText = ""; + DialogBoxHandler = (name, wnd) => { - Name = "A", - Output = new WaveImpactAsphaltCoverWaveConditionsOutput(Enumerable.Empty()) + var helper = new MessageBoxTester(wnd); + messageBoxText = helper.Text; + + helper.ClickOk(); }; - calculation.Attach(observer); - var context = new WaveImpactAsphaltCoverWaveConditionsCalculationContext(calculation, - parent, - failureMechanism, - assessmentSection); using (var treeViewControl = new TreeViewControl()) { - var appFeatureCommandHandler = mocks.Stub(); - var importHandler = mocks.Stub(); - var exportHandler = mocks.Stub(); - var updateHandler = mocks.Stub(); - var viewCommands = mocks.Stub(); - var menuBuilder = new ContextMenuBuilder(appFeatureCommandHandler, - importHandler, - exportHandler, - updateHandler, - viewCommands, - context, - treeViewControl); - var gui = mocks.Stub(); - gui.Stub(g => g.Get(context, 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()); mocks.ReplayAll(); plugin.Gui = gui; - DialogBoxHandler = (name, wnd) => + using (ContextMenuStrip contextMenu = info.ContextMenuStrip(nodeData, null, treeViewControl)) { - var messageBox = new MessageBoxTester(wnd); - messageBox.ClickOk(); - }; - - using (ContextMenuStrip contextMenu = info.ContextMenuStrip(context, null, treeViewControl)) - { // When - ToolStripItem validateMenuItem = contextMenu.Items[clearOutputMenuItemIndex]; - validateMenuItem.PerformClick(); + contextMenu.Items[clearOutputMenuItemIndex].PerformClick(); // Then - Assert.IsNull(calculation.Output); - // Check expectancies in TearDown() + Assert.AreEqual("Weet u zeker dat u de uitvoer van deze berekening wilt wissen?", messageBoxText); + + Assert.IsFalse(calculation.HasOutput); } } }