Index: Ringtoets/StabilityPointStructures/src/Ringtoets.StabilityPointStructures.Plugin/StabilityPointStructuresPlugin.cs =================================================================== diff -u -rec82979ab7ef689a1687ebccc771d38f882c5bb7 -r2678ee310030f02f415f1799c61635081d754165 --- Ringtoets/StabilityPointStructures/src/Ringtoets.StabilityPointStructures.Plugin/StabilityPointStructuresPlugin.cs (.../StabilityPointStructuresPlugin.cs) (revision ec82979ab7ef689a1687ebccc771d38f882c5bb7) +++ Ringtoets/StabilityPointStructures/src/Ringtoets.StabilityPointStructures.Plugin/StabilityPointStructuresPlugin.cs (.../StabilityPointStructuresPlugin.cs) (revision 2678ee310030f02f415f1799c61635081d754165) @@ -504,6 +504,12 @@ var parentGroupContext = (StabilityPointStructuresCalculationGroupContext) parentNodeData; parentGroupContext.WrappedData.Children.Remove(context.WrappedData); + foreach (var calculation in context.WrappedData.GetCalculations().Cast>()) + { + StructuresHelper.Delete(context.FailureMechanism.SectionResults, + calculation, + context.FailureMechanism.Calculations.Cast>()); + } parentGroupContext.NotifyObservers(); } @@ -582,6 +588,10 @@ if (calculationGroupContext != null) { calculationGroupContext.WrappedData.Children.Remove(context.WrappedData); + StructuresHelper.Delete( + context.FailureMechanism.SectionResults, + context.WrappedData, + context.FailureMechanism.Calculations.Cast>()); calculationGroupContext.NotifyObservers(); } } Index: Ringtoets/StabilityPointStructures/test/Ringtoets.StabilityPointStructures.Forms.Test/TreeNodeInfos/StabilityPointStructuresCalculationContextTreeNodeInfoTest.cs =================================================================== diff -u -ra14d1309ecf82ff5b0385a2f6e3b2c4a216a4184 -r2678ee310030f02f415f1799c61635081d754165 --- Ringtoets/StabilityPointStructures/test/Ringtoets.StabilityPointStructures.Forms.Test/TreeNodeInfos/StabilityPointStructuresCalculationContextTreeNodeInfoTest.cs (.../StabilityPointStructuresCalculationContextTreeNodeInfoTest.cs) (revision a14d1309ecf82ff5b0385a2f6e3b2c4a216a4184) +++ Ringtoets/StabilityPointStructures/test/Ringtoets.StabilityPointStructures.Forms.Test/TreeNodeInfos/StabilityPointStructuresCalculationContextTreeNodeInfoTest.cs (.../StabilityPointStructuresCalculationContextTreeNodeInfoTest.cs) (revision 2678ee310030f02f415f1799c61635081d754165) @@ -465,6 +465,40 @@ CollectionAssert.DoesNotContain(group.Children, elementToBeRemoved); } + [Test] + public void OnNodeRemoved_CalculationInGroupAssignedToSection_CalculationDetachedFromSection() + { + // Setup + var group = new CalculationGroup(); + var failureMechanism = new StabilityPointStructuresFailureMechanism(); + var elementToBeRemoved = new StructuresCalculation(); + var assessmentSectionStub = mocks.Stub(); + var calculationContext = new StabilityPointStructuresCalculationContext(elementToBeRemoved, + failureMechanism, + assessmentSectionStub); + var groupContext = new StabilityPointStructuresCalculationGroupContext(group, + failureMechanism, + assessmentSectionStub); + + mocks.ReplayAll(); + + group.Children.Add(elementToBeRemoved); + + failureMechanism.AddSection(new FailureMechanismSection("section", new[] + { + new Point2D(0, 0) + })); + + StabilityPointStructuresFailureMechanismSectionResult result = failureMechanism.SectionResults.First(); + result.Calculation = elementToBeRemoved; + + // Call + info.OnNodeRemoved(calculationContext, groupContext); + + // Assert + Assert.IsNull(result.Calculation); + } + public override void TearDown() { plugin.Dispose(); Index: Ringtoets/StabilityPointStructures/test/Ringtoets.StabilityPointStructures.Forms.Test/TreeNodeInfos/StabilityPointStructuresCalculationGroupContextTreeNodeInfoTest.cs =================================================================== diff -u -rb78eb7cbd59f1bd31e72631b67b7e12b5b4477a5 -r2678ee310030f02f415f1799c61635081d754165 --- Ringtoets/StabilityPointStructures/test/Ringtoets.StabilityPointStructures.Forms.Test/TreeNodeInfos/StabilityPointStructuresCalculationGroupContextTreeNodeInfoTest.cs (.../StabilityPointStructuresCalculationGroupContextTreeNodeInfoTest.cs) (revision b78eb7cbd59f1bd31e72631b67b7e12b5b4477a5) +++ Ringtoets/StabilityPointStructures/test/Ringtoets.StabilityPointStructures.Forms.Test/TreeNodeInfos/StabilityPointStructuresCalculationGroupContextTreeNodeInfoTest.cs (.../StabilityPointStructuresCalculationGroupContextTreeNodeInfoTest.cs) (revision 2678ee310030f02f415f1799c61635081d754165) @@ -919,6 +919,78 @@ CollectionAssert.DoesNotContain(parentGroup.Children, group); } + [Test] + public void OnNodeRemoved_CalculationInGroupAssignedToSection_CalculationDetachedFromSection() + { + // Setup + var failureMechanism = new StabilityPointStructuresFailureMechanism(); + var assessmentSectionStub = mocks.Stub(); + var group = new CalculationGroup(); + var parentGroup = new CalculationGroup(); + var nodeData = new StabilityPointStructuresCalculationGroupContext(group, + failureMechanism, + assessmentSectionStub); + var parentNodeData = new StabilityPointStructuresCalculationGroupContext(parentGroup, + failureMechanism, + assessmentSectionStub); + + mocks.ReplayAll(); + + parentGroup.Children.Add(group); + + failureMechanism.AddSection(new FailureMechanismSection("section", new[] + { + new Point2D(0, 0) + })); + + var calculation = new StructuresCalculation(); + group.Children.Add(calculation); + + StabilityPointStructuresFailureMechanismSectionResult result = failureMechanism.SectionResults.First(); + result.Calculation = calculation; + + // Call + info.OnNodeRemoved(nodeData, parentNodeData); + + // Assert + Assert.IsNull(result.Calculation); + } + + [Test] + public void OnNodeRemoved_NestedCalculationGroupContainingCalculations_RemoveGroupAndCalculationsAndNotifyObservers() + { + // Setup + var observerMock = mocks.StrictMock(); + var assessmentSectionStub = mocks.Stub(); + var failureMechanism = new StabilityPointStructuresFailureMechanism(); + var group = new CalculationGroup(); + var parentGroup = new CalculationGroup(); + var nodeData = new StabilityPointStructuresCalculationGroupContext(group, + failureMechanism, + assessmentSectionStub); + var parentNodeData = new StabilityPointStructuresCalculationGroupContext(parentGroup, + failureMechanism, + assessmentSectionStub); + var calculation = new StructuresCalculation(); + + observerMock.Expect(o => o.UpdateObserver()); + + mocks.ReplayAll(); + + group.Children.Add(calculation); + parentGroup.Children.Add(group); + parentNodeData.Attach(observerMock); + + // Precondition + Assert.IsTrue(info.CanRemove(nodeData, parentNodeData)); + + // Call + info.OnNodeRemoved(nodeData, parentNodeData); + + // Assert + CollectionAssert.DoesNotContain(parentGroup.Children, group); + } + public override void TearDown() { plugin.Dispose();