Index: Ringtoets/Integration/src/Ringtoets.Integration.Plugin/FileImporters/ForeshoreProfileReplaceDataStrategy.cs =================================================================== diff -u -r670a5510c7638037a4f7e0c3efea0a261085bfbb -r91d2618c244882958683e28675970ef50bbf2fe6 --- Ringtoets/Integration/src/Ringtoets.Integration.Plugin/FileImporters/ForeshoreProfileReplaceDataStrategy.cs (.../ForeshoreProfileReplaceDataStrategy.cs) (revision 670a5510c7638037a4f7e0c3efea0a261085bfbb) +++ Ringtoets/Integration/src/Ringtoets.Integration.Plugin/FileImporters/ForeshoreProfileReplaceDataStrategy.cs (.../ForeshoreProfileReplaceDataStrategy.cs) (revision 91d2618c244882958683e28675970ef50bbf2fe6) @@ -27,12 +27,12 @@ using Ringtoets.Common.Data.DikeProfiles; using Ringtoets.Common.Data.Exceptions; using Ringtoets.Common.Data.FailureMechanism; -using Ringtoets.Common.Data.Structures; using Ringtoets.Common.Data.UpdateDataStrategies; using Ringtoets.Common.IO.FileImporters; using Ringtoets.GrassCoverErosionOutwards.Data; using Ringtoets.HeightStructures.Data; using Ringtoets.Integration.Plugin.Properties; +using Ringtoets.Integration.Service; using Ringtoets.StabilityPointStructures.Data; using Ringtoets.StabilityStoneCover.Data; using Ringtoets.WaveImpactAsphaltCover.Data; @@ -92,154 +92,40 @@ var waveImpactAsphaltCoverFailureMechanism = failureMechanism as WaveImpactAsphaltCoverFailureMechanism; if (waveImpactAsphaltCoverFailureMechanism != null) { - return ClearForeshoreProfilesDependentData(waveImpactAsphaltCoverFailureMechanism); + return RingtoetsDataSynchronizationService.RemoveAllForeshoreProfiles(waveImpactAsphaltCoverFailureMechanism); } var stabilityStoneCoverFailureMechanism = failureMechanism as StabilityStoneCoverFailureMechanism; if (stabilityStoneCoverFailureMechanism != null) { - return ClearForeshoreProfilesDependentData(stabilityStoneCoverFailureMechanism); + return RingtoetsDataSynchronizationService.RemoveAllForeshoreProfiles(stabilityStoneCoverFailureMechanism); } var grassCoverErosionOutwardsFailureMechanism = failureMechanism as GrassCoverErosionOutwardsFailureMechanism; if (grassCoverErosionOutwardsFailureMechanism != null) { - return ClearForeshoreProfilesDependentData(grassCoverErosionOutwardsFailureMechanism); + return RingtoetsDataSynchronizationService.RemoveAllForeshoreProfiles(grassCoverErosionOutwardsFailureMechanism); } var heightStructuresFailureMechanism = failureMechanism as HeightStructuresFailureMechanism; if (heightStructuresFailureMechanism != null) { - return ClearForeshoreProfilesDependentData(heightStructuresFailureMechanism); + return RingtoetsDataSynchronizationService.RemoveAllForeshoreProfiles(heightStructuresFailureMechanism); } var stabilityPointStructuresFailureMechanism = failureMechanism as StabilityPointStructuresFailureMechanism; if (stabilityPointStructuresFailureMechanism != null) { - return ClearForeshoreProfilesDependentData(stabilityPointStructuresFailureMechanism); + return RingtoetsDataSynchronizationService.RemoveAllForeshoreProfiles(stabilityPointStructuresFailureMechanism); } var closingStructuresFailureMechanism = failureMechanism as ClosingStructuresFailureMechanism; if (closingStructuresFailureMechanism != null) { - return ClearForeshoreProfileDependentData(closingStructuresFailureMechanism); + return RingtoetsDataSynchronizationService.RemoveAllForeshoreProfiles(closingStructuresFailureMechanism); } return Enumerable.Empty(); } - - private static IEnumerable ClearForeshoreProfileDependentData(ClosingStructuresFailureMechanism closingStructuresFailureMechanism) - { - IEnumerable> affectedCalculations = - closingStructuresFailureMechanism.Calculations - .OfType>() - .Where(calc => calc.InputParameters.ForeshoreProfile != null); - - var affectedObjects = new List(); - foreach (var calculation in affectedCalculations) - { - calculation.InputParameters.ForeshoreProfile = null; - affectedObjects.Add(calculation.InputParameters); - } - - closingStructuresFailureMechanism.ForeshoreProfiles.Clear(); - affectedObjects.Add(closingStructuresFailureMechanism.ForeshoreProfiles); - return affectedObjects; - } - - private static IEnumerable ClearForeshoreProfilesDependentData(StabilityPointStructuresFailureMechanism stabilityPointStructuresFailureMechanism) - { - IEnumerable> affectedCalculations = - stabilityPointStructuresFailureMechanism.Calculations - .OfType>() - .Where(calc => calc.InputParameters.ForeshoreProfile != null); - - var affectedObjects = new List(); - foreach (var calculation in affectedCalculations) - { - calculation.InputParameters.ForeshoreProfile = null; - affectedObjects.Add(calculation.InputParameters); - } - - stabilityPointStructuresFailureMechanism.ForeshoreProfiles.Clear(); - affectedObjects.Add(stabilityPointStructuresFailureMechanism.ForeshoreProfiles); - return affectedObjects; - } - - private static IEnumerable ClearForeshoreProfilesDependentData(HeightStructuresFailureMechanism heightStructuresFailureMechanism) - { - IEnumerable> affectedCalculations = - heightStructuresFailureMechanism.Calculations - .OfType>() - .Where(calc => calc.InputParameters.ForeshoreProfile != null); - - var affectedObjects = new List(); - foreach (var calculation in affectedCalculations) - { - calculation.InputParameters.ForeshoreProfile = null; - affectedObjects.Add(calculation.InputParameters); - } - - heightStructuresFailureMechanism.ForeshoreProfiles.Clear(); - affectedObjects.Add(heightStructuresFailureMechanism.ForeshoreProfiles); - return affectedObjects; - } - - private static IEnumerable ClearForeshoreProfilesDependentData(GrassCoverErosionOutwardsFailureMechanism grassCoverErosionOutwardsFailureMechanism) - { - IEnumerable affectedCalculations = - grassCoverErosionOutwardsFailureMechanism.Calculations - .OfType() - .Where(calc => calc.InputParameters.ForeshoreProfile != null); - - var affectedObjects = new List(); - foreach (var calculation in affectedCalculations) - { - calculation.InputParameters.ForeshoreProfile = null; - affectedObjects.Add(calculation.InputParameters); - } - - grassCoverErosionOutwardsFailureMechanism.ForeshoreProfiles.Clear(); - affectedObjects.Add(grassCoverErosionOutwardsFailureMechanism.ForeshoreProfiles); - return affectedObjects; - } - - private static IEnumerable ClearForeshoreProfilesDependentData(StabilityStoneCoverFailureMechanism stabilityStoneCoverFailureMechanism) - { - IEnumerable affectedCalculations = - stabilityStoneCoverFailureMechanism.Calculations - .OfType() - .Where(calc => calc.InputParameters.ForeshoreProfile != null); - - var affectedObjects = new List(); - foreach (var calculation in affectedCalculations) - { - calculation.InputParameters.ForeshoreProfile = null; - affectedObjects.Add(calculation.InputParameters); - } - - stabilityStoneCoverFailureMechanism.ForeshoreProfiles.Clear(); - affectedObjects.Add(stabilityStoneCoverFailureMechanism.ForeshoreProfiles); - return affectedObjects; - } - - private static IEnumerable ClearForeshoreProfilesDependentData(WaveImpactAsphaltCoverFailureMechanism waveImpactAsphaltCoverFailureMechanism) - { - IEnumerable affectedCalculations = - waveImpactAsphaltCoverFailureMechanism.Calculations - .OfType() - .Where(calc => calc.InputParameters.ForeshoreProfile != null); - - var affectedObjects = new List(); - foreach (var calculation in affectedCalculations) - { - calculation.InputParameters.ForeshoreProfile = null; - affectedObjects.Add(calculation.InputParameters); - } - - waveImpactAsphaltCoverFailureMechanism.ForeshoreProfiles.Clear(); - affectedObjects.Add(waveImpactAsphaltCoverFailureMechanism.ForeshoreProfiles); - return affectedObjects; - } } } \ No newline at end of file Index: Ringtoets/Integration/src/Ringtoets.Integration.Service/RingtoetsDataSynchronizationService.cs =================================================================== diff -u -r802ea30d1fe8fbae93e58dff9ab054dbabca11ae -r91d2618c244882958683e28675970ef50bbf2fe6 --- Ringtoets/Integration/src/Ringtoets.Integration.Service/RingtoetsDataSynchronizationService.cs (.../RingtoetsDataSynchronizationService.cs) (revision 802ea30d1fe8fbae93e58dff9ab054dbabca11ae) +++ Ringtoets/Integration/src/Ringtoets.Integration.Service/RingtoetsDataSynchronizationService.cs (.../RingtoetsDataSynchronizationService.cs) (revision 91d2618c244882958683e28675970ef50bbf2fe6) @@ -205,7 +205,7 @@ /// Clears the output of the hydraulic boundary locations within the and the /// hydraulic boundary locations that are contained within specific failure mechanisms of the . /// - /// The wich contains the locations. + /// The which contains the locations. /// The which contains the failure mechanisms. /// All objects affected by the operation. /// Thrown when any parameter is null. @@ -582,6 +582,204 @@ return changedObservables; } + /// + /// Removes all from the + /// and clears all data that depends on it, either directly or indirectly. + /// + /// The failure mechanism + /// containing the . + /// All observable objects affected by this method. + /// Thrown when + /// is null. + public static IEnumerable RemoveAllForeshoreProfiles(ClosingStructuresFailureMechanism failureMechanism) + { + if (failureMechanism == null) + { + throw new ArgumentNullException(nameof(failureMechanism)); + } + + IEnumerable> affectedCalculations = + failureMechanism.Calculations + .OfType>() + .Where(calc => calc.InputParameters.ForeshoreProfile != null); + + var affectedObjects = new List(); + foreach (StructuresCalculation calculation in affectedCalculations) + { + calculation.InputParameters.ForeshoreProfile = null; + affectedObjects.Add(calculation.InputParameters); + } + + failureMechanism.ForeshoreProfiles.Clear(); + affectedObjects.Add(failureMechanism.ForeshoreProfiles); + return affectedObjects; + } + + /// + /// Removes all from the + /// and clears all data that depends on it, either directly or indirectly. + /// + /// The failure mechanism + /// containing the . + /// All observable objects affected by this method. + /// Thrown when + /// is null. + public static IEnumerable RemoveAllForeshoreProfiles(StabilityPointStructuresFailureMechanism failureMechanism) + { + if (failureMechanism == null) + { + throw new ArgumentNullException(nameof(failureMechanism)); + } + + IEnumerable> affectedCalculations = + failureMechanism.Calculations + .OfType>() + .Where(calc => calc.InputParameters.ForeshoreProfile != null); + + var affectedObjects = new List(); + foreach (StructuresCalculation calculation in affectedCalculations) + { + calculation.InputParameters.ForeshoreProfile = null; + affectedObjects.Add(calculation.InputParameters); + } + + failureMechanism.ForeshoreProfiles.Clear(); + affectedObjects.Add(failureMechanism.ForeshoreProfiles); + return affectedObjects; + } + + /// + /// Removes all from the + /// and clears all data that depends on it, either directly or indirectly. + /// + /// The failure mechanism + /// containing the . + /// All observable objects affected by this method. + /// Thrown when + /// is null. + public static IEnumerable RemoveAllForeshoreProfiles(HeightStructuresFailureMechanism failureMechanism) + { + if (failureMechanism == null) + { + throw new ArgumentNullException(nameof(failureMechanism)); + } + + IEnumerable> affectedCalculations = + failureMechanism.Calculations + .OfType>() + .Where(calc => calc.InputParameters.ForeshoreProfile != null); + + var affectedObjects = new List(); + foreach (StructuresCalculation calculation in affectedCalculations) + { + calculation.InputParameters.ForeshoreProfile = null; + affectedObjects.Add(calculation.InputParameters); + } + + failureMechanism.ForeshoreProfiles.Clear(); + affectedObjects.Add(failureMechanism.ForeshoreProfiles); + return affectedObjects; + } + + /// + /// Removes all from the + /// and clears all data that depends on it, either directly or indirectly. + /// + /// The failure mechanism + /// containing the . + /// All observable objects affected by this method. + /// Thrown when + /// is null. + public static IEnumerable RemoveAllForeshoreProfiles(GrassCoverErosionOutwardsFailureMechanism failureMechanism) + { + if (failureMechanism == null) + { + throw new ArgumentNullException(nameof(failureMechanism)); + } + + IEnumerable affectedCalculations = + failureMechanism.Calculations + .OfType() + .Where(calc => calc.InputParameters.ForeshoreProfile != null); + + var affectedObjects = new List(); + foreach (GrassCoverErosionOutwardsWaveConditionsCalculation calculation in affectedCalculations) + { + calculation.InputParameters.ForeshoreProfile = null; + affectedObjects.Add(calculation.InputParameters); + } + + failureMechanism.ForeshoreProfiles.Clear(); + affectedObjects.Add(failureMechanism.ForeshoreProfiles); + return affectedObjects; + } + + /// + /// Removes all from the + /// and clears all data that depends on it, either directly or indirectly. + /// + /// The failure mechanism + /// containing the . + /// All observable objects affected by this method. + /// Thrown when + /// is null. + public static IEnumerable RemoveAllForeshoreProfiles(StabilityStoneCoverFailureMechanism failureMechanism) + { + if (failureMechanism == null) + { + throw new ArgumentNullException(nameof(failureMechanism)); + } + + IEnumerable affectedCalculations = + failureMechanism.Calculations + .OfType() + .Where(calc => calc.InputParameters.ForeshoreProfile != null); + + var affectedObjects = new List(); + foreach (StabilityStoneCoverWaveConditionsCalculation calculation in affectedCalculations) + { + calculation.InputParameters.ForeshoreProfile = null; + affectedObjects.Add(calculation.InputParameters); + } + + failureMechanism.ForeshoreProfiles.Clear(); + affectedObjects.Add(failureMechanism.ForeshoreProfiles); + return affectedObjects; + } + + /// + /// Removes all from the + /// and clears all data that depends on it, either directly or indirectly. + /// + /// The failure mechanism + /// containing the . + /// All observable objects affected by this method. + /// Thrown when + /// is null. + public static IEnumerable RemoveAllForeshoreProfiles(WaveImpactAsphaltCoverFailureMechanism failureMechanism) + { + if (failureMechanism == null) + { + throw new ArgumentNullException(nameof(failureMechanism)); + } + + IEnumerable affectedCalculations = + failureMechanism.Calculations + .OfType() + .Where(calc => calc.InputParameters.ForeshoreProfile != null); + + var affectedObjects = new List(); + foreach (WaveImpactAsphaltCoverWaveConditionsCalculation calculation in affectedCalculations) + { + calculation.InputParameters.ForeshoreProfile = null; + affectedObjects.Add(calculation.InputParameters); + } + + failureMechanism.ForeshoreProfiles.Clear(); + affectedObjects.Add(failureMechanism.ForeshoreProfiles); + return affectedObjects; + } + private static ClearResults GetClearResultsForFailureMechanism(IFailureMechanism failureMechanism) { var pipingFailureMechanism = failureMechanism as PipingFailureMechanism; Index: Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/FileImporters/ForeshoreProfileReplaceDataStrategyTest.cs =================================================================== diff -u -r670a5510c7638037a4f7e0c3efea0a261085bfbb -r91d2618c244882958683e28675970ef50bbf2fe6 --- Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/FileImporters/ForeshoreProfileReplaceDataStrategyTest.cs (.../ForeshoreProfileReplaceDataStrategyTest.cs) (revision 670a5510c7638037a4f7e0c3efea0a261085bfbb) +++ Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/FileImporters/ForeshoreProfileReplaceDataStrategyTest.cs (.../ForeshoreProfileReplaceDataStrategyTest.cs) (revision 91d2618c244882958683e28675970ef50bbf2fe6) @@ -100,7 +100,7 @@ } [Test] - public void Constructor_UnsupportedFailureMechanism_ThrowsUnsupportedException() + public void Constructor_UnsupportedFailureMechanism_ThrowsNotSupportedException() { // Call TestDelegate call = () => new ForeshoreProfileReplaceDataStrategy(new TestFailureMechanism()); @@ -305,38 +305,6 @@ }, affectedObjects); } - [Test] - [TestCaseSource(nameof(SupportedFailureMechanismsAndEmptyForeshoreProfileCollection))] - public void UpdateForeshoreProfilesWithImportedData_CalculationsWithForeshoreProfile_CalculationUpdatedAndReturnsAffectedData( - IFailureMechanism failureMechanism, ForeshoreProfileCollection foreshoreProfiles) - { - // Setup - var foreshoreProfile = new TestForeshoreProfile("Profile 1", "ID 1"); - foreshoreProfiles.AddRange(new[] - { - foreshoreProfile - }, sourceFilePath); - - var strategy = new ForeshoreProfileReplaceDataStrategy(failureMechanism); - - var importedForeshoreProfiles = new[] - { - new TestForeshoreProfile("Profile 2", "ID 2") - }; - - // Call - IEnumerable affectedObjects = strategy.UpdateForeshoreProfilesWithImportedData(foreshoreProfiles, - importedForeshoreProfiles, - sourceFilePath); - - // Assert - CollectionAssert.AreEqual(importedForeshoreProfiles, foreshoreProfiles); - CollectionAssert.AreEqual(new IObservable[] - { - foreshoreProfiles - }, affectedObjects); - } - #region Wave Impact Asphalt Cover [Test] Index: Ringtoets/Integration/test/Ringtoets.Integration.Service.Test/RingtoetsDataSynchronizationServiceTest.cs =================================================================== diff -u -r20e9bfea15dfe132ee137283a9f24bc4c413ce4a -r91d2618c244882958683e28675970ef50bbf2fe6 --- Ringtoets/Integration/test/Ringtoets.Integration.Service.Test/RingtoetsDataSynchronizationServiceTest.cs (.../RingtoetsDataSynchronizationServiceTest.cs) (revision 20e9bfea15dfe132ee137283a9f24bc4c413ce4a) +++ Ringtoets/Integration/test/Ringtoets.Integration.Service.Test/RingtoetsDataSynchronizationServiceTest.cs (.../RingtoetsDataSynchronizationServiceTest.cs) (revision 91d2618c244882958683e28675970ef50bbf2fe6) @@ -1236,6 +1236,258 @@ } [Test] + public void RemoveAllForeshoreProfile_ClosingStructuresFailureMechanismNull_ThrowsArgumentNullException() + { + // Call + TestDelegate call = () => RingtoetsDataSynchronizationService.RemoveAllForeshoreProfiles((ClosingStructuresFailureMechanism) null); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("failureMechanism", exception.ParamName); + } + + [Test] + public void RemoveAllForeshoreProfile_FullyConfiguredClosingStructuresFailureMechanism_RemovesAllForeshoreProfilesAndDependentData() + { + // Setup + ClosingStructuresFailureMechanism failureMechanism = TestDataGenerator.GetClosingStructuresFailureMechanismWithAllCalculationConfigurations(); + + StructuresCalculation[] calculationsWithForeshoreProfiles = failureMechanism.Calculations + .Cast>() + .Where(calc => calc.InputParameters.ForeshoreProfile != null) + .ToArray(); + + // Pre-condition + CollectionAssert.IsNotEmpty(calculationsWithForeshoreProfiles); + + // Call + IEnumerable affectedObjects = RingtoetsDataSynchronizationService.RemoveAllForeshoreProfiles(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.ForeshoreProfiles); + + IEnumerable expectedAffectedObjects = + calculationsWithForeshoreProfiles.Select(calc => calc.InputParameters) + .Concat(new IObservable[] + { + failureMechanism.ForeshoreProfiles + }); + CollectionAssert.AreEquivalent(expectedAffectedObjects, affectedObjects); + } + + [Test] + public void RemoveAllForeshoreProfile_StabilityPointStructuresFailureMechanismNull_ThrowsArgumentNullException() + { + // Call + TestDelegate call = () => RingtoetsDataSynchronizationService.RemoveAllForeshoreProfiles((StabilityPointStructuresFailureMechanism) null); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("failureMechanism", exception.ParamName); + } + + [Test] + public void RemoveAllForeshoreProfile_FullyConfiguredStabilityPointStructuresFailureMechanism_RemovesAllForeshoreProfilesAndDependentData() + { + // Setup + StabilityPointStructuresFailureMechanism failureMechanism = TestDataGenerator.GetStabilityPointStructuresFailureMechanismWithAllCalculationConfigurations(); + + StructuresCalculation[] calculationsWithForeshoreProfiles = failureMechanism.Calculations + .Cast>() + .Where(calc => calc.InputParameters.ForeshoreProfile != null) + .ToArray(); + + // Pre-condition + CollectionAssert.IsNotEmpty(calculationsWithForeshoreProfiles); + + // Call + IEnumerable affectedObjects = RingtoetsDataSynchronizationService.RemoveAllForeshoreProfiles(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.ForeshoreProfiles); + + IEnumerable expectedAffectedObjects = + calculationsWithForeshoreProfiles.Select(calc => calc.InputParameters) + .Concat(new IObservable[] + { + failureMechanism.ForeshoreProfiles + }); + CollectionAssert.AreEquivalent(expectedAffectedObjects, affectedObjects); + } + + [Test] + public void RemoveAllForeshoreProfile_HeightStructuresFailureMechanismNull_ThrowsArgumentNullException() + { + // Call + TestDelegate call = () => RingtoetsDataSynchronizationService.RemoveAllForeshoreProfiles((HeightStructuresFailureMechanism) null); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("failureMechanism", exception.ParamName); + } + + [Test] + public void RemoveAllForeshoreProfile_FullyConfiguredHeightStructuresFailureMechanism_RemovesAllForeshoreProfilesAndDependentData() + { + // Setup + HeightStructuresFailureMechanism failureMechanism = TestDataGenerator.GetHeightStructuresFailureMechanismWithAlLCalculationConfigurations(); + + StructuresCalculation[] calculationsWithForeshoreProfiles = failureMechanism.Calculations + .Cast>() + .Where(calc => calc.InputParameters.ForeshoreProfile != null) + .ToArray(); + + // Pre-condition + CollectionAssert.IsNotEmpty(calculationsWithForeshoreProfiles); + + // Call + IEnumerable affectedObjects = RingtoetsDataSynchronizationService.RemoveAllForeshoreProfiles(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.ForeshoreProfiles); + + IEnumerable expectedAffectedObjects = + calculationsWithForeshoreProfiles.Select(calc => calc.InputParameters) + .Concat(new IObservable[] + { + failureMechanism.ForeshoreProfiles + }); + CollectionAssert.AreEquivalent(expectedAffectedObjects, affectedObjects); + } + + [Test] + public void RemoveAllForeshoreProfile_GrassCoverErosionOutwardsFailureMechanismNull_ThrowsArgumentNullException() + { + // Call + TestDelegate call = () => RingtoetsDataSynchronizationService.RemoveAllForeshoreProfiles((GrassCoverErosionOutwardsFailureMechanism) null); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("failureMechanism", exception.ParamName); + } + + [Test] + public void RemoveAllForeshoreProfile_FullyConfiguredGrassCoverErosionOutwardsFailureMechanism_RemovesAllForeshoreProfilesAndDependentData() + { + // Setup + GrassCoverErosionOutwardsFailureMechanism failureMechanism = TestDataGenerator.GetGrassCoverErosionOutwardsFailureMechanismWithAllCalculationConfigurations(); + + GrassCoverErosionOutwardsWaveConditionsCalculation[] calculationsWithForeshoreProfiles = failureMechanism.Calculations + .Cast() + .Where(calc => calc.InputParameters.ForeshoreProfile != null) + .ToArray(); + + // Pre-condition + CollectionAssert.IsNotEmpty(calculationsWithForeshoreProfiles); + + // Call + IEnumerable affectedObjects = RingtoetsDataSynchronizationService.RemoveAllForeshoreProfiles(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.ForeshoreProfiles); + + IEnumerable expectedAffectedObjects = + calculationsWithForeshoreProfiles.Select(calc => calc.InputParameters) + .Concat(new IObservable[] + { + failureMechanism.ForeshoreProfiles + }); + CollectionAssert.AreEquivalent(expectedAffectedObjects, affectedObjects); + } + + [Test] + public void RemoveAllForeshoreProfile_StabilityStoneCoverFailureMechanismNull_ThrowsArgumentNullException() + { + // Call + TestDelegate call = () => RingtoetsDataSynchronizationService.RemoveAllForeshoreProfiles((StabilityStoneCoverFailureMechanism) null); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("failureMechanism", exception.ParamName); + } + + [Test] + public void RemoveAllForeshoreProfile_FullyConfiguredStabilityStoneCoverFailureMechanism_RemovesAllForeshoreProfilesAndDependentData() + { + // Setup + StabilityStoneCoverFailureMechanism failureMechanism = TestDataGenerator.GetStabilityStoneCoverFailureMechanismWithAllCalculationConfigurations(); + + StabilityStoneCoverWaveConditionsCalculation[] calculationsWithForeshoreProfiles = failureMechanism.Calculations + .Cast() + .Where(calc => calc.InputParameters.ForeshoreProfile != null) + .ToArray(); + + // Pre-condition + CollectionAssert.IsNotEmpty(calculationsWithForeshoreProfiles); + + // Call + IEnumerable affectedObjects = RingtoetsDataSynchronizationService.RemoveAllForeshoreProfiles(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.ForeshoreProfiles); + + IEnumerable expectedAffectedObjects = + calculationsWithForeshoreProfiles.Select(calc => calc.InputParameters) + .Concat(new IObservable[] + { + failureMechanism.ForeshoreProfiles + }); + CollectionAssert.AreEquivalent(expectedAffectedObjects, affectedObjects); + } + + [Test] + public void RemoveAllForeshoreProfile_WaveImpactAsphaltCoverFailureMechanismNull_ThrowsArgumentNullException() + { + // Call + TestDelegate call = () => RingtoetsDataSynchronizationService.RemoveAllForeshoreProfiles((WaveImpactAsphaltCoverFailureMechanism) null); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("failureMechanism", exception.ParamName); + } + + [Test] + public void RemoveAllForeshoreProfile_FullyConfiguredWaveImpactAsphaltCoverFailureMechanism_RemovesAllForeshoreProfilesAndDependentData() + { + // Setup + WaveImpactAsphaltCoverFailureMechanism failureMechanism = TestDataGenerator.GetWaveImpactAsphaltCoverFailureMechanismWithAllCalculationConfigurations(); + + WaveImpactAsphaltCoverWaveConditionsCalculation[] calculationsWithForeshoreProfiles = failureMechanism.Calculations + .Cast() + .Where(calc => calc.InputParameters.ForeshoreProfile != null) + .ToArray(); + + // Pre-condition + CollectionAssert.IsNotEmpty(calculationsWithForeshoreProfiles); + + // Call + IEnumerable affectedObjects = RingtoetsDataSynchronizationService.RemoveAllForeshoreProfiles(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.ForeshoreProfiles); + + IEnumerable expectedAffectedObjects = + calculationsWithForeshoreProfiles.Select(calc => calc.InputParameters) + .Concat(new IObservable[] + { + failureMechanism.ForeshoreProfiles + }); + CollectionAssert.AreEquivalent(expectedAffectedObjects, affectedObjects); + } + + [Test] public void RemoveDikeProfile_GrassCoverErosionInwardsFailureMechanismNull_ThrowsArgumentNullException() { // Setup