Index: Ringtoets/WaveImpactAsphaltCover/test/Ringtoets.WaveImpactAsphaltCover.Plugin.Test/TreeNodeInfos/WaveImpactAsphaltCoverWaveConditionsCalculationContextTreeNodeInfoTest.cs =================================================================== diff -u -r41da80335e9db4b38a470de5b247f759ca497997 -r3d95e2d4d19772aab17604346c7a6def74bb1192 --- Ringtoets/WaveImpactAsphaltCover/test/Ringtoets.WaveImpactAsphaltCover.Plugin.Test/TreeNodeInfos/WaveImpactAsphaltCoverWaveConditionsCalculationContextTreeNodeInfoTest.cs (.../WaveImpactAsphaltCoverWaveConditionsCalculationContextTreeNodeInfoTest.cs) (revision 41da80335e9db4b38a470de5b247f759ca497997) +++ Ringtoets/WaveImpactAsphaltCover/test/Ringtoets.WaveImpactAsphaltCover.Plugin.Test/TreeNodeInfos/WaveImpactAsphaltCoverWaveConditionsCalculationContextTreeNodeInfoTest.cs (.../WaveImpactAsphaltCoverWaveConditionsCalculationContextTreeNodeInfoTest.cs) (revision 3d95e2d4d19772aab17604346c7a6def74bb1192) @@ -686,21 +686,28 @@ } [Test] - public void ContextMenuStrip_CalculationWithForeshoreProfileAndInputOutOfSync_ContextMenuItemUpdateForeshoreProfileEnabledAndToolTipSet() + [Combinatorial] + public void ContextMenuStripm_ForeshoreProfileStates_CreatesExpectedItem( + [Values(true, false)] bool hasForeshoreProfile, + [Values(true, false)] bool isSynchronized) { // Setup - var assessmentSectionStub = mocks.Stub(); + var assessmentSection = mocks.Stub(); var failureMechanism = new WaveImpactAsphaltCoverFailureMechanism(); - var calculation = new WaveImpactAsphaltCoverWaveConditionsCalculation + var calculation = new WaveImpactAsphaltCoverWaveConditionsCalculation(); + + if (hasForeshoreProfile) { - InputParameters = + calculation.InputParameters.ForeshoreProfile = new TestForeshoreProfile(); + if (!isSynchronized) { - ForeshoreProfile = new TestForeshoreProfile() + calculation.InputParameters.UseBreakWater = true; } - }; + } + var nodeData = new WaveImpactAsphaltCoverWaveConditionsCalculationContext(calculation, failureMechanism, - assessmentSectionStub); + assessmentSection); using (var treeViewControl = new TreeViewControl()) { @@ -711,17 +718,42 @@ plugin.Gui = gui; - calculation.InputParameters.UseBreakWater = true; - // Call using (ContextMenuStrip menu = info.ContextMenuStrip(nodeData, null, treeViewControl)) { // Assert - TestHelper.AssertContextMenuStripContainsItem(menu, - contextMenuUpdateForeshoreProfileIndex, - "&Bijwerken voorlandprofiel...", - "Berekening bijwerken met het voorlandprofiel.", - RingtoetsCommonFormsResources.UpdateItemIcon); + if (hasForeshoreProfile) + { + if (isSynchronized) + { + TestHelper.AssertContextMenuStripContainsItem( + menu, + contextMenuUpdateForeshoreProfileIndex, + "&Bijwerken voorlandprofiel...", + "Er zijn geen wijzigingen om bij te werken.", + RingtoetsCommonFormsResources.UpdateItemIcon, + false); + } + else + { + TestHelper.AssertContextMenuStripContainsItem( + menu, + contextMenuUpdateForeshoreProfileIndex, + "&Bijwerken voorlandprofiel...", + "Berekening bijwerken met het voorlandprofiel.", + RingtoetsCommonFormsResources.UpdateItemIcon); + } + } + else + { + TestHelper.AssertContextMenuStripContainsItem( + menu, + contextMenuUpdateForeshoreProfileIndex, + "&Bijwerken voorlandprofiel...", + "Er moet een voorlandprofiel geselecteerd zijn.", + RingtoetsCommonFormsResources.UpdateItemIcon, + false); + } } } } @@ -734,7 +766,7 @@ var calculationInputObserver = mocks.StrictMock(); calculationInputObserver.Expect(o => o.UpdateObserver()); - var assessmentSectionStub = mocks.Stub(); + var assessmentSection = mocks.Stub(); var failureMechanism = new WaveImpactAsphaltCoverFailureMechanism(); var calculation = new WaveImpactAsphaltCoverWaveConditionsCalculation @@ -746,19 +778,19 @@ }; var nodeData = new WaveImpactAsphaltCoverWaveConditionsCalculationContext(calculation, failureMechanism, - assessmentSectionStub); + assessmentSection); calculation.Attach(calculationObserver); calculation.InputParameters.Attach(calculationInputObserver); using (var treeViewControl = new TreeViewControl()) { - var guiStub = mocks.Stub(); - guiStub.Stub(g => g.Get(nodeData, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder()); - guiStub.Stub(cmp => cmp.MainWindow).Return(mocks.Stub()); + var gui = mocks.Stub(); + gui.Stub(g => g.Get(nodeData, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder()); + gui.Stub(cmp => cmp.MainWindow).Return(mocks.Stub()); mocks.ReplayAll(); - plugin.Gui = guiStub; + plugin.Gui = gui; calculation.InputParameters.UseBreakWater = false; @@ -776,6 +808,83 @@ [Test] [TestCase(true)] [TestCase(false)] + public void GivenCalculationWithOutputAndWithInputOutOfSync_WhenPerformClick_ThenInquiryAndExpectedOutputAndNotifications(bool continuation) + { + // Given + var calculationObserver = mocks.StrictMock(); + var calculationInputObserver = mocks.StrictMock(); + var assessmentSectionStub = mocks.Stub(); + var failureMechanism = new WaveImpactAsphaltCoverFailureMechanism(); + + var calculation = new WaveImpactAsphaltCoverWaveConditionsCalculation + { + InputParameters = + { + ForeshoreProfile = new TestForeshoreProfile(true) + }, + Output = new WaveImpactAsphaltCoverWaveConditionsOutput(Enumerable.Empty()) + }; + + var nodeData = new WaveImpactAsphaltCoverWaveConditionsCalculationContext(calculation, + failureMechanism, + assessmentSectionStub); + + calculation.Attach(calculationObserver); + calculation.InputParameters.Attach(calculationInputObserver); + + if (continuation) + { + calculationObserver.Expect(o => o.UpdateObserver()); + calculationInputObserver.Expect(o => o.UpdateObserver()); + } + + var messageBoxText = ""; + DialogBoxHandler = (name, wnd) => + { + var helper = new MessageBoxTester(wnd); + messageBoxText = helper.Text; + + if (continuation) + { + helper.ClickOk(); + } + else + { + helper.ClickCancel(); + } + }; + + using (var treeViewControl = new TreeViewControl()) + { + var gui = mocks.Stub(); + gui.Stub(g => g.Get(nodeData, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder()); + gui.Stub(cmp => cmp.MainWindow).Return(mocks.Stub()); + mocks.ReplayAll(); + + plugin.Gui = gui; + + calculation.InputParameters.UseBreakWater = false; + + using (ContextMenuStrip contextMenuStrip = info.ContextMenuStrip(nodeData, null, treeViewControl)) + { + // When + contextMenuStrip.Items[contextMenuUpdateForeshoreProfileIndex].PerformClick(); + + // Then + Assert.AreEqual(continuation, calculation.InputParameters.UseBreakWater); + Assert.AreEqual(!continuation, calculation.HasOutput); + } + } + + string expectedMessageBoxText = "Als u kiest voor bijwerken, dan wordt het resultaat van deze berekening " + + $"verwijderd.{Environment.NewLine}{Environment.NewLine}Weet u zeker dat u wilt doorgaan?"; + + Assert.AreEqual(expectedMessageBoxText, messageBoxText); + } + + [Test] + [TestCase(true)] + [TestCase(false)] public void GivenCalculation_WhenValidating_ThenCalculationValidated(bool validCalculation) { // Given