Index: Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Plugin.Test/TreeNodeInfos/ClosingStructuresCalculationContextTreeNodeInfoTest.cs =================================================================== diff -u -r41da80335e9db4b38a470de5b247f759ca497997 -r3d95e2d4d19772aab17604346c7a6def74bb1192 --- Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Plugin.Test/TreeNodeInfos/ClosingStructuresCalculationContextTreeNodeInfoTest.cs (.../ClosingStructuresCalculationContextTreeNodeInfoTest.cs) (revision 41da80335e9db4b38a470de5b247f759ca497997) +++ Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Plugin.Test/TreeNodeInfos/ClosingStructuresCalculationContextTreeNodeInfoTest.cs (.../ClosingStructuresCalculationContextTreeNodeInfoTest.cs) (revision 3d95e2d4d19772aab17604346c7a6def74bb1192) @@ -760,21 +760,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 TestClosingStructuresFailureMechanism(); - var calculation = new StructuresCalculation + var calculation = new StructuresCalculation(); + + if (hasForeshoreProfile) { - InputParameters = + calculation.InputParameters.ForeshoreProfile = new TestForeshoreProfile(); + if (!isSynchronized) { - ForeshoreProfile = new TestForeshoreProfile() + calculation.InputParameters.UseBreakWater = true; } - }; + } + var nodeData = new ClosingStructuresCalculationContext(calculation, failureMechanism, - assessmentSectionStub); + assessmentSection); using (var treeViewControl = new TreeViewControl()) { @@ -784,17 +791,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); + } } } } @@ -846,6 +878,82 @@ } [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 TestClosingStructuresFailureMechanism(); + + var calculation = new StructuresCalculation + { + InputParameters = + { + ForeshoreProfile = new TestForeshoreProfile(true) + }, + Output = new TestStructuresOutput() + }; + + var nodeData = new ClosingStructuresCalculationContext(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()) + { + 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] public void GivenSuccessfulCalculation_WhenCalculatingFromContextMenu_ThenOutputSetLogMessagesAddedAndUpdateObserver() { // Given Index: Ringtoets/Common/test/Ringtoets.Common.Forms.Test/TreeNodeInfos/RingtoetsContextMenuItemFactoryTest.cs =================================================================== diff -u -r5b29217fb2099ab005ad86d9f53dbd8369210372 -r3d95e2d4d19772aab17604346c7a6def74bb1192 --- Ringtoets/Common/test/Ringtoets.Common.Forms.Test/TreeNodeInfos/RingtoetsContextMenuItemFactoryTest.cs (.../RingtoetsContextMenuItemFactoryTest.cs) (revision 5b29217fb2099ab005ad86d9f53dbd8369210372) +++ Ringtoets/Common/test/Ringtoets.Common.Forms.Test/TreeNodeInfos/RingtoetsContextMenuItemFactoryTest.cs (.../RingtoetsContextMenuItemFactoryTest.cs) (revision 3d95e2d4d19772aab17604346c7a6def74bb1192) @@ -655,6 +655,7 @@ } [Test] + [Combinatorial] public void CreateUpdateForeshoreProfileOfCalculationItem_WithVariousOutputPerformClick_ExpectedAction( [Values(true, false)] bool hasOutput, [Values(true, false)] bool continuation) Index: Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.Plugin.Test/TreeNodeInfos/GrassCoverErosionOutwardsWaveConditionsCalculationContextTreeNodeInfoTest.cs =================================================================== diff -u -r41da80335e9db4b38a470de5b247f759ca497997 -r3d95e2d4d19772aab17604346c7a6def74bb1192 --- Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.Plugin.Test/TreeNodeInfos/GrassCoverErosionOutwardsWaveConditionsCalculationContextTreeNodeInfoTest.cs (.../GrassCoverErosionOutwardsWaveConditionsCalculationContextTreeNodeInfoTest.cs) (revision 41da80335e9db4b38a470de5b247f759ca497997) +++ Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.Plugin.Test/TreeNodeInfos/GrassCoverErosionOutwardsWaveConditionsCalculationContextTreeNodeInfoTest.cs (.../GrassCoverErosionOutwardsWaveConditionsCalculationContextTreeNodeInfoTest.cs) (revision 3d95e2d4d19772aab17604346c7a6def74bb1192) @@ -761,21 +761,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 GrassCoverErosionOutwardsFailureMechanism(); - var calculation = new GrassCoverErosionOutwardsWaveConditionsCalculation + var calculation = new GrassCoverErosionOutwardsWaveConditionsCalculation(); + + if (hasForeshoreProfile) { - InputParameters = + calculation.InputParameters.ForeshoreProfile = new TestForeshoreProfile(); + if (!isSynchronized) { - ForeshoreProfile = new TestForeshoreProfile() + calculation.InputParameters.UseBreakWater = true; } - }; + } + var nodeData = new GrassCoverErosionOutwardsWaveConditionsCalculationContext(calculation, failureMechanism, - assessmentSectionStub); + assessmentSection); using (var treeViewControl = new TreeViewControl()) { @@ -786,17 +793,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); + } } } } @@ -851,6 +883,85 @@ [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 GrassCoverErosionOutwardsFailureMechanism + { + Contribution = 5 + }; + var calculation = new GrassCoverErosionOutwardsWaveConditionsCalculation + { + InputParameters = + { + ForeshoreProfile = new TestForeshoreProfile(true) + }, + Output = new GrassCoverErosionOutwardsWaveConditionsOutput(Enumerable.Empty()) + }; + + var nodeData = new GrassCoverErosionOutwardsWaveConditionsCalculationContext(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 Index: Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Plugin.Test/TreeNodeInfos/HeightStructuresCalculationContextTreeNodeInfoTest.cs =================================================================== diff -u -r41da80335e9db4b38a470de5b247f759ca497997 -r3d95e2d4d19772aab17604346c7a6def74bb1192 --- Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Plugin.Test/TreeNodeInfos/HeightStructuresCalculationContextTreeNodeInfoTest.cs (.../HeightStructuresCalculationContextTreeNodeInfoTest.cs) (revision 41da80335e9db4b38a470de5b247f759ca497997) +++ Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Plugin.Test/TreeNodeInfos/HeightStructuresCalculationContextTreeNodeInfoTest.cs (.../HeightStructuresCalculationContextTreeNodeInfoTest.cs) (revision 3d95e2d4d19772aab17604346c7a6def74bb1192) @@ -904,21 +904,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 failureMechanism = new HeightStructuresFailureMechanism(); - var calculation = new StructuresCalculation + var assessmentSection = mocks.Stub(); + var failureMechanism = new TestHeightStructuresFailureMechanism(); + var calculation = new StructuresCalculation(); + + if (hasForeshoreProfile) { - InputParameters = + calculation.InputParameters.ForeshoreProfile = new TestForeshoreProfile(); + if (!isSynchronized) { - ForeshoreProfile = new TestForeshoreProfile() + calculation.InputParameters.UseBreakWater = true; } - }; + } + var nodeData = new HeightStructuresCalculationContext(calculation, failureMechanism, - assessmentSectionStub); + assessmentSection); using (var treeViewControl = new TreeViewControl()) { @@ -929,17 +936,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); + } } } } @@ -952,7 +984,7 @@ var calculationInputObserver = mocks.StrictMock(); calculationInputObserver.Expect(o => o.UpdateObserver()); - var assessmentSectionStub = mocks.Stub(); + var assessmentSection = mocks.Stub(); var failureMechanism = new HeightStructuresFailureMechanism(); var calculation = new StructuresCalculation @@ -964,19 +996,19 @@ }; var nodeData = new HeightStructuresCalculationContext(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; @@ -992,6 +1024,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 TestHeightStructuresFailureMechanism(); + + var calculation = new StructuresCalculation + { + InputParameters = + { + ForeshoreProfile = new TestForeshoreProfile(true) + }, + Output = new TestStructuresOutput() + }; + + var nodeData = new HeightStructuresCalculationContext(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] public void GivenCalculationThatSucceeds_WhenCalculatingFromContextMenu_ThenOutputSetLogMessagesAddedAndUpdateObserver() { // Given Index: Ringtoets/StabilityPointStructures/test/Ringtoets.StabilityPointStructures.Plugin.Test/TreeNodeInfos/StabilityPointStructuresCalculationContextTreeNodeInfoTest.cs =================================================================== diff -u -r41da80335e9db4b38a470de5b247f759ca497997 -r3d95e2d4d19772aab17604346c7a6def74bb1192 --- Ringtoets/StabilityPointStructures/test/Ringtoets.StabilityPointStructures.Plugin.Test/TreeNodeInfos/StabilityPointStructuresCalculationContextTreeNodeInfoTest.cs (.../StabilityPointStructuresCalculationContextTreeNodeInfoTest.cs) (revision 41da80335e9db4b38a470de5b247f759ca497997) +++ Ringtoets/StabilityPointStructures/test/Ringtoets.StabilityPointStructures.Plugin.Test/TreeNodeInfos/StabilityPointStructuresCalculationContextTreeNodeInfoTest.cs (.../StabilityPointStructuresCalculationContextTreeNodeInfoTest.cs) (revision 3d95e2d4d19772aab17604346c7a6def74bb1192) @@ -442,21 +442,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 TestStabilityPointStructuresFailureMechanism(); - var calculation = new StructuresCalculation + var calculation = new StructuresCalculation(); + + if (hasForeshoreProfile) { - InputParameters = + calculation.InputParameters.ForeshoreProfile = new TestForeshoreProfile(); + if (!isSynchronized) { - ForeshoreProfile = new TestForeshoreProfile() + calculation.InputParameters.UseBreakWater = true; } - }; + } + var nodeData = new StabilityPointStructuresCalculationContext(calculation, failureMechanism, - assessmentSectionStub); + assessmentSection); using (var treeViewControl = new TreeViewControl()) { @@ -467,17 +474,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); + } } } } @@ -490,7 +522,7 @@ var calculationInputObserver = mocks.StrictMock(); calculationInputObserver.Expect(o => o.UpdateObserver()); - var assessmentSectionStub = mocks.Stub(); + var assessmentSection = mocks.Stub(); var failureMechanism = new TestStabilityPointStructuresFailureMechanism(); var calculation = new StructuresCalculation @@ -502,7 +534,7 @@ }; var nodeData = new StabilityPointStructuresCalculationContext(calculation, failureMechanism, - assessmentSectionStub); + assessmentSection); calculation.Attach(calculationObserver); calculation.InputParameters.Attach(calculationInputObserver); @@ -530,6 +562,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 TestStabilityPointStructuresFailureMechanism(); + + var calculation = new StructuresCalculation + { + InputParameters = + { + ForeshoreProfile = new TestForeshoreProfile(true) + }, + Output = new TestStructuresOutput() + }; + + var nodeData = new StabilityPointStructuresCalculationContext(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] public void GivenCalculationThatSucceeds_WhenCalculatingFromContextMenu_ThenOutputSetLogMessagesAddedAndUpdateObserver() { // Given Index: Ringtoets/StabilityStoneCover/test/Ringtoets.StabilityStoneCover.Plugin.Test/TreeNodeInfos/StabilityStoneCoverWaveConditionsCalculationContextTreeNodeInfoTest.cs =================================================================== diff -u -r41da80335e9db4b38a470de5b247f759ca497997 -r3d95e2d4d19772aab17604346c7a6def74bb1192 --- Ringtoets/StabilityStoneCover/test/Ringtoets.StabilityStoneCover.Plugin.Test/TreeNodeInfos/StabilityStoneCoverWaveConditionsCalculationContextTreeNodeInfoTest.cs (.../StabilityStoneCoverWaveConditionsCalculationContextTreeNodeInfoTest.cs) (revision 41da80335e9db4b38a470de5b247f759ca497997) +++ Ringtoets/StabilityStoneCover/test/Ringtoets.StabilityStoneCover.Plugin.Test/TreeNodeInfos/StabilityStoneCoverWaveConditionsCalculationContextTreeNodeInfoTest.cs (.../StabilityStoneCoverWaveConditionsCalculationContextTreeNodeInfoTest.cs) (revision 3d95e2d4d19772aab17604346c7a6def74bb1192) @@ -728,21 +728,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 StabilityStoneCoverFailureMechanism(); - var calculation = new StabilityStoneCoverWaveConditionsCalculation + var calculation = new StabilityStoneCoverWaveConditionsCalculation(); + + if (hasForeshoreProfile) { - InputParameters = + calculation.InputParameters.ForeshoreProfile = new TestForeshoreProfile(); + if (!isSynchronized) { - ForeshoreProfile = new TestForeshoreProfile() + calculation.InputParameters.UseBreakWater = true; } - }; + } + var nodeData = new StabilityStoneCoverWaveConditionsCalculationContext(calculation, failureMechanism, - assessmentSectionStub); + assessmentSection); using (var treeViewControl = new TreeViewControl()) { @@ -753,17 +760,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); + } } } } @@ -776,7 +808,7 @@ var calculationInputObserver = mocks.StrictMock(); calculationInputObserver.Expect(o => o.UpdateObserver()); - var assessmentSectionStub = mocks.Stub(); + var assessmentSection = mocks.Stub(); var failureMechanism = new StabilityStoneCoverFailureMechanism(); var calculation = new StabilityStoneCoverWaveConditionsCalculation @@ -788,19 +820,19 @@ }; var nodeData = new StabilityStoneCoverWaveConditionsCalculationContext(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; @@ -816,7 +848,84 @@ } [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 StabilityStoneCoverFailureMechanism(); + + var calculation = new StabilityStoneCoverWaveConditionsCalculation + { + InputParameters = + { + ForeshoreProfile = new TestForeshoreProfile(true) + }, + Output = new StabilityStoneCoverWaveConditionsOutput(Enumerable.Empty(), Enumerable.Empty()) + }; + + var nodeData = new StabilityStoneCoverWaveConditionsCalculationContext(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(false)] [TestCase(true)] public void GivenCalculation_WhenValidating_ThenCalculationValidated(bool validCalculation) { 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