Index: Ringtoets/Common/src/Ringtoets.Common.Service/Structures/StructuresCalculationServiceBase.cs =================================================================== diff -u -r470f6846d3dcd6f759a48d838cee8d1b9bbdeac7 -r058c36d676ce75456e648d75e460c24f0bc06ae7 --- Ringtoets/Common/src/Ringtoets.Common.Service/Structures/StructuresCalculationServiceBase.cs (.../StructuresCalculationServiceBase.cs) (revision 470f6846d3dcd6f759a48d838cee8d1b9bbdeac7) +++ Ringtoets/Common/src/Ringtoets.Common.Service/Structures/StructuresCalculationServiceBase.cs (.../StructuresCalculationServiceBase.cs) (revision 058c36d676ce75456e648d75e460c24f0bc06ae7) @@ -64,6 +64,7 @@ { private static readonly ILog log = LogManager.GetLogger(typeof(StructuresCalculationServiceBase)); + private readonly IStructuresCalculationMessageProvider messageProvider; private IStructuresCalculator calculator; @@ -165,22 +166,7 @@ var exceptionThrown = false; try { - calculator.Calculate(input); - - if (!canceled && string.IsNullOrEmpty(calculator.LastErrorFileContent)) - { - ProbabilityAssessmentOutput probabilityAssessmentOutput = - ProbabilityAssessmentService.Calculate(norm, - contribution, - lengthEffectN, - calculator.ExceedanceProbabilityBeta); - calculation.Output = new StructuresOutput(probabilityAssessmentOutput); - - if (calculation.InputParameters.ShouldIllustrationPointsBeCalculated) - { - SetIllustrationPointsResult(calculation.Output, calculator.IllustrationPointsResult); - } - } + PerformCalculation(calculation, lengthEffectN, norm, contribution, input); } catch (HydraRingCalculationException) { @@ -219,35 +205,6 @@ } /// - /// Sets a based on the information - /// of to the . - /// - /// The - /// for which to set the . - /// The to base the - /// to create on. - private void SetIllustrationPointsResult(StructuresOutput structuresOutput, - HydraRingGeneralResult hydraRingGeneralResult) - { - if (hydraRingGeneralResult == null) - { - log.Warn(calculator.IllustrationPointsParserErrorMessage); - return; - } - - try - { - GeneralResult generalResult = - GeneralResultConverter.CreateGeneralResultTopLevelFaultTreeIllustrationPoint(hydraRingGeneralResult); - structuresOutput.SetIllustrationPoints(generalResult); - } - catch (IllustrationPointConversionException e) - { - log.Warn(Resources.SetIllustrationPointsResult_Converting_IllustrationPointResult_Failed, e); - } - } - - /// /// Cancels any currently running structures calculation. /// public void Cancel() @@ -280,6 +237,81 @@ string hydraulicBoundaryDatabaseFilePath); /// + /// Performs a structures calculation. + /// + /// The structures calculation to use. + /// The 'N' parameter used to factor in the 'length effect'. + /// The norm used in the calculation. + /// The contribution used in the calculation. + /// The HydraRing calculation input used for the calculation. + /// Thrown when an error occurs while performing the calculation. + private void PerformCalculation(StructuresCalculation calculation, + double lengthEffectN, + double norm, + double contribution, + TCalculationInput calculationInput) + { + calculator.Calculate(calculationInput); + + if (canceled || !string.IsNullOrEmpty(calculator.LastErrorFileContent)) + { + return; + } + + ProbabilityAssessmentOutput probabilityAssessmentOutput = + ProbabilityAssessmentService.Calculate(norm, + contribution, + lengthEffectN, + calculator.ExceedanceProbabilityBeta); + SetOutput(calculation, probabilityAssessmentOutput); + } + + /// + /// Sets the calculated output to the calculation object. + /// + /// The calculation to set the output for. + /// The calculated output. + private void SetOutput(StructuresCalculation calculation, + ProbabilityAssessmentOutput probabilityAssessmentOutput) + { + calculation.Output = new StructuresOutput(probabilityAssessmentOutput); + + if (calculation.InputParameters.ShouldIllustrationPointsBeCalculated) + { + SetIllustrationPointsResult(calculation.Output, calculator.IllustrationPointsResult); + } + } + + /// + /// Sets a based on the information + /// of to the . + /// + /// The + /// for which to set the . + /// The to base the + /// to create on. + private void SetIllustrationPointsResult(StructuresOutput structuresOutput, + HydraRingGeneralResult hydraRingGeneralResult) + { + if (hydraRingGeneralResult == null) + { + log.Warn(calculator.IllustrationPointsParserErrorMessage); + return; + } + + try + { + GeneralResult generalResult = + GeneralResultConverter.CreateGeneralResultTopLevelFaultTreeIllustrationPoint(hydraRingGeneralResult); + structuresOutput.SetIllustrationPoints(generalResult); + } + catch (IllustrationPointConversionException e) + { + log.Warn(Resources.SetIllustrationPointsResult_Converting_IllustrationPointResult_Failed, e); + } + } + + /// /// Validates the input. /// /// The input of the calculation. Index: Ringtoets/Common/test/Ringtoets.Common.Service.Test/DesignWaterLevelCalculationServiceTest.cs =================================================================== diff -u -r893c37884e74d551780cfd9cb4b9899779832650 -r058c36d676ce75456e648d75e460c24f0bc06ae7 --- Ringtoets/Common/test/Ringtoets.Common.Service.Test/DesignWaterLevelCalculationServiceTest.cs (.../DesignWaterLevelCalculationServiceTest.cs) (revision 893c37884e74d551780cfd9cb4b9899779832650) +++ Ringtoets/Common/test/Ringtoets.Common.Service.Test/DesignWaterLevelCalculationServiceTest.cs (.../DesignWaterLevelCalculationServiceTest.cs) (revision 058c36d676ce75456e648d75e460c24f0bc06ae7) @@ -135,10 +135,6 @@ // Setup string validFilePath = Path.Combine(testDataPath, validFile); - const long id = 100; - const string locationName = "punt_flw_ 1"; - const double norm = 1.0 / 30; - var calculator = new TestDesignWaterLevelCalculator { IllustrationPointsResult = new TestGeneralResult(), @@ -150,8 +146,8 @@ calculatorFactory.Expect(cf => cf.CreateDesignWaterLevelCalculator(testDataPath)).Return(calculator); var calculation = mockRepository.Stub(); - calculation.Stub(c => c.Name).Return(locationName); - calculation.Expect(c => c.Id).Return(id); + 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(); @@ -162,7 +158,7 @@ // Call Action call = () => new DesignWaterLevelCalculationService().Calculate(calculation, validFilePath, - norm, + 1.0 / 30, calculationMessageProvider); // Assert @@ -176,7 +172,7 @@ CalculationServiceTestHelper.AssertCalculationEndMessage(msgs[2]); }); - AssessmentLevelCalculationInput expectedInput = CreateInput(id, norm); + AssessmentLevelCalculationInput expectedInput = CreateInput(100, 1.0 / 30); AssertInput(expectedInput, calculator.ReceivedInputs.Single()); Assert.IsFalse(calculator.IsCanceled); @@ -193,8 +189,6 @@ // Setup string validFilePath = Path.Combine(testDataPath, validFile); - const long id = 100; - const string locationName = "punt_flw_ 1"; const double norm = 1.0 / 30; var calculator = new TestDesignWaterLevelCalculator @@ -208,13 +202,13 @@ calculatorFactory.Expect(cf => cf.CreateDesignWaterLevelCalculator(testDataPath)).Return(calculator); var calculation = mockRepository.Stub(); - calculation.Stub(c => c.Name).Return(locationName); - calculation.Expect(c => c.Id).Return(id); + 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(locationName)).Return(failedConvergenceMessage); + calculationMessageProvider.Expect(c => c.GetCalculatedNotConvergedMessage("punt_flw_ 1")).Return(failedConvergenceMessage); mockRepository.ReplayAll(); using (new HydraRingCalculatorFactoryConfig(calculatorFactory)) @@ -237,7 +231,7 @@ CalculationServiceTestHelper.AssertCalculationEndMessage(msgs[3]); }); - AssessmentLevelCalculationInput expectedInput = CreateInput(id, norm); + AssessmentLevelCalculationInput expectedInput = CreateInput(100, norm); AssertInput(expectedInput, calculator.ReceivedInputs.Single()); Assert.IsFalse(calculator.IsCanceled); Assert.IsNotNull(calculation.Output); @@ -252,10 +246,6 @@ // Setup string validFilePath = Path.Combine(testDataPath, validFile); - const long id = 100; - const string locationName = "punt_flw_ 1"; - const double norm = 1.0 / 30; - var calculator = new TestDesignWaterLevelCalculator { IllustrationPointsResult = TestGeneralResult.CreateGeneralResultWithFaultTreeIllustrationPoints(), @@ -267,8 +257,8 @@ calculatorFactory.Expect(cf => cf.CreateDesignWaterLevelCalculator(testDataPath)).Return(calculator); var calculation = mockRepository.Stub(); - calculation.Stub(c => c.Name).Return(locationName); - calculation.Expect(c => c.Id).Return(id); + 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(); @@ -279,7 +269,7 @@ // Call Action call = () => new DesignWaterLevelCalculationService().Calculate(calculation, validFilePath, - norm, + 1.0 / 30, calculationMessageProvider); // Assert @@ -310,7 +300,6 @@ // Setup string validFilePath = Path.Combine(testDataPath, validFile); - const string locationName = "punt_flw_ 1"; var expectedException = new HydraRingFileParserException(); var mockRepository = new MockRepository(); @@ -324,11 +313,11 @@ calculatorFactory.Expect(cf => cf.CreateDesignWaterLevelCalculator(testDataPath)).Return(calculator); var calculation = mockRepository.Stub(); - calculation.Stub(c => c.Name).Return(locationName); + 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(locationName)).Return(string.Empty); + calculationMessageProvider.Stub(mp => mp.GetCalculatedNotConvergedMessage("punt_flw_ 1")).Return(string.Empty); mockRepository.ReplayAll(); using (new HydraRingCalculatorFactoryConfig(calculatorFactory)) @@ -353,8 +342,6 @@ // Setup string validFilePath = Path.Combine(testDataPath, validFile); - const string locationName = "punt_flw_ 1"; - const string parserErrorMessage = "Some Error Message"; var mockRepository = new MockRepository(); var calculator = new TestDesignWaterLevelCalculator @@ -367,7 +354,7 @@ calculatorFactory.Expect(cf => cf.CreateDesignWaterLevelCalculator(testDataPath)).Return(calculator); var calculation = mockRepository.Stub(); - calculation.Stub(c => c.Name).Return(locationName); + calculation.Stub(c => c.Name).Return("punt_flw_ 1"); calculation.Expect(c => c.Id).Return(100); calculation.Expect(c => c.CalculateIllustrationPoints).Return(true); @@ -405,8 +392,6 @@ // Setup string validFilePath = Path.Combine(testDataPath, validFile); - const string locationName = "punt_flw_ 1"; - var mockRepository = new MockRepository(); var calculator = new TestDesignWaterLevelCalculator { @@ -418,7 +403,7 @@ calculatorFactory.Expect(cf => cf.CreateDesignWaterLevelCalculator(testDataPath)).Return(calculator); var calculation = mockRepository.Stub(); - calculation.Stub(c => c.Name).Return(locationName); + calculation.Stub(c => c.Name).Return("punt_flw_ 1"); calculation.Expect(c => c.Id).Return(100); calculation.Expect(c => c.CalculateIllustrationPoints).Return(false); Index: Ringtoets/Common/test/Ringtoets.Common.Service.Test/Structures/StructuresCalculationServiceBaseTest.cs =================================================================== diff -u -r893c37884e74d551780cfd9cb4b9899779832650 -r058c36d676ce75456e648d75e460c24f0bc06ae7 --- Ringtoets/Common/test/Ringtoets.Common.Service.Test/Structures/StructuresCalculationServiceBaseTest.cs (.../StructuresCalculationServiceBaseTest.cs) (revision 893c37884e74d551780cfd9cb4b9899779832650) +++ Ringtoets/Common/test/Ringtoets.Common.Service.Test/Structures/StructuresCalculationServiceBaseTest.cs (.../StructuresCalculationServiceBaseTest.cs) (revision 058c36d676ce75456e648d75e460c24f0bc06ae7) @@ -388,7 +388,7 @@ calculatorFactory.Expect(cf => cf.CreateStructuresCalculator(testDataPath)) .Return(calculator); - const string performedCalculationMessage = "Calculation succesful"; + const string performedCalculationMessage = "Calculation successful"; var messageProvider = mocks.StrictMock(); messageProvider.Expect(mp => mp.GetCalculationPerformedMessage(validFilePath)).Return(performedCalculationMessage); mocks.ReplayAll(); @@ -448,7 +448,7 @@ calculatorFactory.Expect(cf => cf.CreateStructuresCalculator(testDataPath)) .Return(calculator); - const string performedCalculationMessage = "Calculation succesful"; + const string performedCalculationMessage = "Calculation successful"; var messageProvider = mocks.StrictMock(); messageProvider.Expect(mp => mp.GetCalculationPerformedMessage(validFilePath)).Return(performedCalculationMessage); mocks.ReplayAll(); @@ -501,7 +501,7 @@ calculatorFactory.Expect(cf => cf.CreateStructuresCalculator(testDataPath)) .Return(calculator); - const string performedCalculationMessage = "Calculation succesful"; + const string performedCalculationMessage = "Calculation successful"; var messageProvider = mocks.StrictMock(); messageProvider.Expect(mp => mp.GetCalculationPerformedMessage(validFilePath)).Return(performedCalculationMessage); mocks.ReplayAll(); @@ -553,7 +553,7 @@ calculatorFactory.Expect(cf => cf.CreateStructuresCalculator(testDataPath)) .Return(calculator); - const string performedCalculationMessage = "Calculation succesful"; + const string performedCalculationMessage = "Calculation successful"; var messageProvider = mocks.StrictMock(); messageProvider.Expect(mp => mp.GetCalculationPerformedMessage(validFilePath)).Return(performedCalculationMessage); mocks.ReplayAll(); Index: Ringtoets/Common/test/Ringtoets.Common.Service.Test/WaveHeightCalculationServiceTest.cs =================================================================== diff -u -r893c37884e74d551780cfd9cb4b9899779832650 -r058c36d676ce75456e648d75e460c24f0bc06ae7 --- Ringtoets/Common/test/Ringtoets.Common.Service.Test/WaveHeightCalculationServiceTest.cs (.../WaveHeightCalculationServiceTest.cs) (revision 893c37884e74d551780cfd9cb4b9899779832650) +++ Ringtoets/Common/test/Ringtoets.Common.Service.Test/WaveHeightCalculationServiceTest.cs (.../WaveHeightCalculationServiceTest.cs) (revision 058c36d676ce75456e648d75e460c24f0bc06ae7) @@ -135,8 +135,6 @@ // Setup string validFilePath = Path.Combine(testDataPath, validFile); - const long id = 100; - const string locationName = "punt_flw_ 1"; const double norm = 1.0 / 30; var calculator = new TestWaveHeightCalculator @@ -150,8 +148,8 @@ calculatorFactory.Expect(cf => cf.CreateWaveHeightCalculator(testDataPath)).Return(calculator); var calculation = mockRepository.Stub(); - calculation.Stub(c => c.Name).Return(locationName); - calculation.Expect(c => c.Id).Return(id); + calculation.Stub(c => c.Name).Return("punt_flw_ 1"); + calculation.Expect(c => c.Id).Return(100); calculation.Expect(c => c.CalculateIllustrationPoints).Return(readIllustrationPoints); var calculationMessageProvider = mockRepository.StrictMock(); @@ -175,7 +173,7 @@ CalculationServiceTestHelper.AssertCalculationEndMessage(msgs[2]); }); - AssessmentLevelCalculationInput expectedInput = CreateInput(id, norm); + AssessmentLevelCalculationInput expectedInput = CreateInput(100, norm); AssertInput(expectedInput, calculator.ReceivedInputs.Single()); Assert.IsFalse(calculator.IsCanceled); Assert.IsNotNull(calculation.Output); @@ -192,10 +190,6 @@ // Setup string validFilePath = Path.Combine(testDataPath, validFile); - const long id = 100; - const string locationName = "punt_flw_ 1"; - const double norm = 1.0 / 30; - var calculator = new TestWaveHeightCalculator { IllustrationPointsResult = new TestGeneralResult(), @@ -207,20 +201,20 @@ calculatorFactory.Expect(cf => cf.CreateWaveHeightCalculator(testDataPath)).Return(calculator); var calculation = mockRepository.Stub(); - calculation.Stub(c => c.Name).Return(locationName); - calculation.Expect(c => c.Id).Return(id); + 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(); const string failedConvergenceMessage = "Did not converge"; - calculationMessageProvider.Expect(mp => mp.GetCalculatedNotConvergedMessage(locationName)).Return(failedConvergenceMessage); + calculationMessageProvider.Expect(mp => mp.GetCalculatedNotConvergedMessage("punt_flw_ 1")).Return(failedConvergenceMessage); mockRepository.ReplayAll(); using (new HydraRingCalculatorFactoryConfig(calculatorFactory)) { Action call = () => new WaveHeightCalculationService().Calculate(calculation, validFilePath, - norm, + 1.0 / 30, calculationMessageProvider); // Assert @@ -247,10 +241,6 @@ // Setup string validFilePath = Path.Combine(testDataPath, validFile); - const long id = 100; - const string locationName = "punt_flw_ 1"; - const double norm = 1.0 / 30; - var calculator = new TestWaveHeightCalculator { IllustrationPointsResult = TestGeneralResult.CreateGeneralResultWithFaultTreeIllustrationPoints(), @@ -262,8 +252,8 @@ calculatorFactory.Expect(cf => cf.CreateWaveHeightCalculator(testDataPath)).Return(calculator); var calculation = mockRepository.Stub(); - calculation.Stub(c => c.Name).Return(locationName); - calculation.Expect(c => c.Id).Return(id); + 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(); @@ -274,7 +264,7 @@ // Call Action call = () => new WaveHeightCalculationService().Calculate(calculation, validFilePath, - norm, + 1.0 / 30, calculationMessageProvider); // Assert @@ -305,7 +295,6 @@ // Setup string validFilePath = Path.Combine(testDataPath, validFile); - const string locationName = "punt_flw_ 1"; var expectedException = new HydraRingFileParserException(); var mockRepository = new MockRepository(); @@ -319,11 +308,11 @@ calculatorFactory.Expect(cf => cf.CreateWaveHeightCalculator(testDataPath)).Return(calculator); var calculation = mockRepository.Stub(); - calculation.Stub(c => c.Name).Return(locationName); + 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(locationName)).Return(string.Empty); + calculationMessageProvider.Stub(mp => mp.GetCalculatedNotConvergedMessage("punt_flw_ 1")).Return(string.Empty); mockRepository.ReplayAll(); using (new HydraRingCalculatorFactoryConfig(calculatorFactory)) @@ -348,8 +337,6 @@ // Setup string validFilePath = Path.Combine(testDataPath, validFile); - const string locationName = "punt_flw_ 1"; - const string parserErrorMessage = "Parser error"; var mockRepository = new MockRepository(); var calculator = new TestWaveHeightCalculator @@ -362,7 +349,7 @@ calculatorFactory.Expect(cf => cf.CreateWaveHeightCalculator(testDataPath)).Return(calculator); var calculation = mockRepository.Stub(); - calculation.Stub(c => c.Name).Return(locationName); + calculation.Stub(c => c.Name).Return("punt_flw_ 1"); calculation.Expect(c => c.Id).Return(100); calculation.Expect(c => c.CalculateIllustrationPoints).Return(true); @@ -400,8 +387,6 @@ // Setup string validFilePath = Path.Combine(testDataPath, validFile); - const string locationName = "punt_flw_ 1"; - var mockRepository = new MockRepository(); var calculator = new TestWaveHeightCalculator { @@ -413,7 +398,7 @@ calculatorFactory.Expect(cf => cf.CreateWaveHeightCalculator(testDataPath)).Return(calculator); var calculation = mockRepository.Stub(); - calculation.Stub(c => c.Name).Return(locationName); + calculation.Stub(c => c.Name).Return("punt_flw_ 1"); calculation.Expect(c => c.Id).Return(100); calculation.Expect(c => c.CalculateIllustrationPoints).Return(false);