Index: Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Service/GrassCoverErosionInwardsCalculationActivityFactory.cs =================================================================== diff -u --- Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Service/GrassCoverErosionInwardsCalculationActivityFactory.cs (revision 0) +++ Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Service/GrassCoverErosionInwardsCalculationActivityFactory.cs (revision 2499bda2fc2db87a27ce064deb6f9d2e2769d0fa) @@ -0,0 +1,132 @@ +// 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 Ringtoets.Common.Data.AssessmentSection; +using Ringtoets.Common.Data.Calculation; +using Ringtoets.Common.Service; +using Ringtoets.GrassCoverErosionInwards.Data; + +namespace Ringtoets.GrassCoverErosionInwards.Service +{ + /// + /// This class defines factory methodes used to create instances of for + /// grass cover erosion inwards calculations. + /// + public static class GrassCoverErosionInwardsCalculationActivityFactory + { + /// + /// Creates a collection of based on the calculations in + /// . + /// + /// The failure mechanism containing the calculations to create + /// activities for. + /// The assessment section the belongs to. + /// A collection of . + /// Thrown when any parameter is null. + public static IEnumerable CreateCalculationActivities(GrassCoverErosionInwardsFailureMechanism failureMechanism, + IAssessmentSection assessmentSection) + { + if (failureMechanism == null) + { + throw new ArgumentNullException(nameof(failureMechanism)); + } + + if (assessmentSection == null) + { + throw new ArgumentNullException(nameof(assessmentSection)); + } + + return CreateCalculationActivities(failureMechanism.CalculationsGroup, failureMechanism, assessmentSection); + } + + /// + /// Creates a collection of based on the calculations in + /// . + /// + /// The calculations to create activities for. + /// The failure mechanism the calculations belongs to. + /// The assessment section the calculations in + /// belong to. + /// A collection of . + /// Thrown when any parameter is null. + public static IEnumerable CreateCalculationActivities(CalculationGroup calculationGroup, + GrassCoverErosionInwardsFailureMechanism failureMechanism, + IAssessmentSection assessmentSection) + { + if (calculationGroup == null) + { + throw new ArgumentNullException(nameof(calculationGroup)); + } + + if (failureMechanism == null) + { + throw new ArgumentNullException(nameof(failureMechanism)); + } + + if (assessmentSection == null) + { + throw new ArgumentNullException(nameof(assessmentSection)); + } + + return calculationGroup.GetCalculations() + .OfType() + .Select(calc => CreateCalculationActivity(calc, failureMechanism, assessmentSection)) + .ToArray(); + } + + /// + /// Creates a collection of based on the given . + /// + /// The calculation to create an activity for. + /// The failure mechanism the calculation belongs to. + /// The assessment section the + /// belongs to. + /// A . + /// Thrown when any parameter is null. + public static CalculatableActivity CreateCalculationActivity(GrassCoverErosionInwardsCalculation calculation, + GrassCoverErosionInwardsFailureMechanism failureMechanism, + IAssessmentSection assessmentSection) + { + if (calculation == null) + { + throw new ArgumentNullException(nameof(calculation)); + } + + if (failureMechanism == null) + { + throw new ArgumentNullException(nameof(failureMechanism)); + } + + if (assessmentSection == null) + { + throw new ArgumentNullException(nameof(assessmentSection)); + } + + return new GrassCoverErosionInwardsCalculationActivity(calculation, + assessmentSection.HydraulicBoundaryDatabase.FilePath, + failureMechanism, + assessmentSection); + } + } +} \ No newline at end of file Index: Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Service/Ringtoets.GrassCoverErosionInwards.Service.csproj =================================================================== diff -u -r0ea8ce11449d4befadb2b80492479e6f74f9fae8 -r2499bda2fc2db87a27ce064deb6f9d2e2769d0fa --- Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Service/Ringtoets.GrassCoverErosionInwards.Service.csproj (.../Ringtoets.GrassCoverErosionInwards.Service.csproj) (revision 0ea8ce11449d4befadb2b80492479e6f74f9fae8) +++ Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Service/Ringtoets.GrassCoverErosionInwards.Service.csproj (.../Ringtoets.GrassCoverErosionInwards.Service.csproj) (revision 2499bda2fc2db87a27ce064deb6f9d2e2769d0fa) @@ -18,6 +18,7 @@ + True Index: Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Service.Test/GrassCoverErosionInwardsCalculationActivityFactoryTest.cs =================================================================== diff -u --- Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Service.Test/GrassCoverErosionInwardsCalculationActivityFactoryTest.cs (revision 0) +++ Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Service.Test/GrassCoverErosionInwardsCalculationActivityFactoryTest.cs (revision 2499bda2fc2db87a27ce064deb6f9d2e2769d0fa) @@ -0,0 +1,314 @@ +// 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.Geometry; +using Core.Common.Base.Service; +using Core.Common.TestUtil; +using NUnit.Framework; +using Rhino.Mocks; +using Ringtoets.Common.Data.AssessmentSection; +using Ringtoets.Common.Data.Calculation; +using Ringtoets.Common.Data.DikeProfiles; +using Ringtoets.Common.Data.Hydraulics; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.Common.Service; +using Ringtoets.GrassCoverErosionInwards.Data; +using Ringtoets.HydraRing.Calculation.Calculator.Factory; +using Ringtoets.HydraRing.Calculation.TestUtil.Calculator; + +namespace Ringtoets.GrassCoverErosionInwards.Service.Test +{ + [TestFixture] + public class GrassCoverErosionInwardsCalculationActivityFactoryTest + { + private static readonly string testDataPath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Integration.Service, "HydraRingCalculation"); + private static readonly string validFilePath = Path.Combine(testDataPath, "HRD dutch coast south.sqlite"); + + [Test] + public void CreateCalculationActivity_CalculationNull_ThrowsArgumentNullException() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + // Call + TestDelegate test = () => GrassCoverErosionInwardsCalculationActivityFactory.CreateCalculationActivity(null, + new GrassCoverErosionInwardsFailureMechanism(), + assessmentSection); + + // Assert + var exception = Assert.Throws(test); + Assert.AreEqual("calculation", exception.ParamName); + mocks.VerifyAll(); + } + + [Test] + public void CreateCalculationActivity_FailureMechanismNull_ThrowsArgumentNullException() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + // Call + TestDelegate test = () => GrassCoverErosionInwardsCalculationActivityFactory.CreateCalculationActivity(new GrassCoverErosionInwardsCalculation(), + null, + assessmentSection); + + // Assert + var exception = Assert.Throws(test); + Assert.AreEqual("failureMechanism", exception.ParamName); + mocks.VerifyAll(); + } + + [Test] + public void CreateCalculationActivity_AssessmentSectionNull_ThrowsArgumentNullException() + { + // Setup + var calculation = new GrassCoverErosionInwardsCalculation(); + var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); + + // Call + TestDelegate test = () => GrassCoverErosionInwardsCalculationActivityFactory.CreateCalculationActivity(calculation, failureMechanism, null); + + // Assert + var exception = Assert.Throws(test); + Assert.AreEqual("assessmentSection", exception.ParamName); + } + + [Test] + public void CreateCalculationActivity_WithValidCalculation_ReturnsGrassCoverErosionInwardsCalculationActivityWithParametersSet() + { + // Setup + var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); + + var mocks = new MockRepository(); + IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, + mocks, + validFilePath); + + mocks.ReplayAll(); + + GrassCoverErosionInwardsCalculation calculation = CreateCalculation(); + + // Call + CalculatableActivity activity = GrassCoverErosionInwardsCalculationActivityFactory.CreateCalculationActivity(calculation, + failureMechanism, + assessmentSection); + + // Assert + Assert.IsInstanceOf(activity); + AssertGrassCoverErosionInwardsCalculationActivity(activity, calculation); + mocks.VerifyAll(); + } + + [Test] + public void CreateCalculationActivitiesForCalculationGroup_CalculationGroupNull_ThrowsArgumentNullException() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + // Call + TestDelegate test = () => GrassCoverErosionInwardsCalculationActivityFactory.CreateCalculationActivities(null, + new GrassCoverErosionInwardsFailureMechanism(), + assessmentSection); + + // Assert + var exception = Assert.Throws(test); + Assert.AreEqual("calculationGroup", exception.ParamName); + mocks.VerifyAll(); + } + + [Test] + public void CreateCalculationActivitiesForCalculationGroup_FailureMechanismNull_ThrowsArgumentNullException() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + // Call + TestDelegate test = () => GrassCoverErosionInwardsCalculationActivityFactory.CreateCalculationActivities(new CalculationGroup(), + null, + assessmentSection); + + // Assert + var exception = Assert.Throws(test); + Assert.AreEqual("failureMechanism", exception.ParamName); + mocks.VerifyAll(); + } + + [Test] + public void CreateCalculationActivitiesForCalculationGroup_AssessmentSectionNull_ThrowsArgumentNullException() + { + // Call + TestDelegate test = () => GrassCoverErosionInwardsCalculationActivityFactory.CreateCalculationActivities(new CalculationGroup(), + new GrassCoverErosionInwardsFailureMechanism(), + null); + + // Assert + var exception = Assert.Throws(test); + Assert.AreEqual("assessmentSection", exception.ParamName); + } + + [Test] + public void CreateCalculationActivitiesForCalculationGroup_WithValidCalculations_ReturnsGrassCoverErosionInwardsCalculationActivitiesWithParametersSet() + { + // Setup + var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); + + var mocks = new MockRepository(); + IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, + mocks, + validFilePath); + + mocks.ReplayAll(); + + GrassCoverErosionInwardsCalculation calculation1 = CreateCalculation(); + GrassCoverErosionInwardsCalculation calculation2 = CreateCalculation(); + + var calculations = new CalculationGroup + { + Children = + { + calculation1, + calculation2 + } + }; + + // Call + IEnumerable activities = GrassCoverErosionInwardsCalculationActivityFactory.CreateCalculationActivities( + calculations, failureMechanism, assessmentSection); + + // Assert + CollectionAssert.AllItemsAreInstancesOfType(activities, typeof(GrassCoverErosionInwardsCalculationActivity)); + AssertGrassCoverErosionInwardsCalculationActivity(activities.First(), calculation1); + AssertGrassCoverErosionInwardsCalculationActivity(activities.ElementAt(1), calculation2); + mocks.VerifyAll(); + } + + [Test] + public void CreateCalculationActivitiesForFailureMechanism_FailureMechanismNull_ThrowsArgumentNullException() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + // Call + TestDelegate test = () => GrassCoverErosionInwardsCalculationActivityFactory.CreateCalculationActivities(null, assessmentSection); + + // Assert + var exception = Assert.Throws(test); + Assert.AreEqual("failureMechanism", exception.ParamName); + mocks.VerifyAll(); + } + + [Test] + public void CreateCalculationActivitiesForFailureMechanism_AssessmentSectionNull_ThrowsArgumentNullException() + { + // Call + TestDelegate test = () => GrassCoverErosionInwardsCalculationActivityFactory.CreateCalculationActivities(new GrassCoverErosionInwardsFailureMechanism(), null); + + // Assert + var exception = Assert.Throws(test); + Assert.AreEqual("assessmentSection", exception.ParamName); + } + + [Test] + public void CreateCalculationActivitiesForFailureMechanism_WithValidCalculations_ReturnsGrassCoverErosionInwardsCalculationActivitiesWithParametersSet() + { + // Setup + var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); + + var mocks = new MockRepository(); + IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, + mocks, + validFilePath); + + mocks.ReplayAll(); + + GrassCoverErosionInwardsCalculation calculation1 = CreateCalculation(); + GrassCoverErosionInwardsCalculation calculation2 = CreateCalculation(); + + failureMechanism.CalculationsGroup.Children.AddRange(new[] + { + calculation1, + calculation2 + }); + + // Call + IEnumerable activities = GrassCoverErosionInwardsCalculationActivityFactory.CreateCalculationActivities( + failureMechanism, assessmentSection); + + // Assert + CollectionAssert.AllItemsAreInstancesOfType(activities, typeof(GrassCoverErosionInwardsCalculationActivity)); + AssertGrassCoverErosionInwardsCalculationActivity(activities.First(), calculation1); + AssertGrassCoverErosionInwardsCalculationActivity(activities.ElementAt(1), calculation2); + mocks.VerifyAll(); + } + + private static GrassCoverErosionInwardsCalculation CreateCalculation() + { + return new GrassCoverErosionInwardsCalculation + { + InputParameters = + { + HydraulicBoundaryLocation = new HydraulicBoundaryLocation(1, "name", 2, 2), + DikeProfile = new DikeProfile(new Point2D(0, 0), + new RoughnessPoint[0], + new Point2D[0], + new BreakWater(BreakWaterType.Dam, new Random(39).NextDouble()), + new DikeProfile.ConstructionProperties + { + Id = "id" + }) + } + }; + } + + private static void AssertGrassCoverErosionInwardsCalculationActivity(Activity activity, + GrassCoverErosionInwardsCalculation calculation) + { + var mocks = new MockRepository(); + var testCalculator = new TestOvertoppingCalculator(); + var calculatorFactory = mocks.StrictMock(); + calculatorFactory.Expect(cf => cf.CreateOvertoppingCalculator(testDataPath, "")) + .Return(testCalculator); + mocks.ReplayAll(); + + using (new HydraRingCalculatorFactoryConfig(calculatorFactory)) + { + activity.Run(); + Assert.AreEqual(calculation.InputParameters.BreakWater.Height, testCalculator.ReceivedInputs.Single().BreakWater.Height); + } + + mocks.VerifyAll(); + } + } +} \ No newline at end of file Index: Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Service.Test/GrassCoverErosionInwardsCalculationServiceTest.cs =================================================================== diff -u -r6cbc1078b43d2c341d9f5b867a37a67adc8d029b -r2499bda2fc2db87a27ce064deb6f9d2e2769d0fa --- Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Service.Test/GrassCoverErosionInwardsCalculationServiceTest.cs (.../GrassCoverErosionInwardsCalculationServiceTest.cs) (revision 6cbc1078b43d2c341d9f5b867a37a67adc8d029b) +++ Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Service.Test/GrassCoverErosionInwardsCalculationServiceTest.cs (.../GrassCoverErosionInwardsCalculationServiceTest.cs) (revision 2499bda2fc2db87a27ce064deb6f9d2e2769d0fa) @@ -694,7 +694,7 @@ } [Test] - public void Calculate_GeneralinputNull_ThrowArgumentNullException() + public void Calculate_GeneralInputNull_ThrowArgumentNullException() { // Setup var calculation = new GrassCoverErosionInwardsCalculation(); Index: Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Service.Test/Ringtoets.GrassCoverErosionInwards.Service.Test.csproj =================================================================== diff -u -r4aca01a706f23d3ba928d2c5fd405681bc3ba55d -r2499bda2fc2db87a27ce064deb6f9d2e2769d0fa --- Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Service.Test/Ringtoets.GrassCoverErosionInwards.Service.Test.csproj (.../Ringtoets.GrassCoverErosionInwards.Service.Test.csproj) (revision 4aca01a706f23d3ba928d2c5fd405681bc3ba55d) +++ Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Service.Test/Ringtoets.GrassCoverErosionInwards.Service.Test.csproj (.../Ringtoets.GrassCoverErosionInwards.Service.Test.csproj) (revision 2499bda2fc2db87a27ce064deb6f9d2e2769d0fa) @@ -25,6 +25,7 @@ +