Index: Ringtoets/Common/src/Ringtoets.Common.Service/DesignWaterLevelCalculationService.cs =================================================================== diff -u -rf27e8e2e7c8d056c76f2f883ae6bdf03edb740fc -r90f951ec95877a68c026e026ff0573ddf1eae96d --- Ringtoets/Common/src/Ringtoets.Common.Service/DesignWaterLevelCalculationService.cs (.../DesignWaterLevelCalculationService.cs) (revision f27e8e2e7c8d056c76f2f883ae6bdf03edb740fc) +++ Ringtoets/Common/src/Ringtoets.Common.Service/DesignWaterLevelCalculationService.cs (.../DesignWaterLevelCalculationService.cs) (revision 90f951ec95877a68c026e026ff0573ddf1eae96d) @@ -62,7 +62,7 @@ CalculationServiceHelper.LogValidationBegin(); string databaseFilePathValidationProblem = HydraulicBoundaryDatabaseHelper.ValidateFilesForCalculation(hydraulicBoundaryDatabaseFilePath, - preprocessorDirectory); + preprocessorDirectory); if (!string.IsNullOrEmpty(databaseFilePathValidationProblem)) { CalculationServiceHelper.LogMessagesAsError(Resources.Hydraulic_boundary_database_connection_failed_0_, @@ -93,16 +93,14 @@ /// /// Performs a calculation for the design water level. /// - /// The design water level calculation to use. + /// The calculation wrapper to use. /// The path which points to the hydraulic boundary database file. /// The preprocessor directory. /// The norm of the assessment section. /// The object which is used to build log messages. /// Preprocessing is disabled when /// equals . - /// Thrown when , - /// or - /// is null. + /// Thrown when is null. /// Thrown when /// /// contains invalid characters. @@ -116,16 +114,17 @@ /// Unable to read required data from database file. /// /// Thrown when an error occurs while performing the calculation. - public void Calculate(IHydraulicBoundaryCalculationWrapper designWaterLevelCalculation, + public void Calculate(HydraulicBoundaryCalculationWrapper calculationWrapper, string hydraulicBoundaryDatabaseFilePath, string preprocessorDirectory, double norm, ICalculationMessageProvider messageProvider) { - if (designWaterLevelCalculation == null) + if (calculationWrapper == null) { - throw new ArgumentNullException(nameof(designWaterLevelCalculation)); + throw new ArgumentNullException(nameof(calculationWrapper)); } + string hlcdDirectory = Path.GetDirectoryName(hydraulicBoundaryDatabaseFilePath); CalculationServiceHelper.LogCalculationBegin(); @@ -136,7 +135,7 @@ try { - PerformCalculation(designWaterLevelCalculation, + PerformCalculation(calculationWrapper, hydraulicBoundaryDatabaseFilePath, !string.IsNullOrEmpty(preprocessorDirectory), norm, @@ -148,8 +147,8 @@ { string lastErrorContent = calculator.LastErrorFileContent; log.Error(string.IsNullOrEmpty(lastErrorContent) - ? messageProvider.GetCalculationFailedMessage(designWaterLevelCalculation.Name) - : messageProvider.GetCalculationFailedWithErrorReportMessage(designWaterLevelCalculation.Name, + ? messageProvider.GetCalculationFailedMessage(calculationWrapper.Name) + : messageProvider.GetCalculationFailedWithErrorReportMessage(calculationWrapper.Name, lastErrorContent)); exceptionThrown = true; @@ -162,7 +161,7 @@ bool errorOccurred = CalculationServiceHelper.HasErrorOccurred(canceled, exceptionThrown, lastErrorFileContent); if (errorOccurred) { - log.Error(messageProvider.GetCalculationFailedWithErrorReportMessage(designWaterLevelCalculation.Name, + log.Error(messageProvider.GetCalculationFailedWithErrorReportMessage(calculationWrapper.Name, lastErrorFileContent)); } @@ -188,7 +187,7 @@ /// /// Performs a calculation for the design water level. /// - /// The design water level calculation to use. + /// The calculation wrapper to use. /// The path which points to the hydraulic boundary database file. /// Indicator whether to use the preprocessor in the calculation. /// The norm of the assessment section. @@ -201,13 +200,13 @@ /// Unable to read required data from database file. /// /// Thrown when an error occurs while performing the calculation. - private void PerformCalculation(IHydraulicBoundaryCalculationWrapper designWaterLevelCalculation, + private void PerformCalculation(IHydraulicBoundaryCalculationWrapper calculationWrapper, string hydraulicBoundaryDatabaseFilePath, bool usePreprocessor, double norm, ICalculationMessageProvider messageProvider) { - AssessmentLevelCalculationInput calculationInput = CreateInput(designWaterLevelCalculation, norm, hydraulicBoundaryDatabaseFilePath, usePreprocessor); + AssessmentLevelCalculationInput calculationInput = CreateInput(calculationWrapper, norm, hydraulicBoundaryDatabaseFilePath, usePreprocessor); calculator.Calculate(calculationInput); @@ -219,21 +218,21 @@ GeneralResult generalResult = null; try { - generalResult = designWaterLevelCalculation.CalculateIllustrationPoints + generalResult = calculationWrapper.CalculateIllustrationPoints ? GetGeneralResult(calculator.IllustrationPointsResult) : null; } catch (ArgumentException e) { log.Warn(string.Format(Resources.CalculationService_Error_in_reading_illustrationPoints_for_CalculationName_0_with_ErrorMessage_1, - designWaterLevelCalculation.Name, + calculationWrapper.Name, e.Message)); } HydraulicBoundaryLocationOutput hydraulicBoundaryLocationOutput = CreateHydraulicBoundaryLocationOutput( - messageProvider, designWaterLevelCalculation.Name, calculationInput.Beta, norm, calculator.Converged, generalResult); + messageProvider, calculationWrapper.Name, calculationInput.Beta, norm, calculator.Converged, generalResult); - designWaterLevelCalculation.Output = hydraulicBoundaryLocationOutput; + calculationWrapper.Output = hydraulicBoundaryLocationOutput; } /// Index: Ringtoets/Common/test/Ringtoets.Common.Service.Test/DesignWaterLevelCalculationServiceTest.cs =================================================================== diff -u -rf27e8e2e7c8d056c76f2f883ae6bdf03edb740fc -r90f951ec95877a68c026e026ff0573ddf1eae96d --- Ringtoets/Common/test/Ringtoets.Common.Service.Test/DesignWaterLevelCalculationServiceTest.cs (.../DesignWaterLevelCalculationServiceTest.cs) (revision f27e8e2e7c8d056c76f2f883ae6bdf03edb740fc) +++ Ringtoets/Common/test/Ringtoets.Common.Service.Test/DesignWaterLevelCalculationServiceTest.cs (.../DesignWaterLevelCalculationServiceTest.cs) (revision 90f951ec95877a68c026e026ff0573ddf1eae96d) @@ -134,7 +134,7 @@ } [Test] - public void Calculate_DesignWaterLevelCalculationNull_ThrowArgumentNullException() + public void Calculate_CalculationWrapperNull_ThrowArgumentNullException() { // Setup var mockRepository = new MockRepository(); @@ -146,13 +146,13 @@ // Assert var exception = Assert.Throws(test); - Assert.AreEqual("designWaterLevelCalculation", exception.ParamName); + Assert.AreEqual("calculationWrapper", exception.ParamName); } [Test] [TestCase(true)] [TestCase(false)] - public void Calculate_ValidDesignWaterLevelCalculationAndConverges_StartsCalculationWithRightParametersAndLogs(bool calculateIllustrationPoints) + public void Calculate_ValidDesignWaterLevelCalculationAndConverges_StartsCalculationWithRightParametersAndLogs(bool readIllustrationPoints) { // Setup var calculator = new TestDesignWaterLevelCalculator @@ -165,18 +165,22 @@ var calculatorFactory = mockRepository.StrictMock(); calculatorFactory.Expect(cf => cf.CreateDesignWaterLevelCalculator(testDataPath, validPreprocessorDirectory)).Return(calculator); - var calculation = mockRepository.Stub(); - calculation.Stub(c => c.Name).Return("punt_flw_ 1"); - calculation.Expect(c => c.Id).Return(100); - calculation.Expect(c => c.CalculateIllustrationPoints).Return(calculateIllustrationPoints); - var calculationMessageProvider = mockRepository.StrictMock(); mockRepository.ReplayAll(); + var location = new HydraulicBoundaryLocation(100, "punt_flw_ 1", 0.0, 0.0); + var calculation = new HydraulicBoundaryLocationCalculation + { + InputParameters = + { + ShouldIllustrationPointsBeCalculated = readIllustrationPoints + } + }; + using (new HydraRingCalculatorFactoryConfig(calculatorFactory)) { // Call - Action call = () => new DesignWaterLevelCalculationService().Calculate(calculation, + Action call = () => new DesignWaterLevelCalculationService().Calculate(new HydraulicBoundaryCalculationWrapper(location, calculation), validFilePath, validPreprocessorDirectory, 1.0 / 30, @@ -197,7 +201,7 @@ AssertInput(expectedInput, calculator.ReceivedInputs.Single()); Assert.IsFalse(calculator.IsCanceled); - Assert.AreEqual(calculateIllustrationPoints, calculation.Output.HasGeneralResult); + Assert.AreEqual(readIllustrationPoints, calculation.Output.HasGeneralResult); } mockRepository.VerifyAll(); } @@ -222,18 +226,16 @@ var calculatorFactory = mockRepository.StrictMock(); calculatorFactory.Expect(cf => cf.CreateDesignWaterLevelCalculator(testDataPath, preprocessorDirectory)).Return(calculator); - var calculation = mockRepository.Stub(); - calculation.Stub(c => c.Name).Return("punt_flw_ 1"); - calculation.Expect(c => c.Id).Return(100); - calculation.Expect(c => c.CalculateIllustrationPoints).Return(false); - var calculationMessageProvider = mockRepository.StrictMock(); mockRepository.ReplayAll(); + var location = new HydraulicBoundaryLocation(100, "punt_flw_ 1", 0.0, 0.0); + var calculation = new HydraulicBoundaryLocationCalculation(); + using (new HydraRingCalculatorFactoryConfig(calculatorFactory)) { // Call - new DesignWaterLevelCalculationService().Calculate(calculation, + new DesignWaterLevelCalculationService().Calculate(new HydraulicBoundaryCalculationWrapper(location, calculation), validFilePath, preprocessorDirectory, 1.0 / 30, @@ -263,20 +265,24 @@ var calculatorFactory = mockRepository.StrictMock(); calculatorFactory.Expect(cf => cf.CreateDesignWaterLevelCalculator(testDataPath, validPreprocessorDirectory)).Return(calculator); - var calculation = mockRepository.Stub(); - calculation.Stub(c => c.Name).Return("punt_flw_ 1"); - calculation.Expect(c => c.Id).Return(100); - calculation.Expect(c => c.CalculateIllustrationPoints).Return(readIllustrationPoints); - const string failedConvergenceMessage = "Did not converge"; var calculationMessageProvider = mockRepository.StrictMock(); calculationMessageProvider.Expect(c => c.GetCalculatedNotConvergedMessage("punt_flw_ 1")).Return(failedConvergenceMessage); mockRepository.ReplayAll(); + var location = new HydraulicBoundaryLocation(100, "punt_flw_ 1", 0.0, 0.0); + var calculation = new HydraulicBoundaryLocationCalculation + { + InputParameters = + { + ShouldIllustrationPointsBeCalculated = readIllustrationPoints + } + }; + using (new HydraRingCalculatorFactoryConfig(calculatorFactory)) { // Call - Action call = () => new DesignWaterLevelCalculationService().Calculate(calculation, + Action call = () => new DesignWaterLevelCalculationService().Calculate(new HydraulicBoundaryCalculationWrapper(location, calculation), validFilePath, validPreprocessorDirectory, norm, @@ -317,18 +323,22 @@ var calculatorFactory = mockRepository.StrictMock(); calculatorFactory.Expect(cf => cf.CreateDesignWaterLevelCalculator(testDataPath, validPreprocessorDirectory)).Return(calculator); - var calculation = mockRepository.Stub(); - calculation.Stub(c => c.Name).Return("punt_flw_ 1"); - calculation.Expect(c => c.Id).Return(100); - calculation.Expect(c => c.CalculateIllustrationPoints).Return(true); - var calculationMessageProvider = mockRepository.StrictMock(); mockRepository.ReplayAll(); + var location = new HydraulicBoundaryLocation(100, "punt_flw_ 1", 0.0, 0.0); + var calculation = new HydraulicBoundaryLocationCalculation + { + InputParameters = + { + ShouldIllustrationPointsBeCalculated = true + } + }; + using (new HydraRingCalculatorFactoryConfig(calculatorFactory)) { // Call - Action call = () => new DesignWaterLevelCalculationService().Calculate(calculation, + Action call = () => new DesignWaterLevelCalculationService().Calculate(new HydraulicBoundaryCalculationWrapper(location, calculation), validFilePath, validPreprocessorDirectory, 1.0 / 30, @@ -370,18 +380,22 @@ var calculatorFactory = mockRepository.StrictMock(); calculatorFactory.Expect(cf => cf.CreateDesignWaterLevelCalculator(testDataPath, validPreprocessorDirectory)).Return(calculator); - var calculation = mockRepository.Stub(); - calculation.Stub(c => c.Name).Return("punt_flw_ 1"); - calculation.Stub(c => c.Id).Return(100); - calculation.Stub(c => c.CalculateIllustrationPoints).Return(true); - var calculationMessageProvider = mockRepository.StrictMock(); mockRepository.ReplayAll(); + var location = new HydraulicBoundaryLocation(100, "punt_flw_ 1", 0.0, 0.0); + var calculation = new HydraulicBoundaryLocationCalculation + { + InputParameters = + { + ShouldIllustrationPointsBeCalculated = true + } + }; + using (new HydraRingCalculatorFactoryConfig(calculatorFactory)) { // Call - Action call = () => new DesignWaterLevelCalculationService().Calculate(calculation, + Action call = () => new DesignWaterLevelCalculationService().Calculate(new HydraulicBoundaryCalculationWrapper(location, calculation), validFilePath, validPreprocessorDirectory, 1.0 / 30, @@ -425,19 +439,18 @@ var calculatorFactory = mockRepository.StrictMock(); calculatorFactory.Expect(cf => cf.CreateDesignWaterLevelCalculator(testDataPath, validPreprocessorDirectory)).Return(calculator); - var calculation = mockRepository.Stub(); - calculation.Stub(c => c.Name).Return("punt_flw_ 1"); - calculation.Expect(c => c.Id).Return(100); - var calculationMessageProvider = mockRepository.Stub(); calculationMessageProvider.Stub(mp => mp.GetCalculatedNotConvergedMessage("punt_flw_ 1")).Return(string.Empty); mockRepository.ReplayAll(); + var location = new HydraulicBoundaryLocation(100, "punt_flw_ 1", 0.0, 0.0); + var calculation = new HydraulicBoundaryLocationCalculation(); + using (new HydraRingCalculatorFactoryConfig(calculatorFactory)) { // Call TestDelegate call = () => new DesignWaterLevelCalculationService() - .Calculate(calculation, + .Calculate(new HydraulicBoundaryCalculationWrapper(location, calculation), validFilePath, validPreprocessorDirectory, 1.0 / 30, @@ -465,19 +478,23 @@ var calculatorFactory = mockRepository.StrictMock(); calculatorFactory.Expect(cf => cf.CreateDesignWaterLevelCalculator(testDataPath, validPreprocessorDirectory)).Return(calculator); - var calculation = mockRepository.Stub(); - calculation.Stub(c => c.Name).Return("punt_flw_ 1"); - calculation.Expect(c => c.Id).Return(100); - calculation.Expect(c => c.CalculateIllustrationPoints).Return(true); - var calculationMessageProvider = mockRepository.Stub(); mockRepository.ReplayAll(); + var location = new HydraulicBoundaryLocation(100, "punt_flw_ 1", 0.0, 0.0); + var calculation = new HydraulicBoundaryLocationCalculation + { + InputParameters = + { + ShouldIllustrationPointsBeCalculated = true + } + }; + using (new HydraRingCalculatorFactoryConfig(calculatorFactory)) { // Call Action call = () => new DesignWaterLevelCalculationService() - .Calculate(calculation, + .Calculate(new HydraulicBoundaryCalculationWrapper(location, calculation), validFilePath, validPreprocessorDirectory, 1.0 / 30, @@ -513,19 +530,17 @@ var calculatorFactory = mockRepository.StrictMock(); calculatorFactory.Expect(cf => cf.CreateDesignWaterLevelCalculator(testDataPath, validPreprocessorDirectory)).Return(calculator); - var calculation = mockRepository.Stub(); - calculation.Stub(c => c.Name).Return("punt_flw_ 1"); - calculation.Expect(c => c.Id).Return(100); - calculation.Expect(c => c.CalculateIllustrationPoints).Return(false); - var calculationMessageProvider = mockRepository.Stub(); mockRepository.ReplayAll(); + var location = new HydraulicBoundaryLocation(100, "punt_flw_ 1", 0.0, 0.0); + var calculation = new HydraulicBoundaryLocationCalculation(); + using (new HydraRingCalculatorFactoryConfig(calculatorFactory)) { // Call Action call = () => new DesignWaterLevelCalculationService() - .Calculate(calculation, + .Calculate(new HydraulicBoundaryCalculationWrapper(location, calculation), validFilePath, validPreprocessorDirectory, 1.0 / 30, @@ -555,13 +570,12 @@ var calculatorFactory = mockRepository.StrictMock(); calculatorFactory.Expect(cf => cf.CreateDesignWaterLevelCalculator(testDataPath, validPreprocessorDirectory)).Return(calculator); - var calculation = mockRepository.Stub(); - calculation.Stub(c => c.Name).Return("name"); - calculation.Expect(c => c.Id).Return(0); - var calculationMessageProvider = mockRepository.Stub(); mockRepository.ReplayAll(); + var location = new HydraulicBoundaryLocation(100, "punt_flw_ 1", 0.0, 0.0); + var calculation = new HydraulicBoundaryLocationCalculation(); + const double norm = 1.0 / 30; using (new HydraRingCalculatorFactoryConfig(calculatorFactory)) @@ -570,7 +584,7 @@ calculator.CalculationFinishedHandler += (s, e) => service.Cancel(); // Call - service.Calculate(calculation, + service.Calculate(new HydraulicBoundaryCalculationWrapper(location, calculation), validFilePath, validPreprocessorDirectory, norm, @@ -604,10 +618,6 @@ var calculatorFactory = mockRepository.StrictMock(); calculatorFactory.Expect(cf => cf.CreateDesignWaterLevelCalculator(testDataPath, validPreprocessorDirectory)).Return(calculator); - var calculation = mockRepository.Stub(); - calculation.Stub(c => c.Name).Return(locationName); - calculation.Expect(c => c.Id).Return(0); - var calculationMessageProvider = mockRepository.Stub(); if (endInFailure && string.IsNullOrEmpty(lastErrorFileContent)) { @@ -623,6 +633,9 @@ } mockRepository.ReplayAll(); + var location = new HydraulicBoundaryLocation(100, locationName, 0.0, 0.0); + var calculation = new HydraulicBoundaryLocationCalculation(); + using (new HydraRingCalculatorFactoryConfig(calculatorFactory)) { HydraRingCalculationException exception = null; @@ -632,7 +645,7 @@ { try { - new DesignWaterLevelCalculationService().Calculate(calculation, + new DesignWaterLevelCalculationService().Calculate(new HydraulicBoundaryCalculationWrapper(location, calculation), validFilePath, validPreprocessorDirectory, norm,