Index: Ringtoets/Common/src/Ringtoets.Common.Data/Hydraulics/DesignWaterLevelCalculation.cs =================================================================== diff -u --- Ringtoets/Common/src/Ringtoets.Common.Data/Hydraulics/DesignWaterLevelCalculation.cs (revision 0) +++ Ringtoets/Common/src/Ringtoets.Common.Data/Hydraulics/DesignWaterLevelCalculation.cs (revision ec03b23520b9fbc7e2f79f2a5589bb832b510fda) @@ -0,0 +1,89 @@ +// 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 Core.Common.Base; + +namespace Ringtoets.Common.Data.Hydraulics +{ + /// + /// Adapter class for a design water level calculation. + /// + public class DesignWaterLevelCalculation : IDesignWaterLevelCalculation + { + private readonly HydraulicBoundaryLocation hydraulicBoundaryLocation; + + /// + /// Creates a new instance of . + /// + /// The hydraulic boundary location to wrap. + /// Thrown when + /// is null. + public DesignWaterLevelCalculation(HydraulicBoundaryLocation hydraulicBoundaryLocation) + { + if (hydraulicBoundaryLocation == null) + { + throw new ArgumentNullException(nameof(hydraulicBoundaryLocation)); + } + this.hydraulicBoundaryLocation = hydraulicBoundaryLocation; + } + + /// + /// Gets a value indicating whether this calculation has already been calculated. + /// + /// + public bool IsCalculated() + { + HydraulicBoundaryLocationCalculation calculation = hydraulicBoundaryLocation.DesignWaterLevelCalculation; + return calculation.HasOutput + && calculation.InputParameters.ShouldIllustrationPointsBeCalculated == calculation.Output.HasIllustrationPoints; + } + + /// + /// Gets the observable object to notify upon an internal state change. + /// + /// + public IObservable GetObservableObject() + { + return hydraulicBoundaryLocation; + } + + public long GetId() + { + return hydraulicBoundaryLocation.Id; + } + + public string GetName() + { + return hydraulicBoundaryLocation.Name; + } + + public bool GetCalculateIllustrationPoints() + { + return hydraulicBoundaryLocation.DesignWaterLevelCalculation.InputParameters.ShouldIllustrationPointsBeCalculated; + } + + public void SetOutput(HydraulicBoundaryLocationOutput output) + { + hydraulicBoundaryLocation.DesignWaterLevelCalculation.Output = output; + } + } +} \ No newline at end of file Index: Ringtoets/Common/src/Ringtoets.Common.Data/Hydraulics/IDesignWaterLevelCalculation.cs =================================================================== diff -u --- Ringtoets/Common/src/Ringtoets.Common.Data/Hydraulics/IDesignWaterLevelCalculation.cs (revision 0) +++ Ringtoets/Common/src/Ringtoets.Common.Data/Hydraulics/IDesignWaterLevelCalculation.cs (revision ec03b23520b9fbc7e2f79f2a5589bb832b510fda) @@ -0,0 +1,52 @@ +// 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. + +namespace Ringtoets.Common.Data.Hydraulics +{ + /// + /// Interface for a design water level calculation + /// + public interface IDesignWaterLevelCalculation + { + /// + /// Gets the database id of the hydraulic boundary location. + /// + /// The database id of the hydraulic boundary location. + long GetId(); + + /// + /// Gets the name of the hydraulic boundary location. + /// + /// The name of the hydraulic boundary location. + string GetName(); + + /// + /// Gets if the illustration points should be calculated. + /// + /// The illustration points should be calculated. + bool GetCalculateIllustrationPoints(); + + /// + ///Sets the output of the design water level calculation. + /// + void SetOutput(HydraulicBoundaryLocationOutput output); + } +} \ No newline at end of file Index: Ringtoets/Common/src/Ringtoets.Common.Data/Ringtoets.Common.Data.csproj =================================================================== diff -u -raea63ba505ca62fb7294ef1f88febbb9154ca258 -rec03b23520b9fbc7e2f79f2a5589bb832b510fda --- Ringtoets/Common/src/Ringtoets.Common.Data/Ringtoets.Common.Data.csproj (.../Ringtoets.Common.Data.csproj) (revision aea63ba505ca62fb7294ef1f88febbb9154ca258) +++ Ringtoets/Common/src/Ringtoets.Common.Data/Ringtoets.Common.Data.csproj (.../Ringtoets.Common.Data.csproj) (revision ec03b23520b9fbc7e2f79f2a5589bb832b510fda) @@ -61,11 +61,13 @@ + + Index: Ringtoets/Common/src/Ringtoets.Common.Forms/GuiServices/HydraulicBoundaryLocationCalculationGuiService.cs =================================================================== diff -u -rb3b6c13cf736c134476b3db34281332d01ca86b1 -rec03b23520b9fbc7e2f79f2a5589bb832b510fda --- Ringtoets/Common/src/Ringtoets.Common.Forms/GuiServices/HydraulicBoundaryLocationCalculationGuiService.cs (.../HydraulicBoundaryLocationCalculationGuiService.cs) (revision b3b6c13cf736c134476b3db34281332d01ca86b1) +++ Ringtoets/Common/src/Ringtoets.Common.Forms/GuiServices/HydraulicBoundaryLocationCalculationGuiService.cs (.../HydraulicBoundaryLocationCalculationGuiService.cs) (revision ec03b23520b9fbc7e2f79f2a5589bb832b510fda) @@ -73,7 +73,7 @@ } return RunActivities(hydraulicBoundaryDatabaseFilePath, - locations.Select(location => new DesignWaterLevelCalculationActivity(location, + locations.Select(location => new DesignWaterLevelCalculationActivity(new DesignWaterLevelCalculation(location), hydraulicBoundaryDatabaseFilePath, norm, messageProvider)).ToArray()); Index: Ringtoets/Common/src/Ringtoets.Common.Service/DesignWaterLevelCalculationActivity.cs =================================================================== diff -u -rc51034a5f036c03b70e9c9a8a50b18575e686277 -rec03b23520b9fbc7e2f79f2a5589bb832b510fda --- Ringtoets/Common/src/Ringtoets.Common.Service/DesignWaterLevelCalculationActivity.cs (.../DesignWaterLevelCalculationActivity.cs) (revision c51034a5f036c03b70e9c9a8a50b18575e686277) +++ Ringtoets/Common/src/Ringtoets.Common.Service/DesignWaterLevelCalculationActivity.cs (.../DesignWaterLevelCalculationActivity.cs) (revision ec03b23520b9fbc7e2f79f2a5589bb832b510fda) @@ -32,7 +32,7 @@ /// public class DesignWaterLevelCalculationActivity : HydraRingActivityBase { - private readonly HydraulicBoundaryLocation hydraulicBoundaryLocation; + private readonly DesignWaterLevelCalculation designWaterLevelCalculation; private readonly double norm; private readonly string hydraulicBoundaryDatabaseFilePath; private readonly ICalculationMessageProvider messageProvider; @@ -41,35 +41,35 @@ /// /// Creates a new instance of . /// - /// The to perform the calculation for. + /// The to perform the calculation for. /// The hydraulic boundary database file that should be used for performing the calculation. /// The norm to use during the calculation. /// The provider of the messages to use during the calculation. - /// Thrown when or + /// Thrown when or /// is null. - public DesignWaterLevelCalculationActivity(HydraulicBoundaryLocation hydraulicBoundaryLocation, + public DesignWaterLevelCalculationActivity(DesignWaterLevelCalculation designWaterLevelCalculation, string hydraulicBoundaryDatabaseFilePath, double norm, ICalculationMessageProvider messageProvider) { - if (hydraulicBoundaryLocation == null) + if (designWaterLevelCalculation == null) { - throw new ArgumentNullException(nameof(hydraulicBoundaryLocation)); + throw new ArgumentNullException(nameof(designWaterLevelCalculation)); } if (messageProvider == null) { throw new ArgumentNullException(nameof(messageProvider)); } - this.hydraulicBoundaryLocation = hydraulicBoundaryLocation; + this.designWaterLevelCalculation = designWaterLevelCalculation; this.messageProvider = messageProvider; this.hydraulicBoundaryDatabaseFilePath = hydraulicBoundaryDatabaseFilePath; this.norm = norm; calculationService = new DesignWaterLevelCalculationService(); - Description = messageProvider.GetActivityDescription(hydraulicBoundaryLocation.Name); + Description = messageProvider.GetActivityDescription(designWaterLevelCalculation.GetName()); } protected override bool Validate() @@ -81,7 +81,7 @@ } return DesignWaterLevelCalculationService.Validate( - hydraulicBoundaryLocation.Name, + designWaterLevelCalculation.GetName(), hydraulicBoundaryDatabaseFilePath, messageProvider); } @@ -91,7 +91,7 @@ if (State != ActivityState.Skipped) { calculationService.Calculate( - hydraulicBoundaryLocation, + designWaterLevelCalculation, hydraulicBoundaryDatabaseFilePath, norm, messageProvider); @@ -105,16 +105,14 @@ protected override void OnFinish() { - hydraulicBoundaryLocation.NotifyObservers(); + designWaterLevelCalculation.GetObservableObject().NotifyObservers(); } private bool AlreadyCalculated { get { - HydraulicBoundaryLocationCalculation calculation = hydraulicBoundaryLocation.DesignWaterLevelCalculation; - return calculation.HasOutput - && calculation.InputParameters.ShouldIllustrationPointsBeCalculated == calculation.Output.HasIllustrationPoints; + return designWaterLevelCalculation.IsCalculated(); } } } Index: Ringtoets/Common/src/Ringtoets.Common.Service/DesignWaterLevelCalculationService.cs =================================================================== diff -u -r8bb6e849266ec28412ebfe23beccd7235c4db9bf -rec03b23520b9fbc7e2f79f2a5589bb832b510fda --- Ringtoets/Common/src/Ringtoets.Common.Service/DesignWaterLevelCalculationService.cs (.../DesignWaterLevelCalculationService.cs) (revision 8bb6e849266ec28412ebfe23beccd7235c4db9bf) +++ Ringtoets/Common/src/Ringtoets.Common.Service/DesignWaterLevelCalculationService.cs (.../DesignWaterLevelCalculationService.cs) (revision ec03b23520b9fbc7e2f79f2a5589bb832b510fda) @@ -73,11 +73,11 @@ /// /// Performs a calculation for the design water level. /// - /// The hydraulic boundary location used in the calculation. + /// The design water level calculation to use. /// The path which points to the hydraulic boundary database file. /// The norm of the assessment section. /// The object which is used to build log messages. - /// Thrown when + /// Thrown when /// is null. /// Thrown when /// @@ -92,17 +92,17 @@ /// Unable to read required data from database file. /// /// Thrown when an error occurs while performing the calculation. - public void Calculate(HydraulicBoundaryLocation hydraulicBoundaryLocation, + public void Calculate(IDesignWaterLevelCalculation designWaterLevelCalculation, string hydraulicBoundaryDatabaseFilePath, double norm, ICalculationMessageProvider messageProvider) { - if (hydraulicBoundaryLocation == null) + if (designWaterLevelCalculation == null) { - throw new ArgumentNullException(nameof(hydraulicBoundaryLocation)); + throw new ArgumentNullException(nameof(designWaterLevelCalculation)); } string hlcdDirectory = Path.GetDirectoryName(hydraulicBoundaryDatabaseFilePath); - string calculationName = messageProvider.GetCalculationName(hydraulicBoundaryLocation.Name); + string calculationName = messageProvider.GetCalculationName(designWaterLevelCalculation.GetName()); CalculationServiceHelper.LogCalculationBegin(calculationName); @@ -112,13 +112,13 @@ try { - AssessmentLevelCalculationInput calculationInput = CreateInput(hydraulicBoundaryLocation, norm, hydraulicBoundaryDatabaseFilePath); + AssessmentLevelCalculationInput calculationInput = CreateInput(designWaterLevelCalculation, norm, hydraulicBoundaryDatabaseFilePath); calculator.Calculate(calculationInput); - if (string.IsNullOrEmpty(calculator.LastErrorFileContent)) + if (!canceled && string.IsNullOrEmpty(calculator.LastErrorFileContent)) { - hydraulicBoundaryLocation.DesignWaterLevelCalculation.Output = CreateHydraulicBoundaryLocationOutput( - messageProvider, hydraulicBoundaryLocation.Name, calculationInput.Beta, norm, calculator.Converged); + designWaterLevelCalculation.SetOutput(CreateHydraulicBoundaryLocationOutput( + messageProvider, designWaterLevelCalculation.GetName(), calculationInput.Beta, norm, calculator.Converged)); } } catch (HydraRingCalculationException) @@ -127,8 +127,8 @@ { string lastErrorContent = calculator.LastErrorFileContent; log.Error(string.IsNullOrEmpty(lastErrorContent) - ? messageProvider.GetCalculationFailedUnexplainedMessage(hydraulicBoundaryLocation.Name) - : messageProvider.GetCalculationFailedMessage(hydraulicBoundaryLocation.Name, lastErrorContent)); + ? messageProvider.GetCalculationFailedUnexplainedMessage(designWaterLevelCalculation.GetName()) + : messageProvider.GetCalculationFailedMessage(designWaterLevelCalculation.GetName(), lastErrorContent)); exceptionThrown = true; throw; @@ -140,7 +140,7 @@ bool errorOccurred = CalculationServiceHelper.HasErrorOccurred(canceled, exceptionThrown, lastErrorFileContent); if (errorOccurred) { - log.Error(messageProvider.GetCalculationFailedMessage(hydraulicBoundaryLocation.Name, lastErrorFileContent)); + log.Error(messageProvider.GetCalculationFailedMessage(designWaterLevelCalculation.GetName(), lastErrorFileContent)); } log.InfoFormat(Resources.DesignWaterLevelCalculationService_Calculate_Calculation_temporary_directory_can_be_found_on_location_0, calculator.OutputDirectory); @@ -197,9 +197,9 @@ } /// - /// Creates the input for a wave height calculation. + /// Creates the input for a design water level calculation. /// - /// The + /// The /// to create the input from. /// The norm to use during the calculation. /// The file path to the hydraulic @@ -215,11 +215,11 @@ /// Unable to read required data from database file. /// /// - private static AssessmentLevelCalculationInput CreateInput(HydraulicBoundaryLocation hydraulicBoundaryLocation, + private static AssessmentLevelCalculationInput CreateInput(IDesignWaterLevelCalculation designWaterLevelCalculation, double norm, string hydraulicBoundaryDatabaseFilePath) { - var assessmentLevelCalculationInput = new AssessmentLevelCalculationInput(1, hydraulicBoundaryLocation.Id, norm); + var assessmentLevelCalculationInput = new AssessmentLevelCalculationInput(1, designWaterLevelCalculation.GetId(), norm); HydraRingSettingsDatabaseHelper.AssignSettingsFromDatabase(assessmentLevelCalculationInput, hydraulicBoundaryDatabaseFilePath); Index: Ringtoets/Common/test/Ringtoets.Common.Data.Test/Hydraulics/DesignWaterLevelCalculationTest.cs =================================================================== diff -u --- Ringtoets/Common/test/Ringtoets.Common.Data.Test/Hydraulics/DesignWaterLevelCalculationTest.cs (revision 0) +++ Ringtoets/Common/test/Ringtoets.Common.Data.Test/Hydraulics/DesignWaterLevelCalculationTest.cs (revision ec03b23520b9fbc7e2f79f2a5589bb832b510fda) @@ -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 NUnit.Framework; +using Ringtoets.Common.Data.Hydraulics; +using Ringtoets.Common.Data.TestUtil; + +namespace Ringtoets.Common.Data.Test.Hydraulics +{ + [TestFixture] + public class DesignWaterLevelCalculationTest + { + private static IEnumerable HydraulicBoundaryLocationsToCalculate + { + get + { + yield return new TestCaseData(new TestHydraulicBoundaryLocation("WithOutputWithoutIllustrationPoints") + { + DesignWaterLevelCalculation = + { + InputParameters = + { + ShouldIllustrationPointsBeCalculated = true + }, + Output = new TestHydraulicBoundaryLocationOutput(1.0, CalculationConvergence.CalculatedConverged) + } + }, true); + + yield return new TestCaseData(new TestHydraulicBoundaryLocation("WithoutOutput"), true); + + yield return new TestCaseData(new TestHydraulicBoundaryLocation("WithValidOutput") + { + DesignWaterLevelCalculation = + { + Output = new TestHydraulicBoundaryLocationOutput(1.0, CalculationConvergence.CalculatedConverged) + } + }, false); + } + } + + [Test] + public void Constructor_HydraulicBoundaryLocationNull_ThrowsArgumentNullException() + { + // Call + TestDelegate call = () => new DesignWaterLevelCalculation(null); + + // Assert + string paramName = Assert.Throws(call).ParamName; + Assert.AreEqual("hydraulicBoundaryLocation", paramName); + } + + [Test] + public void Constructor_ValidHydraulicBoundaryLocation_SetsProperties( + [Values(true, false)] bool calculateIllustrationPoints) + { + // Setup + var hydraulicBoundaryLocation = new HydraulicBoundaryLocation(1, "name", 1, 1) + { + DesignWaterLevelCalculation = + { + InputParameters = + { + ShouldIllustrationPointsBeCalculated = calculateIllustrationPoints + } + } + }; + + // Call + var calculation = new DesignWaterLevelCalculation(hydraulicBoundaryLocation); + + // Assert + Assert.IsInstanceOf(calculation); + Assert.AreEqual(hydraulicBoundaryLocation.Id, calculation.GetId()); + Assert.AreSame(hydraulicBoundaryLocation.Name, calculation.GetName()); + + HydraulicBoundaryLocationCalculation hydraulicBoundaryLocationCalculation = hydraulicBoundaryLocation.DesignWaterLevelCalculation; + Assert.AreEqual(hydraulicBoundaryLocationCalculation.InputParameters.ShouldIllustrationPointsBeCalculated, calculation.GetCalculateIllustrationPoints()); + + Assert.AreSame(hydraulicBoundaryLocation, calculation.GetObservableObject()); + } + + [Test] + [TestCaseSource(nameof(HydraulicBoundaryLocationsToCalculate))] + public void IsCalculated_NotFullyCalculated_ReturnIsCalculated(HydraulicBoundaryLocation hydraulicBoundaryLocation, + bool shouldBeCalculated) + { + // Setup + var calculation = new DesignWaterLevelCalculation(hydraulicBoundaryLocation); + + // Call + bool isCalculated = calculation.IsCalculated(); + + // Assert + Assert.AreEqual(!shouldBeCalculated, isCalculated); + } + + [Test] + public void SetOutput_ValidOutput_SetsOutput() + { + // Setup + var hydraulicBoundaryLocation = new TestHydraulicBoundaryLocation(); + var calculation = new DesignWaterLevelCalculation(hydraulicBoundaryLocation); + var output = new TestHydraulicBoundaryLocationOutput(1); + + // Call + calculation.SetOutput(output); + + // Assert + Assert.AreSame(hydraulicBoundaryLocation.DesignWaterLevelCalculation.Output, output); + } + } +} \ No newline at end of file Index: Ringtoets/Common/test/Ringtoets.Common.Data.Test/Ringtoets.Common.Data.Test.csproj =================================================================== diff -u -raea63ba505ca62fb7294ef1f88febbb9154ca258 -rec03b23520b9fbc7e2f79f2a5589bb832b510fda --- Ringtoets/Common/test/Ringtoets.Common.Data.Test/Ringtoets.Common.Data.Test.csproj (.../Ringtoets.Common.Data.Test.csproj) (revision aea63ba505ca62fb7294ef1f88febbb9154ca258) +++ Ringtoets/Common/test/Ringtoets.Common.Data.Test/Ringtoets.Common.Data.Test.csproj (.../Ringtoets.Common.Data.Test.csproj) (revision ec03b23520b9fbc7e2f79f2a5589bb832b510fda) @@ -73,6 +73,7 @@ + Index: Ringtoets/Common/test/Ringtoets.Common.Service.Test/DesignWaterLevelCalculationActivityTest.cs =================================================================== diff -u -r96a6ad152dc45508f0501e489c29611244e9d76c -rec03b23520b9fbc7e2f79f2a5589bb832b510fda --- Ringtoets/Common/test/Ringtoets.Common.Service.Test/DesignWaterLevelCalculationActivityTest.cs (.../DesignWaterLevelCalculationActivityTest.cs) (revision 96a6ad152dc45508f0501e489c29611244e9d76c) +++ Ringtoets/Common/test/Ringtoets.Common.Service.Test/DesignWaterLevelCalculationActivityTest.cs (.../DesignWaterLevelCalculationActivityTest.cs) (revision ec03b23520b9fbc7e2f79f2a5589bb832b510fda) @@ -80,7 +80,7 @@ const string locationName = "locationName"; const string activityDescription = "GetActivityDescription"; - var hydraulicBoundaryLocation = new HydraulicBoundaryLocation(0, locationName, 0, 0); + var calculation = new DesignWaterLevelCalculation(new TestHydraulicBoundaryLocation(locationName)); var calculationMessageProvider = mockRepository.StrictMock(); calculationMessageProvider.Expect(calc => calc.GetActivityDescription(locationName)).Return(activityDescription); @@ -89,7 +89,7 @@ string validFilePath = Path.Combine(testDataPath, validFile); // Call - var activity = new DesignWaterLevelCalculationActivity(hydraulicBoundaryLocation, + var activity = new DesignWaterLevelCalculationActivity(calculation, validFilePath, 1, calculationMessageProvider); @@ -106,12 +106,12 @@ public void ParameteredConstructor_NullCalculationServiceMessageProvider_ThrowsArgumentNullException() { // Setup - var hydraulicBoundaryLocation = new HydraulicBoundaryLocation(0, string.Empty, 0, 0); + var calculation = new DesignWaterLevelCalculation(new TestHydraulicBoundaryLocation(string.Empty)); string validFilePath = Path.Combine(testDataPath, validFile); // Call - TestDelegate call = () => new DesignWaterLevelCalculationActivity(hydraulicBoundaryLocation, + TestDelegate call = () => new DesignWaterLevelCalculationActivity(calculation, validFilePath, 1, null); @@ -122,7 +122,7 @@ } [Test] - public void ParameteredConstructor_HydraulicBoundaryLocationNull_ThrowsArgumentNullException() + public void ParameteredConstructor_DesignWaterLevelCalculationNull_ThrowsArgumentNullException() { // Setup var calculationMessageProviderStub = mockRepository.Stub(); @@ -138,7 +138,7 @@ // Assert var exception = Assert.Throws(call); - Assert.AreEqual("hydraulicBoundaryLocation", exception.ParamName); + Assert.AreEqual("designWaterLevelCalculation", exception.ParamName); mockRepository.VerifyAll(); } @@ -150,14 +150,14 @@ const string locationName = "testLocation"; const string calculationName = "calculationName"; - var hydraulicBoundaryLocation = new HydraulicBoundaryLocation(1, locationName, 0, 0); + var calculation = new DesignWaterLevelCalculation(new TestHydraulicBoundaryLocation(locationName)); var calculationMessageProvider = mockRepository.StrictMock(); calculationMessageProvider.Expect(calc => calc.GetActivityDescription(locationName)).Return(string.Empty); calculationMessageProvider.Expect(calc => calc.GetCalculationName(locationName)).Return(calculationName).Repeat.AtLeastOnce(); mockRepository.ReplayAll(); - var activity = new DesignWaterLevelCalculationActivity(hydraulicBoundaryLocation, + var activity = new DesignWaterLevelCalculationActivity(calculation, inValidFilePath, 1, calculationMessageProvider); @@ -187,7 +187,7 @@ const string calculationName = "calculationName"; const double norm = 1.0 / 30; - var hydraulicBoundaryLocation = new HydraulicBoundaryLocation(0, locationName, 0, 0); + var calculation = new DesignWaterLevelCalculation(new TestHydraulicBoundaryLocation(locationName)); var calculator = new TestDesignWaterLevelCalculator { Converged = true @@ -200,7 +200,7 @@ calculationMessageProvider.Stub(calc => calc.GetCalculationName(locationName)).Return(calculationName); mockRepository.ReplayAll(); - var activity = new DesignWaterLevelCalculationActivity(hydraulicBoundaryLocation, + var activity = new DesignWaterLevelCalculationActivity(calculation, validFilePath, norm, calculationMessageProvider); @@ -224,7 +224,7 @@ AssessmentLevelCalculationInput designWaterLevelCalculationInput = calculator.ReceivedInputs.Single(); - Assert.AreEqual(hydraulicBoundaryLocation.Id, designWaterLevelCalculationInput.HydraulicBoundaryLocationId); + Assert.AreEqual(calculation.GetId(), designWaterLevelCalculationInput.HydraulicBoundaryLocationId); Assert.AreEqual(StatisticsConverter.ProbabilityToReliability(norm), designWaterLevelCalculationInput.Beta); } Assert.AreEqual(ActivityState.Executed, activity.State); @@ -255,8 +255,9 @@ Output = new TestHydraulicBoundaryLocationOutput(3.0, CalculationConvergence.CalculatedConverged) } }; + var calculation = new DesignWaterLevelCalculation(hydraulicBoundaryLocation); - var activity = new DesignWaterLevelCalculationActivity(hydraulicBoundaryLocation, + var activity = new DesignWaterLevelCalculationActivity(calculation, validFilePath, norm, calculationMessageProvider); @@ -294,7 +295,9 @@ string validFilePath = Path.Combine(testDataPath, validFile); - var activity = new DesignWaterLevelCalculationActivity(hydraulicBoundaryLocation, + var calculation = new DesignWaterLevelCalculation(hydraulicBoundaryLocation); + + var activity = new DesignWaterLevelCalculationActivity(calculation, validFilePath, norm, calculationMessageProvider); @@ -351,8 +354,10 @@ } }; + var calculation = new DesignWaterLevelCalculation(hydraulicBoundaryLocation); + string validFilePath = Path.Combine(testDataPath, validFile); - var activity = new DesignWaterLevelCalculationActivity(hydraulicBoundaryLocation, + var activity = new DesignWaterLevelCalculationActivity(calculation, validFilePath, 30, calculationMessageProvider); @@ -402,9 +407,11 @@ } }; + var calculation = new DesignWaterLevelCalculation(hydraulicBoundaryLocation); + string validFilePath = Path.Combine(testDataPath, validFile); const double norm = 1.0 / 300; - var activity = new DesignWaterLevelCalculationActivity(hydraulicBoundaryLocation, + var activity = new DesignWaterLevelCalculationActivity(calculation, validFilePath, norm, calculationMessageProvider); @@ -454,8 +461,10 @@ string validFilePath = Path.Combine(testDataPath, validFile); + var calculation = new DesignWaterLevelCalculation(hydraulicBoundaryLocation); + const double norm = 1.0 / 30; - var activity = new DesignWaterLevelCalculationActivity(hydraulicBoundaryLocation, + var activity = new DesignWaterLevelCalculationActivity(calculation, validFilePath, norm, calculationMessageProvider); @@ -480,14 +489,15 @@ { // Setup var hydraulicBoundaryLocation = new TestHydraulicBoundaryLocation(); + var calculation = new DesignWaterLevelCalculation(hydraulicBoundaryLocation); var calculationMessageProvider = mockRepository.Stub(); var observer = mockRepository.StrictMock(); observer.Expect(o => o.UpdateObserver()); hydraulicBoundaryLocation.Attach(observer); mockRepository.ReplayAll(); - var activity = new TestDesignWaterLevelCalculationActivity(hydraulicBoundaryLocation, + var activity = new TestDesignWaterLevelCalculationActivity(calculation, Path.Combine(testDataPath, validFile), 1.0, calculationMessageProvider, @@ -502,12 +512,12 @@ private class TestDesignWaterLevelCalculationActivity : DesignWaterLevelCalculationActivity { - public TestDesignWaterLevelCalculationActivity(HydraulicBoundaryLocation hydraulicBoundaryLocation, + public TestDesignWaterLevelCalculationActivity(DesignWaterLevelCalculation designWaterLevelCalculation, string hydraulicBoundaryDatabaseFilePath, double norm, ICalculationMessageProvider messageProvider, ActivityState state) - : base(hydraulicBoundaryLocation, + : base(designWaterLevelCalculation, hydraulicBoundaryDatabaseFilePath, norm, messageProvider) Index: Ringtoets/Common/test/Ringtoets.Common.Service.Test/DesignWaterLevelCalculationServiceTest.cs =================================================================== diff -u -r96a6ad152dc45508f0501e489c29611244e9d76c -rec03b23520b9fbc7e2f79f2a5589bb832b510fda --- Ringtoets/Common/test/Ringtoets.Common.Service.Test/DesignWaterLevelCalculationServiceTest.cs (.../DesignWaterLevelCalculationServiceTest.cs) (revision 96a6ad152dc45508f0501e489c29611244e9d76c) +++ Ringtoets/Common/test/Ringtoets.Common.Service.Test/DesignWaterLevelCalculationServiceTest.cs (.../DesignWaterLevelCalculationServiceTest.cs) (revision ec03b23520b9fbc7e2f79f2a5589bb832b510fda) @@ -25,6 +25,7 @@ using Core.Common.TestUtil; using NUnit.Framework; using Rhino.Mocks; +using Rhino.Mocks.Constraints; using Ringtoets.Common.Data.Hydraulics; using Ringtoets.Common.Service.MessageProviders; using Ringtoets.Common.Service.TestUtil; @@ -129,7 +130,7 @@ } [Test] - public void Calculate_HydraulicBoundaryLocationNull_ThrowArgumentNullException() + public void Calculate_DesignWaterLevelCalculationNull_ThrowArgumentNullException() { // Setup var mockRepository = new MockRepository(); @@ -141,7 +142,7 @@ // Assert var exception = Assert.Throws(test); - Assert.AreEqual("hydraulicBoundaryLocation", exception.ParamName); + Assert.AreEqual("designWaterLevelCalculation", exception.ParamName); } [Test] @@ -150,6 +151,7 @@ // Setup string validFilePath = Path.Combine(testDataPath, validFile); + const long id = 100; const string locationName = "punt_flw_ 1"; const double norm = 1.0 / 30; @@ -158,23 +160,27 @@ var mockRepository = new MockRepository(); var calculatorFactory = mockRepository.StrictMock(); calculatorFactory.Expect(cf => cf.CreateDesignWaterLevelCalculator(testDataPath)).Return(calculator); + + var calculation = mockRepository.Stub(); + calculation.Stub(c => c.GetName()).Return(locationName); + calculation.Expect(c => c.GetId()).Return(id); + calculation.Expect(c => c.SetOutput(null)).Constraints(new TypeOf(typeof(HydraulicBoundaryLocationOutput))); + var calculationMessageProviderStub = mockRepository.Stub(); calculationMessageProviderStub.Stub(calc => calc.GetCalculationName(locationName)).Return(string.Empty); calculationMessageProviderStub.Stub(calc => calc.GetCalculatedNotConvergedMessage(locationName)).Return(string.Empty); mockRepository.ReplayAll(); - var hydraulicBoundaryLocation = new HydraulicBoundaryLocation(1300001, locationName, 0, 0); - using (new HydraRingCalculatorFactoryConfig(calculatorFactory)) { // Call - new DesignWaterLevelCalculationService().Calculate(hydraulicBoundaryLocation, + new DesignWaterLevelCalculationService().Calculate(calculation, validFilePath, norm, calculationMessageProviderStub); // Assert - AssessmentLevelCalculationInput expectedInput = CreateInput(hydraulicBoundaryLocation, norm); + AssessmentLevelCalculationInput expectedInput = CreateInput(id, norm); AssertInput(expectedInput, calculator.ReceivedInputs.Single()); Assert.IsFalse(calculator.IsCanceled); } @@ -192,20 +198,23 @@ var mockRepository = new MockRepository(); var calculatorFactory = mockRepository.StrictMock(); calculatorFactory.Expect(cf => cf.CreateDesignWaterLevelCalculator(testDataPath)).Return(calculator); + + var calculation = mockRepository.Stub(); + calculation.Stub(c => c.GetName()).Return("name"); + calculation.Expect(c => c.GetId()).Return(0); + var calculationMessageProviderStub = mockRepository.Stub(); mockRepository.ReplayAll(); const double norm = 1.0 / 30; - var hydraulicBoundaryLocation = new HydraulicBoundaryLocation(1300001, "punt_flw_ 1", 0, 0); - using (new HydraRingCalculatorFactoryConfig(calculatorFactory)) { var service = new DesignWaterLevelCalculationService(); calculator.CalculationFinishedHandler += (s, e) => service.Cancel(); // Call - service.Calculate(hydraulicBoundaryLocation, + service.Calculate(calculation, validFilePath, norm, calculationMessageProviderStub); @@ -236,13 +245,16 @@ var mockRepository = new MockRepository(); var calculatorFactory = mockRepository.StrictMock(); calculatorFactory.Expect(cf => cf.CreateDesignWaterLevelCalculator(testDataPath)).Return(calculator); + + var calculation = mockRepository.Stub(); + calculation.Stub(c => c.GetName()).Return(locationName); + calculation.Expect(c => c.GetId()).Return(0); + var calculationMessageProviderMock = mockRepository.StrictMock(); calculationMessageProviderMock.Stub(calc => calc.GetCalculationName(locationName)).Return(calculationName); calculationMessageProviderMock.Stub(calc => calc.GetCalculationFailedMessage(null, null)).IgnoreArguments().Return(calculationFailedMessage); mockRepository.ReplayAll(); - var hydraulicBoundaryLocation = new HydraulicBoundaryLocation(1, locationName, 0, 0); - using (new HydraRingCalculatorFactoryConfig(calculatorFactory)) { var exceptionThrown = false; @@ -252,7 +264,7 @@ { try { - new DesignWaterLevelCalculationService().Calculate(hydraulicBoundaryLocation, + new DesignWaterLevelCalculationService().Calculate(calculation, validFilePath, norm, calculationMessageProviderMock); @@ -274,7 +286,6 @@ CalculationServiceTestHelper.AssertCalculationEndMessage(calculationName, msgs[3]); }); Assert.IsTrue(exceptionThrown); - Assert.IsNaN(hydraulicBoundaryLocation.DesignWaterLevel); } mockRepository.VerifyAll(); } @@ -298,13 +309,16 @@ var mockRepository = new MockRepository(); var calculatorFactory = mockRepository.StrictMock(); calculatorFactory.Expect(cf => cf.CreateDesignWaterLevelCalculator(testDataPath)).Return(calculator); + + var calculation = mockRepository.Stub(); + calculation.Stub(c => c.GetName()).Return(locationName); + calculation.Expect(c => c.GetId()).Return(0); + var calculationMessageProviderMock = mockRepository.StrictMock(); calculationMessageProviderMock.Stub(calc => calc.GetCalculationName(locationName)).Return(calculationName); calculationMessageProviderMock.Stub(calc => calc.GetCalculationFailedUnexplainedMessage(locationName)).Return(calculationFailedUnexplainedMessage); mockRepository.ReplayAll(); - var hydraulicBoundaryLocation = new HydraulicBoundaryLocation(1, locationName, 0, 0); - using (new HydraRingCalculatorFactoryConfig(calculatorFactory)) { var exceptionThrown = false; @@ -314,7 +328,7 @@ { try { - new DesignWaterLevelCalculationService().Calculate(hydraulicBoundaryLocation, + new DesignWaterLevelCalculationService().Calculate(calculation, validFilePath, norm, calculationMessageProviderMock); @@ -336,7 +350,6 @@ CalculationServiceTestHelper.AssertCalculationEndMessage(calculationName, msgs[3]); }); Assert.IsTrue(exceptionThrown); - Assert.IsNaN(hydraulicBoundaryLocation.DesignWaterLevel); } mockRepository.VerifyAll(); } @@ -361,13 +374,16 @@ var mockRepository = new MockRepository(); var calculatorFactory = mockRepository.StrictMock(); calculatorFactory.Expect(cf => cf.CreateDesignWaterLevelCalculator(testDataPath)).Return(calculator); + + var calculation = mockRepository.Stub(); + calculation.Stub(c => c.GetName()).Return(locationName); + calculation.Expect(c => c.GetId()).Return(0); + var calculationMessageProviderMock = mockRepository.StrictMock(); calculationMessageProviderMock.Stub(calc => calc.GetCalculationName(locationName)).Return(calculationName); calculationMessageProviderMock.Stub(calc => calc.GetCalculationFailedMessage(null, null)).IgnoreArguments().Return(calculationFailedMessage); mockRepository.ReplayAll(); - var hydraulicBoundaryLocation = new HydraulicBoundaryLocation(1, locationName, 0, 0); - using (new HydraRingCalculatorFactoryConfig(calculatorFactory)) { var exceptionThrown = false; @@ -378,7 +394,7 @@ { try { - new DesignWaterLevelCalculationService().Calculate(hydraulicBoundaryLocation, + new DesignWaterLevelCalculationService().Calculate(calculation, validFilePath, norm, calculationMessageProviderMock); @@ -401,7 +417,6 @@ CalculationServiceTestHelper.AssertCalculationEndMessage(calculationName, msgs[3]); }); Assert.IsTrue(exceptionThrown); - Assert.IsNaN(hydraulicBoundaryLocation.DesignWaterLevel); Assert.AreEqual(calculator.LastErrorFileContent, exceptionMessage); } mockRepository.VerifyAll(); @@ -414,9 +429,9 @@ Assert.AreEqual(expectedInput.Beta, hydraRingCalculationInput.Beta); } - private static AssessmentLevelCalculationInput CreateInput(HydraulicBoundaryLocation hydraulicBoundaryLocation, double norm) + private static AssessmentLevelCalculationInput CreateInput(long hydraulicBoundaryLocationId, double norm) { - return new AssessmentLevelCalculationInput(1, hydraulicBoundaryLocation.Id, norm); + return new AssessmentLevelCalculationInput(1, hydraulicBoundaryLocationId, norm); } } } \ No newline at end of file