Index: Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.Service/ClosingStructuresCalculationService.cs =================================================================== diff -u -r2ebc37cd8cfea18e73b2db4975be5a48272ba9ba -r539779c3ab8d787b26f6a2b1ec518eace8d49a02 --- Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.Service/ClosingStructuresCalculationService.cs (.../ClosingStructuresCalculationService.cs) (revision 2ebc37cd8cfea18e73b2db4975be5a48272ba9ba) +++ Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.Service/ClosingStructuresCalculationService.cs (.../ClosingStructuresCalculationService.cs) (revision 539779c3ab8d787b26f6a2b1ec518eace8d49a02) @@ -109,26 +109,6 @@ } } - private static StructuresClosureCalculationInput CreateStructuresClosureCalculationInput(StructuresCalculation calculation, ClosingStructuresFailureMechanism failureMechanism, FailureMechanismSection failureMechanismSection) - { - StructuresClosureCalculationInput input; - switch (calculation.InputParameters.InflowModelType) - { - case ClosingStructureInflowModelType.VerticalWall: - input = CreateClosureVerticalWallCalculationInput(calculation, failureMechanismSection, failureMechanism.GeneralInput); - break; - case ClosingStructureInflowModelType.LowSill: - input = CreateLowSillCalculationInput(calculation, failureMechanismSection, failureMechanism.GeneralInput); - break; - case ClosingStructureInflowModelType.FloodedCulvert: - input = CreateFloodedCulvertCalculationInput(calculation, failureMechanismSection, failureMechanism.GeneralInput); - break; - default: - throw new NotSupportedException("ClosingStructureInflowModelType"); - } - return input; - } - /// /// Cancels any ongoing structures closure calculation. /// @@ -152,15 +132,35 @@ return !messages.Any(); } + private static StructuresClosureCalculationInput CreateStructuresClosureCalculationInput(StructuresCalculation calculation, ClosingStructuresFailureMechanism failureMechanism, FailureMechanismSection failureMechanismSection) + { + StructuresClosureCalculationInput input; + switch (calculation.InputParameters.InflowModelType) + { + case ClosingStructureInflowModelType.VerticalWall: + input = CreateClosureVerticalWallCalculationInput(calculation, failureMechanismSection, failureMechanism.GeneralInput); + break; + case ClosingStructureInflowModelType.LowSill: + input = CreateLowSillCalculationInput(calculation, failureMechanismSection, failureMechanism.GeneralInput); + break; + case ClosingStructureInflowModelType.FloodedCulvert: + input = CreateFloodedCulvertCalculationInput(calculation, failureMechanismSection, failureMechanism.GeneralInput); + break; + default: + throw new NotSupportedException("ClosingStructureInflowModelType"); + } + return input; + } + private static StructuresClosureVerticalWallCalculationInput CreateClosureVerticalWallCalculationInput(StructuresCalculation calculation, FailureMechanismSection failureMechanismSection, GeneralClosingStructuresInput generalInput) { return new StructuresClosureVerticalWallCalculationInput( calculation.InputParameters.HydraulicBoundaryLocation.Id, new HydraRingSection(1, failureMechanismSection.GetSectionLength(), calculation.InputParameters.StructureNormalOrientation), - ParseForeshore(calculation.InputParameters), - ParseBreakWater(calculation.InputParameters), + CalculationInputParser.ParseForeshore(calculation.InputParameters), + CalculationInputParser.ParseBreakWater(calculation.InputParameters), generalInput.GravitationalAcceleration, calculation.InputParameters.FactorStormDurationOpenStructure, calculation.InputParameters.FailureProbabilityOpenStructure, @@ -190,8 +190,8 @@ return new StructuresClosureLowSillCalculationInput( calculation.InputParameters.HydraulicBoundaryLocation.Id, new HydraRingSection(1, failureMechanismSection.GetSectionLength(), calculation.InputParameters.StructureNormalOrientation), - ParseForeshore(calculation.InputParameters), - ParseBreakWater(calculation.InputParameters), + CalculationInputParser.ParseForeshore(calculation.InputParameters), + CalculationInputParser.ParseBreakWater(calculation.InputParameters), generalInput.GravitationalAcceleration, calculation.InputParameters.FactorStormDurationOpenStructure, calculation.InputParameters.FailureProbabilityOpenStructure, @@ -220,8 +220,8 @@ return new StructuresClosureFloodedCulvertCalculationInput( calculation.InputParameters.HydraulicBoundaryLocation.Id, new HydraRingSection(1, failureMechanismSection.GetSectionLength(), calculation.InputParameters.StructureNormalOrientation), - ParseForeshore(calculation.InputParameters), - ParseBreakWater(calculation.InputParameters), + CalculationInputParser.ParseForeshore(calculation.InputParameters), + CalculationInputParser.ParseBreakWater(calculation.InputParameters), generalInput.GravitationalAcceleration, calculation.InputParameters.FactorStormDurationOpenStructure, calculation.InputParameters.FailureProbabilityOpenStructure, @@ -241,16 +241,6 @@ calculation.InputParameters.InsideWaterLevel.Mean, calculation.InputParameters.InsideWaterLevel.StandardDeviation); } - private static IEnumerable ParseForeshore(ClosingStructuresInput input) - { - return input.UseForeshore ? input.ForeshoreGeometry.Select(c => new HydraRingForelandPoint(c.X, c.Y)) : new HydraRingForelandPoint[0]; - } - - private static HydraRingBreakWater ParseBreakWater(ClosingStructuresInput input) - { - return input.UseBreakWater ? new HydraRingBreakWater((int) input.BreakWater.Type, input.BreakWater.Height) : null; - } - private static string[] ValidateInput(ClosingStructuresInput inputParameters, IAssessmentSection assessmentSection) { var validationResult = new List(); Index: Ringtoets/Common/src/Ringtoets.Common.Service/CalculationInputParser.cs =================================================================== diff -u --- Ringtoets/Common/src/Ringtoets.Common.Service/CalculationInputParser.cs (revision 0) +++ Ringtoets/Common/src/Ringtoets.Common.Service/CalculationInputParser.cs (revision 539779c3ab8d787b26f6a2b1ec518eace8d49a02) @@ -0,0 +1,56 @@ +// Copyright (C) Stichting Deltares 2016. 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.Collections.Generic; +using System.Linq; +using Ringtoets.Common.Data.DikeProfiles; +using Ringtoets.HydraRing.Calculation.Data; + +namespace Ringtoets.Common.Service +{ + /// + /// Helper class to parse the breakwater and foreshore properties of a calculation input. + /// + public static class CalculationInputParser + { + /// + /// Parses the foreshore geometry of a calculation input object into a of + /// . + /// + /// A calculation input object that implements . + /// A of . + public static IEnumerable ParseForeshore(IUseForeshore input) + { + return input.UseForeshore ? input.ForeshoreGeometry.Select(c => new HydraRingForelandPoint(c.X, c.Y)) : new HydraRingForelandPoint[0]; + } + + /// + /// Parses the breakwater properties of a calculation input object into a object. + /// + /// A calculation input object that implements . + /// A object, null if + /// is false + public static HydraRingBreakWater ParseBreakWater(IUseBreakWater input) + { + return input.UseBreakWater ? new HydraRingBreakWater((int) input.BreakWater.Type, input.BreakWater.Height) : null; + } + } +} \ No newline at end of file Index: Ringtoets/Common/src/Ringtoets.Common.Service/Ringtoets.Common.Service.csproj =================================================================== diff -u -rc786273ba6460b0498c00ff70d1703eee74fadb8 -r539779c3ab8d787b26f6a2b1ec518eace8d49a02 --- Ringtoets/Common/src/Ringtoets.Common.Service/Ringtoets.Common.Service.csproj (.../Ringtoets.Common.Service.csproj) (revision c786273ba6460b0498c00ff70d1703eee74fadb8) +++ Ringtoets/Common/src/Ringtoets.Common.Service/Ringtoets.Common.Service.csproj (.../Ringtoets.Common.Service.csproj) (revision 539779c3ab8d787b26f6a2b1ec518eace8d49a02) @@ -49,6 +49,7 @@ + Index: Ringtoets/Common/test/Ringtoets.Common.Service.Test/CalculationInputParserTest.cs =================================================================== diff -u --- Ringtoets/Common/test/Ringtoets.Common.Service.Test/CalculationInputParserTest.cs (revision 0) +++ Ringtoets/Common/test/Ringtoets.Common.Service.Test/CalculationInputParserTest.cs (revision 539779c3ab8d787b26f6a2b1ec518eace8d49a02) @@ -0,0 +1,132 @@ +// Copyright (C) Stichting Deltares 2016. 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; +using System.Collections.Generic; +using System.Linq; +using Core.Common.Base.Data; +using Core.Common.Base.Geometry; +using NUnit.Framework; +using Rhino.Mocks; +using Ringtoets.Common.Data.DikeProfiles; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.HydraRing.Calculation.Data; + +namespace Ringtoets.Common.Service.Test +{ + [TestFixture] + public class CalculationInputParserTest + { + [Test] + public void ParseForeshore_Use_ReturnCollection() + { + // Setup + var mockRepository = new MockRepository(); + var foreshoreStub = mockRepository.Stub(); + foreshoreStub.UseForeshore = true; + + Point2D pointOne = new Point2D(1, 1); + Point2D pointTwo = new Point2D(2, 2); + foreshoreStub.Stub(call => call.ForeshoreGeometry).Return(new RoundedPoint2DCollection(2, new[] + { + pointOne, + pointTwo + })); + mockRepository.ReplayAll(); + + // Call + IEnumerable parsedForeshore = CalculationInputParser.ParseForeshore(foreshoreStub); + + // Assert + HydraRingForelandPoint[] actualForelandPoints = parsedForeshore.ToArray(); + Assert.AreEqual(pointOne.X, actualForelandPoints[0].X); + Assert.AreEqual(pointOne.Y, actualForelandPoints[0].Z); + Assert.AreEqual(pointTwo.X, actualForelandPoints[1].X); + Assert.AreEqual(pointTwo.Y, actualForelandPoints[1].Z); + + mockRepository.VerifyAll(); + } + + [Test] + public void ParseForeshore_DoesNotUse_ReturnEmptyCollection() + { + // Setup + var mockRepository = new MockRepository(); + var foreshoreStub = mockRepository.Stub(); + foreshoreStub.UseForeshore = false; + mockRepository.ReplayAll(); + + // Call + IEnumerable parsedForeshore = CalculationInputParser.ParseForeshore(foreshoreStub); + + // Assert + CollectionAssert.IsEmpty(parsedForeshore); + mockRepository.VerifyAll(); + } + + [Test] + [TestCase(BreakWaterType.Wall)] + [TestCase(BreakWaterType.Caisson)] + [TestCase(BreakWaterType.Dam)] + public void ParseBreakWater_Use_ReturnHydraRingBreakWater(BreakWaterType breakWaterType) + { + // Setup + var random = new Random(22); + var breakWaterHeight = random.NextDouble(); + + var mockRepository = new MockRepository(); + var breakWaterStub = mockRepository.Stub(); + breakWaterStub.UseBreakWater = true; + var expectedBreakWater = new BreakWater(breakWaterType, breakWaterHeight); + breakWaterStub.Stub(call => call.BreakWater).Return(expectedBreakWater); + mockRepository.ReplayAll(); + + // Call + HydraRingBreakWater parsedBreakWater = CalculationInputParser.ParseBreakWater(breakWaterStub); + + // Assert + Assert.AreEqual((int) expectedBreakWater.Type, parsedBreakWater.Type); + Assert.AreEqual(expectedBreakWater.Height, parsedBreakWater.Height, expectedBreakWater.Height.GetAccuracy()); + mockRepository.VerifyAll(); + } + + [Test] + [TestCase(BreakWaterType.Wall)] + [TestCase(BreakWaterType.Caisson)] + [TestCase(BreakWaterType.Dam)] + public void ParseBreakWater_DoesNotUse_ReturnNull(BreakWaterType breakWaterType) + { + // Setup + var mockRepository = new MockRepository(); + var breakWaterStub = mockRepository.Stub(); + breakWaterStub.UseBreakWater = false; + mockRepository.ReplayAll(); + + // Call + HydraRingBreakWater parsedBreakWater = CalculationInputParser.ParseBreakWater(breakWaterStub); + + // Assert + Assert.IsNull(parsedBreakWater); + mockRepository.VerifyAll(); + } + } +} \ No newline at end of file Index: Ringtoets/Common/test/Ringtoets.Common.Service.Test/Ringtoets.Common.Service.Test.csproj =================================================================== diff -u -rc786273ba6460b0498c00ff70d1703eee74fadb8 -r539779c3ab8d787b26f6a2b1ec518eace8d49a02 --- Ringtoets/Common/test/Ringtoets.Common.Service.Test/Ringtoets.Common.Service.Test.csproj (.../Ringtoets.Common.Service.Test.csproj) (revision c786273ba6460b0498c00ff70d1703eee74fadb8) +++ Ringtoets/Common/test/Ringtoets.Common.Service.Test/Ringtoets.Common.Service.Test.csproj (.../Ringtoets.Common.Service.Test.csproj) (revision 539779c3ab8d787b26f6a2b1ec518eace8d49a02) @@ -57,6 +57,7 @@ Properties\GlobalAssembly.cs + Index: Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Service/GrassCoverErosionInwardsCalculationService.cs =================================================================== diff -u -r16cb360eae0014270ebb6700054afdbbd565ae65 -r539779c3ab8d787b26f6a2b1ec518eace8d49a02 --- Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Service/GrassCoverErosionInwardsCalculationService.cs (.../GrassCoverErosionInwardsCalculationService.cs) (revision 16cb360eae0014270ebb6700054afdbbd565ae65) +++ Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Service/GrassCoverErosionInwardsCalculationService.cs (.../GrassCoverErosionInwardsCalculationService.cs) (revision 539779c3ab8d787b26f6a2b1ec518eace8d49a02) @@ -208,8 +208,8 @@ return new OvertoppingCalculationInput(calculation.InputParameters.HydraulicBoundaryLocation.Id, new HydraRingSection(1, failureMechanismSection.GetSectionLength(), calculation.InputParameters.Orientation), ParseProfilePoints(calculation.InputParameters.DikeGeometry), - ParseForeshore(calculation.InputParameters), - ParseBreakWater(calculation.InputParameters), + CalculationInputParser.ParseForeshore(calculation.InputParameters), + CalculationInputParser.ParseBreakWater(calculation.InputParameters), calculation.InputParameters.DikeHeight, generalInput.CriticalOvertoppingModelFactor, generalInput.FbFactor.Mean, @@ -232,8 +232,8 @@ assessmentSection.FailureMechanismContribution.Norm, new HydraRingSection(1, failureMechanismSection.GetSectionLength(), calculation.InputParameters.Orientation), ParseProfilePoints(calculation.InputParameters.DikeGeometry), - ParseForeshore(calculation.InputParameters), - ParseBreakWater(calculation.InputParameters), + CalculationInputParser.ParseForeshore(calculation.InputParameters), + CalculationInputParser.ParseBreakWater(calculation.InputParameters), generalInput.CriticalOvertoppingModelFactor, generalInput.FbFactor.Mean, generalInput.FbFactor.StandardDeviation, @@ -248,16 +248,6 @@ generalInput.FshallowModelFactor.StandardDeviation); } - private static HydraRingBreakWater ParseBreakWater(GrassCoverErosionInwardsInput input) - { - return input.UseBreakWater ? new HydraRingBreakWater((int) input.BreakWater.Type, input.BreakWater.Height) : null; - } - - private static IEnumerable ParseForeshore(GrassCoverErosionInwardsInput input) - { - return input.UseForeshore ? input.ForeshoreGeometry.Select(c => new HydraRingForelandPoint(c.X, c.Y)) : new HydraRingForelandPoint[0]; - } - private static IEnumerable ParseProfilePoints(RoughnessPoint[] roughnessProfilePoints) { for (var i = 0; i < roughnessProfilePoints.Length; i++) Index: Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Service/HeightStructuresCalculationService.cs =================================================================== diff -u -r3e2b418a9bbc27e2e990b15325b1350e6d56dc3d -r539779c3ab8d787b26f6a2b1ec518eace8d49a02 --- Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Service/HeightStructuresCalculationService.cs (.../HeightStructuresCalculationService.cs) (revision 3e2b418a9bbc27e2e990b15325b1350e6d56dc3d) +++ Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Service/HeightStructuresCalculationService.cs (.../HeightStructuresCalculationService.cs) (revision 539779c3ab8d787b26f6a2b1ec518eace8d49a02) @@ -143,8 +143,8 @@ return new StructuresOvertoppingCalculationInput( calculation.InputParameters.HydraulicBoundaryLocation.Id, new HydraRingSection(1, failureMechanismSection.GetSectionLength(), calculation.InputParameters.StructureNormalOrientation), - ParseForeshore(calculation.InputParameters), - ParseBreakWater(calculation.InputParameters), + CalculationInputParser.ParseForeshore(calculation.InputParameters), + CalculationInputParser.ParseBreakWater(calculation.InputParameters), generalInput.GravitationalAcceleration, generalInput.ModelFactorOvertoppingFlow.Mean, generalInput.ModelFactorOvertoppingFlow.StandardDeviation, calculation.InputParameters.LevelCrestStructure.Mean, calculation.InputParameters.LevelCrestStructure.StandardDeviation, @@ -162,16 +162,6 @@ calculation.InputParameters.StormDuration.Mean, calculation.InputParameters.StormDuration.CoefficientOfVariation); } - private static IEnumerable ParseForeshore(HeightStructuresInput input) - { - return input.UseForeshore ? input.ForeshoreGeometry.Select(c => new HydraRingForelandPoint(c.X, c.Y)) : new HydraRingForelandPoint[0]; - } - - private static HydraRingBreakWater ParseBreakWater(HeightStructuresInput input) - { - return input.UseBreakWater ? new HydraRingBreakWater((int) input.BreakWater.Type, input.BreakWater.Height) : null; - } - private static string[] ValidateInput(HeightStructuresInput inputParameters, IAssessmentSection assessmentSection) { var validationResults = new List();