Index: Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/Handlers/AssessmentSectionCompositionChangeHandlerTest.cs =================================================================== diff -u -rf1d92a5cb2eebdf9f6c093b9ae66bb7ff95b6e41 -r78aa94c3edc04ede4e0304d6a1510d8a7da76e8f --- Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/Handlers/AssessmentSectionCompositionChangeHandlerTest.cs (.../AssessmentSectionCompositionChangeHandlerTest.cs) (revision f1d92a5cb2eebdf9f6c093b9ae66bb7ff95b6e41) +++ Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/Handlers/AssessmentSectionCompositionChangeHandlerTest.cs (.../AssessmentSectionCompositionChangeHandlerTest.cs) (revision 78aa94c3edc04ede4e0304d6a1510d8a7da76e8f) @@ -195,10 +195,14 @@ .Where(c => c.HasOutput) .ToArray(); - DuneLocation[] duneLocationWithOutput = assessmentSection.GetFailureMechanisms().OfType() - .SelectMany(f => f.DuneLocations) - .Where(loc => loc.Calculation.Output != null) - .ToArray(); + DuneLocationCalculation[] duneLocationCalculationsWithOutput = assessmentSection.DuneErosion.DuneLocations.Select(loc => loc.Calculation) + .Where(calc => calc.Output != null) + .Concat(assessmentSection.DuneErosion.CalculationsForMechanismSpecificFactorizedSignalingNorm.Where(HasDuneErosionLocationCalculationOutput)) + .Concat(assessmentSection.DuneErosion.CalculationsForMechanismSpecificSignalingNorm.Where(HasDuneErosionLocationCalculationOutput)) + .Concat(assessmentSection.DuneErosion.CalculationsForMechanismSpecificLowerLimitNorm.Where(HasDuneErosionLocationCalculationOutput)) + .Concat(assessmentSection.DuneErosion.CalculationsForLowerLimitNorm.Where(HasDuneErosionLocationCalculationOutput)) + .Concat(assessmentSection.DuneErosion.CalculationsForFactorizedLowerLimitNorm.Where(HasDuneErosionLocationCalculationOutput)) + .ToArray(); GrassCoverErosionOutwardsFailureMechanism failureMechanism = assessmentSection.GrassCoverErosionOutwards; IEnumerable hydraulicBoundaryLocationCalculationsWithOutput = @@ -213,7 +217,7 @@ Assert.True(calculationsWithOutput.All(c => c.HasOutput), "All calculations that had output still have them."); - Assert.True(duneLocationWithOutput.All(loc => loc.Calculation.Output != null)); + Assert.True(duneLocationCalculationsWithOutput.All(calc => calc.Output != null)); Assert.True(hydraulicBoundaryLocationCalculationsWithOutput.All(calc => calc.HasOutput)); CollectionAssert.IsEmpty(affectedObjects); @@ -233,30 +237,23 @@ AssessmentSection assessmentSection = TestDataGenerator.GetAssessmentSectionWithAllCalculationConfigurations(oldComposition); - GrassCoverErosionOutwardsFailureMechanism grassCoverErosionOutwardsFailureMechanism = assessmentSection.GetFailureMechanisms() - .OfType() - .Single(); - - DuneErosionFailureMechanism duneErosionFailureMechanism = assessmentSection.GetFailureMechanisms() - .OfType() - .Single(); - IEnumerable unaffectedObjects = GetDuneIrrelevantFailureMechanisms(assessmentSection) .SelectMany(fm => fm.Calculations) .Where(calc => calc.HasOutput) - .ToList(); + .ToArray(); - IEnumerable expectedAffectedObjects = - duneErosionFailureMechanism.DuneLocations.Where(dl => dl.Calculation.Output != null) - .Concat(GetAllAffectedGrassCoverErosionOutwardsCalculations(grassCoverErosionOutwardsFailureMechanism)) - .Concat(new IObservable[] - { - assessmentSection - }) - .Concat(GetDuneRelevantFailureMechanisms(assessmentSection) - .SelectMany(fm => fm.Calculations) - .Where(calc => calc.HasOutput)) - .ToList(); + GrassCoverErosionOutwardsFailureMechanism grassCoverErosionOutwardsFailureMechanism = assessmentSection.GrassCoverErosionOutwards; + DuneErosionFailureMechanism duneErosionFailureMechanism = assessmentSection.DuneErosion; + IEnumerable expectedAffectedObjects = GetAllAffectedDuneErosionLocationCalculations(duneErosionFailureMechanism) + .Concat(GetAllAffectedGrassCoverErosionOutwardsCalculations(grassCoverErosionOutwardsFailureMechanism)) + .Concat(new IObservable[] + { + assessmentSection + }) + .Concat(GetDuneRelevantFailureMechanisms(assessmentSection) + .SelectMany(fm => fm.Calculations) + .Where(calc => calc.HasOutput)) + .ToArray(); var handler = new AssessmentSectionCompositionChangeHandler(viewCommands); @@ -277,12 +274,8 @@ CollectionAssert.IsSubsetOf(expectedAffectedObjects, affectedObjects); GrassCoverErosionOutwardsHydraulicBoundaryLocationsTestHelper.AssertHydraulicBoundaryLocationCalculationsHaveNoOutputs(grassCoverErosionOutwardsFailureMechanism); + AssertDuneLocationCalculationsHaveNoOutputs(duneErosionFailureMechanism); - foreach (DuneLocation duneLocation in assessmentSection.DuneErosion.DuneLocations) - { - Assert.IsNull(duneLocation.Calculation.Output); - } - mocks.VerifyAll(); } @@ -301,25 +294,22 @@ AssessmentSection assessmentSection = TestDataGenerator.GetAssessmentSectionWithAllCalculationConfigurations(oldComposition); - DuneErosionFailureMechanism duneErosionFailureMechanism = assessmentSection.GetFailureMechanisms() - .OfType() - .Single(); - IEnumerable expectedUnaffectedObjects = assessmentSection.GetFailureMechanisms() .SelectMany(fm => fm.Calculations) .Where(calc => calc.HasOutput) - .ToList(); + .ToArray(); GrassCoverErosionOutwardsFailureMechanism grassCoverErosionOutwardsFailureMechanism = assessmentSection.GrassCoverErosionOutwards; IEnumerable hydraulicBoundaryLocationCalculationsWithOutput = GrassCoverErosionOutwardsHydraulicBoundaryLocationsTestHelper.GetAllHydraulicBoundaryLocationCalculationsWithOutput(grassCoverErosionOutwardsFailureMechanism); - IEnumerable expectedAffectedObjects = duneErosionFailureMechanism.DuneLocations.Where(dl => dl.Calculation.Output != null) - .Concat(new IObservable[] - { - assessmentSection - }) - .ToList(); + DuneErosionFailureMechanism duneErosionFailureMechanism = assessmentSection.DuneErosion; + IEnumerable expectedAffectedObjects = GetAllAffectedDuneErosionLocationCalculations(duneErosionFailureMechanism) + .Concat(new IObservable[] + { + assessmentSection + }) + .ToArray(); var handler = new AssessmentSectionCompositionChangeHandler(viewCommands); @@ -335,11 +325,9 @@ CollectionAssert.IsSubsetOf(expectedAffectedObjects, affectedObjects); AssertOutputNotCleared(expectedUnaffectedObjects, assessmentSection.GetFailureMechanisms()); + Assert.IsTrue(hydraulicBoundaryLocationCalculationsWithOutput.All(c => c.HasOutput)); - foreach (DuneLocation duneLocation in assessmentSection.DuneErosion.DuneLocations) - { - Assert.IsNull(duneLocation.Calculation.Output); - } + AssertDuneLocationCalculationsHaveNoOutputs(duneErosionFailureMechanism); mocks.VerifyAll(); } @@ -357,25 +345,19 @@ AssessmentSection assessmentSection = TestDataGenerator.GetAssessmentSectionWithAllCalculationConfigurationsWithoutCalculationOutput(oldComposition); - GrassCoverErosionOutwardsFailureMechanism grassCoverErosionOutwardsFailureMechanism = assessmentSection.GetFailureMechanisms() - .OfType() - .Single(); - - DuneErosionFailureMechanism duneErosionFailureMechanism = assessmentSection.GetFailureMechanisms() - .OfType() - .Single(); - + GrassCoverErosionOutwardsFailureMechanism grassCoverErosionOutwardsFailureMechanism = assessmentSection.GrassCoverErosionOutwards; + DuneErosionFailureMechanism duneErosionFailureMechanism = assessmentSection.DuneErosion; IEnumerable expectedAffectedObjects = - duneErosionFailureMechanism.DuneLocations.Where(dl => dl.Calculation.Output != null) - .Concat(GetAllAffectedGrassCoverErosionOutwardsCalculations(grassCoverErosionOutwardsFailureMechanism)) - .Concat(new IObservable[] - { - assessmentSection - }) - .Concat(GetDuneRelevantFailureMechanisms(assessmentSection) - .SelectMany(fm => fm.Calculations) - .Where(calc => calc.HasOutput)) - .ToArray(); + GetAllAffectedDuneErosionLocationCalculations(duneErosionFailureMechanism) + .Concat(GetAllAffectedGrassCoverErosionOutwardsCalculations(grassCoverErosionOutwardsFailureMechanism)) + .Concat(new IObservable[] + { + assessmentSection + }) + .Concat(GetDuneRelevantFailureMechanisms(assessmentSection) + .SelectMany(fm => fm.Calculations) + .Where(calc => calc.HasOutput)) + .ToArray(); var handler = new AssessmentSectionCompositionChangeHandler(viewCommands); @@ -390,10 +372,7 @@ Assert.True(assessmentSection.GetFailureMechanisms().SelectMany(fm => fm.Calculations).All(c => !c.HasOutput)); CollectionAssert.IsSubsetOf(expectedAffectedObjects, affectedObjects); GrassCoverErosionOutwardsHydraulicBoundaryLocationsTestHelper.AssertHydraulicBoundaryLocationCalculationsHaveNoOutputs(grassCoverErosionOutwardsFailureMechanism); - foreach (DuneLocation duneLocation in assessmentSection.DuneErosion.DuneLocations) - { - Assert.IsNull(duneLocation.Calculation.Output); - } + AssertDuneLocationCalculationsHaveNoOutputs(duneErosionFailureMechanism); mocks.VerifyAll(); } @@ -416,13 +395,12 @@ GrassCoverErosionOutwardsHydraulicBoundaryLocationsTestHelper.GetAllHydraulicBoundaryLocationCalculationsWithOutput(failureMechanism); DuneErosionFailureMechanism duneErosionFailureMechanism = assessmentSection.DuneErosion; - - IEnumerable expectedAffectedObjects = duneErosionFailureMechanism.DuneLocations.Where(dl => dl.Calculation.Output != null) - .Concat(new IObservable[] + IEnumerable expectedAffectedObjects = + GetAllAffectedDuneErosionLocationCalculations(duneErosionFailureMechanism).Concat(new IObservable[] { assessmentSection }) - .ToList(); + .ToArray(); var handler = new AssessmentSectionCompositionChangeHandler(viewCommands); @@ -438,10 +416,7 @@ CollectionAssert.IsSubsetOf(expectedAffectedObjects, affectedObjects); Assert.IsTrue(hydraulicBoundaryLocationCalculationsWithOutput.All(calc => calc.HasOutput)); - foreach (DuneLocation duneLocation in assessmentSection.DuneErosion.DuneLocations) - { - Assert.IsNull(duneLocation.Calculation.Output); - } + AssertDuneLocationCalculationsHaveNoOutputs(duneErosionFailureMechanism); mocks.VerifyAll(); } @@ -462,7 +437,7 @@ IEnumerable notAffectedObjects = GetDuneIrrelevantFailureMechanisms(assessmentSection) .SelectMany(fm => fm.Calculations) .Where(calc => calc.HasOutput) - .ToList(); + .ToArray(); IObservable[] expectedAffectedObjects = new IObservable[] { @@ -502,10 +477,10 @@ AssessmentSection assessmentSection = TestDataGenerator.GetAssessmentSectionWithAllCalculationConfigurationsWithoutHydraulicBoundaryLocationAndDuneOutput(oldComposition); - List expectedUnaffectedObjects = assessmentSection.GetFailureMechanisms() - .SelectMany(fm => fm.Calculations) - .Where(calc => calc.HasOutput) - .ToList(); + IEnumerable expectedUnaffectedObjects = assessmentSection.GetFailureMechanisms() + .SelectMany(fm => fm.Calculations) + .Where(calc => calc.HasOutput) + .ToArray(); IObservable[] expectedAffectedObjects = { @@ -622,6 +597,35 @@ #endregion + #region Dune Erosion Failure Mechanism Helpers + + private static IEnumerable GetAllAffectedDuneErosionLocationCalculations(DuneErosionFailureMechanism failureMechanism) + { + return failureMechanism.DuneLocations.Where(dl => dl.Calculation.Output != null).Cast() + .Concat(failureMechanism.CalculationsForMechanismSpecificFactorizedSignalingNorm.Where(HasDuneErosionLocationCalculationOutput)) + .Concat(failureMechanism.CalculationsForMechanismSpecificSignalingNorm.Where(HasDuneErosionLocationCalculationOutput)) + .Concat(failureMechanism.CalculationsForMechanismSpecificLowerLimitNorm.Where(HasDuneErosionLocationCalculationOutput)) + .Concat(failureMechanism.CalculationsForLowerLimitNorm.Where(HasDuneErosionLocationCalculationOutput)) + .Concat(failureMechanism.CalculationsForFactorizedLowerLimitNorm.Where(HasDuneErosionLocationCalculationOutput)); + } + + private static bool HasDuneErosionLocationCalculationOutput(DuneLocationCalculation calculation) + { + return calculation.Output != null; + } + + private static void AssertDuneLocationCalculationsHaveNoOutputs(DuneErosionFailureMechanism failureMechanism) + { + Assert.True(failureMechanism.DuneLocations.All(dl => dl.Calculation.Output == null)); + Assert.True(failureMechanism.CalculationsForMechanismSpecificFactorizedSignalingNorm.All(calc => calc.Output == null)); + Assert.True(failureMechanism.CalculationsForMechanismSpecificSignalingNorm.All(calc => calc.Output == null)); + Assert.True(failureMechanism.CalculationsForMechanismSpecificLowerLimitNorm.All(calc => calc.Output == null)); + Assert.True(failureMechanism.CalculationsForLowerLimitNorm.All(calc => calc.Output == null)); + Assert.True(failureMechanism.CalculationsForFactorizedLowerLimitNorm.All(calc => calc.Output == null)); + } + + #endregion + #region LinQ queries for expectancies ///