Index: Ringtoets/Integration/src/Ringtoets.Integration.Service/AssessmentSectionHydraulicBoundaryLocationCalculationActivityFactory.cs =================================================================== diff -u --- Ringtoets/Integration/src/Ringtoets.Integration.Service/AssessmentSectionHydraulicBoundaryLocationCalculationActivityFactory.cs (revision 0) +++ Ringtoets/Integration/src/Ringtoets.Integration.Service/AssessmentSectionHydraulicBoundaryLocationCalculationActivityFactory.cs (revision 5cb386767f4e8fcfee8737bcd44126664d203144) @@ -0,0 +1,122 @@ +// 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 Ringtoets.Common.Data.AssessmentSection; +using Ringtoets.Common.Service; +using RingtoetsCommonDataResources = Ringtoets.Common.Data.Properties.Resources; + +namespace Ringtoets.Integration.Service +{ + /// + /// This class defines factory methods that can be used to create instances of for + /// hydraulic boundary location calculations on assessment section level. + /// + public static class AssessmentSectionHydraulicBoundaryLocationCalculationActivityFactory + { + /// + /// Creates a collection of for wave height calculations + /// based on the given . + /// + /// The assessment section to create the activities for. + /// A collection of . + /// Thrown when is null. + public static IEnumerable CreateWaveHeightCalculationActivities(IAssessmentSection assessmentSection) + { + if (assessmentSection == null) + { + throw new ArgumentNullException(nameof(assessmentSection)); + } + + var activities = new List(); + + activities.AddRange(HydraulicBoundaryLocationCalculationActivityFactory.CreateWaveHeightCalculationActivities( + assessmentSection, + assessmentSection.WaveHeightCalculationsForFactorizedSignalingNorm, + assessmentSection.GetNorm(AssessmentSectionCategoryType.FactorizedSignalingNorm), + RingtoetsCommonDataResources.AssessmentSectionCategoryType_FactorizedSignalingNorm_DisplayName)); + + activities.AddRange(HydraulicBoundaryLocationCalculationActivityFactory.CreateWaveHeightCalculationActivities( + assessmentSection, + assessmentSection.WaveHeightCalculationsForSignalingNorm, + assessmentSection.GetNorm(AssessmentSectionCategoryType.SignalingNorm), + RingtoetsCommonDataResources.AssessmentSectionCategoryType_SignalingNorm_DisplayName)); + + activities.AddRange(HydraulicBoundaryLocationCalculationActivityFactory.CreateWaveHeightCalculationActivities( + assessmentSection, + assessmentSection.WaveHeightCalculationsForLowerLimitNorm, + assessmentSection.GetNorm(AssessmentSectionCategoryType.LowerLimitNorm), + RingtoetsCommonDataResources.AssessmentSectionCategoryType_LowerLimitNorm_DisplayName)); + + activities.AddRange(HydraulicBoundaryLocationCalculationActivityFactory.CreateWaveHeightCalculationActivities( + assessmentSection, + assessmentSection.WaveHeightCalculationsForFactorizedLowerLimitNorm, + assessmentSection.GetNorm(AssessmentSectionCategoryType.FactorizedLowerLimitNorm), + RingtoetsCommonDataResources.AssessmentSectionCategoryType_FactorizedLowerLimitNorm_DisplayName)); + + return activities; + } + + /// + /// Creates a collection of for wave height calculations + /// based on the given . + /// + /// The assessment section to create the activities for. + /// A collection of . + /// Thrown when is null. + public static IEnumerable CreateDesignWaterLevelCalculationActivities(IAssessmentSection assessmentSection) + { + if (assessmentSection == null) + { + throw new ArgumentNullException(nameof(assessmentSection)); + } + + var activities = new List(); + + activities.AddRange(HydraulicBoundaryLocationCalculationActivityFactory.CreateDesignWaterLevelCalculationActivities( + assessmentSection, + assessmentSection.WaterLevelCalculationsForFactorizedSignalingNorm, + assessmentSection.GetNorm(AssessmentSectionCategoryType.FactorizedSignalingNorm), + RingtoetsCommonDataResources.AssessmentSectionCategoryType_FactorizedSignalingNorm_DisplayName)); + + activities.AddRange(HydraulicBoundaryLocationCalculationActivityFactory.CreateDesignWaterLevelCalculationActivities( + assessmentSection, + assessmentSection.WaterLevelCalculationsForSignalingNorm, + assessmentSection.GetNorm(AssessmentSectionCategoryType.SignalingNorm), + RingtoetsCommonDataResources.AssessmentSectionCategoryType_SignalingNorm_DisplayName)); + + activities.AddRange(HydraulicBoundaryLocationCalculationActivityFactory.CreateDesignWaterLevelCalculationActivities( + assessmentSection, + assessmentSection.WaterLevelCalculationsForLowerLimitNorm, + assessmentSection.GetNorm(AssessmentSectionCategoryType.LowerLimitNorm), + RingtoetsCommonDataResources.AssessmentSectionCategoryType_LowerLimitNorm_DisplayName)); + + activities.AddRange(HydraulicBoundaryLocationCalculationActivityFactory.CreateDesignWaterLevelCalculationActivities( + assessmentSection, + assessmentSection.WaterLevelCalculationsForFactorizedLowerLimitNorm, + assessmentSection.GetNorm(AssessmentSectionCategoryType.FactorizedLowerLimitNorm), + RingtoetsCommonDataResources.AssessmentSectionCategoryType_FactorizedLowerLimitNorm_DisplayName)); + + return activities; + } + } +} \ No newline at end of file Index: Ringtoets/Integration/src/Ringtoets.Integration.Service/Ringtoets.Integration.Service.csproj =================================================================== diff -u -re43447e29761f3bb845f13fc3418d9fb856ab323 -r5cb386767f4e8fcfee8737bcd44126664d203144 --- Ringtoets/Integration/src/Ringtoets.Integration.Service/Ringtoets.Integration.Service.csproj (.../Ringtoets.Integration.Service.csproj) (revision e43447e29761f3bb845f13fc3418d9fb856ab323) +++ Ringtoets/Integration/src/Ringtoets.Integration.Service/Ringtoets.Integration.Service.csproj (.../Ringtoets.Integration.Service.csproj) (revision 5cb386767f4e8fcfee8737bcd44126664d203144) @@ -15,6 +15,7 @@ + Index: Ringtoets/Integration/test/Ringtoets.Integration.Service.Test/AssessmentSectionHydraulicBoundaryLocationCalculationActivityFactoryTest.cs =================================================================== diff -u --- Ringtoets/Integration/test/Ringtoets.Integration.Service.Test/AssessmentSectionHydraulicBoundaryLocationCalculationActivityFactoryTest.cs (revision 0) +++ Ringtoets/Integration/test/Ringtoets.Integration.Service.Test/AssessmentSectionHydraulicBoundaryLocationCalculationActivityFactoryTest.cs (revision 5cb386767f4e8fcfee8737bcd44126664d203144) @@ -0,0 +1,227 @@ +// 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.IO; +using System.Linq; +using Core.Common.Base.Service; +using Core.Common.TestUtil; +using Core.Common.Util; +using NUnit.Framework; +using Rhino.Mocks; +using Ringtoets.Common.Data.Hydraulics; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.Common.Service; +using Ringtoets.HydraRing.Calculation.Calculator.Factory; +using Ringtoets.HydraRing.Calculation.Data.Input.Hydraulics; +using Ringtoets.HydraRing.Calculation.TestUtil.Calculator; + +namespace Ringtoets.Integration.Service.Test +{ + [TestFixture] + public class AssessmentSectionHydraulicBoundaryLocationCalculationActivityFactoryTest + { + private static readonly string testDataPath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Integration.Service, "HydraRingCalculation"); + + [Test] + public void CreateDesignWaterLevelCalculationActivities_AssessmentSectionNull_ThrowsArgumentNullException() + { + // Call + TestDelegate test = () => AssessmentSectionHydraulicBoundaryLocationCalculationActivityFactory.CreateDesignWaterLevelCalculationActivities(null); + + // Assert + var exception = Assert.Throws(test); + Assert.AreEqual("assessmentSection", exception.ParamName); + } + + [Test] + public void CreateDesignWaterLevelCalculationActivities_WithValidData_ExpectedInputSetToActivities() + { + // Setup + var assessmentSection = new AssessmentSectionStub + { + HydraulicBoundaryDatabase = + { + FilePath = Path.Combine(testDataPath, "HRD ijsselmeer.sqlite") + } + }; + + var hydraulicBoundaryLocation1 = new TestHydraulicBoundaryLocation("locationName 1"); + var hydraulicBoundaryLocation2 = new TestHydraulicBoundaryLocation("locationName 2"); + assessmentSection.SetHydraulicBoundaryLocationCalculations(new[] + { + hydraulicBoundaryLocation1, + hydraulicBoundaryLocation2 + }); + + // Call + IEnumerable activities = + AssessmentSectionHydraulicBoundaryLocationCalculationActivityFactory.CreateDesignWaterLevelCalculationActivities(assessmentSection); + + // Assert + double signalingNorm = assessmentSection.FailureMechanismContribution.SignalingNorm; + double factorizedSignalingNorm = signalingNorm / 30; + AssertDesignWaterLevelCalculationActivity(activities.First(), + hydraulicBoundaryLocation1, + factorizedSignalingNorm); + AssertDesignWaterLevelCalculationActivity(activities.ElementAt(1), + hydraulicBoundaryLocation2, + factorizedSignalingNorm); + + AssertDesignWaterLevelCalculationActivity(activities.ElementAt(2), + hydraulicBoundaryLocation1, + signalingNorm); + AssertDesignWaterLevelCalculationActivity(activities.ElementAt(3), + hydraulicBoundaryLocation2, + signalingNorm); + + double lowerLimitNorm = assessmentSection.FailureMechanismContribution.LowerLimitNorm; + AssertDesignWaterLevelCalculationActivity(activities.ElementAt(4), + hydraulicBoundaryLocation1, + lowerLimitNorm); + AssertDesignWaterLevelCalculationActivity(activities.ElementAt(5), + hydraulicBoundaryLocation2, + lowerLimitNorm); + + double factorizedLowerLimitNorm = lowerLimitNorm * 30; + AssertDesignWaterLevelCalculationActivity(activities.ElementAt(6), + hydraulicBoundaryLocation1, + factorizedLowerLimitNorm); + AssertDesignWaterLevelCalculationActivity(activities.ElementAt(7), + hydraulicBoundaryLocation2, + factorizedLowerLimitNorm); + } + + [Test] + public void CreateWaveHeightCalculationActivities_AssessmentSectionNull_ThrowsArgumentNullException() + { + // Call + TestDelegate test = () => AssessmentSectionHydraulicBoundaryLocationCalculationActivityFactory.CreateWaveHeightCalculationActivities(null); + + // Assert + var exception = Assert.Throws(test); + Assert.AreEqual("assessmentSection", exception.ParamName); + } + + [Test] + public void CreateWaveHeightCalculationActivities_WithValidData_ExpectedInputSetToActivities() + { + // Setup + var assessmentSection = new AssessmentSectionStub + { + HydraulicBoundaryDatabase = + { + FilePath = Path.Combine(testDataPath, "HRD ijsselmeer.sqlite") + } + }; + + var hydraulicBoundaryLocation1 = new TestHydraulicBoundaryLocation("locationName 1"); + var hydraulicBoundaryLocation2 = new TestHydraulicBoundaryLocation("locationName 2"); + assessmentSection.SetHydraulicBoundaryLocationCalculations(new[] + { + hydraulicBoundaryLocation1, + hydraulicBoundaryLocation2 + }); + + // Call + IEnumerable activities = + AssessmentSectionHydraulicBoundaryLocationCalculationActivityFactory.CreateWaveHeightCalculationActivities(assessmentSection); + + // Assert + double signalingNorm = assessmentSection.FailureMechanismContribution.SignalingNorm; + double factorizedSignalingNorm = signalingNorm / 30; + AssertWaveHeightCalculationActivity(activities.First(), + hydraulicBoundaryLocation1, + factorizedSignalingNorm); + AssertWaveHeightCalculationActivity(activities.ElementAt(1), + hydraulicBoundaryLocation2, + factorizedSignalingNorm); + + AssertWaveHeightCalculationActivity(activities.ElementAt(2), + hydraulicBoundaryLocation1, + signalingNorm); + AssertWaveHeightCalculationActivity(activities.ElementAt(3), + hydraulicBoundaryLocation2, + signalingNorm); + + double lowerLimitNorm = assessmentSection.FailureMechanismContribution.LowerLimitNorm; + AssertWaveHeightCalculationActivity(activities.ElementAt(4), + hydraulicBoundaryLocation1, + lowerLimitNorm); + AssertWaveHeightCalculationActivity(activities.ElementAt(5), + hydraulicBoundaryLocation2, + lowerLimitNorm); + + double factorizedLowerLimitNorm = lowerLimitNorm * 30; + AssertWaveHeightCalculationActivity(activities.ElementAt(6), + hydraulicBoundaryLocation1, + factorizedLowerLimitNorm); + AssertWaveHeightCalculationActivity(activities.ElementAt(7), + hydraulicBoundaryLocation2, + factorizedLowerLimitNorm); + } + + private static void AssertDesignWaterLevelCalculationActivity(Activity activity, + HydraulicBoundaryLocation hydraulicBoundaryLocation, + double norm) + { + var mocks = new MockRepository(); + var designWaterLevelCalculator = new TestDesignWaterLevelCalculator(); + var calculatorFactory = mocks.Stub(); + calculatorFactory.Expect(cf => cf.CreateDesignWaterLevelCalculator(testDataPath, string.Empty)).Return(designWaterLevelCalculator); + mocks.ReplayAll(); + + using (new HydraRingCalculatorFactoryConfig(calculatorFactory)) + { + activity.Run(); + + AssessmentLevelCalculationInput actualCalculationInput = designWaterLevelCalculator.ReceivedInputs.Single(); + Assert.AreEqual(hydraulicBoundaryLocation.Id, actualCalculationInput.HydraulicBoundaryLocationId); + Assert.AreEqual(StatisticsConverter.ProbabilityToReliability(norm), actualCalculationInput.Beta); + } + + mocks.VerifyAll(); + } + + private static void AssertWaveHeightCalculationActivity(Activity activity, + HydraulicBoundaryLocation hydraulicBoundaryLocation, + double norm) + { + var mocks = new MockRepository(); + var waveHeightCalculator = new TestWaveHeightCalculator(); + var calculatorFactory = mocks.Stub(); + calculatorFactory.Expect(cf => cf.CreateWaveHeightCalculator(testDataPath, string.Empty)).Return(waveHeightCalculator); + mocks.ReplayAll(); + + using (new HydraRingCalculatorFactoryConfig(calculatorFactory)) + { + activity.Run(); + + WaveHeightCalculationInput actualCalculationInput = waveHeightCalculator.ReceivedInputs.Single(); + Assert.AreEqual(hydraulicBoundaryLocation.Id, actualCalculationInput.HydraulicBoundaryLocationId); + Assert.AreEqual(StatisticsConverter.ProbabilityToReliability(norm), actualCalculationInput.Beta); + } + + mocks.VerifyAll(); + } + } +} \ No newline at end of file Index: Ringtoets/Integration/test/Ringtoets.Integration.Service.Test/Ringtoets.Integration.Service.Test.csproj =================================================================== diff -u -re43447e29761f3bb845f13fc3418d9fb856ab323 -r5cb386767f4e8fcfee8737bcd44126664d203144 --- Ringtoets/Integration/test/Ringtoets.Integration.Service.Test/Ringtoets.Integration.Service.Test.csproj (.../Ringtoets.Integration.Service.Test.csproj) (revision e43447e29761f3bb845f13fc3418d9fb856ab323) +++ Ringtoets/Integration/test/Ringtoets.Integration.Service.Test/Ringtoets.Integration.Service.Test.csproj (.../Ringtoets.Integration.Service.Test.csproj) (revision 5cb386767f4e8fcfee8737bcd44126664d203144) @@ -23,6 +23,7 @@ + @@ -37,6 +38,10 @@ {3bbfd65b-b277-4e50-ae6d-bd24c3434609} Core.Common.Base + + {F49BD8B2-332A-4C91-A196-8CCE0A2C7D98} + Core.Common.Util + {D749EE4C-CE50-4C17-BF01-9A953028C126} Core.Common.TestUtil @@ -81,6 +86,14 @@ {1C0017D8-35B5-4CA0-8FC7-A83F46DBDC99} Ringtoets.HeightStructures.Data + + {888D4097-8BC2-4703-9FB1-8744C94D525E} + Ringtoets.HydraRing.Calculation + + + {74CBA865-9338-447F-BAD9-28312446AE84} + Ringtoets.HydraRing.Calculation.TestUtil + {83D6B73E-91D5-46B0-9218-955DA1F75F7C} Ringtoets.MacroStabilityInwards.Data