Index: Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/Handlers/AssessmentSectionCompositionChangeHandlerTest.cs =================================================================== diff -u -r817156ca32d96c4e7df9d37a86faca94f24798f1 -r87e9fb044b1fd8f4ed4c31f430839e8ff67d7b6b --- Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/Handlers/AssessmentSectionCompositionChangeHandlerTest.cs (.../AssessmentSectionCompositionChangeHandlerTest.cs) (revision 817156ca32d96c4e7df9d37a86faca94f24798f1) +++ Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/Handlers/AssessmentSectionCompositionChangeHandlerTest.cs (.../AssessmentSectionCompositionChangeHandlerTest.cs) (revision 87e9fb044b1fd8f4ed4c31f430839e8ff67d7b6b) @@ -183,9 +183,10 @@ // Precondition Assert.AreNotEqual(assessmentSection.Composition, newComposition); - IEnumerable notAffectedObjects = GetDuneIrrelevantFailureMechanisms(assessmentSection) + IEnumerable unaffectedObjects = GetDuneIrrelevantFailureMechanisms(assessmentSection) .SelectMany(fm => fm.Calculations) - .Where(calc => calc.HasOutput); + .Where(calc => calc.HasOutput) + .ToList(); IObservable[] expectedAffectedObjects = new IObservable[] { @@ -213,22 +214,11 @@ Assert.AreEqual(newComposition, assessmentSection.Composition); // Assert - // What should NOT be deleted when changing: - // - The Hydraulic Boundary location output defined at assessment section level - // - Calculation output related to wave impact asphalt cover - // - Calculation output related stability stone cover - Assert.IsTrue(GetDuneRelevantFailureMechanisms(assessmentSection).SelectMany(fm => fm.Calculations) - .All(calc => !calc.HasOutput)); - - CollectionAssert.AreEquivalent(notAffectedObjects, GetDuneIrrelevantFailureMechanisms(assessmentSection) - .SelectMany(fm => fm.Calculations) - .Where(calc => calc.HasOutput)); - + AssertCorrectOutputClearedWhenCompositionDune(unaffectedObjects, assessmentSection); CollectionAssert.AreEquivalent(expectedAffectedObjects, affectedObjects); foreach (HydraulicBoundaryLocation location in assessmentSection.GrassCoverErosionOutwards.HydraulicBoundaryLocations) { - // Sufficient to evaluate if the output is null or not Assert.IsNull(location.WaveHeightOutput); Assert.IsNull(location.DesignWaterLevelOutput); } @@ -256,9 +246,10 @@ // Precondition Assert.AreNotEqual(assessmentSection.Composition, newComposition); - var expectedNotAffectedObjects = assessmentSection.GetFailureMechanisms() - .SelectMany(fm => fm.Calculations) - .Where(calc => calc.HasOutput); + var expectedUnaffectedObjects = assessmentSection.GetFailureMechanisms() + .SelectMany(fm => fm.Calculations) + .Where(calc => calc.HasOutput) + .ToList(); IObservable[] expectedAffectedObjects = new IObservable[] { @@ -282,17 +273,10 @@ Assert.AreEqual(newComposition, assessmentSection.Composition); CollectionAssert.AreEquivalent(expectedAffectedObjects, affectedObjects); + AssertOutputNotCleared(expectedUnaffectedObjects, assessmentSection.GetFailureMechanisms()); - // The calculations within the failure mechanisms should not have been deleted in this scenario, - // except for the calculated hydraulic boundary location output for the dune erosion failure mechanism. - CollectionAssert.AreEquivalent(expectedNotAffectedObjects, assessmentSection.GetFailureMechanisms() - .SelectMany(fm => fm.Calculations) - .Where(calc => calc.HasOutput)); - foreach (HydraulicBoundaryLocation location in assessmentSection.GrassCoverErosionOutwards.HydraulicBoundaryLocations) { - // Sufficient to evaluate if the output is null or not. - // Note: could also be replaced with a LINQ query Assert.IsNotNull(location.WaveHeightOutput); Assert.IsNotNull(location.DesignWaterLevelOutput); } @@ -422,7 +406,8 @@ IEnumerable notAffectedObjects = GetDuneIrrelevantFailureMechanisms(assessmentSection) .SelectMany(fm => fm.Calculations) - .Where(calc => calc.HasOutput); + .Where(calc => calc.HasOutput) + .ToList(); IObservable[] expectedAffectedObjects = new IObservable[] { @@ -443,15 +428,7 @@ Assert.AreEqual(newComposition, assessmentSection.Composition); // Assert - // What should NOT be deleted when changing: - // - The Hydraulic Boundary location output defined at assessment section level - // - Calculation output related to wave impact asphalt cover - // - Calculation output related stability stone cover - Assert.IsTrue(GetDuneRelevantFailureMechanisms(assessmentSection).SelectMany(fm => fm.Calculations) - .All(calc => !calc.HasOutput)); - CollectionAssert.AreEquivalent(notAffectedObjects, GetDuneIrrelevantFailureMechanisms(assessmentSection).SelectMany(fm => fm.Calculations) - .Where(calc => calc.HasOutput)); - + AssertCorrectOutputClearedWhenCompositionDune(notAffectedObjects, assessmentSection); CollectionAssert.AreEquivalent(expectedAffectedObjects, affectedObjects); } @@ -473,9 +450,10 @@ || loc.WaveHeightOutput != null)); CollectionAssert.IsEmpty(assessmentSection.DuneErosion.DuneLocations.Where(dl => dl.Output != null)); - var expectedNotAffectedObjects = assessmentSection.GetFailureMechanisms() - .SelectMany(fm => fm.Calculations) - .Where(calc => calc.HasOutput); + var expectedUnaffectedObjects = assessmentSection.GetFailureMechanisms() + .SelectMany(fm => fm.Calculations) + .Where(calc => calc.HasOutput) + .ToList(); IObservable[] expectedAffectedObjects = new[] { @@ -489,26 +467,50 @@ // Assert Assert.AreEqual(newComposition, assessmentSection.Composition); + AssertOutputNotCleared(expectedUnaffectedObjects, assessmentSection.GetFailureMechanisms()); - // The calculations within the failure mechanisms should not have been deleted in this scenario, - CollectionAssert.AreEquivalent(expectedNotAffectedObjects, assessmentSection.GetFailureMechanisms() - .SelectMany(fm => fm.Calculations) - .Where(calc => calc.HasOutput)); - CollectionAssert.AreEquivalent(expectedAffectedObjects, affectedObjects); } + /// + /// Asserts whether the expected unaffected objects retain their outputs when cleared. + /// + /// The list of objects that should not have been affected. + /// The failure mechanisms to assert. + private static void AssertOutputNotCleared(IEnumerable expectedUnaffectedObjects, IEnumerable failureMechanisms) + { + CollectionAssert.AreEquivalent(expectedUnaffectedObjects, + failureMechanisms.SelectMany(fm => fm.Calculations) + .Where(calc => calc.HasOutput), + "The calculation output within the failure mechanisms should not have been deleted in this scenario"); + } + + /// + /// Asserts whether the correct failure mechanism outputs are cleared when the + /// changes to . + /// + /// The objects that should not have been affected. + /// The assessment section to assert. + private static void AssertCorrectOutputClearedWhenCompositionDune(IEnumerable unaffectedObjects, IAssessmentSection assessmentSection) + { + Assert.IsTrue(GetDuneRelevantFailureMechanisms(assessmentSection).SelectMany(fm => fm.Calculations) + .All(calc => !calc.HasOutput)); + + AssertOutputNotCleared(unaffectedObjects, GetDuneIrrelevantFailureMechanisms(assessmentSection)); + } + #region LinQ queries for expectancies /// - /// Function retrieves the failure mechanisms that should be cleared when the - /// AssessmentSectionComposition changes to Dunes. + /// Retrieves the failure mechanisms that should be cleared when the + /// changes to Dunes. /// - /// - /// A collection of objects that are cleared when changing the assessmentsectioncomposition to dunes. + /// The assessment section to retrieve the failure mechanisms from. + /// A collection of affected failure mechanisms when changing to + /// . private static IEnumerable GetDuneRelevantFailureMechanisms(IAssessmentSection assessmentSection) { - var affectedObjects = new List(); + var relevantFailureMechanisms = new List(); foreach (IFailureMechanism failureMechanism in assessmentSection.GetFailureMechanisms()) { @@ -521,44 +523,45 @@ if (pipingFailureMechanism != null) { - affectedObjects.Add(pipingFailureMechanism); + relevantFailureMechanisms.Add(pipingFailureMechanism); } if (grassCoverErosionInwardsFailureMechanism != null) { - affectedObjects.Add(grassCoverErosionInwardsFailureMechanism); + relevantFailureMechanisms.Add(grassCoverErosionInwardsFailureMechanism); } if (grassCoverErosionOutwardsFailureMechanism != null) { - affectedObjects.Add(grassCoverErosionOutwardsFailureMechanism); + relevantFailureMechanisms.Add(grassCoverErosionOutwardsFailureMechanism); } if (heightStructuresFailureMechanism != null) { - affectedObjects.Add(heightStructuresFailureMechanism); + relevantFailureMechanisms.Add(heightStructuresFailureMechanism); } if (closingStructuresFailureMechanism != null) { - affectedObjects.Add(closingStructuresFailureMechanism); + relevantFailureMechanisms.Add(closingStructuresFailureMechanism); } if (stabilityPointStructuresFailureMechanism != null) { - affectedObjects.Add(stabilityPointStructuresFailureMechanism); + relevantFailureMechanisms.Add(stabilityPointStructuresFailureMechanism); } } - return affectedObjects; + return relevantFailureMechanisms; } /// - /// Function retrieves all failure mechanisms that should be untouched when the - /// AssessmentSectionComposition changes to Dunes. + /// Retrieves all failure mechanisms that should be untouched when the + /// changes to Dunes. /// - /// - /// A collection of objects that are untouched when changing the assessmentsectioncomposition to dunes. + /// The assessment section to retrieve the failure mechanisms from. + /// A collection of irrelevant (unaffected) failure mechanisms when changing the + /// to . private static IEnumerable GetDuneIrrelevantFailureMechanisms(IAssessmentSection assessmentSection) { var failureMechanisms = new List(); Index: Ringtoets/Integration/test/Ringtoets.Integration.Service.Test/RingtoetsDataSynchronizationServiceTest.cs =================================================================== diff -u -rd82035163d2c3826a24e898b45e13147edd475a9 -r87e9fb044b1fd8f4ed4c31f430839e8ff67d7b6b --- Ringtoets/Integration/test/Ringtoets.Integration.Service.Test/RingtoetsDataSynchronizationServiceTest.cs (.../RingtoetsDataSynchronizationServiceTest.cs) (revision d82035163d2c3826a24e898b45e13147edd475a9) +++ Ringtoets/Integration/test/Ringtoets.Integration.Service.Test/RingtoetsDataSynchronizationServiceTest.cs (.../RingtoetsDataSynchronizationServiceTest.cs) (revision 87e9fb044b1fd8f4ed4c31f430839e8ff67d7b6b) @@ -57,7 +57,7 @@ public void ClearFailureMechanismCalculationOutputs_WithoutAssessmentSection_ThrowsArgumentNullException() { // Call - TestDelegate test = () => RingtoetsDataSynchronizationService.ClearFailureMechanismCalculationOutputs((IAssessmentSection)null); + TestDelegate test = () => RingtoetsDataSynchronizationService.ClearFailureMechanismCalculationOutputs((IAssessmentSection) null); // Assert var exception = Assert.Throws(test); @@ -88,10 +88,10 @@ } [Test] - public void ClearFailureMechanismCalculationOutputs_WithouFailureMechanisms_ThrowsArgumentNullException() + public void ClearFailureMechanismCalculationOutputs_WithoutFailureMechanisms_ThrowsArgumentNullException() { // Call - TestDelegate test = () => RingtoetsDataSynchronizationService.ClearFailureMechanismCalculationOutputs((IEnumerable)null); + TestDelegate test = () => RingtoetsDataSynchronizationService.ClearFailureMechanismCalculationOutputs((IEnumerable) null); // Assert var exception = Assert.Throws(test); @@ -265,7 +265,7 @@ public void ClearHydraulicBoundaryLocationOutputOfFailureMechanisms_AssessmentSectionNull_ThrowsArgumentNullException() { // Call - TestDelegate test = () => RingtoetsDataSynchronizationService.ClearHydraulicBoundaryLocationOutputOfFailureMechanisms((IAssessmentSection)null); + TestDelegate test = () => RingtoetsDataSynchronizationService.ClearHydraulicBoundaryLocationOutputOfFailureMechanisms((IAssessmentSection) null); // Assert var exception = Assert.Throws(test); @@ -280,7 +280,7 @@ IAssessmentSection assessmentSection = mockRepository.Stub(); assessmentSection.Stub(section => section.GetFailureMechanisms()).Return(new IFailureMechanism[] { - new GrassCoverErosionOutwardsFailureMechanism(), + new GrassCoverErosionOutwardsFailureMechanism(), new DuneErosionFailureMechanism() }); mockRepository.ReplayAll(); @@ -334,7 +334,7 @@ public void ClearHydraulicBoundaryLocationOutputOfFailureMechanisms_FailureMechanismsNull_ThrowsArgumentNullException() { // Call - TestDelegate test = () => RingtoetsDataSynchronizationService.ClearHydraulicBoundaryLocationOutputOfFailureMechanisms((IEnumerable)null); + TestDelegate test = () => RingtoetsDataSynchronizationService.ClearHydraulicBoundaryLocationOutputOfFailureMechanisms((IEnumerable) null); // Assert var exception = Assert.Throws(test); @@ -358,8 +358,8 @@ [Test] [TestCaseSource(nameof(GrassAndDuneLocations2))] public void ClearHydraulicBoundaryLocationOutputForFailureMechanisms_FailureMechanismsGrassCoverErosionOutwardsAndDuneLocations_ClearDataAndReturnAffectedLocations(HydraulicBoundaryLocation grassCoverErosionLocation, - DuneLocation duneLocation, - IEnumerable expectedAffectedItems) + DuneLocation duneLocation, + IEnumerable expectedAffectedItems) { // Setup var grassCoverErosionOutwardsFailureMechanism = new GrassCoverErosionOutwardsFailureMechanism(); @@ -436,7 +436,7 @@ public void GetHydraulicBoundaryLocationCollectionsOfFailureMechanisms_AssessmentSectionNull_ThrowsArgumentNullException() { // Call - TestDelegate test = () => RingtoetsDataSynchronizationService.GetHydraulicBoundaryLocationCollectionsOfFailureMechanisms((IAssessmentSection)null); + TestDelegate test = () => RingtoetsDataSynchronizationService.GetHydraulicBoundaryLocationCollectionsOfFailureMechanisms((IAssessmentSection) null); // Assert var exception = Assert.Throws(test); @@ -467,7 +467,7 @@ public void GetHydraulicBoundaryLocationCollectionsOfFailureMechanisms_FailureMechanismsNull_ThrowsArgumentNullException() { // Call - TestDelegate test = () => RingtoetsDataSynchronizationService.GetHydraulicBoundaryLocationCollectionsOfFailureMechanisms((IEnumerable)null); + TestDelegate test = () => RingtoetsDataSynchronizationService.GetHydraulicBoundaryLocationCollectionsOfFailureMechanisms((IEnumerable) null); // Assert var exception = Assert.Throws(test); @@ -477,13 +477,13 @@ [Test] [TestCaseSource(nameof(FailureMechanisms2))] public void GetHydraulicBoundaryLocationCollectionsOfFailureMechanisms_FailureMechanismsGrassCoverOutwardsAndDuneLocations_ReturnsExpectedAffectedCollections(IEnumerable availableFailureMechanisms, - IEnumerable expectedCollections) + IEnumerable expectedCollections) { // Call - IEnumerable affectedCollections = RingtoetsDataSynchronizationService.GetHydraulicBoundaryLocationCollectionsOfFailureMechanisms(availableFailureMechanisms); + IEnumerable affectedObjects = RingtoetsDataSynchronizationService.GetHydraulicBoundaryLocationCollectionsOfFailureMechanisms(availableFailureMechanisms); // Assert - CollectionAssert.AreEquivalent(expectedCollections, affectedCollections); + CollectionAssert.AreEquivalent(expectedCollections, affectedObjects); } [Test] @@ -1311,7 +1311,7 @@ } IObservable[] array = observables.ToArray(); - Assert.AreEqual(1 + (calculations.Length*2) + sectionResults.Length, array.Length); + Assert.AreEqual(1 + (calculations.Length * 2) + sectionResults.Length, array.Length); CollectionAssert.Contains(array, failureMechanism.DikeProfiles); foreach (GrassCoverErosionInwardsCalculation calculation in calculations) { @@ -1524,15 +1524,15 @@ new TestHydraulicBoundaryLocation(), new TestDuneLocation(), new IObservable[0] - ).SetName("GrassAndDuneLocationNoOutput"); + ).SetName("GrassAndDuneLocationNoOutput"); yield return new TestCaseData( grassBoundaryLocationWithOutput = TestHydraulicBoundaryLocation.CreateFullyCalculated(), new TestDuneLocation(), new IObservable[] { grassBoundaryLocationWithOutput } - ).SetName("DuneLocationWithoutOutputGrassLocationWithOutput"); + ).SetName("DuneLocationWithoutOutputGrassLocationWithOutput"); yield return new TestCaseData( new TestHydraulicBoundaryLocation(), duneLocationWithOutput = new TestDuneLocation @@ -1543,7 +1543,7 @@ { duneLocationWithOutput } - ).SetName("GrassLocationWithoutOutputDuneLocationWithOutput"); + ).SetName("GrassLocationWithoutOutputDuneLocationWithOutput"); yield return new TestCaseData( grassBoundaryLocationWithOutput = TestHydraulicBoundaryLocation.CreateFullyCalculated(), duneLocationWithOutput = new TestDuneLocation @@ -1555,7 +1555,7 @@ grassBoundaryLocationWithOutput, duneLocationWithOutput } - ).SetName("GrassAndDuneLocationWithOutput"); + ).SetName("GrassAndDuneLocationWithOutput"); } } @@ -1570,15 +1570,15 @@ new TestHydraulicBoundaryLocation(), new TestDuneLocation(), new IObservable[0] - ).SetName("GrassAndDuneLocationNoOutput2"); + ).SetName("GrassAndDuneLocationNoOutput2"); yield return new TestCaseData( grassBoundaryLocationWithOutput = TestHydraulicBoundaryLocation.CreateFullyCalculated(), new TestDuneLocation(), new IObservable[] { grassBoundaryLocationWithOutput } - ).SetName("GrassLocationWithOutput2"); + ).SetName("GrassLocationWithOutput2"); yield return new TestCaseData( new TestHydraulicBoundaryLocation(), duneLocationWithOutput = new TestDuneLocation @@ -1589,7 +1589,7 @@ { duneLocationWithOutput } - ).SetName("DuneLocationWithOutput2"); + ).SetName("DuneLocationWithOutput2"); yield return new TestCaseData( grassBoundaryLocationWithOutput = TestHydraulicBoundaryLocation.CreateFullyCalculated(), duneLocationWithOutput = new TestDuneLocation @@ -1601,7 +1601,7 @@ grassBoundaryLocationWithOutput, duneLocationWithOutput } - ).SetName("GrassAndDuneLocationWithOutput2"); + ).SetName("GrassAndDuneLocationWithOutput2"); } } @@ -1672,7 +1672,7 @@ new TestHydraulicBoundaryLocation(), new TestDuneLocation(), new IObservable[0] - ).SetName("AllTypesNoOutput"); + ).SetName("AllTypesNoOutput"); yield return new TestCaseData( new TestHydraulicBoundaryLocation(), grassCoverErosionOutwardsLocation = TestHydraulicBoundaryLocation.CreateFullyCalculated(),