Index: Ringtoets/Common/src/Ringtoets.Common.Forms/Properties/Resources.Designer.cs =================================================================== diff -u -rada94ef2b6943fb9a2d8e59256871205a7d4c4ee -ra15e6824491a708be9c960aaa119b79a2ee3274d --- Ringtoets/Common/src/Ringtoets.Common.Forms/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision ada94ef2b6943fb9a2d8e59256871205a7d4c4ee) +++ Ringtoets/Common/src/Ringtoets.Common.Forms/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision a15e6824491a708be9c960aaa119b79a2ee3274d) @@ -757,6 +757,35 @@ } /// + /// Looks up a localized string similar to De geselecteerde voorlandprofielen hebben geen wijzigingen om bij te werken.. + /// + public static string CreateUpdateForshoreProfileOfCalculationsItem_Update_calculations_no_ForeshoreProfile_changes_ToolTip { + get { + return ResourceManager.GetString("CreateUpdateForshoreProfileOfCalculationsItem_Update_calculations_no_ForeshorePro" + + "file_changes_ToolTip", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Berekeningen bijwerken waar een voorlandprofiel geselecteerd is.. + /// + public static string CreateUpdateForshoreProfileOfCalculationsItem_Update_calculations_with_ForeshoreProfile_ToolTip { + get { + return ResourceManager.GetString("CreateUpdateForshoreProfileOfCalculationsItem_Update_calculations_with_ForeshoreP" + + "rofile_ToolTip", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to &Bijwerken voorlandprofielen.... + /// + public static string CreateUpdateForshoreProfileOfCalculationsItem_Update_ForeshoreProfile_data { + get { + return ResourceManager.GetString("CreateUpdateForshoreProfileOfCalculationsItem_Update_ForeshoreProfile_data", resourceCulture); + } + } + + /// /// Looks up a localized resource of type System.Drawing.Bitmap. /// public static System.Drawing.Bitmap DatabaseIcon { @@ -2625,6 +2654,18 @@ } /// + /// Looks up a localized string similar to Wanneer het voorlandprofiel wijzigt als gevolg van het bijwerken, zal het resultaat van de berekeningen worden verwijderd. + /// + ///Weet u zeker dat u wilt doorgaan?. + /// + public static string UpdateForshoreProfileOfCalculations_Confirm_calculation_outputs_cleared_when_updating_ForeshoreProfile_dependent_data { + get { + return ResourceManager.GetString("UpdateForshoreProfileOfCalculations_Confirm_calculation_outputs_cleared_when_upda" + + "ting_ForeshoreProfile_dependent_data", resourceCulture); + } + } + + /// /// Looks up a localized resource of type System.Drawing.Bitmap. /// public static System.Drawing.Bitmap UpdateItemIcon { Index: Ringtoets/Common/src/Ringtoets.Common.Forms/Properties/Resources.resx =================================================================== diff -u -rada94ef2b6943fb9a2d8e59256871205a7d4c4ee -ra15e6824491a708be9c960aaa119b79a2ee3274d --- Ringtoets/Common/src/Ringtoets.Common.Forms/Properties/Resources.resx (.../Resources.resx) (revision ada94ef2b6943fb9a2d8e59256871205a7d4c4ee) +++ Ringtoets/Common/src/Ringtoets.Common.Forms/Properties/Resources.resx (.../Resources.resx) (revision a15e6824491a708be9c960aaa119b79a2ee3274d) @@ -992,4 +992,18 @@ &Bijwerken voorlandprofiel... + + &Bijwerken voorlandprofielen... + + + Berekeningen bijwerken waar een voorlandprofiel geselecteerd is. + + + De geselecteerde voorlandprofielen hebben geen wijzigingen om bij te werken. + + + Wanneer het voorlandprofiel wijzigt als gevolg van het bijwerken, zal het resultaat van de berekeningen worden verwijderd. + +Weet u zeker dat u wilt doorgaan? + \ No newline at end of file Index: Ringtoets/Common/src/Ringtoets.Common.Forms/TreeNodeInfos/RingtoetsContextMenuBuilder.cs =================================================================== diff -u -r5bf6a765222c80d0d2b52cad46f0699dede3f2c2 -ra15e6824491a708be9c960aaa119b79a2ee3274d --- Ringtoets/Common/src/Ringtoets.Common.Forms/TreeNodeInfos/RingtoetsContextMenuBuilder.cs (.../RingtoetsContextMenuBuilder.cs) (revision 5bf6a765222c80d0d2b52cad46f0699dede3f2c2) +++ Ringtoets/Common/src/Ringtoets.Common.Forms/TreeNodeInfos/RingtoetsContextMenuBuilder.cs (.../RingtoetsContextMenuBuilder.cs) (revision a15e6824491a708be9c960aaa119b79a2ee3274d) @@ -20,6 +20,7 @@ // All rights reserved. using System; +using System.Collections.Generic; using System.Windows.Forms; using Core.Common.Gui; using Core.Common.Gui.ContextMenu; @@ -272,6 +273,29 @@ return this; } + /// + /// Adds an item to the , which is bound to the action + /// when updating the of the . + /// + /// The type of calculation input that has can have + /// a foreshore profile. + /// The calculations to update. + /// Object responsible for inquiring the required data. + /// The action to perform when the foreshore profile is updated. + /// The itself. + public RingtoetsContextMenuBuilder AddUpdateForeshoreProfileOfCalculationsItem( + IEnumerable> calculations, + IInquiryHelper inquiryHelper, + Action> updateAction) + where TCalculationInput : ICalculationInput, IHasForeshoreProfile + { + contextMenuBuilder.AddCustomItem(RingtoetsContextMenuItemFactory.CreateUpdateForshoreProfileOfCalculationsItem( + calculations, + inquiryHelper, + updateAction)); + return this; + } + #region Decorated members /// Index: Ringtoets/Common/src/Ringtoets.Common.Forms/TreeNodeInfos/RingtoetsContextMenuItemFactory.cs =================================================================== diff -u -rada94ef2b6943fb9a2d8e59256871205a7d4c4ee -ra15e6824491a708be9c960aaa119b79a2ee3274d --- Ringtoets/Common/src/Ringtoets.Common.Forms/TreeNodeInfos/RingtoetsContextMenuItemFactory.cs (.../RingtoetsContextMenuItemFactory.cs) (revision ada94ef2b6943fb9a2d8e59256871205a7d4c4ee) +++ Ringtoets/Common/src/Ringtoets.Common.Forms/TreeNodeInfos/RingtoetsContextMenuItemFactory.cs (.../RingtoetsContextMenuItemFactory.cs) (revision a15e6824491a708be9c960aaa119b79a2ee3274d) @@ -26,6 +26,7 @@ using System.Windows.Forms; using Core.Common.Gui; using Core.Common.Gui.ContextMenu; +using Core.Common.Utils.Extensions; using Ringtoets.Common.Data.Calculation; using Ringtoets.Common.Data.DikeProfiles; using Ringtoets.Common.Data.FailureMechanism; @@ -390,14 +391,20 @@ ? Resources.CreateUpdateForshoreProfileOfCalculationItem_Update_calculation_with_ForeshoreProfile_ToolTip : Resources.CreateUpdateForshoreProfileOfCalculationItem_Update_calculation_no_ForeshoreProfile_ToolTip; + string confirmOutputMessage = Resources.UpdateForshoreProfileOfCalculation_Confirm_calculation_output_cleared_when_updating_ForeshoreProfile_dependent_data; + var menuItem = new StrictContextMenuItem( Resources.CreateUpdateForshoreProfileOfCalculationItem_Update_ForeshoreProfile_data, toolTipMessage, Resources.UpdateItemIcon, (o, args) => { - UpdateForeshoreProfileDependentDataOfCalculation(calculation, + UpdateForeshoreProfileDependentDataOfCalculation(new[] + { + calculation + }, inquiryHelper, + confirmOutputMessage, updateAction); }) { @@ -407,21 +414,61 @@ return menuItem; } - private static void UpdateForeshoreProfileDependentDataOfCalculation( - ICalculation calculation, + /// + /// Creates a which is bound to the action when updating + /// the of the . + /// + /// The type of calculation input that has can have a foreshore profile. + /// The calculations to update. + /// Object responsible for inquiring the required data. + /// The action to perform when the foreshore profile is updated. + /// The created . + public static StrictContextMenuItem CreateUpdateForshoreProfileOfCalculationsItem( + IEnumerable> calculations, IInquiryHelper inquiryHelper, Action> updateAction) where TCalculationInput : ICalculationInput, IHasForeshoreProfile { - string message = Resources.UpdateForshoreProfileOfCalculation_Confirm_calculation_output_cleared_when_updating_ForeshoreProfile_dependent_data; + ICalculation[] calculationsWithForeshoreProfileChanges = calculations.Where( + c => c.InputParameters.ForeshoreProfile != null + && !c.InputParameters.IsForeshoreProfileParametersSynchronized).ToArray(); - if (ForeshoreProfileDependentDataShouldUpdate(new[] + bool hasForeshoreProfileChanges = calculationsWithForeshoreProfileChanges.Any(); + + string toolTipMessage = hasForeshoreProfileChanges + ? Resources.CreateUpdateForshoreProfileOfCalculationsItem_Update_calculations_with_ForeshoreProfile_ToolTip + : Resources.CreateUpdateForshoreProfileOfCalculationsItem_Update_calculations_no_ForeshoreProfile_changes_ToolTip; + + string confirmOutputMessage = Resources.UpdateForshoreProfileOfCalculations_Confirm_calculation_outputs_cleared_when_updating_ForeshoreProfile_dependent_data; + + var menuItem = new StrictContextMenuItem( + Resources.CreateUpdateForshoreProfileOfCalculationsItem_Update_ForeshoreProfile_data, + toolTipMessage, + Resources.UpdateItemIcon, + (o, args) => { - calculation - }, message, inquiryHelper - )) + UpdateForeshoreProfileDependentDataOfCalculation(calculationsWithForeshoreProfileChanges, + inquiryHelper, + confirmOutputMessage, + updateAction); + }) { - updateAction(calculation); + Enabled = hasForeshoreProfileChanges + }; + + return menuItem; + } + + private static void UpdateForeshoreProfileDependentDataOfCalculation( + ICalculation[] calculations, + IInquiryHelper inquiryHelper, + string confirmOutputMessage, + Action> updateAction) + where TCalculationInput : ICalculationInput, IHasForeshoreProfile + { + if (ForeshoreProfileDependentDataShouldUpdate(calculations, confirmOutputMessage, inquiryHelper)) + { + calculations.ForEachElementDo(updateAction); } } Index: Ringtoets/Common/test/Ringtoets.Common.Forms.Test/TreeNodeInfos/RingtoetsContextMenuBuilderTest.cs =================================================================== diff -u -rada94ef2b6943fb9a2d8e59256871205a7d4c4ee -ra15e6824491a708be9c960aaa119b79a2ee3274d --- Ringtoets/Common/test/Ringtoets.Common.Forms.Test/TreeNodeInfos/RingtoetsContextMenuBuilderTest.cs (.../RingtoetsContextMenuBuilderTest.cs) (revision ada94ef2b6943fb9a2d8e59256871205a7d4c4ee) +++ Ringtoets/Common/test/Ringtoets.Common.Forms.Test/TreeNodeInfos/RingtoetsContextMenuBuilderTest.cs (.../RingtoetsContextMenuBuilderTest.cs) (revision a15e6824491a708be9c960aaa119b79a2ee3274d) @@ -1675,8 +1675,8 @@ TestHelper.AssertContextMenuStripContainsItem(result, 0, "&Bijwerken voorlandprofiel...", synchronized - ? "Geselecteerd voorlandprofiel heeft geen wijzingingen om bij te werken." - : "Berekening bijwerken waar een voorlandprofiel geselecteerd is.", + ? "Geselecteerd voorlandprofiel heeft geen wijzingingen om bij te werken." + : "Berekening bijwerken waar een voorlandprofiel geselecteerd is.", RingtoetsFormsResources.UpdateItemIcon, !synchronized); } @@ -1731,8 +1731,136 @@ mocks.VerifyAll(); } - public interface ICalculationInputWithForeshoreProfile : ICalculationInput, IHasForeshoreProfile {} + #endregion + #region AddUpdateForeshoreProfileOfCalculationsItem + + [Test] + [TestCase(true)] + [TestCase(false)] + public void AddUpdateForeshoreProfileOfCalculationsItem_CalculationWithForeshoreProfile_ItemAddedToContextMenuEnabledIfNotSynchronized( + bool synchronized) + { + // Setup + var mocks = new MockRepository(); + var applicationFeatureCommandsMock = mocks.StrictMock(); + var importHandlerMock = mocks.StrictMock(); + var exportHandlerMock = mocks.StrictMock(); + var updateHandlerMock = mocks.StrictMock(); + var viewCommandsMock = mocks.StrictMock(); + + var calculationMock = mocks.StrictMock>(); + var inputMock = mocks.StrictMock(); + inputMock.Expect(i => i.ForeshoreProfile).Return(new TestForeshoreProfile()); + inputMock.Expect(i => i.IsForeshoreProfileParametersSynchronized).Return(synchronized); + calculationMock.Stub(c => c.InputParameters).Return(inputMock); + + var calculationWithoutChangesMock = mocks.StrictMock>(); + var inputWithoutChangesMock = mocks.StrictMock(); + inputWithoutChangesMock.Stub(ci => ci.ForeshoreProfile).Return(new TestForeshoreProfile()); + inputWithoutChangesMock.Stub(ci => ci.IsForeshoreProfileParametersSynchronized).Return(true); + calculationWithoutChangesMock.Stub(c => c.InputParameters).Return(inputWithoutChangesMock); + + var inquiryHelperMock = mocks.StrictMock(); + mocks.ReplayAll(); + + using (var treeViewControl = new TreeViewControl()) + { + var contextMenuBuilder = new ContextMenuBuilder(applicationFeatureCommandsMock, + importHandlerMock, + exportHandlerMock, + updateHandlerMock, + viewCommandsMock, + calculationMock, + treeViewControl); + + var ringtoetsContextMenuBuilder = new RingtoetsContextMenuBuilder(contextMenuBuilder); + + // Call + ContextMenuStrip result = ringtoetsContextMenuBuilder.AddUpdateForeshoreProfileOfCalculationsItem( + new[] + { + calculationMock, + calculationWithoutChangesMock + }, + inquiryHelperMock, + c => {}).Build(); + + // Assert + Assert.IsInstanceOf(result); + Assert.AreEqual(1, result.Items.Count); + TestHelper.AssertContextMenuStripContainsItem(result, 0, + "&Bijwerken voorlandprofielen...", + synchronized + ? "De geselecteerde voorlandprofielen hebben geen wijzigingen om bij te werken." + : "Berekeningen bijwerken waar een voorlandprofiel geselecteerd is.", + RingtoetsFormsResources.UpdateItemIcon, + !synchronized); + } + + mocks.VerifyAll(); + } + + [Test] + public void AddUpdateForeshoreProfileOfCalculationsItem_CalculationWithoutForeshoreProfile_ItemAddedToContextMenuDisabled() + { + // Setup + var mocks = new MockRepository(); + var applicationFeatureCommandsMock = mocks.StrictMock(); + var importHandlerMock = mocks.StrictMock(); + var exportHandlerMock = mocks.StrictMock(); + var updateHandlerMock = mocks.StrictMock(); + var viewCommandsMock = mocks.StrictMock(); + + var calculationMock = mocks.StrictMock>(); + var inputMock = mocks.StrictMock(); + inputMock.Expect(i => i.ForeshoreProfile).Return(null); + calculationMock.Expect(c => c.InputParameters).Return(inputMock); + + var calculationWithoutChangesMock = mocks.StrictMock>(); + var inputWithoutChangesMock = mocks.StrictMock(); + inputWithoutChangesMock.Stub(ci => ci.ForeshoreProfile).Return(new TestForeshoreProfile()); + inputWithoutChangesMock.Stub(ci => ci.IsForeshoreProfileParametersSynchronized).Return(true); + calculationWithoutChangesMock.Stub(c => c.InputParameters).Return(inputWithoutChangesMock); + + var inquiryHelperMock = mocks.StrictMock(); + mocks.ReplayAll(); + + using (var treeViewControl = new TreeViewControl()) + { + var contextMenuBuilder = new ContextMenuBuilder(applicationFeatureCommandsMock, + importHandlerMock, + exportHandlerMock, + updateHandlerMock, + viewCommandsMock, + calculationMock, + treeViewControl); + + var ringtoetsContextMenuBuilder = new RingtoetsContextMenuBuilder(contextMenuBuilder); + + // Call + ContextMenuStrip result = ringtoetsContextMenuBuilder.AddUpdateForeshoreProfileOfCalculationsItem( + new[] + { + calculationMock, + calculationWithoutChangesMock + }, + inquiryHelperMock, + c => {}).Build(); + + // Assert + Assert.IsInstanceOf(result); + Assert.AreEqual(1, result.Items.Count); + TestHelper.AssertContextMenuStripContainsItem(result, 0, + "&Bijwerken voorlandprofielen...", + "De geselecteerde voorlandprofielen hebben geen wijzigingen om bij te werken.", + RingtoetsFormsResources.UpdateItemIcon, + false); + } + + mocks.VerifyAll(); + } + #endregion #region Nested types @@ -1791,6 +1919,8 @@ public void ClearOutput() {} } + public interface ICalculationInputWithForeshoreProfile : ICalculationInput, IHasForeshoreProfile {} + #endregion } } \ No newline at end of file Index: Ringtoets/Common/test/Ringtoets.Common.Forms.Test/TreeNodeInfos/RingtoetsContextMenuItemFactoryTest.cs =================================================================== diff -u -rada94ef2b6943fb9a2d8e59256871205a7d4c4ee -ra15e6824491a708be9c960aaa119b79a2ee3274d --- Ringtoets/Common/test/Ringtoets.Common.Forms.Test/TreeNodeInfos/RingtoetsContextMenuItemFactoryTest.cs (.../RingtoetsContextMenuItemFactoryTest.cs) (revision ada94ef2b6943fb9a2d8e59256871205a7d4c4ee) +++ Ringtoets/Common/test/Ringtoets.Common.Forms.Test/TreeNodeInfos/RingtoetsContextMenuItemFactoryTest.cs (.../RingtoetsContextMenuItemFactoryTest.cs) (revision a15e6824491a708be9c960aaa119b79a2ee3274d) @@ -743,8 +743,237 @@ mocks.VerifyAll(); } - public interface ICalculationInputWithForeshoreProfile : ICalculationInput, IHasForeshoreProfile {} + #endregion + #region CreateUpdateForshoreProfileOfCalculationsItem + + [Test] + public void CreateUpdateForshoreProfileOfCalculationsItem_WithoutForeshoreProfile_CreatesDisabledItem() + { + // Setup + var mocks = new MockRepository(); + var calculationMock = mocks.StrictMock>(); + calculationMock.Expect(c => c.InputParameters.ForeshoreProfile).Return(null); + + var inquiryHelperMock = mocks.StrictMock(); + mocks.ReplayAll(); + + // Call + StrictContextMenuItem toolStripItem = RingtoetsContextMenuItemFactory.CreateUpdateForshoreProfileOfCalculationsItem( + new[] + { + calculationMock + }, + inquiryHelperMock, c => {}); + + // Assert + Assert.AreEqual("&Bijwerken voorlandprofielen...", toolStripItem.Text); + Assert.AreEqual("De geselecteerde voorlandprofielen hebben geen wijzigingen om bij te werken.", toolStripItem.ToolTipText); + TestHelper.AssertImagesAreEqual(RingtoetsFormsResources.UpdateItemIcon, toolStripItem.Image); + Assert.IsFalse(toolStripItem.Enabled); + mocks.VerifyAll(); + } + + [Test] + public void CreateUpdateForshoreProfileOfCalculationsItem_WithForeshoreProfileSynchronized_CreatesDisabledItem() + { + // Setup + var mocks = new MockRepository(); + var calculationMock = mocks.StrictMock>(); + var inputMock = mocks.StrictMock(); + inputMock.Stub(ci => ci.ForeshoreProfile).Return(new TestForeshoreProfile()); + inputMock.Stub(ci => ci.IsForeshoreProfileParametersSynchronized).Return(true); + calculationMock.Stub(c => c.InputParameters).Return(inputMock); + + var inquiryHelperMock = mocks.StrictMock(); + mocks.ReplayAll(); + + // Call + StrictContextMenuItem toolStripItem = RingtoetsContextMenuItemFactory.CreateUpdateForshoreProfileOfCalculationsItem( + new[] + { + calculationMock + }, + inquiryHelperMock, c => {}); + + // Assert + Assert.AreEqual("&Bijwerken voorlandprofielen...", toolStripItem.Text); + Assert.AreEqual("De geselecteerde voorlandprofielen hebben geen wijzigingen om bij te werken.", toolStripItem.ToolTipText); + TestHelper.AssertImagesAreEqual(RingtoetsFormsResources.UpdateItemIcon, toolStripItem.Image); + Assert.IsFalse(toolStripItem.Enabled); + mocks.VerifyAll(); + } + + [Test] + public void CreateUpdateForshoreProfileOfCalculationsItem_WithForeshoreProfile_CreatesEnabledItem() + { + // Setup + var mocks = new MockRepository(); + var calculationMock = mocks.StrictMock>(); + var input = mocks.StrictMock(); + input.Expect(i => i.ForeshoreProfile).Return(new TestForeshoreProfile()); + input.Expect(i => i.IsForeshoreProfileParametersSynchronized).Return(false); + calculationMock.Stub(c => c.InputParameters).Return(input); + + var calculationWithoutChangesMock = mocks.StrictMock>(); + var inputWithoutChangesMock = mocks.StrictMock(); + inputWithoutChangesMock.Stub(ci => ci.ForeshoreProfile).Return(new TestForeshoreProfile()); + inputWithoutChangesMock.Stub(ci => ci.IsForeshoreProfileParametersSynchronized).Return(true); + calculationWithoutChangesMock.Stub(c => c.InputParameters).Return(inputWithoutChangesMock); + + var inquiryHelperMock = mocks.StrictMock(); + mocks.ReplayAll(); + + // Call + StrictContextMenuItem toolStripItem = RingtoetsContextMenuItemFactory.CreateUpdateForshoreProfileOfCalculationsItem( + new[] + { + calculationMock, + calculationWithoutChangesMock + }, + inquiryHelperMock, c => {}); + + // Assert + Assert.AreEqual("&Bijwerken voorlandprofielen...", toolStripItem.Text); + Assert.AreEqual("Berekeningen bijwerken waar een voorlandprofiel geselecteerd is.", toolStripItem.ToolTipText); + TestHelper.AssertImagesAreEqual(RingtoetsFormsResources.UpdateItemIcon, toolStripItem.Image); + Assert.IsTrue(toolStripItem.Enabled); + mocks.VerifyAll(); + } + + [Test] + public void CreateUpdateForshoreProfileOfCalculationsItem_WithoutCalculationOutputPerformClick_PerformsAction() + { + // Setup + var mocks = new MockRepository(); + var calculationMock = mocks.StrictMock>(); + var input = mocks.StrictMock(); + input.Expect(i => i.ForeshoreProfile).Return(new TestForeshoreProfile()); + input.Expect(i => i.IsForeshoreProfileParametersSynchronized).Return(false); + calculationMock.Stub(c => c.InputParameters).Return(input); + calculationMock.Expect(c => c.HasOutput).Return(false); + + var calculationWithoutChangesMock = mocks.StrictMock>(); + var inputWithoutChangesMock = mocks.StrictMock(); + inputWithoutChangesMock.Stub(ci => ci.ForeshoreProfile).Return(new TestForeshoreProfile()); + inputWithoutChangesMock.Stub(ci => ci.IsForeshoreProfileParametersSynchronized).Return(true); + calculationWithoutChangesMock.Stub(c => c.InputParameters).Return(inputWithoutChangesMock); + + var inquiryHelperMock = mocks.StrictMock(); + mocks.ReplayAll(); + + ICalculation actionCalculation = null; + StrictContextMenuItem toolStripItem = RingtoetsContextMenuItemFactory.CreateUpdateForshoreProfileOfCalculationsItem( + new[] + { + calculationMock, + calculationWithoutChangesMock + }, + inquiryHelperMock, + c => { actionCalculation = c; }); + + // Call + toolStripItem.PerformClick(); + + // Assert + Assert.AreSame(calculationMock, actionCalculation); + mocks.VerifyAll(); + } + + [Test] + public void CreateUpdateForshoreProfileOfCalculationsItem_WithCalculationOutputPerformClickNoContinuation_DoesNotPerformAction() + { + // Setup + string inquireContinuationMessage = "Wanneer het voorlandprofiel wijzigt als gevolg van het bijwerken, " + + "zal het resultaat van de berekeningen worden verwijderd." + + $"{Environment.NewLine}{Environment.NewLine}" + + "Weet u zeker dat u wilt doorgaan?"; + + var mocks = new MockRepository(); + var calculationMock = mocks.StrictMock>(); + var inputMock = mocks.StrictMock(); + inputMock.Expect(i => i.ForeshoreProfile).Return(new TestForeshoreProfile()); + inputMock.Expect(i => i.IsForeshoreProfileParametersSynchronized).Return(false); + calculationMock.Stub(c => c.InputParameters).Return(inputMock); + calculationMock.Expect(c => c.HasOutput).Return(true); + + var calculationWithoutChangesMock = mocks.StrictMock>(); + var inputWithoutChangesMock = mocks.StrictMock(); + inputWithoutChangesMock.Stub(ci => ci.ForeshoreProfile).Return(new TestForeshoreProfile()); + inputWithoutChangesMock.Stub(ci => ci.IsForeshoreProfileParametersSynchronized).Return(true); + calculationWithoutChangesMock.Stub(c => c.InputParameters).Return(inputWithoutChangesMock); + + var inquiryHelperMock = mocks.StrictMock(); + inquiryHelperMock.Expect(i => i.InquireContinuation(inquireContinuationMessage)).Return(false); + mocks.ReplayAll(); + + var actionPerformed = false; + StrictContextMenuItem toolStripItem = RingtoetsContextMenuItemFactory.CreateUpdateForshoreProfileOfCalculationsItem( + new[] + { + calculationMock, + calculationWithoutChangesMock + }, + inquiryHelperMock, + c => { actionPerformed = true; }); + + // Call + toolStripItem.PerformClick(); + + // Assert + Assert.IsFalse(actionPerformed); + mocks.VerifyAll(); + } + + [Test] + public void CreateUpdateForshoreProfileOfCalculationsItem_WithCalculationOutputPerformClickWithContinuation_PerformsAction() + { + // Setup + string inquireContinuationMessage = "Wanneer het voorlandprofiel wijzigt als gevolg van het bijwerken, " + + "zal het resultaat van de berekeningen worden verwijderd." + + $"{Environment.NewLine}{Environment.NewLine}" + + "Weet u zeker dat u wilt doorgaan?"; + + var mocks = new MockRepository(); + var calculationMock = mocks.StrictMock>(); + var input = mocks.StrictMock(); + input.Expect(i => i.ForeshoreProfile).Return(new TestForeshoreProfile()); + input.Expect(i => i.IsForeshoreProfileParametersSynchronized).Return(false); + calculationMock.Stub(c => c.InputParameters).Return(input); + calculationMock.Expect(c => c.HasOutput).Return(true); + + var calculationWithoutChangesMock = mocks.StrictMock>(); + var inputWithoutChangesMock = mocks.StrictMock(); + inputWithoutChangesMock.Stub(ci => ci.ForeshoreProfile).Return(new TestForeshoreProfile()); + inputWithoutChangesMock.Stub(ci => ci.IsForeshoreProfileParametersSynchronized).Return(true); + calculationWithoutChangesMock.Stub(c => c.InputParameters).Return(inputWithoutChangesMock); + + var inquiryHelperMock = mocks.StrictMock(); + inquiryHelperMock.Expect(i => i.InquireContinuation(inquireContinuationMessage)).Return(true); + mocks.ReplayAll(); + + var actionPerformed = false; + StrictContextMenuItem toolStripItem = RingtoetsContextMenuItemFactory.CreateUpdateForshoreProfileOfCalculationsItem( + new[] + { + calculationMock, + calculationWithoutChangesMock + }, + inquiryHelperMock, + c => + { + Assert.AreSame(calculationMock, c); + actionPerformed = true; + }); + + // Call + toolStripItem.PerformClick(); + + // Assert + Assert.IsTrue(actionPerformed); + mocks.VerifyAll(); + } + #endregion #region CreatePerformCalculationItem @@ -1519,6 +1748,8 @@ public void ClearOutput() {} } + public interface ICalculationInputWithForeshoreProfile : ICalculationInput, IHasForeshoreProfile {} + #endregion } } \ No newline at end of file