Index: Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Forms.Test/TreeNodeInfos/GrassCoverErosionInwardsFailureMechanismContextTreeNodeInfoTest.cs =================================================================== diff -u -r89cf0d104a6e12180d2fae471ae318cad256707a -r17156e33835034c1ac9b920b9d05ad49589e6775 --- Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Forms.Test/TreeNodeInfos/GrassCoverErosionInwardsFailureMechanismContextTreeNodeInfoTest.cs (.../GrassCoverErosionInwardsFailureMechanismContextTreeNodeInfoTest.cs) (revision 89cf0d104a6e12180d2fae471ae318cad256707a) +++ Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Forms.Test/TreeNodeInfos/GrassCoverErosionInwardsFailureMechanismContextTreeNodeInfoTest.cs (.../GrassCoverErosionInwardsFailureMechanismContextTreeNodeInfoTest.cs) (revision 17156e33835034c1ac9b920b9d05ad49589e6775) @@ -35,6 +35,7 @@ using Rhino.Mocks; using Ringtoets.Common.Data; using Ringtoets.Common.Data.AssessmentSection; +using Ringtoets.Common.Data.Calculation; using Ringtoets.Common.Data.FailureMechanism; using Ringtoets.Common.Forms.PresentationObjects; using Ringtoets.GrassCoverErosionInwards.Data; @@ -414,6 +415,72 @@ mocksRepository.VerifyAll(); } + [Test] + [TestCase(true)] + [TestCase(false)] + public void GivenMultipleCalculationsWithOutput_WhenClearingOutputFromContextMenu_ThenCalculationsOutputClearedAndNotified(bool confirm) + { + // Given + var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); + var assessmentSection = mocksRepository.Stub(); + var failureMechanismContext = new GrassCoverErosionInwardsFailureMechanismContext(failureMechanism, assessmentSection); + + var validCalculation = GrassCoverErosionInwardsCalculationFactory.CreateCalculationWithValidInput(); + validCalculation.Name = "A"; + var invalidCalculation = GrassCoverErosionInwardsCalculationFactory.CreateCalculationWithInvalidData(); + invalidCalculation.Name = "B"; + failureMechanism.CalculationsGroup.Children.Add(validCalculation); + failureMechanism.CalculationsGroup.Children.Add(invalidCalculation); + + var gui = mocksRepository.DynamicMock(); + var observerMock = mocksRepository.StrictMock(); + var treeViewControlMock = mocksRepository.StrictMock(); + gui.Expect(cmp => cmp.Get(failureMechanismContext, treeViewControlMock)).Return(new CustomItemsOnlyContextMenuBuilder()); + + if (confirm) + { + observerMock.Expect(o => o.UpdateObserver()).Repeat.Twice(); + } + mocksRepository.ReplayAll(); + + plugin.Gui = gui; + + validCalculation.Output = new GrassCoverErosionInwardsOutput(0, 0, 0, 0, 0); + validCalculation.Attach(observerMock); + invalidCalculation.Output = new GrassCoverErosionInwardsOutput(0, 0, 0, 0, 0); + invalidCalculation.Attach(observerMock); + + var contextMenuAdapter = info.ContextMenuStrip(failureMechanismContext, null, treeViewControlMock); + + string messageBoxText = null, messageBoxTitle = null; + DialogBoxHandler = (name, wnd) => + { + var messageBox = new MessageBoxTester(wnd); + messageBoxText = messageBox.Text; + messageBoxTitle = messageBox.Title; + if (confirm) + { + messageBox.ClickOk(); + } + else + { + messageBox.ClickCancel(); + } + }; + + // When + contextMenuAdapter.Items[contextMenuClearAllIndex].PerformClick(); + + // Then + foreach (var calculation in failureMechanism.CalculationsGroup.Children.OfType()) + { + Assert.AreNotEqual(confirm, calculation.HasOutput); + } + Assert.AreEqual("Bevestigen", messageBoxTitle); + Assert.AreEqual("Weet u zeker dat u alle uitvoer wilt wissen?", messageBoxText); + mocksRepository.VerifyAll(); + } + private const int contextMenuRelevancyIndexWhenRelevant = 1; private const int contextMenuRelevancyIndexWhenNotRelevant = 0; private const int contextMenuCalculateAllIndex = 3;