Index: Riskeer/Integration/src/Riskeer.Integration.Plugin/FileImporters/ForeshoreProfileReplaceDataStrategy.cs =================================================================== diff -u -r86594ccd7329d320872573a1d066fe18959d3cea -r1ceb376282c1b8c7efc172811cbca4993693e58e --- Riskeer/Integration/src/Riskeer.Integration.Plugin/FileImporters/ForeshoreProfileReplaceDataStrategy.cs (.../ForeshoreProfileReplaceDataStrategy.cs) (revision 86594ccd7329d320872573a1d066fe18959d3cea) +++ Riskeer/Integration/src/Riskeer.Integration.Plugin/FileImporters/ForeshoreProfileReplaceDataStrategy.cs (.../ForeshoreProfileReplaceDataStrategy.cs) (revision 1ceb376282c1b8c7efc172811cbca4993693e58e) @@ -64,7 +64,7 @@ { IEnumerable> calculations = FailureMechanism.Calculations .Cast>(); - return RingtoetsDataSynchronizationService.RemoveAllForeshoreProfiles(calculations, foreshoreProfileCollection); + return RiskeerDataSynchronizationService.RemoveAllForeshoreProfiles(calculations, foreshoreProfileCollection); } } } \ No newline at end of file Index: Riskeer/Integration/src/Riskeer.Integration.Plugin/Handlers/AssessmentSectionCompositionChangeHandler.cs =================================================================== diff -u -r86594ccd7329d320872573a1d066fe18959d3cea -r1ceb376282c1b8c7efc172811cbca4993693e58e --- Riskeer/Integration/src/Riskeer.Integration.Plugin/Handlers/AssessmentSectionCompositionChangeHandler.cs (.../AssessmentSectionCompositionChangeHandler.cs) (revision 86594ccd7329d320872573a1d066fe18959d3cea) +++ Riskeer/Integration/src/Riskeer.Integration.Plugin/Handlers/AssessmentSectionCompositionChangeHandler.cs (.../AssessmentSectionCompositionChangeHandler.cs) (revision 1ceb376282c1b8c7efc172811cbca4993693e58e) @@ -95,7 +95,7 @@ IFailureMechanism[] failureMechanismsToClearOutputFor = GetFailureMechanismsToClearOutputFor(assessmentSection, oldFailureMechanismContributions).ToArray(); IObservable[] affectedCalculations = - RingtoetsDataSynchronizationService.ClearFailureMechanismCalculationOutputs(failureMechanismsToClearOutputFor).ToArray(); + RiskeerDataSynchronizationService.ClearFailureMechanismCalculationOutputs(failureMechanismsToClearOutputFor).ToArray(); if (affectedCalculations.Length > 0) { @@ -157,7 +157,7 @@ private IEnumerable ClearHydraulicBoundaryLocationCalculationOutput(IEnumerable failureMechanismsToClearOutputFor) { IEnumerable affectedObjects = - RingtoetsDataSynchronizationService.ClearHydraulicBoundaryLocationCalculationOutputOfFailureMechanisms(failureMechanismsToClearOutputFor); + RiskeerDataSynchronizationService.ClearHydraulicBoundaryLocationCalculationOutputOfFailureMechanisms(failureMechanismsToClearOutputFor); if (affectedObjects.Any()) { log.Info(Resources.AssessmentSectionCompositionChangeHandler_Waveheight_and_design_water_level_results_cleared); Index: Riskeer/Integration/src/Riskeer.Integration.Plugin/Handlers/FailureMechanismContributionNormChangeHandler.cs =================================================================== diff -u -r86594ccd7329d320872573a1d066fe18959d3cea -r1ceb376282c1b8c7efc172811cbca4993693e58e --- Riskeer/Integration/src/Riskeer.Integration.Plugin/Handlers/FailureMechanismContributionNormChangeHandler.cs (.../FailureMechanismContributionNormChangeHandler.cs) (revision 86594ccd7329d320872573a1d066fe18959d3cea) +++ Riskeer/Integration/src/Riskeer.Integration.Plugin/Handlers/FailureMechanismContributionNormChangeHandler.cs (.../FailureMechanismContributionNormChangeHandler.cs) (revision 1ceb376282c1b8c7efc172811cbca4993693e58e) @@ -92,7 +92,7 @@ private IEnumerable ClearAllNormDependentCalculationOutput() { - List affectedObjects = RingtoetsDataSynchronizationService.ClearFailureMechanismCalculationOutputs(assessmentSection).ToList(); + List affectedObjects = RiskeerDataSynchronizationService.ClearFailureMechanismCalculationOutputs(assessmentSection).ToList(); if (affectedObjects.Count > 0) { log.InfoFormat(Resources.ChangeHandler_Results_of_NumberOfCalculations_0_calculations_cleared, @@ -106,7 +106,7 @@ private IEnumerable ClearAllHydraulicBoundaryLocationCalculationOutput() { - IEnumerable affectedObjects = RingtoetsDataSynchronizationService.ClearHydraulicBoundaryLocationCalculationOutput(assessmentSection); + IEnumerable affectedObjects = RiskeerDataSynchronizationService.ClearHydraulicBoundaryLocationCalculationOutput(assessmentSection); if (affectedObjects.Any()) { Index: Riskeer/Integration/src/Riskeer.Integration.Plugin/Handlers/HydraulicBoundaryDatabaseUpdateHandler.cs =================================================================== diff -u -r86594ccd7329d320872573a1d066fe18959d3cea -r1ceb376282c1b8c7efc172811cbca4993693e58e --- Riskeer/Integration/src/Riskeer.Integration.Plugin/Handlers/HydraulicBoundaryDatabaseUpdateHandler.cs (.../HydraulicBoundaryDatabaseUpdateHandler.cs) (revision 86594ccd7329d320872573a1d066fe18959d3cea) +++ Riskeer/Integration/src/Riskeer.Integration.Plugin/Handlers/HydraulicBoundaryDatabaseUpdateHandler.cs (.../HydraulicBoundaryDatabaseUpdateHandler.cs) (revision 1ceb376282c1b8c7efc172811cbca4993693e58e) @@ -152,7 +152,7 @@ duneLocationsReplacementHandler.Replace(hydraulicBoundaryDatabase.Locations); changedObjects.AddRange(GetLocationsAndCalculationsObservables(hydraulicBoundaryDatabase)); - changedObjects.AddRange(RingtoetsDataSynchronizationService.ClearAllCalculationOutputAndHydraulicBoundaryLocations(assessmentSection)); + changedObjects.AddRange(RiskeerDataSynchronizationService.ClearAllCalculationOutputAndHydraulicBoundaryLocations(assessmentSection)); } else { Index: Riskeer/Integration/src/Riskeer.Integration.Plugin/Handlers/HydraulicLocationConfigurationDatabaseUpdateHandler.cs =================================================================== diff -u -r86594ccd7329d320872573a1d066fe18959d3cea -r1ceb376282c1b8c7efc172811cbca4993693e58e --- Riskeer/Integration/src/Riskeer.Integration.Plugin/Handlers/HydraulicLocationConfigurationDatabaseUpdateHandler.cs (.../HydraulicLocationConfigurationDatabaseUpdateHandler.cs) (revision 86594ccd7329d320872573a1d066fe18959d3cea) +++ Riskeer/Integration/src/Riskeer.Integration.Plugin/Handlers/HydraulicLocationConfigurationDatabaseUpdateHandler.cs (.../HydraulicLocationConfigurationDatabaseUpdateHandler.cs) (revision 1ceb376282c1b8c7efc172811cbca4993693e58e) @@ -88,8 +88,8 @@ hydraulicBoundaryDatabase }; - changedObjects.AddRange(RingtoetsDataSynchronizationService.ClearHydraulicBoundaryLocationCalculationOutput(assessmentSection)); - changedObjects.AddRange(RingtoetsDataSynchronizationService.ClearFailureMechanismCalculationOutputs(assessmentSection)); + changedObjects.AddRange(RiskeerDataSynchronizationService.ClearHydraulicBoundaryLocationCalculationOutput(assessmentSection)); + changedObjects.AddRange(RiskeerDataSynchronizationService.ClearFailureMechanismCalculationOutputs(assessmentSection)); return changedObjects; } Index: Riskeer/Integration/src/Riskeer.Integration.Plugin/Handlers/ReferenceLineUpdateHandler.cs =================================================================== diff -u -r86594ccd7329d320872573a1d066fe18959d3cea -r1ceb376282c1b8c7efc172811cbca4993693e58e --- Riskeer/Integration/src/Riskeer.Integration.Plugin/Handlers/ReferenceLineUpdateHandler.cs (.../ReferenceLineUpdateHandler.cs) (revision 86594ccd7329d320872573a1d066fe18959d3cea) +++ Riskeer/Integration/src/Riskeer.Integration.Plugin/Handlers/ReferenceLineUpdateHandler.cs (.../ReferenceLineUpdateHandler.cs) (revision 1ceb376282c1b8c7efc172811cbca4993693e58e) @@ -86,7 +86,7 @@ removedObjects.Clear(); - ClearResults results = RingtoetsDataSynchronizationService.ClearReferenceLineDependentData(assessmentSection); + ClearResults results = RiskeerDataSynchronizationService.ClearReferenceLineDependentData(assessmentSection); foreach (object removedObject in results.RemovedObjects) { removedObjects.Enqueue(removedObject); Fisheye: Tag 1ceb376282c1b8c7efc172811cbca4993693e58e refers to a dead (removed) revision in file `Riskeer/Integration/src/Riskeer.Integration.Service/RingtoetsDataSynchronizationService.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Riskeer/Integration/src/Riskeer.Integration.Service/Riskeer.Integration.Service.csproj =================================================================== diff -u -r9bba38e3ebe3fe261e7c97c338b016681e07c140 -r1ceb376282c1b8c7efc172811cbca4993693e58e --- Riskeer/Integration/src/Riskeer.Integration.Service/Riskeer.Integration.Service.csproj (.../Riskeer.Integration.Service.csproj) (revision 9bba38e3ebe3fe261e7c97c338b016681e07c140) +++ Riskeer/Integration/src/Riskeer.Integration.Service/Riskeer.Integration.Service.csproj (.../Riskeer.Integration.Service.csproj) (revision 1ceb376282c1b8c7efc172811cbca4993693e58e) @@ -30,7 +30,7 @@ True Resources.resx - + Index: Riskeer/Integration/src/Riskeer.Integration.Service/RiskeerDataSynchronizationService.cs =================================================================== diff -u --- Riskeer/Integration/src/Riskeer.Integration.Service/RiskeerDataSynchronizationService.cs (revision 0) +++ Riskeer/Integration/src/Riskeer.Integration.Service/RiskeerDataSynchronizationService.cs (revision 1ceb376282c1b8c7efc172811cbca4993693e58e) @@ -0,0 +1,730 @@ +// Copyright (C) Stichting Deltares 2019. All rights reserved. +// +// This file is part of Riskeer. +// +// Riskeer is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// All names, logos, and references to "Deltares" are registered trademarks of +// Stichting Deltares and remain full property of Stichting Deltares at all times. +// All rights reserved. + +using System; +using System.Collections.Generic; +using System.Linq; +using Core.Common.Base; +using Riskeer.ClosingStructures.Data; +using Riskeer.ClosingStructures.Service; +using Riskeer.Common.Data.AssessmentSection; +using Riskeer.Common.Data.Calculation; +using Riskeer.Common.Data.DikeProfiles; +using Riskeer.Common.Data.FailureMechanism; +using Riskeer.Common.Data.Structures; +using Riskeer.Common.Service; +using Riskeer.DuneErosion.Data; +using Riskeer.DuneErosion.Service; +using Riskeer.GrassCoverErosionInwards.Data; +using Riskeer.GrassCoverErosionInwards.Service; +using Riskeer.GrassCoverErosionInwards.Util; +using Riskeer.GrassCoverErosionOutwards.Data; +using Riskeer.GrassCoverErosionOutwards.Service; +using Riskeer.HeightStructures.Data; +using Riskeer.HeightStructures.Service; +using Riskeer.MacroStabilityInwards.Data; +using Riskeer.MacroStabilityInwards.Service; +using Riskeer.Piping.Data; +using Riskeer.Piping.Service; +using Riskeer.Revetment.Data; +using Riskeer.StabilityPointStructures.Data; +using Riskeer.StabilityPointStructures.Service; +using Riskeer.StabilityStoneCover.Data; +using Riskeer.StabilityStoneCover.Service; +using Riskeer.WaveImpactAsphaltCover.Data; +using Riskeer.WaveImpactAsphaltCover.Service; + +namespace Riskeer.Integration.Service +{ + /// + /// Service for synchronizing Riskeer items. + /// + public static class RiskeerDataSynchronizationService + { + /// + /// Clears all the output data and hydraulic boundary locations within the . + /// + /// The to clear the data for. + /// An of calculations which are affected by + /// removing data. + /// /// Thrown when is null. + public static IEnumerable ClearAllCalculationOutputAndHydraulicBoundaryLocations(IAssessmentSection assessmentSection) + { + if (assessmentSection == null) + { + throw new ArgumentNullException(nameof(assessmentSection)); + } + + var changedObservables = new List(); + + foreach (IFailureMechanism failureMechanism in assessmentSection.GetFailureMechanisms()) + { + var pipingFailureMechanism = failureMechanism as PipingFailureMechanism; + var grassCoverErosionInwardsFailureMechanism = failureMechanism as GrassCoverErosionInwardsFailureMechanism; + var stabilityStoneCoverFailureMechanism = failureMechanism as StabilityStoneCoverFailureMechanism; + var heightStructuresFailureMechanism = failureMechanism as HeightStructuresFailureMechanism; + var closingStructuresFailureMechanism = failureMechanism as ClosingStructuresFailureMechanism; + var stabilityPointStructuresFailureMechanism = failureMechanism as StabilityPointStructuresFailureMechanism; + var grassCoverErosionOutwardsFailureMechanism = failureMechanism as GrassCoverErosionOutwardsFailureMechanism; + var waveImpactAsphaltCoverFailureMechanism = failureMechanism as WaveImpactAsphaltCoverFailureMechanism; + var macroStabilityInwardsFailureMechanism = failureMechanism as MacroStabilityInwardsFailureMechanism; + + if (pipingFailureMechanism != null) + { + changedObservables.AddRange(PipingDataSynchronizationService.ClearAllCalculationOutputAndHydraulicBoundaryLocations(pipingFailureMechanism)); + } + + if (grassCoverErosionInwardsFailureMechanism != null) + { + changedObservables.AddRange(GrassCoverErosionInwardsDataSynchronizationService.ClearAllCalculationOutputAndHydraulicBoundaryLocations(grassCoverErosionInwardsFailureMechanism)); + } + + if (stabilityStoneCoverFailureMechanism != null) + { + changedObservables.AddRange(StabilityStoneCoverDataSynchronizationService.ClearAllWaveConditionsCalculationOutputAndHydraulicBoundaryLocations(stabilityStoneCoverFailureMechanism)); + } + + if (waveImpactAsphaltCoverFailureMechanism != null) + { + changedObservables.AddRange(WaveImpactAsphaltCoverDataSynchronizationService.ClearAllWaveConditionsCalculationOutputAndHydraulicBoundaryLocations(waveImpactAsphaltCoverFailureMechanism)); + } + + if (grassCoverErosionOutwardsFailureMechanism != null) + { + changedObservables.AddRange(GrassCoverErosionOutwardsDataSynchronizationService.ClearAllWaveConditionsCalculationOutputAndHydraulicBoundaryLocations(grassCoverErosionOutwardsFailureMechanism)); + } + + if (heightStructuresFailureMechanism != null) + { + changedObservables.AddRange(HeightStructuresDataSynchronizationService.ClearAllCalculationOutputAndHydraulicBoundaryLocations(heightStructuresFailureMechanism)); + } + + if (closingStructuresFailureMechanism != null) + { + changedObservables.AddRange(ClosingStructuresDataSynchronizationService.ClearAllCalculationOutputAndHydraulicBoundaryLocations(closingStructuresFailureMechanism)); + } + + if (stabilityPointStructuresFailureMechanism != null) + { + changedObservables.AddRange(StabilityPointStructuresDataSynchronizationService.ClearAllCalculationOutputAndHydraulicBoundaryLocations(stabilityPointStructuresFailureMechanism)); + } + + if (macroStabilityInwardsFailureMechanism != null) + { + changedObservables.AddRange(MacroStabilityInwardsDataSynchronizationService.ClearAllCalculationOutputAndHydraulicBoundaryLocations(macroStabilityInwardsFailureMechanism)); + } + } + + return changedObservables; + } + + /// + /// Clears the output of all calculations in the . + /// + /// The which contains the calculations. + /// An of calculations which are affected by clearing the output. + /// Thrown when is null. + public static IEnumerable ClearFailureMechanismCalculationOutputs(IAssessmentSection assessmentSection) + { + if (assessmentSection == null) + { + throw new ArgumentNullException(nameof(assessmentSection)); + } + + return ClearFailureMechanismCalculationOutputs(assessmentSection.GetFailureMechanisms()); + } + + /// + /// Clears the output of all calculations of the given . + /// + /// The failure mechanisms that contain the calculations. + /// An of calculations that are affected by clearing the output. + /// Thrown when is null. + public static IEnumerable ClearFailureMechanismCalculationOutputs(IEnumerable failureMechanisms) + { + if (failureMechanisms == null) + { + throw new ArgumentNullException(nameof(failureMechanisms)); + } + + var changedObservables = new List(); + + foreach (IFailureMechanism failureMechanism in failureMechanisms) + { + var pipingFailureMechanism = failureMechanism as PipingFailureMechanism; + var grassCoverErosionInwardsFailureMechanism = failureMechanism as GrassCoverErosionInwardsFailureMechanism; + var stabilityStoneCoverFailureMechanism = failureMechanism as StabilityStoneCoverFailureMechanism; + var heightStructuresFailureMechanism = failureMechanism as HeightStructuresFailureMechanism; + var closingStructuresFailureMechanism = failureMechanism as ClosingStructuresFailureMechanism; + var stabilityPointStructuresFailureMechanism = failureMechanism as StabilityPointStructuresFailureMechanism; + var grassCoverErosionOutwardsFailureMechanism = failureMechanism as GrassCoverErosionOutwardsFailureMechanism; + var waveImpactAsphaltCoverFailureMechanism = failureMechanism as WaveImpactAsphaltCoverFailureMechanism; + var macroStabilityInwardsFailureMechanism = failureMechanism as MacroStabilityInwardsFailureMechanism; + + if (pipingFailureMechanism != null) + { + changedObservables.AddRange(PipingDataSynchronizationService.ClearAllCalculationOutput(pipingFailureMechanism)); + } + + if (grassCoverErosionInwardsFailureMechanism != null) + { + changedObservables.AddRange(GrassCoverErosionInwardsDataSynchronizationService.ClearAllCalculationOutput(grassCoverErosionInwardsFailureMechanism)); + } + + if (stabilityStoneCoverFailureMechanism != null) + { + changedObservables.AddRange(StabilityStoneCoverDataSynchronizationService.ClearAllWaveConditionsCalculationOutput(stabilityStoneCoverFailureMechanism)); + } + + if (waveImpactAsphaltCoverFailureMechanism != null) + { + changedObservables.AddRange(WaveImpactAsphaltCoverDataSynchronizationService.ClearAllWaveConditionsCalculationOutput(waveImpactAsphaltCoverFailureMechanism)); + } + + if (grassCoverErosionOutwardsFailureMechanism != null) + { + changedObservables.AddRange(GrassCoverErosionOutwardsDataSynchronizationService.ClearAllWaveConditionsCalculationOutput(grassCoverErosionOutwardsFailureMechanism)); + } + + if (heightStructuresFailureMechanism != null) + { + changedObservables.AddRange(HeightStructuresDataSynchronizationService.ClearAllCalculationOutput(heightStructuresFailureMechanism)); + } + + if (closingStructuresFailureMechanism != null) + { + changedObservables.AddRange(ClosingStructuresDataSynchronizationService.ClearAllCalculationOutput(closingStructuresFailureMechanism)); + } + + if (stabilityPointStructuresFailureMechanism != null) + { + changedObservables.AddRange(StabilityPointStructuresDataSynchronizationService.ClearAllCalculationOutput(stabilityPointStructuresFailureMechanism)); + } + + if (macroStabilityInwardsFailureMechanism != null) + { + changedObservables.AddRange(MacroStabilityInwardsDataSynchronizationService.ClearAllCalculationOutput(macroStabilityInwardsFailureMechanism)); + } + } + + return changedObservables; + } + + /// + /// Clears the hydraulic boundary location calculation output that is contained + /// within specific failure mechanisms of the . + /// + /// The which contains the hydraulic boundary + /// location calculations and failure mechanisms at stake. + /// All objects affected by the operation. + /// Thrown when is null. + public static IEnumerable ClearHydraulicBoundaryLocationCalculationOutput(IAssessmentSection assessmentSection) + { + if (assessmentSection == null) + { + throw new ArgumentNullException(nameof(assessmentSection)); + } + + var affectedObjects = new List(); + + affectedObjects.AddRange(ClearHydraulicBoundaryLocationCalculationOutputOfFailureMechanisms(assessmentSection)); + affectedObjects.AddRange(RiskeerCommonDataSynchronizationService.ClearHydraulicBoundaryLocationCalculationOutput(assessmentSection.WaterLevelCalculationsForFactorizedSignalingNorm)); + affectedObjects.AddRange(RiskeerCommonDataSynchronizationService.ClearHydraulicBoundaryLocationCalculationOutput(assessmentSection.WaterLevelCalculationsForSignalingNorm)); + affectedObjects.AddRange(RiskeerCommonDataSynchronizationService.ClearHydraulicBoundaryLocationCalculationOutput(assessmentSection.WaterLevelCalculationsForLowerLimitNorm)); + affectedObjects.AddRange(RiskeerCommonDataSynchronizationService.ClearHydraulicBoundaryLocationCalculationOutput(assessmentSection.WaterLevelCalculationsForFactorizedLowerLimitNorm)); + affectedObjects.AddRange(RiskeerCommonDataSynchronizationService.ClearHydraulicBoundaryLocationCalculationOutput(assessmentSection.WaveHeightCalculationsForFactorizedSignalingNorm)); + affectedObjects.AddRange(RiskeerCommonDataSynchronizationService.ClearHydraulicBoundaryLocationCalculationOutput(assessmentSection.WaveHeightCalculationsForSignalingNorm)); + affectedObjects.AddRange(RiskeerCommonDataSynchronizationService.ClearHydraulicBoundaryLocationCalculationOutput(assessmentSection.WaveHeightCalculationsForLowerLimitNorm)); + affectedObjects.AddRange(RiskeerCommonDataSynchronizationService.ClearHydraulicBoundaryLocationCalculationOutput(assessmentSection.WaveHeightCalculationsForFactorizedLowerLimitNorm)); + + return affectedObjects.ToArray(); + } + + /// + /// Clears the hydraulic boundary location calculation output that is contained within specific failure mechanisms + /// of the . + /// + /// The which contains the failure mechanisms. + /// All objects affected by the operation. + /// Thrown when is null. + public static IEnumerable ClearHydraulicBoundaryLocationCalculationOutputOfFailureMechanisms(IAssessmentSection assessmentSection) + { + if (assessmentSection == null) + { + throw new ArgumentNullException(nameof(assessmentSection)); + } + + return ClearHydraulicBoundaryLocationCalculationOutputOfFailureMechanisms(assessmentSection.GetFailureMechanisms()); + } + + /// + /// Clears the hydraulic boundary location calculation output that is contained within . + /// + /// The failure mechanisms to clear the hydraulic boundary location calculation output for. + /// All objects affected by the operation. + /// Thrown when is null. + public static IEnumerable ClearHydraulicBoundaryLocationCalculationOutputOfFailureMechanisms(IEnumerable failureMechanisms) + { + if (failureMechanisms == null) + { + throw new ArgumentNullException(nameof(failureMechanisms)); + } + + var changedObservables = new List(); + + foreach (IFailureMechanism failureMechanism in failureMechanisms) + { + var grassCoverErosionOutwardsFailureMechanism = failureMechanism as GrassCoverErosionOutwardsFailureMechanism; + if (grassCoverErosionOutwardsFailureMechanism != null) + { + changedObservables.AddRange(GrassCoverErosionOutwardsDataSynchronizationService.ClearHydraulicBoundaryLocationCalculationOutput(grassCoverErosionOutwardsFailureMechanism)); + } + + var duneErosionFailureMechanism = failureMechanism as DuneErosionFailureMechanism; + if (duneErosionFailureMechanism != null) + { + changedObservables.AddRange(DuneErosionDataSynchronizationService.ClearDuneLocationCalculationOutput(duneErosionFailureMechanism)); + } + } + + return changedObservables; + } + + /// + /// Clears the reference line and all data that depends on it, either directly or indirectly. + /// + /// The assessment section. + /// The results of the clear action. + /// Thrown when + /// is null. + public static ClearResults ClearReferenceLineDependentData(IAssessmentSection assessmentSection) + { + if (assessmentSection == null) + { + throw new ArgumentNullException(nameof(assessmentSection)); + } + + var changedObjects = new List(); + var removedObjects = new List(); + + foreach (IFailureMechanism failureMechanism in assessmentSection.GetFailureMechanisms()) + { + ClearResults results = GetClearResultsForFailureMechanism(failureMechanism); + + changedObjects.AddRange(results.ChangedObjects); + removedObjects.AddRange(results.RemovedObjects); + } + + return new ClearResults(changedObjects, removedObjects); + } + + /// + /// Removes a given from the + /// and clears all data that depends on it, either directly or indirectly. + /// + /// The failure mechanism containing . + /// The profile residing in + /// that should be removed. + /// All observable objects affected by this method. + /// Thrown when + /// or is null. + public static IEnumerable RemoveForeshoreProfile(HeightStructuresFailureMechanism failureMechanism, ForeshoreProfile profile) + { + if (failureMechanism == null) + { + throw new ArgumentNullException(nameof(failureMechanism)); + } + + if (profile == null) + { + throw new ArgumentNullException(nameof(profile)); + } + + var changedObservables = new List(); + IEnumerable> calculations = failureMechanism.Calculations.Cast>(); + changedObservables.AddRange(RiskeerCommonDataSynchronizationService.ClearForeshoreProfile(calculations, profile)); + + failureMechanism.ForeshoreProfiles.Remove(profile); + changedObservables.Add(failureMechanism.ForeshoreProfiles); + + return changedObservables; + } + + /// + /// Removes a given from the + /// and clears all data that depends on it, either directly or indirectly. + /// + /// The failure mechanism containing . + /// The profile residing in + /// that should be removed. + /// All observable objects affected by this method. + /// Thrown when + /// or is null. + public static IEnumerable RemoveForeshoreProfile(ClosingStructuresFailureMechanism failureMechanism, ForeshoreProfile profile) + { + if (failureMechanism == null) + { + throw new ArgumentNullException(nameof(failureMechanism)); + } + + if (profile == null) + { + throw new ArgumentNullException(nameof(profile)); + } + + var changedObservables = new List(); + IEnumerable> calculations = failureMechanism.Calculations.Cast>(); + changedObservables.AddRange(RiskeerCommonDataSynchronizationService.ClearForeshoreProfile(calculations, profile)); + + failureMechanism.ForeshoreProfiles.Remove(profile); + changedObservables.Add(failureMechanism.ForeshoreProfiles); + + return changedObservables; + } + + /// + /// Removes a given from the + /// and clears all data that depends on it, either directly or indirectly. + /// + /// The failure mechanism containing . + /// The profile residing in + /// that should be removed. + /// All observable objects affected by this method. + /// Thrown when + /// or is null. + public static IEnumerable RemoveForeshoreProfile(StabilityPointStructuresFailureMechanism failureMechanism, ForeshoreProfile profile) + { + if (failureMechanism == null) + { + throw new ArgumentNullException(nameof(failureMechanism)); + } + + if (profile == null) + { + throw new ArgumentNullException(nameof(profile)); + } + + var changedObservables = new List(); + IEnumerable> calculations = failureMechanism.Calculations.Cast>(); + changedObservables.AddRange(RiskeerCommonDataSynchronizationService.ClearForeshoreProfile(calculations, profile)); + + failureMechanism.ForeshoreProfiles.Remove(profile); + changedObservables.Add(failureMechanism.ForeshoreProfiles); + + return changedObservables; + } + + /// + /// Removes a given from the + /// and clears all data that depends on it, either directly or indirectly. + /// + /// The failure mechanism containing . + /// The profile residing in + /// that should be removed. + /// All observable objects affected by this method. + /// Thrown when + /// or is null. + public static IEnumerable RemoveForeshoreProfile(StabilityStoneCoverFailureMechanism failureMechanism, ForeshoreProfile profile) + { + if (failureMechanism == null) + { + throw new ArgumentNullException(nameof(failureMechanism)); + } + + if (profile == null) + { + throw new ArgumentNullException(nameof(profile)); + } + + var changedObservables = new List(); + Tuple[] calculationsWithInput = failureMechanism.Calculations + .Cast() + .Select(c => Tuple.Create(c, c.InputParameters)) + .ToArray(); + changedObservables.AddRange(OnWaveConditionsInputForeshoreProfileRemoved(profile, calculationsWithInput)); + + failureMechanism.ForeshoreProfiles.Remove(profile); + changedObservables.Add(failureMechanism.ForeshoreProfiles); + + return changedObservables; + } + + /// + /// Removes a given from the + /// and clears all data that depends on it, either directly or indirectly. + /// + /// The failure mechanism containing . + /// The profile residing in + /// that should be removed. + /// All observable objects affected by this method. + /// Thrown when + /// or is null. + public static IEnumerable RemoveForeshoreProfile(WaveImpactAsphaltCoverFailureMechanism failureMechanism, ForeshoreProfile profile) + { + if (failureMechanism == null) + { + throw new ArgumentNullException(nameof(failureMechanism)); + } + + if (profile == null) + { + throw new ArgumentNullException(nameof(profile)); + } + + var changedObservables = new List(); + Tuple[] calculationsWithInput = failureMechanism.Calculations + .Cast() + .Select(c => Tuple.Create(c, c.InputParameters)) + .ToArray(); + changedObservables.AddRange(OnWaveConditionsInputForeshoreProfileRemoved(profile, calculationsWithInput)); + + failureMechanism.ForeshoreProfiles.Remove(profile); + changedObservables.Add(failureMechanism.ForeshoreProfiles); + + return changedObservables; + } + + /// + /// Removes a given from the + /// and clears all data that depends on it, either directly or indirectly. + /// + /// The failure mechanism containing . + /// The profile residing in + /// that should be removed. + /// All observable objects affected by this method. + /// Thrown when + /// or is null. + public static IEnumerable RemoveForeshoreProfile(GrassCoverErosionOutwardsFailureMechanism failureMechanism, ForeshoreProfile profile) + { + if (failureMechanism == null) + { + throw new ArgumentNullException(nameof(failureMechanism)); + } + + if (profile == null) + { + throw new ArgumentNullException(nameof(profile)); + } + + var changedObservables = new List(); + Tuple[] calculationsWithInput = failureMechanism.Calculations + .Cast() + .Select(c => Tuple.Create(c, c.InputParameters)) + .ToArray(); + changedObservables.AddRange(OnWaveConditionsInputForeshoreProfileRemoved(profile, calculationsWithInput)); + + failureMechanism.ForeshoreProfiles.Remove(profile); + changedObservables.Add(failureMechanism.ForeshoreProfiles); + + return changedObservables; + } + + /// + /// Removes a given from the + /// and clears all data that depends on it, either directly or indirectly. + /// + /// The failure mechanism containing . + /// The profile residing in + /// that should be removed. + /// All observable objects affected by this method. + /// Thrown when + /// or is null. + public static IEnumerable RemoveDikeProfile(GrassCoverErosionInwardsFailureMechanism failureMechanism, DikeProfile profile) + { + if (failureMechanism == null) + { + throw new ArgumentNullException(nameof(failureMechanism)); + } + + if (profile == null) + { + throw new ArgumentNullException(nameof(profile)); + } + + var changedObservables = new HashSet(); + GrassCoverErosionInwardsCalculation[] calculations = failureMechanism.Calculations + .Cast() + .ToArray(); + GrassCoverErosionInwardsCalculation[] calculationWithRemovedDikeProfile = calculations + .Where(c => ReferenceEquals(c.InputParameters.DikeProfile, profile)) + .ToArray(); + foreach (GrassCoverErosionInwardsCalculation calculation in calculationWithRemovedDikeProfile) + { + foreach (IObservable calculationWithRemovedOutput in RiskeerCommonDataSynchronizationService.ClearCalculationOutput(calculation)) + { + changedObservables.Add(calculationWithRemovedOutput); + } + + calculation.InputParameters.DikeProfile = null; + changedObservables.Add(calculation.InputParameters); + } + + IEnumerable changedSectionResults = + GrassCoverErosionInwardsHelper.UpdateCalculationToSectionResultAssignments(failureMechanism.SectionResults, calculations); + foreach (GrassCoverErosionInwardsFailureMechanismSectionResult result in changedSectionResults) + { + changedObservables.Add(result); + } + + failureMechanism.DikeProfiles.Remove(profile); + changedObservables.Add(failureMechanism.DikeProfiles); + + return changedObservables; + } + + /// + /// Removes all from the + /// and the in addition to clearing all data that depends + /// on it, either directly or indirectly. + /// + /// The calculations that need to be updated. + /// The collection containing the foreshore profiles. + /// An with affected objects. + /// Thrown when any input argument is + /// null. + public static IEnumerable RemoveAllForeshoreProfiles(IEnumerable> calculations, + ForeshoreProfileCollection foreshoreProfiles) + where T : ICalculationInput + { + if (calculations == null) + { + throw new ArgumentNullException(nameof(calculations)); + } + + if (foreshoreProfiles == null) + { + throw new ArgumentNullException(nameof(foreshoreProfiles)); + } + + IEnumerable> calculationsWithForeshoreProfiles = + calculations.Where(calc => ((IHasForeshoreProfile) calc.InputParameters) + .ForeshoreProfile != null); + + var affectedObjects = new List(); + foreach (ICalculation calculation in calculationsWithForeshoreProfiles) + { + ((IHasForeshoreProfile) calculation.InputParameters).ForeshoreProfile = null; + affectedObjects.Add(calculation.InputParameters); + affectedObjects.AddRange(RiskeerCommonDataSynchronizationService.ClearCalculationOutput(calculation)); + } + + foreshoreProfiles.Clear(); + affectedObjects.Add(foreshoreProfiles); + return affectedObjects; + } + + private static ClearResults GetClearResultsForFailureMechanism(IFailureMechanism failureMechanism) + { + var pipingFailureMechanism = failureMechanism as PipingFailureMechanism; + if (pipingFailureMechanism != null) + { + return PipingDataSynchronizationService.ClearReferenceLineDependentData(pipingFailureMechanism); + } + + var macroStabilityInwardsFailureMechanism = failureMechanism as MacroStabilityInwardsFailureMechanism; + if (macroStabilityInwardsFailureMechanism != null) + { + return MacroStabilityInwardsDataSynchronizationService.ClearReferenceLineDependentData(macroStabilityInwardsFailureMechanism); + } + + var grassCoverErosionInwardsFailureMechanism = failureMechanism as GrassCoverErosionInwardsFailureMechanism; + if (grassCoverErosionInwardsFailureMechanism != null) + { + return GrassCoverErosionInwardsDataSynchronizationService.ClearReferenceLineDependentData(grassCoverErosionInwardsFailureMechanism); + } + + var stabilityStoneCoverFailureMechanism = failureMechanism as StabilityStoneCoverFailureMechanism; + if (stabilityStoneCoverFailureMechanism != null) + { + return StabilityStoneCoverDataSynchronizationService.ClearReferenceLineDependentData(stabilityStoneCoverFailureMechanism); + } + + var waveImpactAsphaltCoverFailureMechanism = failureMechanism as WaveImpactAsphaltCoverFailureMechanism; + if (waveImpactAsphaltCoverFailureMechanism != null) + { + return WaveImpactAsphaltCoverDataSynchronizationService.ClearReferenceLineDependentData(waveImpactAsphaltCoverFailureMechanism); + } + + var grassCoverErosionOutwardsFailureMechanism = failureMechanism as GrassCoverErosionOutwardsFailureMechanism; + if (grassCoverErosionOutwardsFailureMechanism != null) + { + return GrassCoverErosionOutwardsDataSynchronizationService.ClearReferenceLineDependentData(grassCoverErosionOutwardsFailureMechanism); + } + + var heightStructuresFailureMechanism = failureMechanism as HeightStructuresFailureMechanism; + if (heightStructuresFailureMechanism != null) + { + return HeightStructuresDataSynchronizationService.ClearReferenceLineDependentData(heightStructuresFailureMechanism); + } + + var closingStructuresFailureMechanism = failureMechanism as ClosingStructuresFailureMechanism; + if (closingStructuresFailureMechanism != null) + { + return ClosingStructuresDataSynchronizationService.ClearReferenceLineDependentData(closingStructuresFailureMechanism); + } + + var stabilityPointStructuresFailureMechanism = failureMechanism as StabilityPointStructuresFailureMechanism; + if (stabilityPointStructuresFailureMechanism != null) + { + return StabilityPointStructuresDataSynchronizationService.ClearReferenceLineDependentData(stabilityPointStructuresFailureMechanism); + } + + return ClearReferenceLineDependentDataForFailureMechanism(failureMechanism); + } + + private static ClearResults ClearReferenceLineDependentDataForFailureMechanism(IFailureMechanism failureMechanism) + { + var removedObjects = new List(); + var changedObjects = new List(); + + removedObjects.AddRange(failureMechanism.Sections); + changedObjects.Add(failureMechanism); + + var failureMechanismWithSectionResults = failureMechanism as IHasSectionResults; + if (failureMechanismWithSectionResults != null) + { + removedObjects.AddRange(failureMechanismWithSectionResults.SectionResults); + changedObjects.Add(failureMechanismWithSectionResults.SectionResults); + } + + failureMechanism.ClearAllSections(); + + return new ClearResults(changedObjects, removedObjects); + } + + private static IEnumerable OnWaveConditionsInputForeshoreProfileRemoved(ForeshoreProfile profile, Tuple[] calculationInputs) + { + var changedObservables = new List(); + foreach (Tuple input in calculationInputs.Where(input => ReferenceEquals(input.Item2.ForeshoreProfile, profile))) + { + foreach (IObservable calculationWithRemovedOutput in RiskeerCommonDataSynchronizationService.ClearCalculationOutput(input.Item1)) + { + changedObservables.Add(calculationWithRemovedOutput); + } + + input.Item2.ForeshoreProfile = null; + changedObservables.Add(input.Item2); + } + + return changedObservables; + } + } +} \ No newline at end of file Index: Riskeer/Integration/test/Riskeer.Integration.Service.Test/Merge/LoadAssessmentSectionServiceTest.cs =================================================================== diff -u -r68f02442e2e790aaa0bde531c328662819908f10 -r1ceb376282c1b8c7efc172811cbca4993693e58e --- Riskeer/Integration/test/Riskeer.Integration.Service.Test/Merge/LoadAssessmentSectionServiceTest.cs (.../LoadAssessmentSectionServiceTest.cs) (revision 68f02442e2e790aaa0bde531c328662819908f10) +++ Riskeer/Integration/test/Riskeer.Integration.Service.Test/Merge/LoadAssessmentSectionServiceTest.cs (.../LoadAssessmentSectionServiceTest.cs) (revision 1ceb376282c1b8c7efc172811cbca4993693e58e) @@ -82,7 +82,7 @@ } [Test] - public void LoadAssessmentSections_LoadingProjectSuccessful_ReturnsRingtoetsProject() + public void LoadAssessmentSections_LoadingProjectSuccessful_ReturnsRiskeerProject() { // Setup var project = new RiskeerProject(); Fisheye: Tag 1ceb376282c1b8c7efc172811cbca4993693e58e refers to a dead (removed) revision in file `Riskeer/Integration/test/Riskeer.Integration.Service.Test/RingtoetsDataSynchronizationServiceTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Riskeer/Integration/test/Riskeer.Integration.Service.Test/Riskeer.Integration.Service.Test.csproj =================================================================== diff -u -r9bba38e3ebe3fe261e7c97c338b016681e07c140 -r1ceb376282c1b8c7efc172811cbca4993693e58e --- Riskeer/Integration/test/Riskeer.Integration.Service.Test/Riskeer.Integration.Service.Test.csproj (.../Riskeer.Integration.Service.Test.csproj) (revision 9bba38e3ebe3fe261e7c97c338b016681e07c140) +++ Riskeer/Integration/test/Riskeer.Integration.Service.Test/Riskeer.Integration.Service.Test.csproj (.../Riskeer.Integration.Service.Test.csproj) (revision 1ceb376282c1b8c7efc172811cbca4993693e58e) @@ -26,7 +26,7 @@ - + Index: Riskeer/Integration/test/Riskeer.Integration.Service.Test/RiskeerDataSynchronizationServiceTest.cs =================================================================== diff -u --- Riskeer/Integration/test/Riskeer.Integration.Service.Test/RiskeerDataSynchronizationServiceTest.cs (revision 0) +++ Riskeer/Integration/test/Riskeer.Integration.Service.Test/RiskeerDataSynchronizationServiceTest.cs (revision 1ceb376282c1b8c7efc172811cbca4993693e58e) @@ -0,0 +1,1667 @@ +// Copyright (C) Stichting Deltares 2019. All rights reserved. +// +// This file is part of Riskeer. +// +// Riskeer is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// All names, logos, and references to "Deltares" are registered trademarks of +// Stichting Deltares and remain full property of Stichting Deltares at all times. +// All rights reserved. + +using System; +using System.Collections.Generic; +using System.Linq; +using Core.Common.Base; +using NUnit.Framework; +using Rhino.Mocks; +using Riskeer.ClosingStructures.Data; +using Riskeer.Common.Data.AssessmentSection; +using Riskeer.Common.Data.Calculation; +using Riskeer.Common.Data.DikeProfiles; +using Riskeer.Common.Data.FailureMechanism; +using Riskeer.Common.Data.Hydraulics; +using Riskeer.Common.Data.Structures; +using Riskeer.Common.Data.TestUtil; +using Riskeer.Common.Service; +using Riskeer.DuneErosion.Data; +using Riskeer.DuneErosion.Data.TestUtil; +using Riskeer.GrassCoverErosionInwards.Data; +using Riskeer.GrassCoverErosionOutwards.Data; +using Riskeer.GrassCoverErosionOutwards.Data.TestUtil; +using Riskeer.HeightStructures.Data; +using Riskeer.Integration.Data; +using Riskeer.Integration.Data.StandAlone; +using Riskeer.Integration.TestUtil; +using Riskeer.MacroStabilityInwards.Data; +using Riskeer.MacroStabilityInwards.Data.SoilProfile; +using Riskeer.MacroStabilityInwards.Primitives; +using Riskeer.Piping.Data; +using Riskeer.Piping.Data.SoilProfile; +using Riskeer.Piping.Primitives; +using Riskeer.StabilityPointStructures.Data; +using Riskeer.StabilityStoneCover.Data; +using Riskeer.WaveImpactAsphaltCover.Data; + +namespace Riskeer.Integration.Service.Test +{ + [TestFixture] + public class RiskeerDataSynchronizationServiceTest + { + [Test] + public void ClearFailureMechanismCalculationOutputs_WithoutAssessmentSection_ThrowsArgumentNullException() + { + // Call + TestDelegate test = () => RiskeerDataSynchronizationService.ClearFailureMechanismCalculationOutputs((IAssessmentSection) null); + + // Assert + var exception = Assert.Throws(test); + Assert.AreEqual("assessmentSection", exception.ParamName); + } + + [Test] + public void ClearFailureMechanismCalculationOutputs_WithAssessmentSection_ClearsFailureMechanismCalculationsOutputAndReturnsAffectedCalculations() + { + // Setup + AssessmentSection assessmentSection = TestDataGenerator.GetAssessmentSectionWithAllCalculationConfigurations(); + IEnumerable expectedAffectedItems = assessmentSection.GetFailureMechanisms() + .SelectMany(f => f.Calculations) + .Where(c => c.HasOutput) + .ToList(); + + // Call + IEnumerable affectedItems = RiskeerDataSynchronizationService.ClearFailureMechanismCalculationOutputs(assessmentSection); + + // 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(assessmentSection.GetFailureMechanisms() + .SelectMany(f => f.Calculations) + .Where(c => c.HasOutput)); + + CollectionAssert.AreEquivalent(expectedAffectedItems, affectedItems); + } + + [Test] + public void ClearFailureMechanismCalculationOutputs_WithoutFailureMechanisms_ThrowsArgumentNullException() + { + // Call + TestDelegate test = () => RiskeerDataSynchronizationService.ClearFailureMechanismCalculationOutputs((IEnumerable) null); + + // Assert + var exception = Assert.Throws(test); + Assert.AreEqual("failureMechanisms", exception.ParamName); + } + + [Test] + public void ClearFailureMechanismCalculationOutputs_WithFailureMechanisms_ClearsFailureMechanismCalculationsOutputAndReturnsAffectedCalculations() + { + // Setup + IEnumerable failureMechanisms = TestDataGenerator.GetAssessmentSectionWithAllCalculationConfigurations() + .GetFailureMechanisms() + .ToList(); + IEnumerable expectedAffectedItems = failureMechanisms + .SelectMany(f => f.Calculations) + .Where(c => c.HasOutput) + .ToList(); + + // Call + IEnumerable affectedItems = RiskeerDataSynchronizationService.ClearFailureMechanismCalculationOutputs(failureMechanisms); + + // 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(failureMechanisms + .SelectMany(f => f.Calculations) + .Where(c => c.HasOutput)); + + CollectionAssert.AreEquivalent(expectedAffectedItems, affectedItems); + } + + [Test] + public void ClearAllCalculationOutputAndHydraulicBoundaryLocations_AssessmentSectionNull_ThrowsArgumentNullException() + { + // Call + TestDelegate test = () => RiskeerDataSynchronizationService.ClearAllCalculationOutputAndHydraulicBoundaryLocations(null); + + // Assert + var exception = Assert.Throws(test); + Assert.AreEqual("assessmentSection", exception.ParamName); + } + + [Test] + public void ClearAllCalculationOutputAndHydraulicBoundaryLocations_VariousCalculations_ClearsHydraulicBoundaryLocationAndCalculationsAndReturnsAffectedObjects() + { + // Setup + AssessmentSection assessmentSection = TestDataGenerator.GetAssessmentSectionWithAllCalculationConfigurations(); + var expectedAffectedItems = new List(); + expectedAffectedItems.AddRange(assessmentSection.ClosingStructures.Calculations + .Cast>() + .Where(c => c.HasOutput)); + expectedAffectedItems.AddRange(assessmentSection.ClosingStructures.Calculations + .Cast>() + .Select(c => c.InputParameters) + .Where(i => i.HydraulicBoundaryLocation != null)); + expectedAffectedItems.AddRange(assessmentSection.GrassCoverErosionInwards.Calculations + .Cast() + .Where(c => c.HasOutput)); + expectedAffectedItems.AddRange(assessmentSection.GrassCoverErosionInwards.Calculations + .Cast() + .Select(c => c.InputParameters) + .Where(i => i.HydraulicBoundaryLocation != null)); + expectedAffectedItems.AddRange(assessmentSection.GrassCoverErosionOutwards.Calculations + .Cast() + .Where(c => c.HasOutput)); + expectedAffectedItems.AddRange(assessmentSection.GrassCoverErosionOutwards.Calculations + .Cast() + .Select(c => c.InputParameters) + .Where(i => i.HydraulicBoundaryLocation != null)); + expectedAffectedItems.AddRange(assessmentSection.HeightStructures.Calculations + .Cast>() + .Where(c => c.HasOutput)); + expectedAffectedItems.AddRange(assessmentSection.HeightStructures.Calculations + .Cast>() + .Select(c => c.InputParameters) + .Where(i => i.HydraulicBoundaryLocation != null)); + expectedAffectedItems.AddRange(assessmentSection.Piping.Calculations + .Cast() + .Where(c => c.HasOutput)); + expectedAffectedItems.AddRange(assessmentSection.Piping.Calculations + .Cast() + .Select(c => c.InputParameters) + .Where(i => i.HydraulicBoundaryLocation != null)); + expectedAffectedItems.AddRange(assessmentSection.StabilityPointStructures.Calculations + .Cast>() + .Where(c => c.HasOutput)); + expectedAffectedItems.AddRange(assessmentSection.StabilityPointStructures.Calculations + .Cast>() + .Select(c => c.InputParameters) + .Where(i => i.HydraulicBoundaryLocation != null)); + expectedAffectedItems.AddRange(assessmentSection.StabilityStoneCover.Calculations + .Cast() + .Where(c => c.HasOutput)); + expectedAffectedItems.AddRange(assessmentSection.StabilityStoneCover.Calculations + .Cast() + .Select(c => c.InputParameters) + .Where(i => i.HydraulicBoundaryLocation != null)); + expectedAffectedItems.AddRange(assessmentSection.WaveImpactAsphaltCover.Calculations + .Cast() + .Where(c => c.HasOutput)); + expectedAffectedItems.AddRange(assessmentSection.WaveImpactAsphaltCover.Calculations + .Cast() + .Select(c => c.InputParameters) + .Where(i => i.HydraulicBoundaryLocation != null)); + expectedAffectedItems.AddRange(assessmentSection.MacroStabilityInwards.Calculations + .Cast() + .Where(c => c.HasOutput)); + expectedAffectedItems.AddRange(assessmentSection.MacroStabilityInwards.Calculations + .Cast() + .Select(c => c.InputParameters) + .Where(i => i.HydraulicBoundaryLocation != null)); + + // Call + IEnumerable affectedItems = RiskeerDataSynchronizationService.ClearAllCalculationOutputAndHydraulicBoundaryLocations(assessmentSection); + + // 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: + Assert.IsTrue(assessmentSection.ClosingStructures.Calculations.Cast>() + .All(c => c.InputParameters.HydraulicBoundaryLocation == null && !c.HasOutput)); + Assert.IsTrue(assessmentSection.GrassCoverErosionInwards.Calculations.Cast() + .All(c => c.InputParameters.HydraulicBoundaryLocation == null && !c.HasOutput)); + Assert.IsTrue(assessmentSection.GrassCoverErosionOutwards.Calculations.Cast() + .All(c => c.InputParameters.HydraulicBoundaryLocation == null && !c.HasOutput)); + Assert.IsTrue(assessmentSection.HeightStructures.Calculations.Cast>() + .All(c => c.InputParameters.HydraulicBoundaryLocation == null && !c.HasOutput)); + Assert.IsTrue(assessmentSection.Piping.Calculations.Cast() + .All(c => c.InputParameters.HydraulicBoundaryLocation == null && !c.HasOutput)); + Assert.IsTrue(assessmentSection.StabilityPointStructures.Calculations.Cast>() + .All(c => c.InputParameters.HydraulicBoundaryLocation == null && !c.HasOutput)); + Assert.IsTrue(assessmentSection.StabilityStoneCover.Calculations.Cast() + .All(c => c.InputParameters.HydraulicBoundaryLocation == null && !c.HasOutput)); + Assert.IsTrue(assessmentSection.WaveImpactAsphaltCover.Calculations.Cast() + .All(c => c.InputParameters.HydraulicBoundaryLocation == null && !c.HasOutput)); + Assert.IsTrue(assessmentSection.MacroStabilityInwards.Calculations.Cast() + .All(c => c.InputParameters.HydraulicBoundaryLocation == null && !c.HasOutput)); + CollectionAssert.AreEquivalent(expectedAffectedItems, affectedItems); + } + + [Test] + public void ClearHydraulicBoundaryLocationCalculationOutput_AssessmentSectionNull_ThrowsArgumentNullException() + { + // Call + TestDelegate test = () => RiskeerDataSynchronizationService.ClearHydraulicBoundaryLocationCalculationOutput(null); + + // Assert + var exception = Assert.Throws(test); + Assert.AreEqual("assessmentSection", exception.ParamName); + } + + [Test] + public void ClearHydraulicBoundaryLocationCalculationOutput_HydraulicBoundaryGrassCoverErosionOutwardsAndDuneLocations_ClearDataAndReturnAffectedObjects() + { + // Setup + var hydraulicBoundaryLocation1 = new TestHydraulicBoundaryLocation(); + var hydraulicBoundaryLocation2 = new TestHydraulicBoundaryLocation(); + var duneLocation1 = new TestDuneLocation(); + var duneLocation2 = new TestDuneLocation(); + + var assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike) + { + HydraulicBoundaryDatabase = + { + Locations = + { + hydraulicBoundaryLocation1, + hydraulicBoundaryLocation2 + } + } + }; + + DuneErosionFailureMechanism duneErosionFailureMechanism = assessmentSection.DuneErosion; + duneErosionFailureMechanism.SetDuneLocations(new[] + { + duneLocation1, + duneLocation2 + }); + + assessmentSection.SetHydraulicBoundaryLocationCalculations(new[] + { + hydraulicBoundaryLocation1, + hydraulicBoundaryLocation2 + }); + + GrassCoverErosionOutwardsFailureMechanism grassCoverErosionOutwardsFailureMechanism = assessmentSection.GrassCoverErosionOutwards; + grassCoverErosionOutwardsFailureMechanism.SetHydraulicBoundaryLocationCalculations(new[] + { + hydraulicBoundaryLocation1, + hydraulicBoundaryLocation2 + }); + + HydraulicBoundaryLocationCalculation hydraulicBoundaryLocationCalculation1 = assessmentSection.WaterLevelCalculationsForFactorizedSignalingNorm + .First(c => ReferenceEquals(c.HydraulicBoundaryLocation, hydraulicBoundaryLocation1)); + HydraulicBoundaryLocationCalculation hydraulicBoundaryLocationCalculation2 = assessmentSection.WaterLevelCalculationsForSignalingNorm + .First(c => ReferenceEquals(c.HydraulicBoundaryLocation, hydraulicBoundaryLocation1)); + HydraulicBoundaryLocationCalculation hydraulicBoundaryLocationCalculation3 = assessmentSection.WaterLevelCalculationsForLowerLimitNorm + .First(c => ReferenceEquals(c.HydraulicBoundaryLocation, hydraulicBoundaryLocation1)); + HydraulicBoundaryLocationCalculation hydraulicBoundaryLocationCalculation4 = assessmentSection.WaterLevelCalculationsForFactorizedLowerLimitNorm + .First(c => ReferenceEquals(c.HydraulicBoundaryLocation, hydraulicBoundaryLocation1)); + HydraulicBoundaryLocationCalculation hydraulicBoundaryLocationCalculation5 = assessmentSection.WaveHeightCalculationsForFactorizedSignalingNorm + .First(c => ReferenceEquals(c.HydraulicBoundaryLocation, hydraulicBoundaryLocation1)); + HydraulicBoundaryLocationCalculation hydraulicBoundaryLocationCalculation6 = assessmentSection.WaveHeightCalculationsForSignalingNorm + .First(c => ReferenceEquals(c.HydraulicBoundaryLocation, hydraulicBoundaryLocation1)); + HydraulicBoundaryLocationCalculation hydraulicBoundaryLocationCalculation7 = assessmentSection.WaveHeightCalculationsForLowerLimitNorm + .First(c => ReferenceEquals(c.HydraulicBoundaryLocation, hydraulicBoundaryLocation1)); + HydraulicBoundaryLocationCalculation hydraulicBoundaryLocationCalculation8 = assessmentSection.WaveHeightCalculationsForFactorizedLowerLimitNorm + .First(c => ReferenceEquals(c.HydraulicBoundaryLocation, hydraulicBoundaryLocation1)); + + hydraulicBoundaryLocationCalculation1.Output = new TestHydraulicBoundaryLocationCalculationOutput(); + hydraulicBoundaryLocationCalculation2.Output = new TestHydraulicBoundaryLocationCalculationOutput(); + hydraulicBoundaryLocationCalculation3.Output = new TestHydraulicBoundaryLocationCalculationOutput(); + hydraulicBoundaryLocationCalculation4.Output = new TestHydraulicBoundaryLocationCalculationOutput(); + hydraulicBoundaryLocationCalculation5.Output = new TestHydraulicBoundaryLocationCalculationOutput(); + hydraulicBoundaryLocationCalculation6.Output = new TestHydraulicBoundaryLocationCalculationOutput(); + hydraulicBoundaryLocationCalculation7.Output = new TestHydraulicBoundaryLocationCalculationOutput(); + hydraulicBoundaryLocationCalculation8.Output = new TestHydraulicBoundaryLocationCalculationOutput(); + + HydraulicBoundaryLocationCalculation grassHydraulicBoundaryLocationCalculation1 = grassCoverErosionOutwardsFailureMechanism.WaterLevelCalculationsForMechanismSpecificFactorizedSignalingNorm + .First(c => ReferenceEquals(c.HydraulicBoundaryLocation, hydraulicBoundaryLocation1)); + HydraulicBoundaryLocationCalculation grassHydraulicBoundaryLocationCalculation2 = grassCoverErosionOutwardsFailureMechanism.WaterLevelCalculationsForMechanismSpecificSignalingNorm + .First(c => ReferenceEquals(c.HydraulicBoundaryLocation, hydraulicBoundaryLocation1)); + HydraulicBoundaryLocationCalculation grassHydraulicBoundaryLocationCalculation3 = grassCoverErosionOutwardsFailureMechanism.WaterLevelCalculationsForMechanismSpecificLowerLimitNorm + .First(c => ReferenceEquals(c.HydraulicBoundaryLocation, hydraulicBoundaryLocation1)); + HydraulicBoundaryLocationCalculation grassHydraulicBoundaryLocationCalculation4 = grassCoverErosionOutwardsFailureMechanism.WaveHeightCalculationsForMechanismSpecificFactorizedSignalingNorm + .First(c => ReferenceEquals(c.HydraulicBoundaryLocation, hydraulicBoundaryLocation1)); + HydraulicBoundaryLocationCalculation grassHydraulicBoundaryLocationCalculation5 = grassCoverErosionOutwardsFailureMechanism.WaveHeightCalculationsForMechanismSpecificSignalingNorm + .First(c => ReferenceEquals(c.HydraulicBoundaryLocation, hydraulicBoundaryLocation1)); + HydraulicBoundaryLocationCalculation grassHydraulicBoundaryLocationCalculation6 = grassCoverErosionOutwardsFailureMechanism.WaveHeightCalculationsForMechanismSpecificLowerLimitNorm + .First(c => ReferenceEquals(c.HydraulicBoundaryLocation, hydraulicBoundaryLocation1)); + + grassHydraulicBoundaryLocationCalculation1.Output = new TestHydraulicBoundaryLocationCalculationOutput(); + grassHydraulicBoundaryLocationCalculation2.Output = new TestHydraulicBoundaryLocationCalculationOutput(); + grassHydraulicBoundaryLocationCalculation3.Output = new TestHydraulicBoundaryLocationCalculationOutput(); + grassHydraulicBoundaryLocationCalculation4.Output = new TestHydraulicBoundaryLocationCalculationOutput(); + grassHydraulicBoundaryLocationCalculation5.Output = new TestHydraulicBoundaryLocationCalculationOutput(); + grassHydraulicBoundaryLocationCalculation6.Output = new TestHydraulicBoundaryLocationCalculationOutput(); + + DuneLocationCalculation duneLocationCalculation1 = duneErosionFailureMechanism.CalculationsForMechanismSpecificFactorizedSignalingNorm.First(c => ReferenceEquals(c.DuneLocation, duneLocation1)); + DuneLocationCalculation duneLocationCalculation2 = duneErosionFailureMechanism.CalculationsForMechanismSpecificSignalingNorm.First(c => ReferenceEquals(c.DuneLocation, duneLocation1)); + DuneLocationCalculation duneLocationCalculation3 = duneErosionFailureMechanism.CalculationsForMechanismSpecificLowerLimitNorm.First(c => ReferenceEquals(c.DuneLocation, duneLocation1)); + DuneLocationCalculation duneLocationCalculation4 = duneErosionFailureMechanism.CalculationsForLowerLimitNorm.First(c => ReferenceEquals(c.DuneLocation, duneLocation1)); + DuneLocationCalculation duneLocationCalculation5 = duneErosionFailureMechanism.CalculationsForFactorizedLowerLimitNorm.First(c => ReferenceEquals(c.DuneLocation, duneLocation1)); + + duneLocationCalculation1.Output = new TestDuneLocationCalculationOutput(); + duneLocationCalculation2.Output = new TestDuneLocationCalculationOutput(); + duneLocationCalculation3.Output = new TestDuneLocationCalculationOutput(); + duneLocationCalculation4.Output = new TestDuneLocationCalculationOutput(); + duneLocationCalculation5.Output = new TestDuneLocationCalculationOutput(); + + var expectedAffectedItems = new IObservable[] + { + hydraulicBoundaryLocationCalculation1, + hydraulicBoundaryLocationCalculation2, + hydraulicBoundaryLocationCalculation3, + hydraulicBoundaryLocationCalculation4, + hydraulicBoundaryLocationCalculation5, + hydraulicBoundaryLocationCalculation6, + hydraulicBoundaryLocationCalculation7, + hydraulicBoundaryLocationCalculation8, + grassHydraulicBoundaryLocationCalculation1, + grassHydraulicBoundaryLocationCalculation2, + grassHydraulicBoundaryLocationCalculation3, + grassHydraulicBoundaryLocationCalculation4, + grassHydraulicBoundaryLocationCalculation5, + grassHydraulicBoundaryLocationCalculation6, + duneLocationCalculation1, + duneLocationCalculation2, + duneLocationCalculation3, + duneLocationCalculation4, + duneLocationCalculation5 + }; + + // Call + IEnumerable affectedObjects = RiskeerDataSynchronizationService.ClearHydraulicBoundaryLocationCalculationOutput(assessmentSection); + + // Assert + CollectionAssert.AreEquivalent(expectedAffectedItems, affectedObjects); + Assert.IsFalse(hydraulicBoundaryLocationCalculation1.HasOutput); + Assert.IsFalse(hydraulicBoundaryLocationCalculation2.HasOutput); + Assert.IsFalse(hydraulicBoundaryLocationCalculation3.HasOutput); + Assert.IsFalse(hydraulicBoundaryLocationCalculation4.HasOutput); + Assert.IsFalse(hydraulicBoundaryLocationCalculation5.HasOutput); + Assert.IsFalse(hydraulicBoundaryLocationCalculation6.HasOutput); + Assert.IsFalse(hydraulicBoundaryLocationCalculation7.HasOutput); + Assert.IsFalse(hydraulicBoundaryLocationCalculation8.HasOutput); + + Assert.IsFalse(grassHydraulicBoundaryLocationCalculation1.HasOutput); + Assert.IsFalse(grassHydraulicBoundaryLocationCalculation2.HasOutput); + Assert.IsFalse(grassHydraulicBoundaryLocationCalculation3.HasOutput); + Assert.IsFalse(grassHydraulicBoundaryLocationCalculation4.HasOutput); + Assert.IsFalse(grassHydraulicBoundaryLocationCalculation5.HasOutput); + Assert.IsFalse(grassHydraulicBoundaryLocationCalculation6.HasOutput); + + Assert.IsNull(duneLocationCalculation1.Output); + Assert.IsNull(duneLocationCalculation2.Output); + Assert.IsNull(duneLocationCalculation3.Output); + Assert.IsNull(duneLocationCalculation4.Output); + Assert.IsNull(duneLocationCalculation5.Output); + } + + [Test] + public void ClearHydraulicBoundaryLocationCalculationOutputOfFailureMechanisms_AssessmentSectionNull_ThrowsArgumentNullException() + { + // Call + TestDelegate test = () => RiskeerDataSynchronizationService.ClearHydraulicBoundaryLocationCalculationOutputOfFailureMechanisms((IAssessmentSection) null); + + // Assert + var exception = Assert.Throws(test); + Assert.AreEqual("assessmentSection", exception.ParamName); + } + + [Test] + public void ClearHydraulicBoundaryLocationCalculationOutputOfFailureMechanisms_AssessmentSectionWithFailureMechanismsContainingNoLocations_DoNothing() + { + // Setup + var mockRepository = new MockRepository(); + var assessmentSection = mockRepository.Stub(); + assessmentSection.Stub(section => section.GetFailureMechanisms()).Return(new IFailureMechanism[] + { + new GrassCoverErosionOutwardsFailureMechanism(), + new DuneErosionFailureMechanism() + }); + mockRepository.ReplayAll(); + + // Call + IEnumerable affectedObjects = RiskeerDataSynchronizationService.ClearHydraulicBoundaryLocationCalculationOutputOfFailureMechanisms(assessmentSection); + + // Assert + CollectionAssert.IsEmpty(affectedObjects); + + mockRepository.VerifyAll(); + } + + [Test] + [TestCase(true)] + [TestCase(false)] + public void ClearHydraulicBoundaryLocationCalculationOutputOfFailureMechanisms_AssessmentSectionWithGrassCoverErosionOutwardsFailureMechanism_ClearDataAndReturnAffectedCalculations(bool hasOutput) + { + // Setup + var grassCoverErosionOutwardsFailureMechanism = new GrassCoverErosionOutwardsFailureMechanism(); + ConfigureGrassCoverErosionOutwardsFailureMechanism(grassCoverErosionOutwardsFailureMechanism, hasOutput); + + var mockRepository = new MockRepository(); + var assessmentSection = mockRepository.Stub(); + assessmentSection.Stub(section => section.GetFailureMechanisms()).Return(new IFailureMechanism[] + { + grassCoverErosionOutwardsFailureMechanism + }); + mockRepository.ReplayAll(); + + IEnumerable expectedAffectedItems = + GrassCoverErosionOutwardsHydraulicBoundaryLocationsTestHelper.GetAllHydraulicBoundaryLocationCalculationsWithOutput(grassCoverErosionOutwardsFailureMechanism); + + // Call + IEnumerable affectedObjects = RiskeerDataSynchronizationService.ClearHydraulicBoundaryLocationCalculationOutputOfFailureMechanisms(assessmentSection); + + // 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.AreEquivalent(expectedAffectedItems, affectedObjects); + GrassCoverErosionOutwardsHydraulicBoundaryLocationsTestHelper.AssertHydraulicBoundaryLocationCalculationsHaveNoOutputs(grassCoverErosionOutwardsFailureMechanism); + mockRepository.VerifyAll(); + } + + [Test] + [TestCase(true)] + [TestCase(false)] + public void ClearHydraulicBoundaryLocationCalculationOutputOfFailureMechanisms_AssessmentSectionWithDuneErosionFailureMechanism_ClearDataAndReturnAffectedCalculations(bool hasOutput) + { + // Setup + var duneErosionFailureMechanism = new DuneErosionFailureMechanism(); + ConfigureDuneErosionFailureMechanism(duneErosionFailureMechanism, hasOutput); + + var mockRepository = new MockRepository(); + var assessmentSection = mockRepository.Stub(); + assessmentSection.Stub(section => section.GetFailureMechanisms()).Return(new IFailureMechanism[] + { + duneErosionFailureMechanism + }); + mockRepository.ReplayAll(); + + IEnumerable expectedAffectedItems = DuneLocationsTestHelper.GetAllDuneLocationCalculationsWithOutput(duneErosionFailureMechanism); + + // Call + IEnumerable affectedObjects = RiskeerDataSynchronizationService.ClearHydraulicBoundaryLocationCalculationOutputOfFailureMechanisms(assessmentSection); + + // 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.AreEquivalent(expectedAffectedItems, affectedObjects); + DuneLocationsTestHelper.AssertDuneLocationCalculationsHaveNoOutputs(duneErosionFailureMechanism); + + mockRepository.VerifyAll(); + } + + [Test] + public void ClearHydraulicBoundaryLocationCalculationOutputOfFailureMechanisms_FailureMechanismsNull_ThrowsArgumentNullException() + { + // Call + TestDelegate test = () => RiskeerDataSynchronizationService.ClearHydraulicBoundaryLocationCalculationOutputOfFailureMechanisms((IEnumerable) null); + + // Assert + var exception = Assert.Throws(test); + Assert.AreEqual("failureMechanisms", exception.ParamName); + } + + [Test] + public void ClearHydraulicBoundaryLocationCalculationOutputOfFailureMechanisms_FailureMechanismsContainingNoLocations_DoNothing() + { + // Call + IEnumerable affectedObjects = RiskeerDataSynchronizationService.ClearHydraulicBoundaryLocationCalculationOutputOfFailureMechanisms(new IFailureMechanism[] + { + new GrassCoverErosionOutwardsFailureMechanism(), + new DuneErosionFailureMechanism() + }); + + // Assert + CollectionAssert.IsEmpty(affectedObjects); + } + + [Test] + [TestCase(true)] + [TestCase(false)] + public void ClearHydraulicBoundaryLocationCalculationOutputOfFailureMechanisms_GrassCoverErosionOutwardsFailureMechanism_ClearDataAndReturnAffectedCalculations(bool hasOutput) + { + // Setup + var grassCoverErosionOutwardsFailureMechanism = new GrassCoverErosionOutwardsFailureMechanism(); + ConfigureGrassCoverErosionOutwardsFailureMechanism(grassCoverErosionOutwardsFailureMechanism, hasOutput); + + IEnumerable expectedAffectedItems = + GrassCoverErosionOutwardsHydraulicBoundaryLocationsTestHelper.GetAllHydraulicBoundaryLocationCalculationsWithOutput(grassCoverErosionOutwardsFailureMechanism); + + // Call + IEnumerable affectedObjects = RiskeerDataSynchronizationService.ClearHydraulicBoundaryLocationCalculationOutputOfFailureMechanisms(new IFailureMechanism[] + { + grassCoverErosionOutwardsFailureMechanism + }); + + // 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.AreEquivalent(expectedAffectedItems, affectedObjects); + GrassCoverErosionOutwardsHydraulicBoundaryLocationsTestHelper.AssertHydraulicBoundaryLocationCalculationsHaveNoOutputs(grassCoverErosionOutwardsFailureMechanism); + } + + [Test] + [TestCase(true)] + [TestCase(false)] + public void ClearHydraulicBoundaryLocationCalculationOutputOfFailureMechanisms_DuneErosionFailureMechanism_ClearDataAndReturnAffectedCalculations(bool hasOutput) + { + // Setup + var duneErosionFailureMechanism = new DuneErosionFailureMechanism(); + ConfigureDuneErosionFailureMechanism(duneErosionFailureMechanism, hasOutput); + + IEnumerable expectedAffectedItems = DuneLocationsTestHelper.GetAllDuneLocationCalculationsWithOutput(duneErosionFailureMechanism); + + // Call + IEnumerable affectedObjects = RiskeerDataSynchronizationService.ClearHydraulicBoundaryLocationCalculationOutputOfFailureMechanisms(new IFailureMechanism[] + { + duneErosionFailureMechanism + }); + + // 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.AreEquivalent(expectedAffectedItems, affectedObjects); + DuneLocationsTestHelper.AssertDuneLocationCalculationsHaveNoOutputs(duneErosionFailureMechanism); + } + + [Test] + public void ClearReferenceLine_AssessmentSectionNull_ThrowArgumentNullException() + { + // Call + TestDelegate call = () => RiskeerDataSynchronizationService.ClearReferenceLineDependentData(null); + + // Assert + string paramName = Assert.Throws(call).ParamName; + Assert.AreEqual("assessmentSection", paramName); + } + + [Test] + public void ClearReferenceLine_FullyConfiguredAssessmentSection_AllReferenceLineDependentDataCleared() + { + // Setup + AssessmentSection assessmentSection = TestDataGenerator.GetAssessmentSectionWithAllCalculationConfigurations(); + + // Call + RiskeerDataSynchronizationService.ClearReferenceLineDependentData(assessmentSection); + + // 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: + PipingFailureMechanism pipingFailureMechanism = assessmentSection.Piping; + CollectionAssert.IsEmpty(pipingFailureMechanism.Sections); + CollectionAssert.IsEmpty(pipingFailureMechanism.SectionResults); + CollectionAssert.IsEmpty(pipingFailureMechanism.CalculationsGroup.Children); + CollectionAssert.IsEmpty(pipingFailureMechanism.StochasticSoilModels); + CollectionAssert.IsEmpty(pipingFailureMechanism.SurfaceLines); + + GrassCoverErosionInwardsFailureMechanism grassCoverErosionInwardsFailureMechanism = assessmentSection.GrassCoverErosionInwards; + CollectionAssert.IsEmpty(grassCoverErosionInwardsFailureMechanism.Sections); + CollectionAssert.IsEmpty(grassCoverErosionInwardsFailureMechanism.SectionResults); + CollectionAssert.IsEmpty(grassCoverErosionInwardsFailureMechanism.CalculationsGroup.Children); + CollectionAssert.IsEmpty(grassCoverErosionInwardsFailureMechanism.DikeProfiles); + + GrassCoverErosionOutwardsFailureMechanism grassCoverErosionOutwardsFailureMechanism = assessmentSection.GrassCoverErosionOutwards; + CollectionAssert.IsEmpty(grassCoverErosionOutwardsFailureMechanism.Sections); + CollectionAssert.IsEmpty(grassCoverErosionOutwardsFailureMechanism.SectionResults); + CollectionAssert.IsEmpty(grassCoverErosionOutwardsFailureMechanism.WaveConditionsCalculationGroup.Children); + CollectionAssert.IsEmpty(grassCoverErosionOutwardsFailureMechanism.ForeshoreProfiles); + + WaveImpactAsphaltCoverFailureMechanism waveImpactAsphaltCoverFailureMechanism = assessmentSection.WaveImpactAsphaltCover; + CollectionAssert.IsEmpty(waveImpactAsphaltCoverFailureMechanism.Sections); + CollectionAssert.IsEmpty(waveImpactAsphaltCoverFailureMechanism.SectionResults); + CollectionAssert.IsEmpty(waveImpactAsphaltCoverFailureMechanism.WaveConditionsCalculationGroup.Children); + CollectionAssert.IsEmpty(waveImpactAsphaltCoverFailureMechanism.ForeshoreProfiles); + + StabilityStoneCoverFailureMechanism stabilityStoneCoverFailureMechanism = assessmentSection.StabilityStoneCover; + CollectionAssert.IsEmpty(stabilityStoneCoverFailureMechanism.Sections); + CollectionAssert.IsEmpty(stabilityStoneCoverFailureMechanism.SectionResults); + CollectionAssert.IsEmpty(stabilityStoneCoverFailureMechanism.WaveConditionsCalculationGroup.Children); + CollectionAssert.IsEmpty(stabilityStoneCoverFailureMechanism.ForeshoreProfiles); + + ClosingStructuresFailureMechanism closingStructuresFailureMechanism = assessmentSection.ClosingStructures; + CollectionAssert.IsEmpty(closingStructuresFailureMechanism.Sections); + CollectionAssert.IsEmpty(closingStructuresFailureMechanism.SectionResults); + CollectionAssert.IsEmpty(closingStructuresFailureMechanism.CalculationsGroup.Children); + CollectionAssert.IsEmpty(closingStructuresFailureMechanism.ForeshoreProfiles); + CollectionAssert.IsEmpty(closingStructuresFailureMechanism.ClosingStructures); + + HeightStructuresFailureMechanism heightStructuresFailureMechanism = assessmentSection.HeightStructures; + CollectionAssert.IsEmpty(heightStructuresFailureMechanism.Sections); + CollectionAssert.IsEmpty(heightStructuresFailureMechanism.SectionResults); + CollectionAssert.IsEmpty(heightStructuresFailureMechanism.CalculationsGroup.Children); + CollectionAssert.IsEmpty(heightStructuresFailureMechanism.ForeshoreProfiles); + CollectionAssert.IsEmpty(heightStructuresFailureMechanism.HeightStructures); + + StabilityPointStructuresFailureMechanism stabilityPointStructuresFailureMechanism = assessmentSection.StabilityPointStructures; + CollectionAssert.IsEmpty(stabilityPointStructuresFailureMechanism.Sections); + CollectionAssert.IsEmpty(stabilityPointStructuresFailureMechanism.SectionResults); + CollectionAssert.IsEmpty(stabilityPointStructuresFailureMechanism.CalculationsGroup.Children); + CollectionAssert.IsEmpty(stabilityPointStructuresFailureMechanism.ForeshoreProfiles); + CollectionAssert.IsEmpty(stabilityPointStructuresFailureMechanism.StabilityPointStructures); + + DuneErosionFailureMechanism duneErosionFailureMechanism = assessmentSection.DuneErosion; + CollectionAssert.IsEmpty(duneErosionFailureMechanism.Sections); + CollectionAssert.IsEmpty(duneErosionFailureMechanism.SectionResults); + + MacroStabilityInwardsFailureMechanism macroStabilityInwardsFailureMechanism = assessmentSection.MacroStabilityInwards; + CollectionAssert.IsEmpty(macroStabilityInwardsFailureMechanism.Sections); + CollectionAssert.IsEmpty(macroStabilityInwardsFailureMechanism.SectionResults); + CollectionAssert.IsEmpty(macroStabilityInwardsFailureMechanism.CalculationsGroup.Children); + CollectionAssert.IsEmpty(macroStabilityInwardsFailureMechanism.StochasticSoilModels); + CollectionAssert.IsEmpty(macroStabilityInwardsFailureMechanism.SurfaceLines); + + MacroStabilityOutwardsFailureMechanism macroStabilityOutwardsFailureMechanism = assessmentSection.MacroStabilityOutwards; + CollectionAssert.IsEmpty(macroStabilityOutwardsFailureMechanism.Sections); + CollectionAssert.IsEmpty(macroStabilityOutwardsFailureMechanism.SectionResults); + + MicrostabilityFailureMechanism microstabilityFailureMechanism = assessmentSection.Microstability; + CollectionAssert.IsEmpty(microstabilityFailureMechanism.Sections); + CollectionAssert.IsEmpty(microstabilityFailureMechanism.SectionResults); + + WaterPressureAsphaltCoverFailureMechanism waterPressureAsphaltCoverFailureMechanism = assessmentSection.WaterPressureAsphaltCover; + CollectionAssert.IsEmpty(waterPressureAsphaltCoverFailureMechanism.Sections); + CollectionAssert.IsEmpty(waterPressureAsphaltCoverFailureMechanism.SectionResults); + + GrassCoverSlipOffOutwardsFailureMechanism grassCoverSlipOffOutwardsFailureMechanism = assessmentSection.GrassCoverSlipOffOutwards; + CollectionAssert.IsEmpty(grassCoverSlipOffOutwardsFailureMechanism.Sections); + CollectionAssert.IsEmpty(grassCoverSlipOffOutwardsFailureMechanism.SectionResults); + + GrassCoverSlipOffInwardsFailureMechanism grassCoverSlipOffInwardsFailureMechanism = assessmentSection.GrassCoverSlipOffInwards; + CollectionAssert.IsEmpty(grassCoverSlipOffInwardsFailureMechanism.Sections); + CollectionAssert.IsEmpty(grassCoverSlipOffInwardsFailureMechanism.SectionResults); + + StrengthStabilityLengthwiseConstructionFailureMechanism stabilityLengthwiseConstructionFailureMechanism = assessmentSection.StrengthStabilityLengthwiseConstruction; + CollectionAssert.IsEmpty(stabilityLengthwiseConstructionFailureMechanism.Sections); + CollectionAssert.IsEmpty(stabilityLengthwiseConstructionFailureMechanism.SectionResults); + + PipingStructureFailureMechanism pipingStructureFailureMechanism = assessmentSection.PipingStructure; + CollectionAssert.IsEmpty(pipingStructureFailureMechanism.Sections); + CollectionAssert.IsEmpty(pipingStructureFailureMechanism.SectionResults); + + TechnicalInnovationFailureMechanism technicalInnovationFailureMechanism = assessmentSection.TechnicalInnovation; + CollectionAssert.IsEmpty(technicalInnovationFailureMechanism.Sections); + CollectionAssert.IsEmpty(technicalInnovationFailureMechanism.SectionResults); + } + + [Test] + public void ClearReferenceLine_FullyConfiguredAssessmentSection_ClearResultsContainAllAffectedObjectsAndAllRemovedObjects() + { + // Setup + AssessmentSection assessmentSection = TestDataGenerator.GetAssessmentSectionWithAllCalculationConfigurations(); + + IEnumerable expectedRemovedObjects = GetExpectedRemovedObjectsWhenClearingReferenceLine(assessmentSection); + + // Call + ClearResults results = RiskeerDataSynchronizationService.ClearReferenceLineDependentData(assessmentSection); + + // Assert + AssertChangedObjects(results, assessmentSection); + + CollectionAssert.AreEquivalent(expectedRemovedObjects, results.RemovedObjects); + CollectionAssert.DoesNotContain(results.RemovedObjects, null); + } + + [Test] + public void RemoveForeshoreProfile_StabilityStoneCoverFailureMechanismNull_ThrowsArgumentNullException() + { + // Setup + ForeshoreProfile profile = new TestForeshoreProfile(); + + // Call + TestDelegate call = () => RiskeerDataSynchronizationService.RemoveForeshoreProfile((StabilityStoneCoverFailureMechanism) null, profile); + + // Assert + string paramName = Assert.Throws(call).ParamName; + Assert.AreEqual("failureMechanism", paramName); + } + + [Test] + public void RemoveForeshoreProfile_StabilityStoneCoverFailureMechanismProfileNull_ThrowsArgumentNullException() + { + // Setup + var failureMechanism = new StabilityStoneCoverFailureMechanism(); + + // Call + TestDelegate call = () => RiskeerDataSynchronizationService.RemoveForeshoreProfile(failureMechanism, null); + + // Assert + string paramName = Assert.Throws(call).ParamName; + Assert.AreEqual("profile", paramName); + } + + [Test] + public void RemoveForeshoreProfile_FullyConfiguredStabilityStoneCoverFailureMechanism_RemoveProfileAndClearDependentData() + { + // Setup + StabilityStoneCoverFailureMechanism failureMechanism = TestDataGenerator.GetStabilityStoneCoverFailureMechanismWithAllCalculationConfigurations(); + ForeshoreProfile profile = failureMechanism.ForeshoreProfiles[0]; + StabilityStoneCoverWaveConditionsCalculation[] calculationsWithForeshoreProfile = + failureMechanism.Calculations + .Cast() + .Where(c => ReferenceEquals(c.InputParameters.ForeshoreProfile, profile)) + .ToArray(); + + StabilityStoneCoverWaveConditionsCalculation[] calculationsWithOutput = calculationsWithForeshoreProfile.Where(c => c.HasOutput).ToArray(); + + // Precondition + CollectionAssert.IsNotEmpty(calculationsWithForeshoreProfile); + + // Call + IEnumerable observables = RiskeerDataSynchronizationService.RemoveForeshoreProfile(failureMechanism, profile); + + // 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.ForeshoreProfiles, profile); + foreach (StabilityStoneCoverWaveConditionsCalculation calculation in calculationsWithForeshoreProfile) + { + Assert.IsNull(calculation.InputParameters.ForeshoreProfile); + } + + IObservable[] array = observables.ToArray(); + int expectedAffectedObjectCount = 1 + calculationsWithOutput.Length + calculationsWithForeshoreProfile.Length; + Assert.AreEqual(expectedAffectedObjectCount, array.Length); + CollectionAssert.Contains(array, failureMechanism.ForeshoreProfiles); + foreach (StabilityStoneCoverWaveConditionsCalculation calculation in calculationsWithForeshoreProfile) + { + Assert.IsNull(calculation.InputParameters.ForeshoreProfile); + CollectionAssert.Contains(array, calculation.InputParameters); + } + + foreach (ICalculation calculation in calculationsWithOutput) + { + Assert.IsFalse(calculation.HasOutput); + CollectionAssert.Contains(array, calculation); + } + } + + [Test] + public void RemoveForeshoreProfile_WaveImpactAsphaltCoverFailureMechanismNull_ThrowsArgumentNullException() + { + // Setup + ForeshoreProfile profile = new TestForeshoreProfile(); + + // Call + TestDelegate call = () => RiskeerDataSynchronizationService.RemoveForeshoreProfile((WaveImpactAsphaltCoverFailureMechanism) null, profile); + + // Assert + string paramName = Assert.Throws(call).ParamName; + Assert.AreEqual("failureMechanism", paramName); + } + + [Test] + public void RemoveForeshoreProfile_WaveImpactAsphaltCoverFailureMechanismProfileNull_ThrowsArgumentNullException() + { + // Setup + var failureMechanism = new WaveImpactAsphaltCoverFailureMechanism(); + + // Call + TestDelegate call = () => RiskeerDataSynchronizationService.RemoveForeshoreProfile(failureMechanism, null); + + // Assert + string paramName = Assert.Throws(call).ParamName; + Assert.AreEqual("profile", paramName); + } + + [Test] + public void RemoveForeshoreProfile_FullyConfiguredWaveImpactAsphaltCoverFailureMechanism_RemoveProfileAndClearDependentData() + { + // Setup + WaveImpactAsphaltCoverFailureMechanism failureMechanism = TestDataGenerator.GetWaveImpactAsphaltCoverFailureMechanismWithAllCalculationConfigurations(); + ForeshoreProfile profile = failureMechanism.ForeshoreProfiles[0]; + WaveImpactAsphaltCoverWaveConditionsCalculation[] calculationsWithForeshoreProfile = + failureMechanism.Calculations + .Cast() + .Where(c => ReferenceEquals(c.InputParameters.ForeshoreProfile, profile)) + .ToArray(); + + WaveImpactAsphaltCoverWaveConditionsCalculation[] calculationsWithOutput = calculationsWithForeshoreProfile.Where(c => c.HasOutput).ToArray(); + + // Precondition + CollectionAssert.IsNotEmpty(calculationsWithForeshoreProfile); + + // Call + IEnumerable observables = RiskeerDataSynchronizationService.RemoveForeshoreProfile(failureMechanism, profile); + + // 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.ForeshoreProfiles, profile); + foreach (WaveImpactAsphaltCoverWaveConditionsCalculation calculation in calculationsWithForeshoreProfile) + { + Assert.IsNull(calculation.InputParameters.ForeshoreProfile); + } + + IObservable[] array = observables.ToArray(); + int expectedAffectedObjectCount = 1 + calculationsWithOutput.Length + calculationsWithForeshoreProfile.Length; + Assert.AreEqual(expectedAffectedObjectCount, array.Length); + CollectionAssert.Contains(array, failureMechanism.ForeshoreProfiles); + foreach (WaveImpactAsphaltCoverWaveConditionsCalculation calculation in calculationsWithForeshoreProfile) + { + Assert.IsNull(calculation.InputParameters.ForeshoreProfile); + CollectionAssert.Contains(array, calculation.InputParameters); + } + + foreach (ICalculation calculation in calculationsWithOutput) + { + Assert.IsFalse(calculation.HasOutput); + CollectionAssert.Contains(array, calculation); + } + } + + [Test] + public void RemoveForeshoreProfile_GrassCoverErosionOutwardsFailureMechanismNull_ThrowsArgumentNullException() + { + // Setup + ForeshoreProfile profile = new TestForeshoreProfile(); + + // Call + TestDelegate call = () => RiskeerDataSynchronizationService.RemoveForeshoreProfile((GrassCoverErosionOutwardsFailureMechanism) null, profile); + + // Assert + string paramName = Assert.Throws(call).ParamName; + Assert.AreEqual("failureMechanism", paramName); + } + + [Test] + public void RemoveForeshoreProfile_GrassCoverErosionOutwardsFailureMechanismProfileNull_ThrowsArgumentNullException() + { + // Setup + var failureMechanism = new GrassCoverErosionOutwardsFailureMechanism(); + + // Call + TestDelegate call = () => RiskeerDataSynchronizationService.RemoveForeshoreProfile(failureMechanism, null); + + // Assert + string paramName = Assert.Throws(call).ParamName; + Assert.AreEqual("profile", paramName); + } + + [Test] + public void RemoveForeshoreProfile_FullyConfiguredGrassCoverErosionOutwardsFailureMechanism_RemoveProfileAndClearDependentData() + { + // Setup + GrassCoverErosionOutwardsFailureMechanism failureMechanism = TestDataGenerator.GetGrassCoverErosionOutwardsFailureMechanismWithAllCalculationConfigurations(); + ForeshoreProfile profile = failureMechanism.ForeshoreProfiles[0]; + GrassCoverErosionOutwardsWaveConditionsCalculation[] calculationsWithForeshoreProfile = + failureMechanism.Calculations.Cast() + .Where(c => ReferenceEquals(c.InputParameters.ForeshoreProfile, profile)) + .ToArray(); + + GrassCoverErosionOutwardsWaveConditionsCalculation[] calculationsWithOutput = calculationsWithForeshoreProfile.Where(c => c.HasOutput).ToArray(); + + // Precondition + CollectionAssert.IsNotEmpty(calculationsWithForeshoreProfile); + + // Call + IEnumerable observables = RiskeerDataSynchronizationService.RemoveForeshoreProfile(failureMechanism, profile); + + // 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.ForeshoreProfiles, profile); + foreach (GrassCoverErosionOutwardsWaveConditionsCalculation calculation in calculationsWithForeshoreProfile) + { + Assert.IsNull(calculation.InputParameters.ForeshoreProfile); + } + + IObservable[] array = observables.ToArray(); + int expectedAffectedObjectCount = 1 + calculationsWithOutput.Length + calculationsWithForeshoreProfile.Length; + Assert.AreEqual(expectedAffectedObjectCount, array.Length); + CollectionAssert.Contains(array, failureMechanism.ForeshoreProfiles); + foreach (GrassCoverErosionOutwardsWaveConditionsCalculation calculation in calculationsWithForeshoreProfile) + { + Assert.IsNull(calculation.InputParameters.ForeshoreProfile); + CollectionAssert.Contains(array, calculation.InputParameters); + } + + foreach (ICalculation calculation in calculationsWithOutput) + { + Assert.IsFalse(calculation.HasOutput); + CollectionAssert.Contains(array, calculation); + } + } + + [Test] + public void RemoveForeshoreProfile_HeightStructuresFailureMechanismNull_ThrowsArgumentNullException() + { + // Setup + ForeshoreProfile profile = new TestForeshoreProfile(); + + // Call + TestDelegate call = () => RiskeerDataSynchronizationService.RemoveForeshoreProfile((HeightStructuresFailureMechanism) null, profile); + + // Assert + string paramName = Assert.Throws(call).ParamName; + Assert.AreEqual("failureMechanism", paramName); + } + + [Test] + public void RemoveForeshoreProfile_HeightStructuresFailureMechanismProfileNull_ThrowsArgumentNullException() + { + // Setup + var failureMechanism = new HeightStructuresFailureMechanism(); + + // Call + TestDelegate call = () => RiskeerDataSynchronizationService.RemoveForeshoreProfile(failureMechanism, null); + + // Assert + string paramName = Assert.Throws(call).ParamName; + Assert.AreEqual("profile", paramName); + } + + [Test] + public void RemoveForeshoreProfile_FullyConfiguredHeightStructuresFailureMechanism_RemoveProfileAndClearDependentData() + { + // Setup + HeightStructuresFailureMechanism failureMechanism = TestDataGenerator.GetHeightStructuresFailureMechanismWithAlLCalculationConfigurations(); + ForeshoreProfile profile = failureMechanism.ForeshoreProfiles[0]; + StructuresCalculation[] calculationsWithForeshoreProfile = + failureMechanism.Calculations + .Cast>() + .Where(c => ReferenceEquals(c.InputParameters.ForeshoreProfile, profile)) + .ToArray(); + + StructuresCalculation[] calculationsWithOutput = calculationsWithForeshoreProfile.Where(c => c.HasOutput).ToArray(); + + // Precondition + CollectionAssert.IsNotEmpty(calculationsWithForeshoreProfile); + + // Call + IEnumerable observables = RiskeerDataSynchronizationService.RemoveForeshoreProfile(failureMechanism, profile); + + // 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.ForeshoreProfiles, profile); + foreach (StructuresCalculation calculation in calculationsWithForeshoreProfile) + { + Assert.IsNull(calculation.InputParameters.ForeshoreProfile); + } + + IObservable[] array = observables.ToArray(); + int expectedAffectedObjectCount = 1 + calculationsWithOutput.Length + calculationsWithForeshoreProfile.Length; + Assert.AreEqual(expectedAffectedObjectCount, array.Length); + CollectionAssert.Contains(array, failureMechanism.ForeshoreProfiles); + foreach (StructuresCalculation calculation in calculationsWithForeshoreProfile) + { + Assert.IsNull(calculation.InputParameters.ForeshoreProfile); + CollectionAssert.Contains(array, calculation.InputParameters); + } + + foreach (ICalculation calculation in calculationsWithOutput) + { + Assert.IsFalse(calculation.HasOutput); + CollectionAssert.Contains(array, calculation); + } + } + + [Test] + public void RemoveForeshoreProfile_ClosingStructuresFailureMechanismNull_ThrowsArgumentNullException() + { + // Setup + ForeshoreProfile profile = new TestForeshoreProfile(); + + // Call + TestDelegate call = () => RiskeerDataSynchronizationService.RemoveForeshoreProfile((ClosingStructuresFailureMechanism) null, profile); + + // Assert + string paramName = Assert.Throws(call).ParamName; + Assert.AreEqual("failureMechanism", paramName); + } + + [Test] + public void RemoveForeshoreProfile_ClosingStructuresFailureMechanismProfileNull_ThrowsArgumentNullException() + { + // Setup + var failureMechanism = new ClosingStructuresFailureMechanism(); + + // Call + TestDelegate call = () => RiskeerDataSynchronizationService.RemoveForeshoreProfile(failureMechanism, null); + + // Assert + string paramName = Assert.Throws(call).ParamName; + Assert.AreEqual("profile", paramName); + } + + [Test] + public void RemoveForeshoreProfile_FullyConfiguredClosingStructuresFailureMechanism_RemoveProfileAndClearDependentData() + { + // Setup + ClosingStructuresFailureMechanism failureMechanism = TestDataGenerator.GetClosingStructuresFailureMechanismWithAllCalculationConfigurations(); + ForeshoreProfile profile = failureMechanism.ForeshoreProfiles[0]; + StructuresCalculation[] calculationsWithForeshoreProfile = + failureMechanism.Calculations + .Cast>() + .Where(c => ReferenceEquals(c.InputParameters.ForeshoreProfile, profile)) + .ToArray(); + + StructuresCalculation[] calculationsWithOutput = calculationsWithForeshoreProfile.Where(c => c.HasOutput).ToArray(); + + // Precondition + CollectionAssert.IsNotEmpty(calculationsWithForeshoreProfile); + + // Call + IEnumerable observables = RiskeerDataSynchronizationService.RemoveForeshoreProfile(failureMechanism, profile); + + // 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.ForeshoreProfiles, profile); + foreach (StructuresCalculation calculation in calculationsWithForeshoreProfile) + { + Assert.IsNull(calculation.InputParameters.ForeshoreProfile); + } + + IObservable[] array = observables.ToArray(); + int expectedAffectedObjectCount = 1 + calculationsWithOutput.Length + calculationsWithForeshoreProfile.Length; + Assert.AreEqual(expectedAffectedObjectCount, array.Length); + CollectionAssert.Contains(array, failureMechanism.ForeshoreProfiles); + foreach (StructuresCalculation calculation in calculationsWithForeshoreProfile) + { + Assert.IsNull(calculation.InputParameters.ForeshoreProfile); + CollectionAssert.Contains(array, calculation.InputParameters); + } + + foreach (ICalculation calculation in calculationsWithOutput) + { + Assert.IsFalse(calculation.HasOutput); + CollectionAssert.Contains(array, calculation); + } + } + + [Test] + public void RemoveForeshoreProfile_StabilityPointStructuresFailureMechanismNull_ThrowsArgumentNullException() + { + // Setup + ForeshoreProfile profile = new TestForeshoreProfile(); + + // Call + TestDelegate call = () => RiskeerDataSynchronizationService.RemoveForeshoreProfile((StabilityPointStructuresFailureMechanism) null, profile); + + // Assert + string paramName = Assert.Throws(call).ParamName; + Assert.AreEqual("failureMechanism", paramName); + } + + [Test] + public void RemoveForeshoreProfile_StabilityPointStructuresFailureMechanismProfileNull_ThrowsArgumentNullException() + { + // Setup + var failureMechanism = new StabilityPointStructuresFailureMechanism(); + + // Call + TestDelegate call = () => RiskeerDataSynchronizationService.RemoveForeshoreProfile(failureMechanism, null); + + // Assert + string paramName = Assert.Throws(call).ParamName; + Assert.AreEqual("profile", paramName); + } + + [Test] + public void RemoveForeshoreProfile_FullyConfiguredStabilityPointStructuresFailureMechanism_RemoveProfileAndClearDependentData() + { + // Setup + StabilityPointStructuresFailureMechanism failureMechanism = TestDataGenerator.GetStabilityPointStructuresFailureMechanismWithAllCalculationConfigurations(); + ForeshoreProfile profile = failureMechanism.ForeshoreProfiles[0]; + StructuresCalculation[] calculationsWithForeshoreProfile = + failureMechanism.Calculations + .Cast>() + .Where(c => ReferenceEquals(c.InputParameters.ForeshoreProfile, profile)) + .ToArray(); + + StructuresCalculation[] calculationsWithOutput = calculationsWithForeshoreProfile.Where(c => c.HasOutput).ToArray(); + + // Precondition + CollectionAssert.IsNotEmpty(calculationsWithForeshoreProfile); + + // Call + IEnumerable observables = RiskeerDataSynchronizationService.RemoveForeshoreProfile(failureMechanism, profile); + + // 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.ForeshoreProfiles, profile); + foreach (StructuresCalculation calculation in calculationsWithForeshoreProfile) + { + Assert.IsNull(calculation.InputParameters.ForeshoreProfile); + } + + IObservable[] array = observables.ToArray(); + int expectedAffectedObjectCount = 1 + calculationsWithOutput.Length + calculationsWithForeshoreProfile.Length; + Assert.AreEqual(expectedAffectedObjectCount, array.Length); + CollectionAssert.Contains(array, failureMechanism.ForeshoreProfiles); + foreach (StructuresCalculation calculation in calculationsWithForeshoreProfile) + { + Assert.IsNull(calculation.InputParameters.ForeshoreProfile); + CollectionAssert.Contains(array, calculation.InputParameters); + } + + foreach (ICalculation calculation in calculationsWithOutput) + { + Assert.IsFalse(calculation.HasOutput); + CollectionAssert.Contains(array, calculation); + } + } + + [Test] + public void RemoveAllForeshoreProfiles_CalculationsNull_ThrowsArgumentNullException() + { + // Call + TestDelegate call = () => RiskeerDataSynchronizationService.RemoveAllForeshoreProfiles(null, + new ForeshoreProfileCollection()); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("calculations", exception.ParamName); + } + + [Test] + public void RemoveAllForeshoreProfiles_ForeshoreProfilesNull_ThrowsArgumentNullException() + { + // Call + TestDelegate call = () => RiskeerDataSynchronizationService.RemoveAllForeshoreProfiles(Enumerable.Empty>(), + null); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("foreshoreProfiles", exception.ParamName); + } + + [Test] + public void RemoveAllForeshoreProfiles_FullyConfiguredClosingStructuresFailureMechanism_RemovesAllForeshoreProfilesAndDependentData() + { + // Setup + var foreshoreProfile = new TestForeshoreProfile(); + var foreshoreProfiles = new ForeshoreProfileCollection(); + foreshoreProfiles.AddRange(new[] + { + foreshoreProfile + }, "path"); + + TestCalculationWithForeshoreProfile calculationWithForeshoreProfileAndOutput = + TestCalculationWithForeshoreProfile.CreateCalculationWithOutput(foreshoreProfile); + TestCalculationWithForeshoreProfile calculationWithForeshoreProfile = + TestCalculationWithForeshoreProfile.CreateCalculationWithoutOutput(foreshoreProfile); + TestCalculationWithForeshoreProfile calculationWithoutForeshoreProfile = + TestCalculationWithForeshoreProfile.CreateDefaultCalculation(); + + var calculations = new List> + { + calculationWithForeshoreProfileAndOutput, + calculationWithForeshoreProfile, + calculationWithoutForeshoreProfile + }; + + TestCalculationWithForeshoreProfile[] calculationsWithForeshoreProfile = + { + calculationWithForeshoreProfileAndOutput, + calculationWithForeshoreProfile + }; + + // Call + IEnumerable affectedObjects = RiskeerDataSynchronizationService.RemoveAllForeshoreProfiles(calculations, foreshoreProfiles); + + // 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(foreshoreProfiles); + Assert.IsFalse(calculationWithForeshoreProfileAndOutput.HasOutput); + Assert.IsTrue(calculationsWithForeshoreProfile.All(calc => calc.InputParameters.ForeshoreProfile == null)); + + IEnumerable expectedAffectedObjects = + calculationsWithForeshoreProfile.Select(calc => calc.InputParameters) + .Concat(new IObservable[] + { + foreshoreProfiles, + calculationWithForeshoreProfileAndOutput + }); + CollectionAssert.AreEquivalent(expectedAffectedObjects, affectedObjects); + } + + [Test] + public void RemoveDikeProfile_GrassCoverErosionInwardsFailureMechanismNull_ThrowsArgumentNullException() + { + // Setup + DikeProfile profile = DikeProfileTestFactory.CreateDikeProfile(); + + // Call + TestDelegate call = () => RiskeerDataSynchronizationService.RemoveDikeProfile(null, profile); + + // Assert + string paramName = Assert.Throws(call).ParamName; + Assert.AreEqual("failureMechanism", paramName); + } + + [Test] + public void RemoveDikeProfile_GrassCoverErosionInwardsFailureMechanismProfileNull_ThrowsArgumentNullException() + { + // Setup + var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); + + // Call + TestDelegate call = () => RiskeerDataSynchronizationService.RemoveDikeProfile(failureMechanism, null); + + // Assert + string paramName = Assert.Throws(call).ParamName; + Assert.AreEqual("profile", paramName); + } + + [Test] + public void RemoveDikeProfile_FullyConfiguredGrassCoverErosionInwardsFailureMechanism_RemoveProfileAndClearDependentData() + { + // Setup + GrassCoverErosionInwardsFailureMechanism failureMechanism = TestDataGenerator.GetGrassCoverErosionInwardsFailureMechanismWithAllCalculationConfigurations(); + DikeProfile profile = failureMechanism.DikeProfiles[0]; + GrassCoverErosionInwardsCalculation[] calculations = failureMechanism.Calculations.Cast() + .Where(c => ReferenceEquals(c.InputParameters.DikeProfile, profile)) + .ToArray(); + int originalNumberOfSectionResultAssignments = failureMechanism.SectionResults.Count(sr => sr.Calculation != null); + GrassCoverErosionInwardsFailureMechanismSectionResult[] sectionResults = failureMechanism.SectionResults + .Where(sr => calculations.Contains(sr.Calculation)) + .ToArray(); + + // Precondition + CollectionAssert.IsNotEmpty(calculations); + CollectionAssert.IsNotEmpty(sectionResults); + + // Call + IEnumerable observables = RiskeerDataSynchronizationService.RemoveDikeProfile(failureMechanism, profile); + + // 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.DikeProfiles, profile); + foreach (GrassCoverErosionInwardsCalculation calculation in calculations) + { + Assert.IsNull(calculation.InputParameters.DikeProfile); + } + + foreach (GrassCoverErosionInwardsFailureMechanismSectionResult sectionResult in sectionResults) + { + Assert.IsNull(sectionResult.Calculation); + } + + IObservable[] array = observables.ToArray(); + Assert.AreEqual(1 + (calculations.Length * 2) + sectionResults.Length, array.Length); + CollectionAssert.Contains(array, failureMechanism.DikeProfiles); + foreach (GrassCoverErosionInwardsCalculation calculation in calculations) + { + CollectionAssert.Contains(array, calculation); + CollectionAssert.Contains(array, calculation.InputParameters); + Assert.IsFalse(calculation.HasOutput); + } + + foreach (GrassCoverErosionInwardsFailureMechanismSectionResult sectionResult in sectionResults) + { + CollectionAssert.Contains(array, sectionResult); + } + + Assert.AreEqual(originalNumberOfSectionResultAssignments - sectionResults.Length, failureMechanism.SectionResults.Count(sr => sr.Calculation != null), + "Other section results with a different calculation/dikeprofile should still have their association."); + } + + private static void AssertChangedObjects(ClearResults results, AssessmentSection assessmentSection) + { + IObservable[] changedObjects = results.ChangedObjects.ToArray(); + Assert.AreEqual(59, changedObjects.Length); + + PipingFailureMechanism pipingFailureMechanism = assessmentSection.Piping; + CollectionAssert.Contains(changedObjects, pipingFailureMechanism); + CollectionAssert.Contains(changedObjects, pipingFailureMechanism.SectionResults); + CollectionAssert.Contains(changedObjects, pipingFailureMechanism.CalculationsGroup); + CollectionAssert.Contains(changedObjects, pipingFailureMechanism.StochasticSoilModels); + CollectionAssert.Contains(changedObjects, pipingFailureMechanism.SurfaceLines); + + GrassCoverErosionInwardsFailureMechanism grassCoverErosionInwardsFailureMechanism = assessmentSection.GrassCoverErosionInwards; + CollectionAssert.Contains(changedObjects, grassCoverErosionInwardsFailureMechanism); + CollectionAssert.Contains(changedObjects, grassCoverErosionInwardsFailureMechanism.SectionResults); + CollectionAssert.Contains(changedObjects, grassCoverErosionInwardsFailureMechanism.CalculationsGroup); + CollectionAssert.Contains(changedObjects, grassCoverErosionInwardsFailureMechanism.DikeProfiles); + + GrassCoverErosionOutwardsFailureMechanism grassCoverErosionOutwardsFailureMechanism = assessmentSection.GrassCoverErosionOutwards; + CollectionAssert.Contains(changedObjects, grassCoverErosionOutwardsFailureMechanism); + CollectionAssert.Contains(changedObjects, grassCoverErosionOutwardsFailureMechanism.SectionResults); + CollectionAssert.Contains(changedObjects, grassCoverErosionOutwardsFailureMechanism.WaveConditionsCalculationGroup); + CollectionAssert.Contains(changedObjects, grassCoverErosionOutwardsFailureMechanism.ForeshoreProfiles); + + WaveImpactAsphaltCoverFailureMechanism waveImpactAsphaltCoverFailureMechanism = assessmentSection.WaveImpactAsphaltCover; + CollectionAssert.Contains(changedObjects, waveImpactAsphaltCoverFailureMechanism); + CollectionAssert.Contains(changedObjects, waveImpactAsphaltCoverFailureMechanism.SectionResults); + CollectionAssert.Contains(changedObjects, waveImpactAsphaltCoverFailureMechanism.WaveConditionsCalculationGroup); + CollectionAssert.Contains(changedObjects, waveImpactAsphaltCoverFailureMechanism.ForeshoreProfiles); + + StabilityStoneCoverFailureMechanism stabilityStoneCoverFailureMechanism = assessmentSection.StabilityStoneCover; + CollectionAssert.Contains(changedObjects, stabilityStoneCoverFailureMechanism); + CollectionAssert.Contains(changedObjects, stabilityStoneCoverFailureMechanism.SectionResults); + CollectionAssert.Contains(changedObjects, stabilityStoneCoverFailureMechanism.WaveConditionsCalculationGroup); + CollectionAssert.Contains(changedObjects, stabilityStoneCoverFailureMechanism.ForeshoreProfiles); + + ClosingStructuresFailureMechanism closingStructuresFailureMechanism = assessmentSection.ClosingStructures; + CollectionAssert.Contains(changedObjects, closingStructuresFailureMechanism); + CollectionAssert.Contains(changedObjects, closingStructuresFailureMechanism.SectionResults); + CollectionAssert.Contains(changedObjects, closingStructuresFailureMechanism.CalculationsGroup); + CollectionAssert.Contains(changedObjects, closingStructuresFailureMechanism.ForeshoreProfiles); + CollectionAssert.Contains(changedObjects, closingStructuresFailureMechanism.ClosingStructures); + + HeightStructuresFailureMechanism heightStructuresFailureMechanism = assessmentSection.HeightStructures; + CollectionAssert.Contains(changedObjects, heightStructuresFailureMechanism); + CollectionAssert.Contains(changedObjects, heightStructuresFailureMechanism.SectionResults); + CollectionAssert.Contains(changedObjects, heightStructuresFailureMechanism.CalculationsGroup); + CollectionAssert.Contains(changedObjects, heightStructuresFailureMechanism.ForeshoreProfiles); + CollectionAssert.Contains(changedObjects, heightStructuresFailureMechanism.HeightStructures); + + StabilityPointStructuresFailureMechanism stabilityPointStructuresFailureMechanism = assessmentSection.StabilityPointStructures; + CollectionAssert.Contains(changedObjects, stabilityPointStructuresFailureMechanism); + CollectionAssert.Contains(changedObjects, stabilityPointStructuresFailureMechanism.SectionResults); + CollectionAssert.Contains(changedObjects, stabilityPointStructuresFailureMechanism.CalculationsGroup); + CollectionAssert.Contains(changedObjects, stabilityPointStructuresFailureMechanism.ForeshoreProfiles); + CollectionAssert.Contains(changedObjects, stabilityPointStructuresFailureMechanism.StabilityPointStructures); + + DuneErosionFailureMechanism duneErosionFailureMechanism = assessmentSection.DuneErosion; + CollectionAssert.Contains(changedObjects, duneErosionFailureMechanism); + CollectionAssert.Contains(changedObjects, duneErosionFailureMechanism.SectionResults); + + MacroStabilityInwardsFailureMechanism macroStabilityInwardsFailureMechanism = assessmentSection.MacroStabilityInwards; + CollectionAssert.Contains(changedObjects, macroStabilityInwardsFailureMechanism); + CollectionAssert.Contains(changedObjects, macroStabilityInwardsFailureMechanism.SectionResults); + CollectionAssert.Contains(changedObjects, macroStabilityInwardsFailureMechanism.CalculationsGroup); + CollectionAssert.Contains(changedObjects, macroStabilityInwardsFailureMechanism.StochasticSoilModels); + CollectionAssert.Contains(changedObjects, macroStabilityInwardsFailureMechanism.SurfaceLines); + + MacroStabilityOutwardsFailureMechanism macroStabilityOutwardsFailureMechanism = assessmentSection.MacroStabilityOutwards; + CollectionAssert.Contains(changedObjects, macroStabilityOutwardsFailureMechanism); + CollectionAssert.Contains(changedObjects, macroStabilityOutwardsFailureMechanism.SectionResults); + + MicrostabilityFailureMechanism microstabilityFailureMechanism = assessmentSection.Microstability; + CollectionAssert.Contains(changedObjects, microstabilityFailureMechanism); + CollectionAssert.Contains(changedObjects, microstabilityFailureMechanism.SectionResults); + + WaterPressureAsphaltCoverFailureMechanism waterPressureAsphaltCoverFailureMechanism = assessmentSection.WaterPressureAsphaltCover; + CollectionAssert.Contains(changedObjects, waterPressureAsphaltCoverFailureMechanism); + CollectionAssert.Contains(changedObjects, waterPressureAsphaltCoverFailureMechanism.SectionResults); + + GrassCoverSlipOffOutwardsFailureMechanism grassCoverSlipOffOutwardsFailureMechanism = assessmentSection.GrassCoverSlipOffOutwards; + CollectionAssert.Contains(changedObjects, grassCoverSlipOffOutwardsFailureMechanism); + CollectionAssert.Contains(changedObjects, grassCoverSlipOffOutwardsFailureMechanism.SectionResults); + + GrassCoverSlipOffInwardsFailureMechanism grassCoverSlipOffInwardsFailureMechanism = assessmentSection.GrassCoverSlipOffInwards; + CollectionAssert.Contains(changedObjects, grassCoverSlipOffInwardsFailureMechanism); + CollectionAssert.Contains(changedObjects, grassCoverSlipOffInwardsFailureMechanism.SectionResults); + + StrengthStabilityLengthwiseConstructionFailureMechanism stabilityLengthwiseConstructionFailureMechanism = assessmentSection.StrengthStabilityLengthwiseConstruction; + CollectionAssert.Contains(changedObjects, stabilityLengthwiseConstructionFailureMechanism); + CollectionAssert.Contains(changedObjects, stabilityLengthwiseConstructionFailureMechanism.SectionResults); + + PipingStructureFailureMechanism pipingStructureFailureMechanism = assessmentSection.PipingStructure; + CollectionAssert.Contains(changedObjects, pipingStructureFailureMechanism); + CollectionAssert.Contains(changedObjects, pipingStructureFailureMechanism.SectionResults); + + TechnicalInnovationFailureMechanism technicalInnovationFailureMechanism = assessmentSection.TechnicalInnovation; + CollectionAssert.Contains(changedObjects, technicalInnovationFailureMechanism); + CollectionAssert.Contains(changedObjects, technicalInnovationFailureMechanism.SectionResults); + } + + private static IEnumerable GetExpectedRemovedObjectsWhenClearingReferenceLine(AssessmentSection assessmentSection) + { + var expectedRemovedObjects = new List(); + expectedRemovedObjects.AddRange(GetExpectedRemovedObjectsWhenClearingReferenceLine(assessmentSection.Piping)); + expectedRemovedObjects.AddRange(GetExpectedRemovedObjectsWhenClearingReferenceLine(assessmentSection.GrassCoverErosionInwards)); + expectedRemovedObjects.AddRange(GetExpectedRemovedObjectsWhenClearingReferenceLine(assessmentSection.MacroStabilityInwards)); + expectedRemovedObjects.AddRange(GetExpectedRemovedObjectsWhenClearingReferenceLine(assessmentSection.MacroStabilityOutwards)); + expectedRemovedObjects.AddRange(GetExpectedRemovedObjectsWhenClearingReferenceLine(assessmentSection.Microstability)); + expectedRemovedObjects.AddRange(GetExpectedRemovedObjectsWhenClearingReferenceLine(assessmentSection.StabilityStoneCover)); + expectedRemovedObjects.AddRange(GetExpectedRemovedObjectsWhenClearingReferenceLine(assessmentSection.WaveImpactAsphaltCover)); + expectedRemovedObjects.AddRange(GetExpectedRemovedObjectsWhenClearingReferenceLine(assessmentSection.WaterPressureAsphaltCover)); + expectedRemovedObjects.AddRange(GetExpectedRemovedObjectsWhenClearingReferenceLine(assessmentSection.GrassCoverErosionOutwards)); + expectedRemovedObjects.AddRange(GetExpectedRemovedObjectsWhenClearingReferenceLine(assessmentSection.GrassCoverSlipOffOutwards)); + expectedRemovedObjects.AddRange(GetExpectedRemovedObjectsWhenClearingReferenceLine(assessmentSection.GrassCoverSlipOffInwards)); + expectedRemovedObjects.AddRange(GetExpectedRemovedObjectsWhenClearingReferenceLine(assessmentSection.HeightStructures)); + expectedRemovedObjects.AddRange(GetExpectedRemovedObjectsWhenClearingReferenceLine(assessmentSection.ClosingStructures)); + expectedRemovedObjects.AddRange(GetExpectedRemovedObjectsWhenClearingReferenceLine(assessmentSection.PipingStructure)); + expectedRemovedObjects.AddRange(GetExpectedRemovedObjectsWhenClearingReferenceLine(assessmentSection.StabilityPointStructures)); + expectedRemovedObjects.AddRange(GetExpectedRemovedObjectsWhenClearingReferenceLine(assessmentSection.StrengthStabilityLengthwiseConstruction)); + expectedRemovedObjects.AddRange(GetExpectedRemovedObjectsWhenClearingReferenceLine(assessmentSection.DuneErosion)); + expectedRemovedObjects.AddRange(GetExpectedRemovedObjectsWhenClearingReferenceLine(assessmentSection.TechnicalInnovation)); + return expectedRemovedObjects; + } + + private static IEnumerable GetExpectedRemovedObjectsWhenClearingReferenceLine(PipingFailureMechanism failureMechanism) + { + foreach (object failureMechanismObject in GetExpectedRemovedObjectsWhenClearingReferenceLine(failureMechanism)) + { + yield return failureMechanismObject; + } + + foreach (ICalculationBase calculationBase in failureMechanism.CalculationsGroup.GetAllChildrenRecursive()) + { + yield return calculationBase; + } + + foreach (PipingStochasticSoilModel stochasticSoilModel in failureMechanism.StochasticSoilModels) + { + yield return stochasticSoilModel; + } + + foreach (PipingSurfaceLine surfaceLine in failureMechanism.SurfaceLines) + { + yield return surfaceLine; + } + } + + private static IEnumerable GetExpectedRemovedObjectsWhenClearingReferenceLine(MacroStabilityInwardsFailureMechanism failureMechanism) + { + foreach (object failureMechanismObject in GetExpectedRemovedObjectsWhenClearingReferenceLine(failureMechanism)) + { + yield return failureMechanismObject; + } + + foreach (ICalculationBase calculationBase in failureMechanism.CalculationsGroup.GetAllChildrenRecursive()) + { + yield return calculationBase; + } + + foreach (MacroStabilityInwardsStochasticSoilModel stochasticSoilModel in failureMechanism.StochasticSoilModels) + { + yield return stochasticSoilModel; + } + + foreach (MacroStabilityInwardsSurfaceLine surfaceLine in failureMechanism.SurfaceLines) + { + yield return surfaceLine; + } + } + + private static IEnumerable GetExpectedRemovedObjectsWhenClearingReferenceLine(GrassCoverErosionInwardsFailureMechanism failureMechanism) + { + foreach (object failureMechanismObject in GetExpectedRemovedObjectsWhenClearingReferenceLine(failureMechanism)) + { + yield return failureMechanismObject; + } + + foreach (ICalculationBase calculationBase in failureMechanism.CalculationsGroup.GetAllChildrenRecursive()) + { + yield return calculationBase; + } + + foreach (DikeProfile profile in failureMechanism.DikeProfiles) + { + yield return profile; + } + } + + private static IEnumerable GetExpectedRemovedObjectsWhenClearingReferenceLine(StabilityStoneCoverFailureMechanism failureMechanism) + { + foreach (object failureMechanismObject in GetExpectedRemovedObjectsWhenClearingReferenceLine(failureMechanism)) + { + yield return failureMechanismObject; + } + + foreach (ICalculationBase calculationBase in failureMechanism.WaveConditionsCalculationGroup.GetAllChildrenRecursive()) + { + yield return calculationBase; + } + + foreach (ForeshoreProfile profile in failureMechanism.ForeshoreProfiles) + { + yield return profile; + } + } + + private static IEnumerable GetExpectedRemovedObjectsWhenClearingReferenceLine(WaveImpactAsphaltCoverFailureMechanism failureMechanism) + { + foreach (object failureMechanismObject in GetExpectedRemovedObjectsWhenClearingReferenceLine(failureMechanism)) + { + yield return failureMechanismObject; + } + + foreach (ICalculationBase calculationBase in failureMechanism.WaveConditionsCalculationGroup.GetAllChildrenRecursive()) + { + yield return calculationBase; + } + + foreach (ForeshoreProfile profile in failureMechanism.ForeshoreProfiles) + { + yield return profile; + } + } + + private static IEnumerable GetExpectedRemovedObjectsWhenClearingReferenceLine(GrassCoverErosionOutwardsFailureMechanism failureMechanism) + { + foreach (object failureMechanismObject in GetExpectedRemovedObjectsWhenClearingReferenceLine(failureMechanism)) + { + yield return failureMechanismObject; + } + + foreach (ICalculationBase calculationBase in failureMechanism.WaveConditionsCalculationGroup.GetAllChildrenRecursive()) + { + yield return calculationBase; + } + + foreach (ForeshoreProfile profile in failureMechanism.ForeshoreProfiles) + { + yield return profile; + } + } + + private static IEnumerable GetExpectedRemovedObjectsWhenClearingReferenceLine(HeightStructuresFailureMechanism failureMechanism) + { + foreach (object failureMechanismObject in GetExpectedRemovedObjectsWhenClearingReferenceLine(failureMechanism)) + { + yield return failureMechanismObject; + } + + foreach (ICalculationBase calculationBase in failureMechanism.CalculationsGroup.GetAllChildrenRecursive()) + { + yield return calculationBase; + } + + foreach (ForeshoreProfile profile in failureMechanism.ForeshoreProfiles) + { + yield return profile; + } + + foreach (HeightStructure structure in failureMechanism.HeightStructures) + { + yield return structure; + } + } + + private static IEnumerable GetExpectedRemovedObjectsWhenClearingReferenceLine(ClosingStructuresFailureMechanism failureMechanism) + { + foreach (object failureMechanismObject in GetExpectedRemovedObjectsWhenClearingReferenceLine(failureMechanism)) + { + yield return failureMechanismObject; + } + + foreach (ICalculationBase calculationBase in failureMechanism.CalculationsGroup.GetAllChildrenRecursive()) + { + yield return calculationBase; + } + + foreach (ForeshoreProfile profile in failureMechanism.ForeshoreProfiles) + { + yield return profile; + } + + foreach (ClosingStructure structure in failureMechanism.ClosingStructures) + { + yield return structure; + } + } + + private static IEnumerable GetExpectedRemovedObjectsWhenClearingReferenceLine(StabilityPointStructuresFailureMechanism failureMechanism) + { + foreach (object failureMechanismObject in GetExpectedRemovedObjectsWhenClearingReferenceLine(failureMechanism)) + { + yield return failureMechanismObject; + } + + foreach (ICalculationBase calculationBase in failureMechanism.CalculationsGroup.GetAllChildrenRecursive()) + { + yield return calculationBase; + } + + foreach (ForeshoreProfile profile in failureMechanism.ForeshoreProfiles) + { + yield return profile; + } + + foreach (StabilityPointStructure structure in failureMechanism.StabilityPointStructures) + { + yield return structure; + } + } + + private static IEnumerable GetExpectedRemovedObjectsWhenClearingReferenceLine(T failureMechanism) + where T : IFailureMechanism, IHasSectionResults + { + foreach (FailureMechanismSection section in failureMechanism.Sections) + { + yield return section; + } + + foreach (FailureMechanismSectionResult sectionResult in failureMechanism.SectionResults) + { + yield return sectionResult; + } + } + + private static void ConfigureGrassCoverErosionOutwardsFailureMechanism(GrassCoverErosionOutwardsFailureMechanism failureMechanism, bool hasOutput) + { + failureMechanism.SetHydraulicBoundaryLocationCalculations(new[] + { + new TestHydraulicBoundaryLocation() + }); + + if (hasOutput) + { + failureMechanism.WaterLevelCalculationsForMechanismSpecificFactorizedSignalingNorm.First().Output = new TestHydraulicBoundaryLocationCalculationOutput(); + failureMechanism.WaterLevelCalculationsForMechanismSpecificSignalingNorm.First().Output = new TestHydraulicBoundaryLocationCalculationOutput(); + failureMechanism.WaterLevelCalculationsForMechanismSpecificLowerLimitNorm.First().Output = new TestHydraulicBoundaryLocationCalculationOutput(); + failureMechanism.WaveHeightCalculationsForMechanismSpecificFactorizedSignalingNorm.First().Output = new TestHydraulicBoundaryLocationCalculationOutput(); + failureMechanism.WaveHeightCalculationsForMechanismSpecificSignalingNorm.First().Output = new TestHydraulicBoundaryLocationCalculationOutput(); + failureMechanism.WaveHeightCalculationsForMechanismSpecificLowerLimitNorm.First().Output = new TestHydraulicBoundaryLocationCalculationOutput(); + } + } + + private static void ConfigureDuneErosionFailureMechanism(DuneErosionFailureMechanism failureMechanism, bool hasOutput) + { + failureMechanism.SetDuneLocations(new[] + { + new TestDuneLocation() + }); + + if (hasOutput) + { + failureMechanism.CalculationsForMechanismSpecificFactorizedSignalingNorm.First().Output = new TestDuneLocationCalculationOutput(); + failureMechanism.CalculationsForMechanismSpecificSignalingNorm.First().Output = new TestDuneLocationCalculationOutput(); + failureMechanism.CalculationsForMechanismSpecificLowerLimitNorm.First().Output = new TestDuneLocationCalculationOutput(); + failureMechanism.CalculationsForLowerLimitNorm.First().Output = new TestDuneLocationCalculationOutput(); + failureMechanism.CalculationsForFactorizedLowerLimitNorm.First().Output = new TestDuneLocationCalculationOutput(); + } + } + } +} \ No newline at end of file Index: Riskeer/Integration/test/Riskeer.Integration.TestUtil/TestDataGenerator.cs =================================================================== diff -u -r86594ccd7329d320872573a1d066fe18959d3cea -r1ceb376282c1b8c7efc172811cbca4993693e58e --- Riskeer/Integration/test/Riskeer.Integration.TestUtil/TestDataGenerator.cs (.../TestDataGenerator.cs) (revision 86594ccd7329d320872573a1d066fe18959d3cea) +++ Riskeer/Integration/test/Riskeer.Integration.TestUtil/TestDataGenerator.cs (.../TestDataGenerator.cs) (revision 1ceb376282c1b8c7efc172811cbca4993693e58e) @@ -125,7 +125,7 @@ AssessmentSectionComposition composition = AssessmentSectionComposition.Dike) { AssessmentSection assessmentSection = GetAssessmentSectionWithAllCalculationConfigurations(composition); - RingtoetsDataSynchronizationService.ClearHydraulicBoundaryLocationCalculationOutput(assessmentSection); + RiskeerDataSynchronizationService.ClearHydraulicBoundaryLocationCalculationOutput(assessmentSection); return assessmentSection; } @@ -141,7 +141,7 @@ AssessmentSectionComposition composition = AssessmentSectionComposition.Dike) { AssessmentSection assessmentSection = GetAssessmentSectionWithAllCalculationConfigurations(composition); - RingtoetsDataSynchronizationService.ClearFailureMechanismCalculationOutputs(assessmentSection); + RiskeerDataSynchronizationService.ClearFailureMechanismCalculationOutputs(assessmentSection); return assessmentSection; }