// Copyright (C) Stichting Deltares 2017. All rights reserved. // // This file is part of Ringtoets. // // Ringtoets 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 Core.Common.Gui.Commands; using Core.Common.TestUtil; using Core.Common.Util.Extensions; using NUnit.Framework; using Rhino.Mocks; using Ringtoets.ClosingStructures.Data; using Ringtoets.Common.Data.AssessmentSection; using Ringtoets.Common.Data.FailureMechanism; using Ringtoets.Common.Data.Hydraulics; using Ringtoets.Common.Data.Structures; using Ringtoets.Common.Data.TestUtil; using Ringtoets.Common.Data.TestUtil.IllustrationPoints; using Ringtoets.GrassCoverErosionInwards.Data; using Ringtoets.HeightStructures.Data; using Ringtoets.Integration.Data; using Ringtoets.Integration.Plugin.Merge; using Ringtoets.MacroStabilityInwards.Data; using Ringtoets.Piping.Data; using Ringtoets.StabilityPointStructures.Data; using Ringtoets.StabilityStoneCover.Data; using Ringtoets.WaveImpactAsphaltCover.Data; namespace Ringtoets.Integration.Plugin.Test.Merge { [TestFixture] public class AssessmentSectionMergeHandlerTest { [Test] public void Constructor_ViewCommandsNull_ThrowsArgumentNullException() { // Call TestDelegate call = () => new AssessmentSectionMergeHandler(null); // Assert var exception = Assert.Throws(call); Assert.AreEqual("viewCommands", exception.ParamName); } [Test] public void Constructor_ExpectedValues() { // Setup var mocks = new MockRepository(); var viewCommands = mocks.StrictMock(); mocks.ReplayAll(); // Call var handler = new AssessmentSectionMergeHandler(viewCommands); // Assert Assert.IsInstanceOf(handler); mocks.VerifyAll(); } [Test] public void PerformMerge_targetAssessmentSectionNull_ThrowsArgumentNullException() { // Setup var mocks = new MockRepository(); var viewCommands = mocks.StrictMock(); mocks.ReplayAll(); var handler = new AssessmentSectionMergeHandler(viewCommands); // Call TestDelegate call = () => handler.PerformMerge(null, new AssessmentSection(AssessmentSectionComposition.Dike), Enumerable.Empty()); // Assert var exception = Assert.Throws(call); Assert.AreEqual("targetAssessmentSection", exception.ParamName); mocks.VerifyAll(); } [Test] public void PerformMerge_sourceAssessmentSectionNull_ThrowsArgumentNullException() { // Setup var mocks = new MockRepository(); var viewCommands = mocks.StrictMock(); mocks.ReplayAll(); var handler = new AssessmentSectionMergeHandler(viewCommands); // Call TestDelegate call = () => handler.PerformMerge(new AssessmentSection(AssessmentSectionComposition.Dike), null, Enumerable.Empty()); // Assert var exception = Assert.Throws(call); Assert.AreEqual("sourceAssessmentSection", exception.ParamName); mocks.VerifyAll(); } [Test] public void PerformMerge_FailureMechanismsToMergeNull_ThrowsArgumentNullException() { // Setup var mocks = new MockRepository(); var viewCommands = mocks.StrictMock(); mocks.ReplayAll(); var handler = new AssessmentSectionMergeHandler(viewCommands); // Call TestDelegate call = () => handler.PerformMerge(new AssessmentSection(AssessmentSectionComposition.Dike), new AssessmentSection(AssessmentSectionComposition.Dike), null); // Assert var exception = Assert.Throws(call); Assert.AreEqual("failureMechanismsToMerge", exception.ParamName); mocks.VerifyAll(); } [Test] public void PerformMerge_WithAllData_AllViewsForTargetAssessmentSectionClosed() { // Setup var targetAssessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike); var mocks = new MockRepository(); var viewCommands = mocks.StrictMock(); viewCommands.Expect(vc => vc.RemoveAllViewsForItem(targetAssessmentSection)); mocks.ReplayAll(); var handler = new AssessmentSectionMergeHandler(viewCommands); // Call handler.PerformMerge(targetAssessmentSection, new AssessmentSection(AssessmentSectionComposition.Dike), Enumerable.Empty()); // Assert mocks.VerifyAll(); } [Test] public void PerformMerge_WithAllData_LogMessageAndNotifyObservers() { // Setup var mocks = new MockRepository(); var viewCommands = mocks.Stub(); var observer = mocks.StrictMock(); observer.Expect(o => o.UpdateObserver()); mocks.ReplayAll(); var handler = new AssessmentSectionMergeHandler(viewCommands); var targetAssessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike); targetAssessmentSection.Attach(observer); // Call Action call = () => handler.PerformMerge(targetAssessmentSection, new AssessmentSection(AssessmentSectionComposition.Dike), Enumerable.Empty()); // Assert TestHelper.AssertLogMessagesWithLevelAreGenerated(call, new[] { new Tuple("Hydraulische belastingen zijn samengevoegd.", LogLevelConstant.Info) }); mocks.VerifyAll(); } [Test] public void PerformMerge_WithAllFailureMechanismsToMerge_SetNewFailureMechanisms() { // Setup var mocks = new MockRepository(); var viewCommands = mocks.Stub(); mocks.ReplayAll(); var handler = new AssessmentSectionMergeHandler(viewCommands); var targetAssessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike); var sourceAssessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike); // Call handler.PerformMerge(targetAssessmentSection, sourceAssessmentSection, sourceAssessmentSection.GetFailureMechanisms()); // Assert Assert.AreSame(sourceAssessmentSection.Piping, targetAssessmentSection.Piping); Assert.AreSame(sourceAssessmentSection.GrassCoverErosionInwards, targetAssessmentSection.GrassCoverErosionInwards); Assert.AreSame(sourceAssessmentSection.MacroStabilityInwards, targetAssessmentSection.MacroStabilityInwards); Assert.AreSame(sourceAssessmentSection.MacroStabilityOutwards, targetAssessmentSection.MacroStabilityOutwards); Assert.AreSame(sourceAssessmentSection.Microstability, targetAssessmentSection.Microstability); Assert.AreSame(sourceAssessmentSection.StabilityStoneCover, targetAssessmentSection.StabilityStoneCover); Assert.AreSame(sourceAssessmentSection.WaveImpactAsphaltCover, targetAssessmentSection.WaveImpactAsphaltCover); Assert.AreSame(sourceAssessmentSection.WaterPressureAsphaltCover, targetAssessmentSection.WaterPressureAsphaltCover); Assert.AreSame(sourceAssessmentSection.GrassCoverSlipOffOutwards, targetAssessmentSection.GrassCoverSlipOffOutwards); Assert.AreSame(sourceAssessmentSection.GrassCoverSlipOffInwards, targetAssessmentSection.GrassCoverSlipOffInwards); Assert.AreSame(sourceAssessmentSection.HeightStructures, targetAssessmentSection.HeightStructures); Assert.AreSame(sourceAssessmentSection.ClosingStructures, targetAssessmentSection.ClosingStructures); Assert.AreSame(sourceAssessmentSection.PipingStructure, targetAssessmentSection.PipingStructure); Assert.AreSame(sourceAssessmentSection.StabilityPointStructures, targetAssessmentSection.StabilityPointStructures); Assert.AreSame(sourceAssessmentSection.StrengthStabilityLengthwiseConstruction, targetAssessmentSection.StrengthStabilityLengthwiseConstruction); Assert.AreSame(sourceAssessmentSection.TechnicalInnovation, targetAssessmentSection.TechnicalInnovation); } [Test] public void PerformMerge_WithNoFailureMechanismsToMerge_FailureMechanismsSame() { // Setup var mocks = new MockRepository(); var viewCommands = mocks.Stub(); mocks.ReplayAll(); var handler = new AssessmentSectionMergeHandler(viewCommands); var targetAssessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike); var sourceAssessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike); // Call handler.PerformMerge(targetAssessmentSection, sourceAssessmentSection, Enumerable.Empty()); // Assert Assert.AreNotSame(sourceAssessmentSection.Piping, targetAssessmentSection.Piping); Assert.AreNotSame(sourceAssessmentSection.GrassCoverErosionInwards, targetAssessmentSection.GrassCoverErosionInwards); Assert.AreNotSame(sourceAssessmentSection.MacroStabilityInwards, targetAssessmentSection.MacroStabilityInwards); Assert.AreNotSame(sourceAssessmentSection.MacroStabilityOutwards, targetAssessmentSection.MacroStabilityOutwards); Assert.AreNotSame(sourceAssessmentSection.Microstability, targetAssessmentSection.Microstability); Assert.AreNotSame(sourceAssessmentSection.StabilityStoneCover, targetAssessmentSection.StabilityStoneCover); Assert.AreNotSame(sourceAssessmentSection.WaveImpactAsphaltCover, targetAssessmentSection.WaveImpactAsphaltCover); Assert.AreNotSame(sourceAssessmentSection.WaterPressureAsphaltCover, targetAssessmentSection.WaterPressureAsphaltCover); Assert.AreNotSame(sourceAssessmentSection.GrassCoverSlipOffOutwards, targetAssessmentSection.GrassCoverSlipOffOutwards); Assert.AreNotSame(sourceAssessmentSection.GrassCoverSlipOffInwards, targetAssessmentSection.GrassCoverSlipOffInwards); Assert.AreNotSame(sourceAssessmentSection.HeightStructures, targetAssessmentSection.HeightStructures); Assert.AreNotSame(sourceAssessmentSection.ClosingStructures, targetAssessmentSection.ClosingStructures); Assert.AreNotSame(sourceAssessmentSection.PipingStructure, targetAssessmentSection.PipingStructure); Assert.AreNotSame(sourceAssessmentSection.StabilityPointStructures, targetAssessmentSection.StabilityPointStructures); Assert.AreNotSame(sourceAssessmentSection.StrengthStabilityLengthwiseConstruction, targetAssessmentSection.StrengthStabilityLengthwiseConstruction); Assert.AreNotSame(sourceAssessmentSection.TechnicalInnovation, targetAssessmentSection.TechnicalInnovation); } [Test] public void PerformMerge_WithAllFailureMechanismsToMerge_LogMessages() { // Setup var mocks = new MockRepository(); var viewCommands = mocks.Stub(); mocks.ReplayAll(); var handler = new AssessmentSectionMergeHandler(viewCommands); var targetAssessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike); var sourceAssessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike); // Call Action call = () => handler.PerformMerge(targetAssessmentSection, sourceAssessmentSection, sourceAssessmentSection.GetFailureMechanisms()); // Assert TestHelper.AssertLogMessages(call, messages => { string[] msgs = messages.ToArray(); Assert.AreEqual(17, msgs.Length); Assert.AreEqual("Gegevens van toetsspoor 'Dijken en dammen - Piping' zijn vervangen.", msgs[1]); Assert.AreEqual("Gegevens van toetsspoor 'Dijken en dammen - Grasbekleding erosie kruin en binnentalud' zijn vervangen.", msgs[2]); Assert.AreEqual("Gegevens van toetsspoor 'Dijken en dammen - Macrostabiliteit binnenwaarts' zijn vervangen.", msgs[3]); Assert.AreEqual("Gegevens van toetsspoor 'Dijken en dammen - Macrostabiliteit buitenwaarts' zijn vervangen.", msgs[4]); Assert.AreEqual("Gegevens van toetsspoor 'Dijken en dammen - Microstabiliteit' zijn vervangen.", msgs[5]); Assert.AreEqual("Gegevens van toetsspoor 'Dijken en dammen - Stabiliteit steenzetting' zijn vervangen.", msgs[6]); Assert.AreEqual("Gegevens van toetsspoor 'Dijken en dammen - Golfklappen op asfaltbekleding' zijn vervangen.", msgs[7]); Assert.AreEqual("Gegevens van toetsspoor 'Dijken en dammen - Wateroverdruk bij asfaltbekleding' zijn vervangen.", msgs[8]); Assert.AreEqual("Gegevens van toetsspoor 'Dijken en dammen - Grasbekleding afschuiven buitentalud' zijn vervangen.", msgs[9]); Assert.AreEqual("Gegevens van toetsspoor 'Dijken en dammen - Grasbekleding afschuiven binnentalud' zijn vervangen.", msgs[10]); Assert.AreEqual("Gegevens van toetsspoor 'Kunstwerken - Hoogte kunstwerk' zijn vervangen.", msgs[11]); Assert.AreEqual("Gegevens van toetsspoor 'Kunstwerken - Betrouwbaarheid sluiting kunstwerk' zijn vervangen.", msgs[12]); Assert.AreEqual("Gegevens van toetsspoor 'Kunstwerken - Piping bij kunstwerk' zijn vervangen.", msgs[13]); Assert.AreEqual("Gegevens van toetsspoor 'Kunstwerken - Sterkte en stabiliteit puntconstructies' zijn vervangen.", msgs[14]); Assert.AreEqual("Gegevens van toetsspoor 'Kunstwerken - Sterkte en stabiliteit langsconstructies' zijn vervangen.", msgs[15]); Assert.AreEqual("Gegevens van toetsspoor 'Technische innovaties - Technische innovaties' zijn vervangen.", msgs[16]); }); } [Test] public void GivenFailureMechanismWithWithCalculations_WhenCalculationHasReferenceToHydraulicBoundaryLocation_ThenReferenceUpdated() { // Given var mocks = new MockRepository(); var viewCommands = mocks.Stub(); mocks.ReplayAll(); var handler = new AssessmentSectionMergeHandler(viewCommands); var targetLocations = new[] { new HydraulicBoundaryLocation(1, "location 1", 1, 1), new HydraulicBoundaryLocation(2, "location 2", 2, 2) }; var sourceLocations = new[] { new HydraulicBoundaryLocation(1, "location 1", 1, 1), new HydraulicBoundaryLocation(2, "location 2", 2, 2) }; AssessmentSection targetAssessmentSection = CreateAssessmentSection(targetLocations); AssessmentSection sourceAssessmentSection = CreateAssessmentSection(sourceLocations); sourceAssessmentSection.Piping.CalculationsGroup.Children.Add(new PipingCalculationScenario(new GeneralPipingInput()) { InputParameters = { HydraulicBoundaryLocation = sourceLocations[0] } }); sourceAssessmentSection.GrassCoverErosionInwards.CalculationsGroup.Children.Add(new GrassCoverErosionInwardsCalculation { InputParameters = { HydraulicBoundaryLocation = sourceLocations[1] } }); sourceAssessmentSection.MacroStabilityInwards.CalculationsGroup.Children.Add(new MacroStabilityInwardsCalculationScenario { InputParameters = { HydraulicBoundaryLocation = sourceLocations[0] } }); sourceAssessmentSection.HeightStructures.CalculationsGroup.Children.Add(new StructuresCalculation { InputParameters = { HydraulicBoundaryLocation = sourceLocations[1] } }); sourceAssessmentSection.ClosingStructures.CalculationsGroup.Children.Add(new StructuresCalculation { InputParameters = { HydraulicBoundaryLocation = sourceLocations[0] } }); sourceAssessmentSection.StabilityPointStructures.CalculationsGroup.Children.Add(new StructuresCalculation { InputParameters = { HydraulicBoundaryLocation = sourceLocations[1] } }); sourceAssessmentSection.StabilityStoneCover.WaveConditionsCalculationGroup.Children.Add(new StabilityStoneCoverWaveConditionsCalculation { InputParameters = { HydraulicBoundaryLocation = sourceLocations[0] } }); sourceAssessmentSection.WaveImpactAsphaltCover.WaveConditionsCalculationGroup.Children.Add(new WaveImpactAsphaltCoverWaveConditionsCalculation { InputParameters = { HydraulicBoundaryLocation = sourceLocations[1] } }); // When handler.PerformMerge(targetAssessmentSection, sourceAssessmentSection, new IFailureMechanism[] { sourceAssessmentSection.Piping, sourceAssessmentSection.GrassCoverErosionInwards, sourceAssessmentSection.MacroStabilityInwards, sourceAssessmentSection.HeightStructures, sourceAssessmentSection.ClosingStructures, sourceAssessmentSection.StabilityPointStructures, sourceAssessmentSection.StabilityStoneCover, sourceAssessmentSection.WaveImpactAsphaltCover }); // Then var pipingCalculation = (PipingCalculationScenario) targetAssessmentSection.Piping.Calculations.Single(); Assert.AreSame(targetLocations[0], pipingCalculation.InputParameters.HydraulicBoundaryLocation); var grassInwardsCalculation = (GrassCoverErosionInwardsCalculation) targetAssessmentSection.GrassCoverErosionInwards.Calculations.Single(); Assert.AreSame(targetLocations[1], grassInwardsCalculation.InputParameters.HydraulicBoundaryLocation); var macroStabilityInwardsCalculation = (MacroStabilityInwardsCalculation) targetAssessmentSection.MacroStabilityInwards.Calculations.Single(); Assert.AreSame(targetLocations[0], macroStabilityInwardsCalculation.InputParameters.HydraulicBoundaryLocation); var heightStructuresCalculation = (StructuresCalculation) targetAssessmentSection.HeightStructures.Calculations.Single(); Assert.AreSame(targetLocations[1], heightStructuresCalculation.InputParameters.HydraulicBoundaryLocation); var closingStructuresCalculation = (StructuresCalculation) targetAssessmentSection.ClosingStructures.Calculations.Single(); Assert.AreSame(targetLocations[0], closingStructuresCalculation.InputParameters.HydraulicBoundaryLocation); var stabilityPointStructuresCalculation = (StructuresCalculation) targetAssessmentSection.StabilityPointStructures.Calculations.Single(); Assert.AreSame(targetLocations[1], stabilityPointStructuresCalculation.InputParameters.HydraulicBoundaryLocation); var stabilityStoneCoverCalculation = (StabilityStoneCoverWaveConditionsCalculation) targetAssessmentSection.StabilityStoneCover.Calculations.Single(); Assert.AreSame(targetLocations[0], stabilityStoneCoverCalculation.InputParameters.HydraulicBoundaryLocation); var waveImpactAsphatlCoverCalculation = (WaveImpactAsphaltCoverWaveConditionsCalculation) targetAssessmentSection.WaveImpactAsphaltCover.Calculations.Single(); Assert.AreSame(targetLocations[1], waveImpactAsphatlCoverCalculation.InputParameters.HydraulicBoundaryLocation); } private static AssessmentSection CreateAssessmentSection(HydraulicBoundaryLocation[] locations) { var assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike); assessmentSection.HydraulicBoundaryDatabase.Locations.AddRange(locations); assessmentSection.SetHydraulicBoundaryLocationCalculations(locations); return assessmentSection; } #region HydraulicBoundaryLocationCalculations [Test] [TestCaseSource(nameof(GetCalculationsFuncs))] public void GivenAssessmentSectionWithHydraulicBoundaryLocationCalculations_WhenTargetAssessmentSectionHasOutput_ThenCalculationsNotChanged( Func> getCalculationsFunc) { // Setup var mocks = new MockRepository(); var viewCommands = mocks.Stub(); mocks.ReplayAll(); var locations = new[] { new TestHydraulicBoundaryLocation(), new TestHydraulicBoundaryLocation() }; AssessmentSection targetAssessmentSection = CreateAssessmentSection(locations); AssessmentSection sourceAssessmentSection = CreateAssessmentSection(locations); IEnumerable targetCalculations = getCalculationsFunc(targetAssessmentSection); IEnumerable sourceCalculations = getCalculationsFunc(sourceAssessmentSection); SetOutput(targetCalculations); sourceCalculations.ForEachElementDo(c => c.InputParameters.ShouldIllustrationPointsBeCalculated = true); var handler = new AssessmentSectionMergeHandler(viewCommands); // Precondition Assert.IsTrue(targetCalculations.All(c => c.HasOutput)); Assert.IsTrue(sourceCalculations.All(c => !c.HasOutput)); Assert.IsTrue(targetCalculations.All(c => !c.InputParameters.ShouldIllustrationPointsBeCalculated)); // Call handler.PerformMerge(targetAssessmentSection, sourceAssessmentSection, Enumerable.Empty()); // Assert Assert.IsTrue(targetCalculations.All(c => c.HasOutput)); Assert.IsTrue(sourceCalculations.All(c => !c.HasOutput)); Assert.IsTrue(targetCalculations.All(c => !c.InputParameters.ShouldIllustrationPointsBeCalculated)); mocks.VerifyAll(); } [Test] [TestCaseSource(nameof(GetCalculationsFuncs))] public void GivenAssessmentSectionWithHydraulicBoundaryLocationCalculations_WhenSourceAssessmentSectionHasOutput_ThenCalculationDataMerged( Func> getCalculationsFunc) { // Setup var mocks = new MockRepository(); var viewCommands = mocks.Stub(); mocks.ReplayAll(); var locations = new[] { new TestHydraulicBoundaryLocation(), new TestHydraulicBoundaryLocation() }; AssessmentSection targetAssessmentSection = CreateAssessmentSection(locations); AssessmentSection sourceAssessmentSection = CreateAssessmentSection(locations); IEnumerable targetCalculations = getCalculationsFunc(targetAssessmentSection); IEnumerable sourceCalculations = getCalculationsFunc(sourceAssessmentSection); SetOutput(sourceCalculations); sourceCalculations.ForEachElementDo(c => c.InputParameters.ShouldIllustrationPointsBeCalculated = true); var handler = new AssessmentSectionMergeHandler(viewCommands); // Precondition Assert.IsTrue(targetCalculations.All(c => !c.HasOutput)); Assert.IsTrue(sourceCalculations.All(c => c.HasOutput)); Assert.IsTrue(targetCalculations.All(c => !c.InputParameters.ShouldIllustrationPointsBeCalculated)); Assert.IsTrue(sourceCalculations.All(c => c.InputParameters.ShouldIllustrationPointsBeCalculated)); // Call handler.PerformMerge(targetAssessmentSection, sourceAssessmentSection, Enumerable.Empty()); // Assert Assert.IsTrue(targetCalculations.All(c => c.HasOutput)); Assert.IsTrue(targetCalculations.All(c => c.InputParameters.ShouldIllustrationPointsBeCalculated)); mocks.VerifyAll(); } [Test] [TestCaseSource(nameof(GetCalculationsFuncs))] public void GivenAssessmentSectionWithHydraulicBoundaryLocationCalculations_WhenTargetAssessmentSectionHasOutputWithIllustrationPoints_ThenCalculationsNotChanged( Func> getCalculationsFunc) { // Setup var mocks = new MockRepository(); var viewCommands = mocks.Stub(); mocks.ReplayAll(); var locations = new[] { new TestHydraulicBoundaryLocation(), new TestHydraulicBoundaryLocation() }; AssessmentSection targetAssessmentSection = CreateAssessmentSection(locations); AssessmentSection sourceAssessmentSection = CreateAssessmentSection(locations); IEnumerable targetCalculations = getCalculationsFunc(targetAssessmentSection); IEnumerable sourceCalculations = getCalculationsFunc(sourceAssessmentSection); SetOutput(targetCalculations, true); SetOutput(sourceCalculations); var handler = new AssessmentSectionMergeHandler(viewCommands); // Precondition Assert.IsTrue(targetCalculations.All(c => c.HasOutput)); Assert.IsTrue(targetCalculations.All(c => c.Output.HasGeneralResult)); Assert.IsTrue(sourceCalculations.All(c => c.HasOutput)); Assert.IsTrue(sourceCalculations.All(c => !c.Output.HasGeneralResult)); // Call handler.PerformMerge(targetAssessmentSection, sourceAssessmentSection, Enumerable.Empty()); // Assert Assert.IsTrue(targetCalculations.All(c => c.HasOutput)); Assert.IsTrue(targetCalculations.All(c => c.Output.HasGeneralResult)); Assert.IsTrue(sourceCalculations.All(c => c.HasOutput)); Assert.IsTrue(sourceCalculations.All(c => !c.Output.HasGeneralResult)); mocks.VerifyAll(); } [Test] [TestCaseSource(nameof(GetCalculationsFuncs))] public void GivenAssessmentSectionWithHydraulicBoundaryLocationCalculations_WhenSourceAssessmentSectionHasOutputWithIllustrationPoints_ThenCalculationsMerged( Func> getCalculationsFunc) { // Setup var mocks = new MockRepository(); var viewCommands = mocks.Stub(); mocks.ReplayAll(); var locations = new[] { new TestHydraulicBoundaryLocation(), new TestHydraulicBoundaryLocation() }; AssessmentSection targetAssessmentSection = CreateAssessmentSection(locations); AssessmentSection sourceAssessmentSection = CreateAssessmentSection(locations); IEnumerable targetCalculations = getCalculationsFunc(targetAssessmentSection); IEnumerable sourceCalculations = getCalculationsFunc(sourceAssessmentSection); SetOutput(targetCalculations); SetOutput(sourceCalculations, true); var handler = new AssessmentSectionMergeHandler(viewCommands); // Precondition Assert.IsTrue(targetCalculations.All(c => c.HasOutput)); Assert.IsTrue(targetCalculations.All(c => !c.Output.HasGeneralResult)); Assert.IsTrue(sourceCalculations.All(c => c.HasOutput)); Assert.IsTrue(sourceCalculations.All(c => c.Output.HasGeneralResult)); // Call handler.PerformMerge(targetAssessmentSection, sourceAssessmentSection, Enumerable.Empty()); // Assert Assert.IsTrue(targetCalculations.All(c => c.HasOutput)); Assert.IsTrue(targetCalculations.All(c => c.Output.HasGeneralResult)); mocks.VerifyAll(); } private static void SetOutput(IEnumerable calculations, bool illustrationPoints = false) { foreach (HydraulicBoundaryLocationCalculation calculation in calculations) { calculation.Output = illustrationPoints ? new TestHydraulicBoundaryLocationCalculationOutput(new TestGeneralResultSubMechanismIllustrationPoint()) : new TestHydraulicBoundaryLocationCalculationOutput(); } } private static IEnumerable GetCalculationsFuncs() { yield return new TestCaseData(new Func>( section => section.WaterLevelCalculationsForFactorizedSignalingNorm)); yield return new TestCaseData(new Func>( section => section.WaterLevelCalculationsForSignalingNorm)); yield return new TestCaseData(new Func>( section => section.WaterLevelCalculationsForLowerLimitNorm)); yield return new TestCaseData(new Func>( section => section.WaterLevelCalculationsForFactorizedLowerLimitNorm)); yield return new TestCaseData(new Func>( section => section.WaveHeightCalculationsForFactorizedSignalingNorm)); yield return new TestCaseData(new Func>( section => section.WaveHeightCalculationsForSignalingNorm)); yield return new TestCaseData(new Func>( section => section.WaveHeightCalculationsForLowerLimitNorm)); yield return new TestCaseData(new Func>( section => section.WaveHeightCalculationsForFactorizedLowerLimitNorm)); } #endregion } }