Index: Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Plugin.Test/TreeNodeInfos/GrassCoverErosionInwardsCalculationGroupContextTreeNodeInfoTest.cs =================================================================== diff -u -r56ac4eb28f5fcc5b20117474e9e4030399d6806a -r047258c748dbf834052838e22715ee54d8c97150 --- Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Plugin.Test/TreeNodeInfos/GrassCoverErosionInwardsCalculationGroupContextTreeNodeInfoTest.cs (.../GrassCoverErosionInwardsCalculationGroupContextTreeNodeInfoTest.cs) (revision 56ac4eb28f5fcc5b20117474e9e4030399d6806a) +++ Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Plugin.Test/TreeNodeInfos/GrassCoverErosionInwardsCalculationGroupContextTreeNodeInfoTest.cs (.../GrassCoverErosionInwardsCalculationGroupContextTreeNodeInfoTest.cs) (revision 047258c748dbf834052838e22715ee54d8c97150) @@ -1006,6 +1006,143 @@ } [Test] + public void GivenCalculationWithDikeProfileWithOutput_WhenDikeProfileHasPartialChangeInDerivedInputAndUpdateDikeProfileClicked_ThenOutputRemovedAndObserversNotified() + { + using (var treeViewControl = new TreeViewControl()) + { + // Given + var calculation1InputObserver = mocks.StrictMock(); + calculation1InputObserver.Expect(obs => obs.UpdateObserver()); + var calculation2InputObserver = mocks.StrictMock(); + calculation2InputObserver.Expect(obs => obs.UpdateObserver()); + + var calculation1Observer = mocks.StrictMock(); + calculation1Observer.Expect(obs => obs.UpdateObserver()); + var calculation2Observer = mocks.StrictMock(); + calculation2Observer.Expect(obs => obs.UpdateObserver()); + + var dikeProfile = new DikeProfile(new Point2D(0, 0), + new[] + { + new RoughnessPoint(new Point2D(1.1, 2.2), 3), + new RoughnessPoint(new Point2D(3.3, 4.4), 5) + }, + new[] + { + new Point2D(1.1, 2.2), + new Point2D(3.3, 4.4) + }, + new BreakWater(BreakWaterType.Caisson, 10), + new DikeProfile.ConstructionProperties + { + Id = "ID" + }); + const double orientation = 10; + const bool useForeshore = true; + var calculation1 = new GrassCoverErosionInwardsCalculation + { + InputParameters = + { + DikeProfile = dikeProfile, + DikeHeight = (RoundedDouble) 30, + Orientation = (RoundedDouble) orientation, + UseForeshore = useForeshore, + UseBreakWater = false + }, + Output = new TestGrassCoverErosionInwardsOutput() + }; + calculation1.Attach(calculation1Observer); + calculation1.InputParameters.Attach(calculation1InputObserver); + + var calculation2 = new GrassCoverErosionInwardsCalculation + { + InputParameters = + { + DikeProfile = dikeProfile, + DikeHeight = (RoundedDouble) 30, + Orientation = (RoundedDouble) orientation, + UseForeshore = useForeshore, + UseBreakWater = false + }, + Output = new TestGrassCoverErosionInwardsOutput() + }; + calculation2.Attach(calculation2Observer); + calculation2.InputParameters.Attach(calculation2InputObserver); + + var childGroup = new CalculationGroup(); + childGroup.Children.Add(calculation1); + + var emptyChildGroup = new CalculationGroup(); + var group = new CalculationGroup(); + var parentGroup = new CalculationGroup(); + + group.Children.Add(childGroup); + group.Children.Add(emptyChildGroup); + group.Children.Add(calculation2); + + var assessmentSection = mocks.Stub(); + var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); + var nodeData = new GrassCoverErosionInwardsCalculationGroupContext(group, + failureMechanism, + assessmentSection); + var parentNodeData = new GrassCoverErosionInwardsCalculationGroupContext(parentGroup, + failureMechanism, + assessmentSection); + + var mainWindow = mocks.Stub(); + gui.Stub(cmp => cmp.Get(nodeData, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder()); + gui.Stub(g => g.MainWindow).Return(mainWindow); + gui.Stub(cmp => cmp.ViewCommands).Return(mocks.Stub()); + mocks.ReplayAll(); + + plugin.Gui = gui; + + string textBoxMessage = null; + DialogBoxHandler = (name, wnd) => + { + var helper = new MessageBoxTester(wnd); + textBoxMessage = helper.Text; + helper.ClickOk(); + }; + + using (ContextMenuStrip menu = info.ContextMenuStrip(nodeData, parentNodeData, treeViewControl)) + { + // When + UpdateDikeProfile(dikeProfile); + menu.Items[contextMenuUpdateDikeProfileAllIndexNestedGroup].PerformClick(); + + // Then + Assert.IsFalse(calculation1.HasOutput); + GrassCoverErosionInwardsInput inputParameters1 = calculation1.InputParameters; + Assert.AreSame(dikeProfile, inputParameters1.DikeProfile); + Assert.AreEqual(dikeProfile.Orientation, inputParameters1.Orientation); + Assert.AreEqual(dikeProfile.DikeHeight, inputParameters1.DikeHeight); + Assert.AreEqual(dikeProfile.HasBreakWater, inputParameters1.UseBreakWater); + Assert.AreEqual(dikeProfile.BreakWater, inputParameters1.BreakWater); + bool expectedUseForeshore1 = dikeProfile.ForeshoreGeometry.Count() > 1; + Assert.AreEqual(expectedUseForeshore1, inputParameters1.UseForeshore); + + Assert.IsFalse(calculation2.HasOutput); + GrassCoverErosionInwardsInput inputParameters2 = calculation2.InputParameters; + Assert.AreSame(dikeProfile, inputParameters2.DikeProfile); + Assert.AreEqual(dikeProfile.Orientation, inputParameters2.Orientation); + Assert.AreEqual(dikeProfile.DikeHeight, inputParameters2.DikeHeight); + Assert.AreEqual(dikeProfile.HasBreakWater, inputParameters2.UseBreakWater); + Assert.AreEqual(dikeProfile.BreakWater, inputParameters2.BreakWater); + bool expectedUseForeshore2 = dikeProfile.ForeshoreGeometry.Count() > 1; + Assert.AreEqual(expectedUseForeshore2, inputParameters2.UseForeshore); + + string expectedMessage = "Wanneer de dijkprofielen wijzigen als gevolg van het bijwerken, " + + "zullen de resultaten van berekeningen die deze dijkprofielen gebruiken, worden " + + $"verwijderd.{Environment.NewLine}{Environment.NewLine}Weet u zeker dat u wilt doorgaan?"; + Assert.AreEqual(expectedMessage, textBoxMessage); + + // Note: observer assertions are verified in the Teardown() + } + } + } + + [Test] public void ContextMenuStrip_HydraulicBoundaryDatabaseNotValid_ContextMenuItemCalculateAllDisabledAndTooltipSet() { // Setup