Index: Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.Service/ClosingStructuresDataSynchronizationService.cs
===================================================================
diff -u -r916bdbd134da55d8f1373fea9b29aba97db34348 -r3e170ea1e6909370ffab6cf597cfaa63bcbc3a71
--- Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.Service/ClosingStructuresDataSynchronizationService.cs (.../ClosingStructuresDataSynchronizationService.cs) (revision 916bdbd134da55d8f1373fea9b29aba97db34348)
+++ Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.Service/ClosingStructuresDataSynchronizationService.cs (.../ClosingStructuresDataSynchronizationService.cs) (revision 3e170ea1e6909370ffab6cf597cfaa63bcbc3a71)
@@ -81,6 +81,39 @@
}
///
+ /// Clears all structures, unassigns them from the calculations in the
+ /// and clears all data that depends on it, either directly or indirectly.
+ ///
+ /// The to
+ /// clear the structures from.
+ /// All objects that are affected by this operation.
+ /// Thrown when any parameter is null.
+ public static IEnumerable RemoveAllStructures(ClosingStructuresFailureMechanism failureMechanism)
+ {
+ if (failureMechanism == null)
+ {
+ throw new ArgumentNullException(nameof(failureMechanism));
+ }
+
+ IEnumerable> calculations =
+ failureMechanism.Calculations.Cast>();
+ StructuresCalculation[] calculationWithRemovedStructure = calculations
+ .Where(c => c.InputParameters.Structure != null)
+ .ToArray();
+
+ List changedObservables = ClearStructureDependentData(
+ failureMechanism.SectionResults2,
+ calculationWithRemovedStructure,
+ calculations);
+
+ StructureCollection structures = failureMechanism.ClosingStructures;
+ structures.Clear();
+ changedObservables.Add(structures);
+
+ return changedObservables;
+ }
+
+ ///
/// Clears the output for all calculations in the .
///
/// The
Index: Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Service.Test/ClosingStructureDataSynchronizationServiceTest.cs
===================================================================
diff -u -r916bdbd134da55d8f1373fea9b29aba97db34348 -r3e170ea1e6909370ffab6cf597cfaa63bcbc3a71
--- Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Service.Test/ClosingStructureDataSynchronizationServiceTest.cs (.../ClosingStructureDataSynchronizationServiceTest.cs) (revision 916bdbd134da55d8f1373fea9b29aba97db34348)
+++ Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Service.Test/ClosingStructureDataSynchronizationServiceTest.cs (.../ClosingStructureDataSynchronizationServiceTest.cs) (revision 3e170ea1e6909370ffab6cf597cfaa63bcbc3a71)
@@ -165,6 +165,117 @@
}
[Test]
+ public void RemoveAllStructures_FailureMechanismNull_ThrowsArgumentNullException()
+ {
+ // Call
+ TestDelegate call = () => ClosingStructuresDataSynchronizationService.RemoveAllStructures(null);
+
+ // Assert
+ string paramName = Assert.Throws(call).ParamName;
+ Assert.AreEqual("failureMechanism", paramName);
+ }
+
+ [Test]
+ public void RemoveAllStructures_FullyConfiguredFailureMechanism_RemoveAllStructuresAndClearDependentData()
+ {
+ // Setup
+ var failureMechanism = new ClosingStructuresFailureMechanism();
+
+ var locationStructureA = new Point2D(0, 0);
+ var structureA = new TestClosingStructure(locationStructureA, "A");
+
+ var locationStructureB = new Point2D(2, 2);
+ var structureB = new TestClosingStructure(locationStructureB, "B");
+
+ failureMechanism.ClosingStructures.AddRange(new[]
+ {
+ structureA,
+ structureB
+ }, "path/to/structures");
+
+ var calculationWithOutput = new StructuresCalculation
+ {
+ Output = new TestStructuresOutput()
+ };
+ var calculationWithStructureA = new StructuresCalculation
+ {
+ InputParameters =
+ {
+ Structure = structureA
+ }
+ };
+ var calculationWithStructureBAndOutput = new StructuresCalculation
+ {
+ InputParameters =
+ {
+ Structure = structureB
+ },
+ Output = new TestStructuresOutput()
+ };
+ var calculationWithStructureAAndOutput = new StructuresCalculation
+ {
+ InputParameters =
+ {
+ Structure = structureA
+ },
+ Output = new TestStructuresOutput()
+ };
+ failureMechanism.CalculationsGroup.Children.AddRange(new[]
+ {
+ calculationWithOutput,
+ calculationWithStructureA,
+ calculationWithStructureBAndOutput,
+ calculationWithStructureAAndOutput
+ });
+
+ failureMechanism.AddSection(new FailureMechanismSection(string.Empty, new[]
+ {
+ new Point2D(0, 0),
+ new Point2D(1, 1)
+ }));
+ ClosingStructuresFailureMechanismSectionResult sectionWithCalculationAtStructureA = failureMechanism.SectionResults2.ElementAt(0);
+ sectionWithCalculationAtStructureA.Calculation = calculationWithStructureA;
+
+ failureMechanism.AddSection(new FailureMechanismSection(string.Empty, new[]
+ {
+ new Point2D(1, 1),
+ new Point2D(2, 2)
+ }));
+ ClosingStructuresFailureMechanismSectionResult sectionWithCalculationAtStructureB = failureMechanism.SectionResults2.ElementAt(1);
+ sectionWithCalculationAtStructureB.Calculation = calculationWithStructureBAndOutput;
+
+ // Call
+ IEnumerable affectedObjects = ClosingStructuresDataSynchronizationService.RemoveAllStructures(failureMechanism);
+
+ // Assert
+ // Note: To make sure the clear is performed regardless of what is done with
+ // the return result, no ToArray() should be called before these assertions:
+ CollectionAssert.DoesNotContain(failureMechanism.ClosingStructures, structureA);
+ Assert.IsNull(calculationWithStructureA.InputParameters.Structure);
+ Assert.IsNull(calculationWithStructureAAndOutput.InputParameters.Structure);
+ Assert.IsNull(calculationWithStructureBAndOutput.InputParameters.Structure);
+ Assert.IsNull(calculationWithStructureAAndOutput.Output);
+ Assert.IsNull(calculationWithStructureBAndOutput.Output);
+ Assert.IsNull(sectionWithCalculationAtStructureA.Calculation);
+ Assert.IsNull(sectionWithCalculationAtStructureB.Calculation);
+ Assert.IsNotNull(calculationWithOutput.Output);
+
+ IObservable[] expectedAffectedObjects =
+ {
+ calculationWithStructureA.InputParameters,
+ calculationWithStructureAAndOutput,
+ calculationWithStructureAAndOutput.InputParameters,
+ calculationWithStructureBAndOutput,
+ calculationWithStructureBAndOutput.InputParameters,
+ sectionWithCalculationAtStructureA,
+ sectionWithCalculationAtStructureB,
+ failureMechanism.ClosingStructures
+ };
+ CollectionAssert.AreEquivalent(expectedAffectedObjects, affectedObjects);
+ }
+
+
+ [Test]
public void ClearAllCalculationOutput_FailureMechanismNull_ThrowsArgumentNullException()
{
// Call