Index: Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/Handlers/AssessmentSectionCompositionChangeHandlerTest.cs =================================================================== diff -u -rd712df3c2f4776b59592caaeb484824def9c2271 -r9cd70453e2e24e2a5896757edd13d36620e09dad --- Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/Handlers/AssessmentSectionCompositionChangeHandlerTest.cs (.../AssessmentSectionCompositionChangeHandlerTest.cs) (revision d712df3c2f4776b59592caaeb484824def9c2271) +++ Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/Handlers/AssessmentSectionCompositionChangeHandlerTest.cs (.../AssessmentSectionCompositionChangeHandlerTest.cs) (revision 9cd70453e2e24e2a5896757edd13d36620e09dad) @@ -28,6 +28,9 @@ using NUnit.Framework; using Ringtoets.Common.Data.AssessmentSection; using Ringtoets.Common.Data.Calculation; +using Ringtoets.Common.Data.Hydraulics; +using Ringtoets.DuneErosion.Data; +using Ringtoets.GrassCoverErosionOutwards.Data; using Ringtoets.Integration.Data; using Ringtoets.Integration.Plugin.Handlers; using Ringtoets.Integration.Service; @@ -127,6 +130,16 @@ .Where(c => c.HasOutput) .ToArray(); + DuneLocation[] duneLocationWithOutput = assessmentSection.GetFailureMechanisms().OfType() + .SelectMany(f => f.DuneLocations) + .Where(loc => loc.Output != null) + .ToArray(); + + HydraulicBoundaryLocation[] hblWithOutput = assessmentSection.GetFailureMechanisms().OfType() + .SelectMany(f => f.HydraulicBoundaryLocations) + .Where(loc => loc.DesignWaterLevelOutput != null || loc.WaveHeightOutput != null) + .ToArray(); + var handler = new AssessmentSectionCompositionChangeHandler(); // Call @@ -136,6 +149,9 @@ Assert.True(calculationsWithOutput.All(c => c.HasOutput), "All calculations that had output still have them."); + Assert.True(duneLocationWithOutput.All(loc => loc.Output != null)); + Assert.True(hblWithOutput.All(loc => loc.DesignWaterLevelOutput != null || loc.WaveHeightOutput != null)); + CollectionAssert.IsEmpty(affectedObjects); } @@ -149,12 +165,25 @@ // Precondition Assert.AreNotEqual(assessmentSection.Composition, newComposition); + GrassCoverErosionOutwardsFailureMechanism grassCoverErosionOutwardsFailureMechanism = assessmentSection.GetFailureMechanisms() + .OfType() + .First(); + + DuneErosionFailureMechanism duneErosionFailureMechanism = assessmentSection.GetFailureMechanisms() + .OfType() + .First(); + IObservable[] expectedAffectedObjects = assessmentSection.GetFailureMechanisms().Cast() .Concat(assessmentSection.GetFailureMechanisms().SelectMany(fm => fm.Calculations).Where(c => c.HasOutput)) .Concat(new[] { assessmentSection }) + .Concat(new IObservable[] + { + grassCoverErosionOutwardsFailureMechanism.HydraulicBoundaryLocations, + duneErosionFailureMechanism.DuneLocations + }) .ToArray(); var handler = new AssessmentSectionCompositionChangeHandler(); @@ -164,12 +193,28 @@ Action call = () => affectedObjects = handler.ChangeComposition(assessmentSection, newComposition); // Assert - string expectedMessage = "De resultaten van 32 berekeningen zijn verwijderd."; - TestHelper.AssertLogMessageIsGenerated(call, expectedMessage, 1); + string[] expectedMessage = + { + "De resultaten van 32 berekeningen zijn verwijderd.", + "Alle berekende resultaten voor alle hydraulische randvoorwaardenlocaties zijn verwijderd." + }; + TestHelper.AssertLogMessagesAreGenerated(call, expectedMessage, 2); Assert.AreEqual(newComposition, assessmentSection.Composition); Assert.True(assessmentSection.GetFailureMechanisms().SelectMany(fm => fm.Calculations).All(c => !c.HasOutput)); CollectionAssert.AreEquivalent(expectedAffectedObjects, affectedObjects); + + foreach (HydraulicBoundaryLocation location in assessmentSection.GrassCoverErosionOutwards.HydraulicBoundaryLocations) + { + Assert.IsNaN(location.DesignWaterLevel); + Assert.IsNaN(location.WaveHeight); + Assert.AreEqual(CalculationConvergence.NotCalculated, location.DesignWaterLevelCalculationConvergence); + Assert.AreEqual(CalculationConvergence.NotCalculated, location.WaveHeightCalculationConvergence); + } + foreach (DuneLocation duneLocation in assessmentSection.DuneErosion.DuneLocations) + { + Assert.IsNull(duneLocation.Output); + } } [Test] @@ -184,11 +229,24 @@ Assert.AreNotEqual(assessmentSection.Composition, newComposition); CollectionAssert.IsEmpty(assessmentSection.GetFailureMechanisms().SelectMany(fm => fm.Calculations).Where(c => c.HasOutput)); + GrassCoverErosionOutwardsFailureMechanism grassCoverErosionOutwardsFailureMechanism = assessmentSection.GetFailureMechanisms() + .OfType() + .First(); + + DuneErosionFailureMechanism duneErosionFailureMechanism = assessmentSection.GetFailureMechanisms() + .OfType() + .First(); + IObservable[] expectedAffectedObjects = assessmentSection.GetFailureMechanisms().Cast() .Concat(new[] { assessmentSection }) + .Concat(new IObservable[] + { + grassCoverErosionOutwardsFailureMechanism.HydraulicBoundaryLocations, + duneErosionFailureMechanism.DuneLocations + }) .ToArray(); var handler = new AssessmentSectionCompositionChangeHandler(); @@ -198,11 +256,60 @@ Action call = () => affectedObjects = handler.ChangeComposition(assessmentSection, newComposition); // Assert - TestHelper.AssertLogMessagesCount(call, 0); + TestHelper.AssertLogMessageIsGenerated(call, "Alle berekende resultaten voor alle hydraulische randvoorwaardenlocaties zijn verwijderd.", 1); Assert.AreEqual(newComposition, assessmentSection.Composition); Assert.True(assessmentSection.GetFailureMechanisms().SelectMany(fm => fm.Calculations).All(c => !c.HasOutput)); CollectionAssert.AreEquivalent(expectedAffectedObjects, affectedObjects); + + foreach (HydraulicBoundaryLocation location in assessmentSection.GrassCoverErosionOutwards.HydraulicBoundaryLocations) + { + Assert.IsNaN(location.DesignWaterLevel); + Assert.IsNaN(location.WaveHeight); + Assert.AreEqual(CalculationConvergence.NotCalculated, location.DesignWaterLevelCalculationConvergence); + Assert.AreEqual(CalculationConvergence.NotCalculated, location.WaveHeightCalculationConvergence); + } + foreach (DuneLocation duneLocation in assessmentSection.DuneErosion.DuneLocations) + { + Assert.IsNull(duneLocation.Output); + } } + + [Test] + public void ChangeComposition_ChangeToDifferentValueAndNoHydraulicBoudaryLocationsWithOutput_ChangeCompositionAndReturnsAllAffectedObjects() + { + // Setup + AssessmentSection assessmentSection = TestDataGenerator.GetFullyConfiguredAssessmentSection(); + RingtoetsDataSynchronizationService.ClearHydraulicBoundaryLocationOutput(assessmentSection.GrassCoverErosionOutwards, + assessmentSection.DuneErosion); + var newComposition = AssessmentSectionComposition.Dune; + + // Precondition + Assert.AreNotEqual(assessmentSection.Composition, newComposition); + CollectionAssert.IsEmpty(assessmentSection.GrassCoverErosionOutwards.HydraulicBoundaryLocations.Where(loc => loc.DesignWaterLevelOutput != null + || loc.WaveHeightOutput != null)); + CollectionAssert.IsEmpty(assessmentSection.DuneErosion.DuneLocations.Where(dl => dl.Output != null)); + + IObservable[] expectedAffectedObjects = assessmentSection.GetFailureMechanisms().Cast() + .Concat(assessmentSection.GetFailureMechanisms().SelectMany(fm => fm.Calculations).Where(c => c.HasOutput)) + .Concat(new[] + { + assessmentSection + }) + .ToArray(); + + var handler = new AssessmentSectionCompositionChangeHandler(); + + // Call + IEnumerable affectedObjects = null; + Action call = () => affectedObjects = handler.ChangeComposition(assessmentSection, newComposition); + + // Assert + TestHelper.AssertLogMessageIsGenerated(call, "De resultaten van 32 berekeningen zijn verwijderd.", 1); + + Assert.AreEqual(newComposition, assessmentSection.Composition); + Assert.True(assessmentSection.GetFailureMechanisms().SelectMany(fm => fm.Calculations).All(c => !c.HasOutput)); + CollectionAssert.AreEquivalent(expectedAffectedObjects, affectedObjects); + } } } \ No newline at end of file