Index: Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Service.Test/HeightStructuresDataSynchronizationServiceTest.cs =================================================================== diff -u -r20e9bfea15dfe132ee137283a9f24bc4c413ce4a -r8b389428ece343431969fce2e902a7b241f2b372 --- Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Service.Test/HeightStructuresDataSynchronizationServiceTest.cs (.../HeightStructuresDataSynchronizationServiceTest.cs) (revision 20e9bfea15dfe132ee137283a9f24bc4c413ce4a) +++ Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Service.Test/HeightStructuresDataSynchronizationServiceTest.cs (.../HeightStructuresDataSynchronizationServiceTest.cs) (revision 8b389428ece343431969fce2e902a7b241f2b372) @@ -373,6 +373,70 @@ "Other section results with a different calculation/structure should still have their association."); } + [Test] + public void RemoveAllStructures_FailureMechanismNull_ThrowsArgumentNullException() + { + // Call + TestDelegate call = () => HeightStructuresDataSynchronizationService.RemoveAllStructures(null); + + // Assert + string paramName = Assert.Throws(call).ParamName; + Assert.AreEqual("failureMechanism", paramName); + } + + [Test] + public void RemoveAllStructures_FullyConfiguredFailureMechanism_RemoveAllHeightStructuresAndClearDependentData() + { + // Setup + HeightStructuresFailureMechanism failureMechanism = CreateFullyConfiguredFailureMechanism(); + StructuresCalculation[] calculationsWithStructure = failureMechanism.Calculations + .Cast>() + .Where(calc => calc.InputParameters.Structure != null) + .ToArray(); + StructuresCalculation[] calculationsWithOutput = calculationsWithStructure.Where(c => c.HasOutput) + .ToArray(); + + HeightStructuresFailureMechanismSectionResult[] sectionResultsWithStructure = failureMechanism.SectionResults + .Where(sr => calculationsWithStructure.Contains(sr.Calculation)) + .ToArray(); + + // Precondition + CollectionAssert.IsNotEmpty(calculationsWithStructure); + + // Call + IEnumerable observables = HeightStructuresDataSynchronizationService.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.IsEmpty(failureMechanism.HeightStructures); + foreach (StructuresCalculation calculation in calculationsWithStructure) + { + Assert.IsNull(calculation.InputParameters.Structure); + } + + IObservable[] affectedObjectsArray = observables.ToArray(); + int expectedAffectedObjectCount = 1 + calculationsWithOutput.Length + calculationsWithStructure.Length + + sectionResultsWithStructure.Length; + Assert.AreEqual(expectedAffectedObjectCount, affectedObjectsArray.Length); + + foreach (StructuresCalculation calculation in calculationsWithOutput) + { + Assert.IsFalse(calculation.HasOutput); + } + + IEnumerable expectedAffectedObjects = + calculationsWithStructure.Select(calc => calc.InputParameters) + .Cast() + .Concat(calculationsWithOutput) + .Concat(sectionResultsWithStructure) + .Concat(new IObservable[] + { + failureMechanism.HeightStructures + }); + CollectionAssert.AreEquivalent(expectedAffectedObjects, affectedObjectsArray); + } + private HeightStructuresFailureMechanism CreateFullyConfiguredFailureMechanism() { var section1 = new FailureMechanismSection("A", new[]