// Copyright (C) Stichting Deltares 2018. 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 NUnit.Framework;
using Rhino.Mocks;
using Ringtoets.ClosingStructures.Data;
using Ringtoets.Common.Data.AssessmentSection;
using Ringtoets.Common.Data.Calculation;
using Ringtoets.Common.Data.DikeProfiles;
using Ringtoets.Common.Data.FailureMechanism;
using Ringtoets.Common.Data.Hydraulics;
using Ringtoets.Common.Data.Structures;
using Ringtoets.Common.Data.TestUtil;
using Ringtoets.Common.Service;
using Ringtoets.DuneErosion.Data;
using Ringtoets.DuneErosion.Data.TestUtil;
using Ringtoets.GrassCoverErosionInwards.Data;
using Ringtoets.GrassCoverErosionOutwards.Data;
using Ringtoets.GrassCoverErosionOutwards.Data.TestUtil;
using Ringtoets.HeightStructures.Data;
using Ringtoets.Integration.TestUtil;
using Ringtoets.MacroStabilityInwards.Data;
using Ringtoets.MacroStabilityInwards.Data.SoilProfile;
using Ringtoets.MacroStabilityInwards.Primitives;
using Ringtoets.Piping.Data;
using Ringtoets.Piping.Data.SoilProfile;
using Ringtoets.Piping.Primitives;
using Ringtoets.StabilityPointStructures.Data;
using Ringtoets.StabilityStoneCover.Data;
using Ringtoets.WaveImpactAsphaltCover.Data;
using Riskeer.Integration.Data;
using Riskeer.Integration.Data.StandAlone;
namespace Ringtoets.Integration.Service.Test
{
[TestFixture]
public class RingtoetsDataSynchronizationServiceTest
{
[Test]
public void ClearFailureMechanismCalculationOutputs_WithoutAssessmentSection_ThrowsArgumentNullException()
{
// Call
TestDelegate test = () => RingtoetsDataSynchronizationService.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 = RingtoetsDataSynchronizationService.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 = () => RingtoetsDataSynchronizationService.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 = RingtoetsDataSynchronizationService.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 = () => RingtoetsDataSynchronizationService.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 = RingtoetsDataSynchronizationService.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 = () => RingtoetsDataSynchronizationService.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 = RingtoetsDataSynchronizationService.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 = () => RingtoetsDataSynchronizationService.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 = RingtoetsDataSynchronizationService.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 = RingtoetsDataSynchronizationService.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 = RingtoetsDataSynchronizationService.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 = () => RingtoetsDataSynchronizationService.ClearHydraulicBoundaryLocationCalculationOutputOfFailureMechanisms((IEnumerable) null);
// Assert
var exception = Assert.Throws(test);
Assert.AreEqual("failureMechanisms", exception.ParamName);
}
[Test]
public void ClearHydraulicBoundaryLocationCalculationOutputOfFailureMechanisms_FailureMechanismsContainingNoLocations_DoNothing()
{
// Call
IEnumerable affectedObjects = RingtoetsDataSynchronizationService.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 = RingtoetsDataSynchronizationService.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 = RingtoetsDataSynchronizationService.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 = () => RingtoetsDataSynchronizationService.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
RingtoetsDataSynchronizationService.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