Index: Riskeer/Common/src/Riskeer.Common.Forms/ChangeHandlers/ClearCalculationOutputChangeHandlerBase.cs =================================================================== diff -u -r8a21e60e9474fe20f665b1a41cc14c778d99d572 -r4c9d9ba8583cf0a3fbbe60d44f28ac03b40fea87 --- Riskeer/Common/src/Riskeer.Common.Forms/ChangeHandlers/ClearCalculationOutputChangeHandlerBase.cs (.../ClearCalculationOutputChangeHandlerBase.cs) (revision 8a21e60e9474fe20f665b1a41cc14c778d99d572) +++ Riskeer/Common/src/Riskeer.Common.Forms/ChangeHandlers/ClearCalculationOutputChangeHandlerBase.cs (.../ClearCalculationOutputChangeHandlerBase.cs) (revision 4c9d9ba8583cf0a3fbbe60d44f28ac03b40fea87) @@ -25,7 +25,6 @@ using Core.Common.Gui.Commands; using Core.Common.Gui.Helpers; using Riskeer.Common.Data.Calculation; -using Riskeer.Common.Forms.Properties; namespace Riskeer.Common.Forms.ChangeHandlers { @@ -69,9 +68,9 @@ ViewCommands = viewCommands; } - public bool InquireConfirmation() + public bool InquireConfirmation(string confirmationMessage) { - return inquiryHelper.InquireContinuation(Resources.FailureMechanism_ContextMenuStrip_Are_you_sure_clear_all_output); + return inquiryHelper.InquireContinuation(confirmationMessage); } public IEnumerable ClearCalculations() Index: Riskeer/Common/src/Riskeer.Common.Forms/ChangeHandlers/IClearCalculationOutputChangeHandler.cs =================================================================== diff -u -r551adc15997614cd3df87522131fc90f4cd2484a -r4c9d9ba8583cf0a3fbbe60d44f28ac03b40fea87 --- Riskeer/Common/src/Riskeer.Common.Forms/ChangeHandlers/IClearCalculationOutputChangeHandler.cs (.../IClearCalculationOutputChangeHandler.cs) (revision 551adc15997614cd3df87522131fc90f4cd2484a) +++ Riskeer/Common/src/Riskeer.Common.Forms/ChangeHandlers/IClearCalculationOutputChangeHandler.cs (.../IClearCalculationOutputChangeHandler.cs) (revision 4c9d9ba8583cf0a3fbbe60d44f28ac03b40fea87) @@ -32,8 +32,9 @@ /// /// Gets confirmation for clearing the illustration points. /// + /// The confirmation message to which the user needs to answer. /// true when confirmation is given, false otherwise. - bool InquireConfirmation(); + bool InquireConfirmation(string confirmationMessage); /// /// Clears all illustration points and returns the affected objects. Index: Riskeer/Common/src/Riskeer.Common.Forms/TreeNodeInfos/RiskeerContextMenuItemFactory.cs =================================================================== diff -u -r57eba4adfdfd8ae3cdfd27fa860b4544aa0eeafe -r4c9d9ba8583cf0a3fbbe60d44f28ac03b40fea87 --- Riskeer/Common/src/Riskeer.Common.Forms/TreeNodeInfos/RiskeerContextMenuItemFactory.cs (.../RiskeerContextMenuItemFactory.cs) (revision 57eba4adfdfd8ae3cdfd27fa860b4544aa0eeafe) +++ Riskeer/Common/src/Riskeer.Common.Forms/TreeNodeInfos/RiskeerContextMenuItemFactory.cs (.../RiskeerContextMenuItemFactory.cs) (revision 4c9d9ba8583cf0a3fbbe60d44f28ac03b40fea87) @@ -94,15 +94,10 @@ string toolTip = enabled ? Resources.CalculationGroup_ClearOutput_ToolTip : Resources.CalculationGroup_ClearOutput_No_calculation_with_output_to_clear; - - return new StrictContextMenuItem( - Resources.Clear_all_output, - toolTip, - Resources.ClearIcon, - (o, args) => ClearAllCalculationOutput(changeHandler)) - { - Enabled = enabled - }; + + return CreateClearCalculationOutputItem(Resources.Clear_all_output, toolTip, enabled, + Resources.FailureMechanism_ContextMenuStrip_Are_you_sure_clear_all_output, + changeHandler); } /// @@ -275,23 +270,21 @@ /// /// Creates a which is bound to the action of clearing the output of a calculation. /// - /// The calculation to clear the output for. + /// The function to determine whether the context menu item should be enabled. + /// Object responsible for clearing the calculation output. /// The created . - public static StrictContextMenuItem CreateClearCalculationOutputItem(ICalculation calculation) + public static StrictContextMenuItem CreateClearCalculationOutputItem( + Func isContextItemEnabledFunc, IClearCalculationOutputChangeHandler changeHandler) { - var clearOutputItem = new StrictContextMenuItem( - Resources.Clear_output, - Resources.Clear_output_ToolTip, - Resources.ClearIcon, - (o, args) => ClearCalculationOutput(calculation)); + bool enabled = isContextItemEnabledFunc(); - if (!calculation.HasOutput) - { - clearOutputItem.Enabled = false; - clearOutputItem.ToolTipText = Resources.ClearOutput_No_output_to_clear; - } + string toolTip = enabled + ? Resources.Clear_output_ToolTip + : Resources.ClearOutput_No_output_to_clear; - return clearOutputItem; + return CreateClearCalculationOutputItem(Resources.Clear_output, toolTip, enabled, + Resources.Calculation_ContextMenuStrip_Are_you_sure_clear_output, + changeHandler); } /// @@ -309,14 +302,9 @@ ? Resources.Clear_all_output_ToolTip : Resources.CalculationGroup_ClearOutput_No_calculation_with_output_to_clear; - return new StrictContextMenuItem( - Resources.Clear_all_output, - toolTip, - Resources.ClearIcon, - (o, args) => ClearAllCalculationOutput(changeHandler)) - { - Enabled = enabled - }; + return CreateClearCalculationOutputItem(Resources.Clear_all_output, toolTip, enabled, + Resources.FailureMechanism_ContextMenuStrip_Are_you_sure_clear_all_output, + changeHandler); } /// @@ -646,10 +634,23 @@ } } - private static void ClearAllCalculationOutput(IClearCalculationOutputChangeHandler changeHandler) + private static StrictContextMenuItem CreateClearCalculationOutputItem( + string text, string toolTip, bool enabled, string confirmationMessage, IClearCalculationOutputChangeHandler changeHandler) { - if (changeHandler.InquireConfirmation()) + return new StrictContextMenuItem( + text, + toolTip, + Resources.ClearIcon, + (o, args) => ClearAllCalculationOutput(changeHandler, confirmationMessage)) { + Enabled = enabled + }; + } + + private static void ClearAllCalculationOutput(IClearCalculationOutputChangeHandler changeHandler, string confirmationMessage) + { + if (changeHandler.InquireConfirmation(confirmationMessage)) + { IEnumerable affectedObjects = changeHandler.ClearCalculations(); affectedObjects.ForEachElementDo(o => o.NotifyObservers()); } @@ -665,17 +666,6 @@ calculationGroup.NotifyObservers(); } - private static void ClearCalculationOutput(ICalculation calculation) - { - if (MessageBox.Show(Resources.Calculation_ContextMenuStrip_Are_you_sure_clear_output, BaseResources.Confirm, MessageBoxButtons.OKCancel) != DialogResult.OK) - { - return; - } - - calculation.ClearOutput(); - calculation.NotifyObservers(); - } - private static void ClearIllustrationPointResults(IClearIllustrationPointsOfCalculationCollectionChangeHandler changeHandler) { IEnumerable affectedObjects = changeHandler.ClearIllustrationPoints(); Index: Riskeer/Common/test/Riskeer.Common.Forms.Test/ChangeHandlers/ClearCalculationOutputChangeHandlerBaseTest.cs =================================================================== diff -u -r8a21e60e9474fe20f665b1a41cc14c778d99d572 -r4c9d9ba8583cf0a3fbbe60d44f28ac03b40fea87 --- Riskeer/Common/test/Riskeer.Common.Forms.Test/ChangeHandlers/ClearCalculationOutputChangeHandlerBaseTest.cs (.../ClearCalculationOutputChangeHandlerBaseTest.cs) (revision 8a21e60e9474fe20f665b1a41cc14c778d99d572) +++ Riskeer/Common/test/Riskeer.Common.Forms.Test/ChangeHandlers/ClearCalculationOutputChangeHandlerBaseTest.cs (.../ClearCalculationOutputChangeHandlerBaseTest.cs) (revision 4c9d9ba8583cf0a3fbbe60d44f28ac03b40fea87) @@ -121,7 +121,7 @@ var changeHandler = new TestClearCalculationOutputChangeHandler(Enumerable.Empty(), inquiryHelper, viewCommands); // Call - bool confirmation = changeHandler.InquireConfirmation(); + bool confirmation = changeHandler.InquireConfirmation(expectedInquiry); // Assert Assert.AreEqual(expectedConfirmation, confirmation); Index: Riskeer/Common/test/Riskeer.Common.Forms.Test/TreeNodeInfos/RiskeerContextMenuItemFactoryTest.cs =================================================================== diff -u -rb7bf733eaf3766a4fe3808ceef56ce2843fc2daa -r4c9d9ba8583cf0a3fbbe60d44f28ac03b40fea87 --- Riskeer/Common/test/Riskeer.Common.Forms.Test/TreeNodeInfos/RiskeerContextMenuItemFactoryTest.cs (.../RiskeerContextMenuItemFactoryTest.cs) (revision b7bf733eaf3766a4fe3808ceef56ce2843fc2daa) +++ Riskeer/Common/test/Riskeer.Common.Forms.Test/TreeNodeInfos/RiskeerContextMenuItemFactoryTest.cs (.../RiskeerContextMenuItemFactoryTest.cs) (revision 4c9d9ba8583cf0a3fbbe60d44f28ac03b40fea87) @@ -187,13 +187,15 @@ public void CreateClearAllCalculationOutputInGroupItem_WhenClickPerformedAndActionContinued_ThenClearCalculationsPerformedAndObserversNotified() { // Given + const string expectedMessage = "Weet u zeker dat u alle uitvoer wilt wissen?"; + var mocks = new MockRepository(); var calculation1 = mocks.StrictMock(); var calculation2 = mocks.StrictMock(); var calculation3 = mocks.StrictMock(); var changeHandler = mocks.StrictMock(); - changeHandler.Expect(ch => ch.InquireConfirmation()).Return(true); + changeHandler.Expect(ch => ch.InquireConfirmation(expectedMessage)).Return(true); changeHandler.Expect(ch => ch.ClearCalculations()).Return(new[] { calculation1, @@ -222,7 +224,9 @@ // Given var mocks = new MockRepository(); var changeHandler = mocks.StrictMock(); - changeHandler.Expect(ch => ch.InquireConfirmation()).Return(false); + changeHandler.Expect(ch => ch.InquireConfirmation(null)) + .IgnoreArguments() + .Return(false); mocks.ReplayAll(); StrictContextMenuItem toolStripItem = RiskeerContextMenuItemFactory.CreateClearAllCalculationOutputInGroupItem( @@ -281,13 +285,15 @@ public void GivenCreateClearAllCalculationOutputInFailureMechanismItem_WhenClickPerformedAndActionContinued_ThenClearCalculationsPerformedAndObserversNotified() { // Given + const string expectedMessage = "Weet u zeker dat u alle uitvoer wilt wissen?"; + var mocks = new MockRepository(); var calculation1 = mocks.StrictMock(); var calculation2 = mocks.StrictMock(); var calculation3 = mocks.StrictMock(); var changeHandler = mocks.StrictMock(); - changeHandler.Expect(ch => ch.InquireConfirmation()).Return(true); + changeHandler.Expect(ch => ch.InquireConfirmation(expectedMessage)).Return(true); changeHandler.Expect(ch => ch.ClearCalculations()).Return(new[] { calculation1, @@ -316,7 +322,9 @@ // Given var mocks = new MockRepository(); var changeHandler = mocks.StrictMock(); - changeHandler.Expect(ch => ch.InquireConfirmation()).Return(false); + changeHandler.Expect(ch => ch.InquireConfirmation(null)) + .IgnoreArguments() + .Return(false); mocks.ReplayAll(); StrictContextMenuItem toolStripItem = RiskeerContextMenuItemFactory.CreateClearAllCalculationOutputInFailureMechanismItem( @@ -384,18 +392,16 @@ } [Test] - public void CreateClearCalculationOutputItem_CalculationWithOutput_CreatesDecoratedAndEnabledItem() + public void CreateClearCalculationOutputItem_EnabledFuncTrue_CreatesDecoratedAndEnabledItem() { // Setup var mocks = new MockRepository(); - var calculationWithOutput = mocks.StrictMock(); - - calculationWithOutput.Expect(c => c.HasOutput).Return(true); - + var changeHandler = mocks.Stub(); mocks.ReplayAll(); // Call - StrictContextMenuItem toolStripItem = RiskeerContextMenuItemFactory.CreateClearCalculationOutputItem(calculationWithOutput); + StrictContextMenuItem toolStripItem = RiskeerContextMenuItemFactory.CreateClearCalculationOutputItem( + () => true, changeHandler); // Assert Assert.AreEqual("&Wis uitvoer...", toolStripItem.Text); @@ -407,18 +413,17 @@ } [Test] - public void CreateClearCalculationOutputItem_CalculationWithoutOutput_CreatesDecoratedAndDisabledItem() + public void CreateClearCalculationOutputItem_EnabledFuncFalse_CreatesDecoratedAndDisabledItem() { // Setup - var mocks = new MockRepository(); - var calculationWithOutput = mocks.StrictMock(); - calculationWithOutput.Expect(c => c.HasOutput).Return(false); - + var mocks = new MockRepository(); + var changeHandler = mocks.Stub(); mocks.ReplayAll(); // Call - StrictContextMenuItem toolStripItem = RiskeerContextMenuItemFactory.CreateClearCalculationOutputItem(calculationWithOutput); + StrictContextMenuItem toolStripItem = RiskeerContextMenuItemFactory.CreateClearCalculationOutputItem( + () => false, changeHandler); // Assert Assert.AreEqual("&Wis uitvoer...", toolStripItem.Text); @@ -430,62 +435,58 @@ } [Test] - public void CreateClearCalculationOutputItem_PerformClickOnCreatedItemAndConfirmChange_CalculationOutputClearedAndObserversNotified() + public void CreateClearCalculationOutputItem_WhenClickPerformedAndActionContinued_ThenClearCalculationsPerformedAndObserversNotified() { - var messageBoxText = ""; - var messageBoxTitle = ""; + // Given + const string expectedMessage = "Weet u zeker dat u de uitvoer van deze berekening wilt wissen?"; + var mocks = new MockRepository(); - var calculationWithOutput = mocks.StrictMock(); + var calculation1 = mocks.StrictMock(); + var calculation2 = mocks.StrictMock(); + var calculation3 = mocks.StrictMock(); - calculationWithOutput.Stub(c => c.HasOutput).Return(true); - calculationWithOutput.Expect(c => c.ClearOutput()); - calculationWithOutput.Expect(c => c.NotifyObservers()); + var changeHandler = mocks.StrictMock(); + changeHandler.Expect(ch => ch.InquireConfirmation(expectedMessage)).Return(true); + changeHandler.Expect(ch => ch.ClearCalculations()).Return(new[] + { + calculation1, + calculation2, + calculation3 + }); + calculation1.Expect(c => c.NotifyObservers()); + calculation2.Expect(c => c.NotifyObservers()); + calculation3.Expect(c => c.NotifyObservers()); mocks.ReplayAll(); - DialogBoxHandler = (name, wnd) => - { - var messageBox = new MessageBoxTester(wnd); - messageBoxText = messageBox.Text; - messageBoxTitle = messageBox.Title; + StrictContextMenuItem toolStripItem = RiskeerContextMenuItemFactory.CreateClearCalculationOutputItem( + () => true, changeHandler); - messageBox.ClickOk(); - }; - - StrictContextMenuItem toolStripItem = RiskeerContextMenuItemFactory.CreateClearCalculationOutputItem(calculationWithOutput); - - // Call + // When toolStripItem.PerformClick(); - // Assert - Assert.AreEqual("Bevestigen", messageBoxTitle); - Assert.AreEqual("Weet u zeker dat u de uitvoer van deze berekening wilt wissen?", messageBoxText); - + // Then mocks.VerifyAll(); } [Test] - public void CreateClearCalculationOutputItem_PerformClickOnCreatedItemAndCancelChange_CalculationOutputNotCleared() + public void CreateClearCalculationOutputItem_WhenWhenClickPerformedAndActionCancelled_ThenNothingHappens() { + // Given var mocks = new MockRepository(); - var calculationWithOutput = mocks.StrictMock(); - - calculationWithOutput.Stub(c => c.HasOutput).Return(true); - + var changeHandler = mocks.StrictMock(); + changeHandler.Expect(ch => ch.InquireConfirmation(null)) + .IgnoreArguments() + .Return(false); mocks.ReplayAll(); - DialogBoxHandler = (name, wnd) => - { - var messageBox = new MessageBoxTester(wnd); + StrictContextMenuItem toolStripItem = RiskeerContextMenuItemFactory.CreateClearCalculationOutputItem( + () => true, changeHandler); - messageBox.ClickCancel(); - }; - - StrictContextMenuItem toolStripItem = RiskeerContextMenuItemFactory.CreateClearCalculationOutputItem(calculationWithOutput); - - // Call + // When toolStripItem.PerformClick(); + // Then mocks.VerifyAll(); } Index: Riskeer/Revetment/src/Riskeer.Revetment.Forms/ChangeHandlers/WaveConditionsCalculationOutputChangeHandler.cs =================================================================== diff -u -r2788b491af7cf0f5238c4ecef3831d8f409451a0 -r4c9d9ba8583cf0a3fbbe60d44f28ac03b40fea87 --- Riskeer/Revetment/src/Riskeer.Revetment.Forms/ChangeHandlers/WaveConditionsCalculationOutputChangeHandler.cs (.../WaveConditionsCalculationOutputChangeHandler.cs) (revision 2788b491af7cf0f5238c4ecef3831d8f409451a0) +++ Riskeer/Revetment/src/Riskeer.Revetment.Forms/ChangeHandlers/WaveConditionsCalculationOutputChangeHandler.cs (.../WaveConditionsCalculationOutputChangeHandler.cs) (revision 4c9d9ba8583cf0a3fbbe60d44f28ac03b40fea87) @@ -26,7 +26,6 @@ using Riskeer.Common.Data.Calculation; using Riskeer.Common.Forms.ChangeHandlers; using Riskeer.Revetment.Data; -using RiskeerCommonFormsResources = Riskeer.Common.Forms.Properties.Resources; namespace Riskeer.Revetment.Forms.ChangeHandlers { @@ -61,9 +60,9 @@ this.inquiryHelper = inquiryHelper; } - public bool InquireConfirmation() + public bool InquireConfirmation(string confirmationMessage) { - return inquiryHelper.InquireContinuation(RiskeerCommonFormsResources.FailureMechanism_ContextMenuStrip_Are_you_sure_clear_all_output); + return inquiryHelper.InquireContinuation(confirmationMessage); } public IEnumerable ClearCalculations() Index: Riskeer/Revetment/test/Riskeer.Revetment.Forms.Test/ChangeHandlers/WaveConditionsCalculationOutputChangeHandlerTest.cs =================================================================== diff -u -r2788b491af7cf0f5238c4ecef3831d8f409451a0 -r4c9d9ba8583cf0a3fbbe60d44f28ac03b40fea87 --- Riskeer/Revetment/test/Riskeer.Revetment.Forms.Test/ChangeHandlers/WaveConditionsCalculationOutputChangeHandlerTest.cs (.../WaveConditionsCalculationOutputChangeHandlerTest.cs) (revision 2788b491af7cf0f5238c4ecef3831d8f409451a0) +++ Riskeer/Revetment/test/Riskeer.Revetment.Forms.Test/ChangeHandlers/WaveConditionsCalculationOutputChangeHandlerTest.cs (.../WaveConditionsCalculationOutputChangeHandlerTest.cs) (revision 4c9d9ba8583cf0a3fbbe60d44f28ac03b40fea87) @@ -96,7 +96,7 @@ var changeHandler = new WaveConditionsCalculationOutputChangeHandler(Enumerable.Empty>(), inquiryHelper); // Call - bool confirmation = changeHandler.InquireConfirmation(); + bool confirmation = changeHandler.InquireConfirmation(expectedInquiry); // Assert Assert.AreEqual(expectedConfirmation, confirmation);