Index: Ringtoets/Common/src/Ringtoets.Common.Data/Probability/ProbabilityAssessmentOutput.cs =================================================================== diff -u -rb980005d38347be63445eae4223e5d9fa2dc0395 -re6e0f3a201a644070997b531763b63f19d44df0e --- Ringtoets/Common/src/Ringtoets.Common.Data/Probability/ProbabilityAssessmentOutput.cs (.../ProbabilityAssessmentOutput.cs) (revision b980005d38347be63445eae4223e5d9fa2dc0395) +++ Ringtoets/Common/src/Ringtoets.Common.Data/Probability/ProbabilityAssessmentOutput.cs (.../ProbabilityAssessmentOutput.cs) (revision e6e0f3a201a644070997b531763b63f19d44df0e) @@ -104,38 +104,5 @@ /// Gets the factor of safety of the failure mechanism. /// public RoundedDouble FactorOfSafety { get; private set; } - - /// - /// Gets the value indicating whether the output contains illustration points. - /// - public bool HasIllustrationPoints - { - get - { - return GeneralFaultTreeIllustrationPoint != null; - } - } - - /// - /// Gets the general result with the fault tree illustration points. - /// - public GeneralResult GeneralFaultTreeIllustrationPoint { get; private set; } - - /// - /// Sets the general result of this output with the fault tree illustration points. - /// - /// The general result which belongs - /// to this output. - /// Thrown when - /// is null. - public void SetIllustrationPoints(GeneralResult generalResultFaultTreeIllustrationPoint) - { - if (generalResultFaultTreeIllustrationPoint == null) - { - throw new ArgumentNullException(nameof(generalResultFaultTreeIllustrationPoint)); - } - - GeneralFaultTreeIllustrationPoint = generalResultFaultTreeIllustrationPoint; - } } } \ No newline at end of file Index: Ringtoets/Common/src/Ringtoets.Common.Data/Structures/StructuresOutput.cs =================================================================== diff -u -rb980005d38347be63445eae4223e5d9fa2dc0395 -re6e0f3a201a644070997b531763b63f19d44df0e --- Ringtoets/Common/src/Ringtoets.Common.Data/Structures/StructuresOutput.cs (.../StructuresOutput.cs) (revision b980005d38347be63445eae4223e5d9fa2dc0395) +++ Ringtoets/Common/src/Ringtoets.Common.Data/Structures/StructuresOutput.cs (.../StructuresOutput.cs) (revision e6e0f3a201a644070997b531763b63f19d44df0e) @@ -20,6 +20,7 @@ // All rights reserved. using System; +using Ringtoets.Common.Data.IllustrationPoints; using Ringtoets.Common.Data.Probability; namespace Ringtoets.Common.Data.Structures @@ -49,5 +50,38 @@ /// Gets the probabilistic assessment output. /// public ProbabilityAssessmentOutput ProbabilityAssessmentOutput { get; } + + /// + /// Gets the value indicating whether the output contains illustration points. + /// + public bool HasIllustrationPoints + { + get + { + return GeneralFaultTreeIllustrationPoint != null; + } + } + + /// + /// Gets the general result with the fault tree illustration points. + /// + public GeneralResult GeneralFaultTreeIllustrationPoint { get; private set; } + + /// + /// Sets the general result of this output with the fault tree illustration points. + /// + /// The general result which belongs + /// to this output. + /// Thrown when + /// is null. + public void SetIllustrationPoints(GeneralResult generalResultFaultTreeIllustrationPoint) + { + if (generalResultFaultTreeIllustrationPoint == null) + { + throw new ArgumentNullException(nameof(generalResultFaultTreeIllustrationPoint)); + } + + GeneralFaultTreeIllustrationPoint = generalResultFaultTreeIllustrationPoint; + } } } \ No newline at end of file Index: Ringtoets/Common/src/Ringtoets.Common.Service/DesignWaterLevelCalculationService.cs =================================================================== diff -u -r797860a90e2e806327a86f77e20a368eaf25d6ed -re6e0f3a201a644070997b531763b63f19d44df0e --- Ringtoets/Common/src/Ringtoets.Common.Service/DesignWaterLevelCalculationService.cs (.../DesignWaterLevelCalculationService.cs) (revision 797860a90e2e806327a86f77e20a368eaf25d6ed) +++ Ringtoets/Common/src/Ringtoets.Common.Service/DesignWaterLevelCalculationService.cs (.../DesignWaterLevelCalculationService.cs) (revision e6e0f3a201a644070997b531763b63f19d44df0e) @@ -121,9 +121,9 @@ if (!canceled) { string lastErrorContent = calculator.LastErrorFileContent; - log.Error(!string.IsNullOrEmpty(lastErrorContent) - ? messageProvider.GetCalculationFailedMessage(designWaterLevelCalculation.Name, lastErrorContent) - : messageProvider.GetCalculationFailedMessage(designWaterLevelCalculation.Name, e.Message), + log.Error(string.IsNullOrEmpty(lastErrorContent) + ? messageProvider.GetCalculationFailedMessage(designWaterLevelCalculation.Name, e.Message) + : messageProvider.GetCalculationFailedMessage(designWaterLevelCalculation.Name, lastErrorContent), e); exceptionThrown = true; @@ -219,7 +219,7 @@ } catch (IllustrationPointConversionException e) { - log.Warn("Het uitlezen van illustratiepunten is mislukt.", e); + log.Warn(Resources.SetIllustrationPointsResult_Converting_IllustrationPointResult_Failed, e); } } } Index: Ringtoets/Common/src/Ringtoets.Common.Service/Properties/Resources.Designer.cs =================================================================== diff -u -r211ed9d209b72a515105428e9ad08ec6972ad95d -re6e0f3a201a644070997b531763b63f19d44df0e --- Ringtoets/Common/src/Ringtoets.Common.Service/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision 211ed9d209b72a515105428e9ad08ec6972ad95d) +++ Ringtoets/Common/src/Ringtoets.Common.Service/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision e6e0f3a201a644070997b531763b63f19d44df0e) @@ -292,6 +292,15 @@ } /// + /// Looks up a localized string similar to Het uitlezen van illustratiepunten is mislukt.. + /// + public static string SetIllustrationPointsResult_Converting_IllustrationPointResult_Failed { + get { + return ResourceManager.GetString("SetIllustrationPointsResult_Converting_IllustrationPointResult_Failed", resourceCulture); + } + } + + /// /// Looks up a localized string similar to Er is geen kunstwerk geselecteerd.. /// public static string StructuresCalculationService_ValidateInput_No_Structure_selected { Index: Ringtoets/Common/src/Ringtoets.Common.Service/Properties/Resources.resx =================================================================== diff -u -r211ed9d209b72a515105428e9ad08ec6972ad95d -re6e0f3a201a644070997b531763b63f19d44df0e --- Ringtoets/Common/src/Ringtoets.Common.Service/Properties/Resources.resx (.../Resources.resx) (revision 211ed9d209b72a515105428e9ad08ec6972ad95d) +++ Ringtoets/Common/src/Ringtoets.Common.Service/Properties/Resources.resx (.../Resources.resx) (revision e6e0f3a201a644070997b531763b63f19d44df0e) @@ -209,4 +209,7 @@ Er konden geen illustratiepunten worden uitgelezen. + + Het uitlezen van illustratiepunten is mislukt. + \ No newline at end of file Index: Ringtoets/Common/src/Ringtoets.Common.Service/Structures/StructuresCalculationServiceBase.cs =================================================================== diff -u -r19f983eab8eac43d27e39f6eb9de019bad677652 -re6e0f3a201a644070997b531763b63f19d44df0e --- Ringtoets/Common/src/Ringtoets.Common.Service/Structures/StructuresCalculationServiceBase.cs (.../StructuresCalculationServiceBase.cs) (revision 19f983eab8eac43d27e39f6eb9de019bad677652) +++ Ringtoets/Common/src/Ringtoets.Common.Service/Structures/StructuresCalculationServiceBase.cs (.../StructuresCalculationServiceBase.cs) (revision e6e0f3a201a644070997b531763b63f19d44df0e) @@ -28,16 +28,21 @@ using log4net; using Ringtoets.Common.Data; using Ringtoets.Common.Data.AssessmentSection; +using Ringtoets.Common.Data.Exceptions; +using Ringtoets.Common.Data.Hydraulics; +using Ringtoets.Common.Data.IllustrationPoints; using Ringtoets.Common.Data.Probability; using Ringtoets.Common.Data.Structures; using Ringtoets.Common.IO.HydraRing; +using Ringtoets.Common.Service.IllustrationPoints; using Ringtoets.Common.Service.MessageProviders; using Ringtoets.Common.Service.Properties; using Ringtoets.Common.Service.ValidationRules; using Ringtoets.HydraRing.Calculation.Calculator; using Ringtoets.HydraRing.Calculation.Calculator.Factory; using Ringtoets.HydraRing.Calculation.Data.Input; using Ringtoets.HydraRing.Calculation.Exceptions; +using HydraRingGeneralResult = Ringtoets.HydraRing.Calculation.Data.Output.IllustrationPoints.GeneralResult; namespace Ringtoets.Common.Service.Structures { @@ -170,9 +175,14 @@ lengthEffectN, calculator.ExceedanceProbabilityBeta); calculation.Output = new StructuresOutput(probabilityAssessmentOutput); + + if (calculation.InputParameters.ShouldIllustrationPointsBeCalculated) + { + SetIllustrationPointsResult(calculation.Output, calculator.IllustrationPointsResult); + } } } - catch (HydraRingCalculationException) + catch (HydraRingCalculationException e) { if (!canceled) { @@ -182,7 +192,7 @@ ? messageProvider.GetCalculationFailedMessage(calculationName) : messageProvider.GetCalculationFailedWithErrorReportMessage(calculationName, lastErrorFileContent); - log.Error(message); + log.Error(message, e); exceptionThrown = true; throw; @@ -209,6 +219,32 @@ } /// + /// Sets a based on the information + /// of to the . + /// + /// The + /// for which to set the . + /// The to base the + /// to create on. + private static void SetIllustrationPointsResult(StructuresOutput structuresOutput, + HydraRingGeneralResult hydraRingGeneralResult) + { + if (hydraRingGeneralResult != null) + { + 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() Index: Ringtoets/Common/src/Ringtoets.Common.Service/WaveHeightCalculationService.cs =================================================================== diff -u -r797860a90e2e806327a86f77e20a368eaf25d6ed -re6e0f3a201a644070997b531763b63f19d44df0e --- Ringtoets/Common/src/Ringtoets.Common.Service/WaveHeightCalculationService.cs (.../WaveHeightCalculationService.cs) (revision 797860a90e2e806327a86f77e20a368eaf25d6ed) +++ Ringtoets/Common/src/Ringtoets.Common.Service/WaveHeightCalculationService.cs (.../WaveHeightCalculationService.cs) (revision e6e0f3a201a644070997b531763b63f19d44df0e) @@ -122,9 +122,9 @@ if (!canceled) { string lastErrorContent = calculator.LastErrorFileContent; - log.Error(!string.IsNullOrEmpty(lastErrorContent) - ? messageProvider.GetCalculationFailedMessage(waveHeightCalculation.Name, lastErrorContent) - : messageProvider.GetCalculationFailedMessage(waveHeightCalculation.Name, e.Message), + log.Error(string.IsNullOrEmpty(lastErrorContent) + ? messageProvider.GetCalculationFailedMessage(waveHeightCalculation.Name, e.Message) + : messageProvider.GetCalculationFailedMessage(waveHeightCalculation.Name, lastErrorContent), e); exceptionThrown = true; @@ -220,7 +220,7 @@ } catch (IllustrationPointConversionException e) { - log.Warn("Het uitlezen van illustratiepunten is mislukt.", e); + log.Warn(Resources.SetIllustrationPointsResult_Converting_IllustrationPointResult_Failed, e); } } } Index: Ringtoets/Common/test/Ringtoets.Common.Data.Test/Structures/StructuresOutputTest.cs =================================================================== diff -u -rb980005d38347be63445eae4223e5d9fa2dc0395 -re6e0f3a201a644070997b531763b63f19d44df0e --- Ringtoets/Common/test/Ringtoets.Common.Data.Test/Structures/StructuresOutputTest.cs (.../StructuresOutputTest.cs) (revision b980005d38347be63445eae4223e5d9fa2dc0395) +++ Ringtoets/Common/test/Ringtoets.Common.Data.Test/Structures/StructuresOutputTest.cs (.../StructuresOutputTest.cs) (revision e6e0f3a201a644070997b531763b63f19d44df0e) @@ -63,22 +63,24 @@ // Assert Assert.AreSame(output, structuresOutput.ProbabilityAssessmentOutput); - Assert.IsFalse(output.HasIllustrationPoints); + Assert.IsFalse(structuresOutput.HasIllustrationPoints); + Assert.IsNull(structuresOutput.GeneralFaultTreeIllustrationPoint); } [Test] public void SetIllustrationPoints_GeneralResultNull_ThrowsArgumentNullException() { // Setup var random = new Random(21); - var output = new ProbabilityAssessmentOutput(random.NextDouble(), + var probabilityAssessmentOutput = new ProbabilityAssessmentOutput(random.NextDouble(), random.NextDouble(), random.NextDouble(), random.NextDouble(), random.NextDouble()); + var structuresOutput = new StructuresOutput(probabilityAssessmentOutput); // Call - TestDelegate call = () => output.SetIllustrationPoints(null) ; + TestDelegate call = () => structuresOutput.SetIllustrationPoints(null) ; // Assert var exception = Assert.Throws(call); @@ -92,18 +94,20 @@ var generalResult = new TestGeneralResultFaultTreeIllustrationPoint(); var random = new Random(21); - var output = new ProbabilityAssessmentOutput(random.NextDouble(), + var probabilityAssessmentOutput = new ProbabilityAssessmentOutput(random.NextDouble(), random.NextDouble(), random.NextDouble(), random.NextDouble(), random.NextDouble()); + var structuresOutput = new StructuresOutput(probabilityAssessmentOutput); + // Call - output.SetIllustrationPoints(generalResult); + structuresOutput.SetIllustrationPoints(generalResult); // Assert - Assert.AreSame(generalResult, output.GeneralFaultTreeIllustrationPoint); - Assert.IsTrue(output.HasIllustrationPoints); + Assert.AreSame(generalResult, structuresOutput.GeneralFaultTreeIllustrationPoint); + Assert.IsTrue(structuresOutput.HasIllustrationPoints); } } } \ No newline at end of file Index: Ringtoets/Common/test/Ringtoets.Common.Service.Test/DesignWaterLevelCalculationServiceTest.cs =================================================================== diff -u -r797860a90e2e806327a86f77e20a368eaf25d6ed -re6e0f3a201a644070997b531763b63f19d44df0e --- Ringtoets/Common/test/Ringtoets.Common.Service.Test/DesignWaterLevelCalculationServiceTest.cs (.../DesignWaterLevelCalculationServiceTest.cs) (revision 797860a90e2e806327a86f77e20a368eaf25d6ed) +++ Ringtoets/Common/test/Ringtoets.Common.Service.Test/DesignWaterLevelCalculationServiceTest.cs (.../DesignWaterLevelCalculationServiceTest.cs) (revision e6e0f3a201a644070997b531763b63f19d44df0e) @@ -188,7 +188,7 @@ [Test] [TestCase(true)] [TestCase(false)] - public void Calculate_ValidDesignWaterLevelCalculationAndDoesNotConverge_StartsCalculationWithRightParametersAndLogsWarning(bool readIllustrationPoints) + public void Calculate_ValidDesignWaterLevelCalculationAndDoesNotConverge_SetsOutputAndLogs(bool readIllustrationPoints) { // Setup string validFilePath = Path.Combine(testDataPath, validFile); @@ -247,7 +247,7 @@ } [Test] - public void Calculate_ValidDesignWaterLevelCalculationButInvalidIllustrationPointResults_StartsCalculationWithRightParametersAndLogsWarning() + public void Calculate_ValidDesignWaterLevelCalculationButInvalidIllustrationPointResults_IllustrationPointNotSetAndLog() { // Setup string validFilePath = Path.Combine(testDataPath, validFile); @@ -298,10 +298,6 @@ Assert.IsInstanceOf(tupleArray[1].Item3); }); - - AssessmentLevelCalculationInput expectedInput = CreateInput(id, norm); - AssertInput(expectedInput, calculator.ReceivedInputs.Single()); - Assert.IsFalse(calculator.IsCanceled); Assert.IsNotNull(calculation.Output); Assert.IsFalse(calculation.Output.HasIllustrationPoints); } @@ -487,15 +483,22 @@ }; // Assert - TestHelper.AssertLogMessages(call, messages => + TestHelper.AssertLogMessagesAndLoggedExceptions(call, messages => { - string[] msgs = messages.ToArray(); + Tuple[] generatedMessages = messages.ToArray(); + + string[] msgs = generatedMessages.Select(msg => msg.Item1).ToArray(); Assert.AreEqual(4, msgs.Length); CalculationServiceTestHelper.AssertCalculationStartMessage(msgs[0]); Assert.AreEqual(calculationFailedMessage, msgs[1]); Assert.AreEqual($"Toetspeil berekening is uitgevoerd op de tijdelijke locatie '{calculator.OutputDirectory}'. " + "Gedetailleerde invoer en uitvoer kan in de bestanden op deze locatie worden gevonden.", msgs[2]); CalculationServiceTestHelper.AssertCalculationEndMessage(msgs[3]); + + if (!endInFailure && string.IsNullOrEmpty(lastErrorFileContent)) + { + Assert.IsInstanceOf(generatedMessages[1].Item3); + } }); Assert.IsInstanceOf(exception); Index: Ringtoets/Common/test/Ringtoets.Common.Service.Test/Ringtoets.Common.Service.Test.csproj =================================================================== diff -u -r797860a90e2e806327a86f77e20a368eaf25d6ed -re6e0f3a201a644070997b531763b63f19d44df0e --- Ringtoets/Common/test/Ringtoets.Common.Service.Test/Ringtoets.Common.Service.Test.csproj (.../Ringtoets.Common.Service.Test.csproj) (revision 797860a90e2e806327a86f77e20a368eaf25d6ed) +++ Ringtoets/Common/test/Ringtoets.Common.Service.Test/Ringtoets.Common.Service.Test.csproj (.../Ringtoets.Common.Service.Test.csproj) (revision e6e0f3a201a644070997b531763b63f19d44df0e) @@ -100,7 +100,6 @@ Copying.licenseheader - Index: Ringtoets/Common/test/Ringtoets.Common.Service.Test/Structures/StructuresCalculationServiceBaseTest.cs =================================================================== diff -u -r19f983eab8eac43d27e39f6eb9de019bad677652 -re6e0f3a201a644070997b531763b63f19d44df0e --- Ringtoets/Common/test/Ringtoets.Common.Service.Test/Structures/StructuresCalculationServiceBaseTest.cs (.../StructuresCalculationServiceBaseTest.cs) (revision 19f983eab8eac43d27e39f6eb9de019bad677652) +++ Ringtoets/Common/test/Ringtoets.Common.Service.Test/Structures/StructuresCalculationServiceBaseTest.cs (.../StructuresCalculationServiceBaseTest.cs) (revision e6e0f3a201a644070997b531763b63f19d44df0e) @@ -24,21 +24,25 @@ using System.Linq; using Core.Common.Base.Geometry; using Core.Common.TestUtil; +using log4net.Core; using NUnit.Framework; using Rhino.Mocks; using Ringtoets.Common.Data.AssessmentSection; +using Ringtoets.Common.Data.Exceptions; using Ringtoets.Common.Data.FailureMechanism; using Ringtoets.Common.Data.Structures; using Ringtoets.Common.Data.TestUtil; using Ringtoets.Common.Service.MessageProviders; using Ringtoets.Common.Service.Structures; using Ringtoets.Common.Service.TestUtil; +using Ringtoets.HydraRing.Calculation.Calculator; using Ringtoets.HydraRing.Calculation.Calculator.Factory; using Ringtoets.HydraRing.Calculation.Data; using Ringtoets.HydraRing.Calculation.Data.Input; using Ringtoets.HydraRing.Calculation.Exceptions; using Ringtoets.HydraRing.Calculation.TestUtil; using Ringtoets.HydraRing.Calculation.TestUtil.Calculator; +using Ringtoets.HydraRing.Calculation.TestUtil.IllustrationPoints; namespace Ringtoets.Common.Service.Test.Structures { @@ -335,92 +339,235 @@ [Test] public void Calculate_CalculationNull_ThrowArgumentNullException() { + // Setup + var mocks = new MockRepository(); + var messageProvider = mocks.Stub(); + mocks.ReplayAll(); + // Call - TestDelegate test = () => new TestStructuresCalculationService() + TestDelegate test = () => new TestStructuresCalculationService(messageProvider) .Calculate(null, new GeneralTestInput(), 0, 1, 1, string.Empty); // Assert var exception = Assert.Throws(test); Assert.AreEqual("calculation", exception.ParamName); + mocks.VerifyAll(); } [Test] public void Calculate_GeneralInputNull_ThrowArgumentNullException() { // Setup + var mocks = new MockRepository(); + var messageProvider = mocks.Stub(); + mocks.ReplayAll(); + var calculation = new TestStructuresCalculation(); // Call - TestDelegate test = () => new TestStructuresCalculationService() + TestDelegate test = () => new TestStructuresCalculationService(messageProvider) .Calculate(calculation, null, 0, 1, 1, string.Empty); // Assert var exception = Assert.Throws(test); Assert.AreEqual("generalInput", exception.ParamName); + mocks.VerifyAll(); } [Test] - public void Calculate_ValidInput_InputPropertiesCorrectlySentToCalculator() + [TestCase(true)] + [TestCase(false)] + public void Calculate_ValidInput_InputPropertiesCorrectlySentToCalculatorAndLogs(bool readIllustrationPoints) { // Setup var mocks = new MockRepository(); - var calculator = new TestStructuresCalculator(); + var calculator = new TestStructuresCalculator + { + OutputDirectory = validFilePath, + IllustrationPointsResult = new TestGeneralResult() + }; var calculatorFactory = mocks.StrictMock(); calculatorFactory.Expect(cf => cf.CreateStructuresCalculator(testDataPath)) .Return(calculator); + + const string performedCalculationMessage = "Calculation succesful"; + var messageProvider = mocks.StrictMock(); + messageProvider.Expect(mp => mp.GetCalculationPerformedMessage(validFilePath)).Return(performedCalculationMessage); mocks.ReplayAll(); var hydraulicBoundaryLocation = new TestHydraulicBoundaryLocation(); var calculation = new TestStructuresCalculation { InputParameters = { - HydraulicBoundaryLocation = hydraulicBoundaryLocation + HydraulicBoundaryLocation = hydraulicBoundaryLocation, + ShouldIllustrationPointsBeCalculated = readIllustrationPoints } }; using (new HydraRingCalculatorFactoryConfig(calculatorFactory)) { - var service = new TestStructuresCalculationService(); + var service = new TestStructuresCalculationService(messageProvider); // Call - service.Calculate(calculation, new GeneralTestInput(), 1, 1, 1, validFilePath); + Action call = () => service.Calculate(calculation, new GeneralTestInput(), 1, 1, 1, validFilePath); // Assert + TestHelper.AssertLogMessages(call, messages => + { + string[] msgs = messages.ToArray(); + Assert.AreEqual(3, msgs.Length); + CalculationServiceTestHelper.AssertCalculationStartMessage(msgs[0]); + Assert.AreEqual(performedCalculationMessage, msgs[1]); + CalculationServiceTestHelper.AssertCalculationEndMessage(msgs[2]); + }); + ExceedanceProbabilityCalculationInput[] calculationInputs = calculator.ReceivedInputs.ToArray(); Assert.AreEqual(1, calculationInputs.Length); var expectedInput = new TestExceedanceProbabilityCalculationInput(hydraulicBoundaryLocation.Id); ExceedanceProbabilityCalculationInput actualInput = calculationInputs[0]; HydraRingDataEqualityHelper.AreEqual(expectedInput, actualInput); + Assert.IsNotNull(calculation.Output); Assert.IsFalse(calculator.IsCanceled); + Assert.AreEqual(readIllustrationPoints, calculation.Output.HasIllustrationPoints); } mocks.VerifyAll(); } [Test] - public void Calculate_CancelCalculationWithValidInput_CancelsCalculatorAndHasNullOutput() + public void Calculate_ValidInputButIllustrationPointsNull_IllustrationPointsNotSet() { // Setup var mocks = new MockRepository(); - var calculator = new TestStructuresCalculator(); + var calculator = new TestStructuresCalculator + { + OutputDirectory = validFilePath + }; var calculatorFactory = mocks.StrictMock(); calculatorFactory.Expect(cf => cf.CreateStructuresCalculator(testDataPath)) .Return(calculator); + + const string performedCalculationMessage = "Calculation succesful"; + var messageProvider = mocks.StrictMock(); + messageProvider.Expect(mp => mp.GetCalculationPerformedMessage(validFilePath)).Return(performedCalculationMessage); mocks.ReplayAll(); var hydraulicBoundaryLocation = new TestHydraulicBoundaryLocation(); var calculation = new TestStructuresCalculation { InputParameters = { + HydraulicBoundaryLocation = hydraulicBoundaryLocation, + ShouldIllustrationPointsBeCalculated = true + } + }; + + using (new HydraRingCalculatorFactoryConfig(calculatorFactory)) + { + var service = new TestStructuresCalculationService(messageProvider); + + // Call + Action call = () => service.Calculate(calculation, new GeneralTestInput(), 1, 1, 1, validFilePath); + + // Assert + TestHelper.AssertLogMessages(call, messages => + { + string[] msgs = messages.ToArray(); + Assert.AreEqual(3, msgs.Length); + + CalculationServiceTestHelper.AssertCalculationStartMessage(msgs[0]); + Assert.AreEqual(performedCalculationMessage, msgs[1]); + CalculationServiceTestHelper.AssertCalculationEndMessage(msgs[2]); + }); + Assert.IsNotNull(calculation.Output); + Assert.IsFalse(calculation.Output.HasIllustrationPoints); + } + mocks.VerifyAll(); + } + + [Test] + public void Calculate_ValidInputButIllustrationPointResultsInvalid_IllustrationPointsNotSetAndLogsWarning() + { + // Setup + var mocks = new MockRepository(); + var calculator = new TestStructuresCalculator + { + OutputDirectory = validFilePath, + IllustrationPointsResult = TestGeneralResult.CreateGeneralResultWithSubMechanismIllustrationPoints() + }; + var calculatorFactory = mocks.StrictMock(); + calculatorFactory.Expect(cf => cf.CreateStructuresCalculator(testDataPath)) + .Return(calculator); + + const string performedCalculationMessage = "Calculation succesful"; + var messageProvider = mocks.StrictMock(); + messageProvider.Expect(mp => mp.GetCalculationPerformedMessage(validFilePath)).Return(performedCalculationMessage); + mocks.ReplayAll(); + + var hydraulicBoundaryLocation = new TestHydraulicBoundaryLocation(); + var calculation = new TestStructuresCalculation + { + InputParameters = + { + HydraulicBoundaryLocation = hydraulicBoundaryLocation, + ShouldIllustrationPointsBeCalculated = true + } + }; + + using (new HydraRingCalculatorFactoryConfig(calculatorFactory)) + { + var service = new TestStructuresCalculationService(messageProvider); + + // Call + Action call = () => service.Calculate(calculation, new GeneralTestInput(), 1, 1, 1, validFilePath); + + // Assert + TestHelper.AssertLogMessagesAndLoggedExceptions(call, messages => + { + Tuple[] tupleArray = messages.ToArray(); + + string[] msgs = tupleArray.Select(tuple => tuple.Item1).ToArray(); + Assert.AreEqual(4, msgs.Length); + + CalculationServiceTestHelper.AssertCalculationStartMessage(msgs[0]); + Assert.AreEqual("Het uitlezen van illustratiepunten is mislukt.", msgs[1]); + Assert.AreEqual(performedCalculationMessage, msgs[2]); + CalculationServiceTestHelper.AssertCalculationEndMessage(msgs[3]); + + Assert.IsInstanceOf(tupleArray[1].Item3); + }); + Assert.IsNotNull(calculation.Output); + Assert.IsFalse(calculation.Output.HasIllustrationPoints); + } + mocks.VerifyAll(); + } + + [Test] + public void Calculate_CancelCalculationWithValidInput_CancelsCalculatorAndHasNullOutput() + { + // Setup + var hydraulicBoundaryLocation = new TestHydraulicBoundaryLocation(); + var calculation = new TestStructuresCalculation + { + InputParameters = + { HydraulicBoundaryLocation = hydraulicBoundaryLocation } }; + var mocks = new MockRepository(); + var calculator = new TestStructuresCalculator(); + var calculatorFactory = mocks.StrictMock(); + calculatorFactory.Expect(cf => cf.CreateStructuresCalculator(testDataPath)) + .Return(calculator); + + var messageProvider = mocks.Stub(); + mocks.ReplayAll(); + using (new HydraRingCalculatorFactoryConfig(calculatorFactory)) { - var service = new TestStructuresCalculationService(); + var service = new TestStructuresCalculationService(messageProvider); calculator.CalculationFinishedHandler += (s, e) => service.Cancel(); // Call @@ -435,14 +582,23 @@ [Test] [TestCaseSource(typeof(HydraRingCalculatorTestCaseProvider), nameof(HydraRingCalculatorTestCaseProvider.GetCalculatorFailingConditionsWithReportDetails), new object[] - { - nameof(Calculate_CalculationFailed_ThrowsHydraRingCalculationExceptionAndLogError) - })] + { + nameof(Calculate_CalculationFailed_ThrowsHydraRingCalculationExceptionAndLogError) + })] public void Calculate_CalculationFailed_ThrowsHydraRingCalculationExceptionAndLogError(bool endInFailure, string lastErrorFileContent, string detailedReport) { // Setup + var hydraulicBoundaryLocation = new TestHydraulicBoundaryLocation(); + var calculation = new TestStructuresCalculation + { + InputParameters = + { + HydraulicBoundaryLocation = hydraulicBoundaryLocation + } + }; + var mocks = new MockRepository(); var calculator = new TestStructuresCalculator { @@ -452,27 +608,39 @@ var calculatorFactory = mocks.StrictMock(); calculatorFactory.Expect(cf => cf.CreateStructuresCalculator(testDataPath)) .Return(calculator); - mocks.ReplayAll(); - var hydraulicBoundaryLocation = new TestHydraulicBoundaryLocation(); - var calculation = new TestStructuresCalculation + const string calculationFailedMessage = "Calculation failed"; + const string calculationPerformedMessage = "Calculation performed"; + var messageProvider = mocks.StrictMock(); + + + // TODO: WTI-1308 remove if statement when it's clear what needs to be done + if (endInFailure && string.IsNullOrEmpty(lastErrorFileContent)) { - InputParameters = - { - HydraulicBoundaryLocation = hydraulicBoundaryLocation - } - }; + messageProvider.Expect(mp => mp.GetCalculationFailedMessage(calculation.Name)).Return(calculationFailedMessage); + } + else + { + messageProvider.Expect(mp => mp.GetCalculationFailedWithErrorReportMessage(calculation.Name, + endInFailure && string.IsNullOrEmpty(lastErrorFileContent) + ? calculator.HydraRingCalculationException.Message + : lastErrorFileContent + )).Return(calculationFailedMessage); + } + messageProvider.Expect(mp => mp.GetCalculationPerformedMessage(calculator.OutputDirectory)).Return(calculationPerformedMessage); + mocks.ReplayAll(); using (new HydraRingCalculatorFactoryConfig(calculatorFactory)) { var exceptionThrown = false; + var structuresCalculationService = new TestStructuresCalculationService(messageProvider); // Call Action call = () => { try { - new TestStructuresCalculationService().Calculate(calculation, new GeneralTestInput(), 0, 0.5, 1, validFilePath); + structuresCalculationService.Calculate(calculation, new GeneralTestInput(), 0, 0.5, 1, validFilePath); } catch (HydraRingCalculationException) { @@ -481,14 +649,21 @@ }; // Assert - TestHelper.AssertLogMessages(call, messages => + TestHelper.AssertLogMessagesAndLoggedExceptions(call, messages => { - string[] msgs = messages.ToArray(); + Tuple[] generatedMessages = messages.ToArray(); + + string[] msgs = generatedMessages.Select(msg => msg.Item1).ToArray(); Assert.AreEqual(4, msgs.Length); CalculationServiceTestHelper.AssertCalculationStartMessage(msgs[0]); - Assert.AreEqual($"Calculation '{calculation.Name}' failed. {detailedReport}", msgs[1]); - Assert.AreEqual("Calculation performed in directory ''.", msgs[2]); + Assert.AreEqual(calculationFailedMessage, msgs[1]); + Assert.AreEqual(calculationPerformedMessage, msgs[2]); CalculationServiceTestHelper.AssertCalculationEndMessage(msgs[3]); + + if (!endInFailure && string.IsNullOrEmpty(lastErrorFileContent)) + { + Assert.IsInstanceOf(generatedMessages[1].Item3); + } }); Assert.IsTrue(exceptionThrown); Assert.IsNull(calculation.Output); @@ -499,8 +674,6 @@ private class TestStructuresCalculationService : StructuresCalculationServiceBase { - public TestStructuresCalculationService() : this(new TestMessageProvider()) {} - public TestStructuresCalculationService(IStructuresCalculationMessageProvider messageProvider) : base(messageProvider) {} protected override ExceedanceProbabilityCalculationInput CreateInput(TestStructuresInput structureInput, @@ -528,24 +701,6 @@ } } - private class TestMessageProvider : IStructuresCalculationMessageProvider - { - public string GetCalculationFailedMessage(string calculationSubject) - { - return $"Calculation '{calculationSubject}' failed. Er is geen foutrapport beschikbaar."; - } - - public string GetCalculationFailedWithErrorReportMessage(string calculationSubject, string errorReport) - { - return $"Calculation '{calculationSubject}' failed. Bekijk het foutrapport door op details te klikken.{Environment.NewLine}{errorReport}"; - } - - public string GetCalculationPerformedMessage(string outputDirectory) - { - return $"Calculation performed in directory '{outputDirectory}'."; - } - } - private class GeneralTestInput { public double N Index: Ringtoets/Common/test/Ringtoets.Common.Service.Test/WaveHeightCalculationServiceTest.cs =================================================================== diff -u -r797860a90e2e806327a86f77e20a368eaf25d6ed -re6e0f3a201a644070997b531763b63f19d44df0e --- Ringtoets/Common/test/Ringtoets.Common.Service.Test/WaveHeightCalculationServiceTest.cs (.../WaveHeightCalculationServiceTest.cs) (revision 797860a90e2e806327a86f77e20a368eaf25d6ed) +++ Ringtoets/Common/test/Ringtoets.Common.Service.Test/WaveHeightCalculationServiceTest.cs (.../WaveHeightCalculationServiceTest.cs) (revision e6e0f3a201a644070997b531763b63f19d44df0e) @@ -187,7 +187,7 @@ [Test] [TestCase(true)] [TestCase(false)] - public void Calculate_ValidWaveHeightCalculationAndDoesNotConverge_StartsCalculationWithRightParametersAndLogsWarning(bool readIllustrationPoints) + public void Calculate_ValidWaveHeightCalculationAndDoesNotConverge_SetsOutputAndLogs(bool readIllustrationPoints) { // Setup string validFilePath = Path.Combine(testDataPath, validFile); @@ -234,9 +234,6 @@ "Gedetailleerde invoer en uitvoer kan in de bestanden op deze locatie worden gevonden.", msgs[2]); CalculationServiceTestHelper.AssertCalculationEndMessage(msgs[3]); }); - - AssessmentLevelCalculationInput expectedInput = CreateInput(id, norm); - AssertInput(expectedInput, calculator.ReceivedInputs.Single()); Assert.IsFalse(calculator.IsCanceled); Assert.IsNotNull(calculation.Output); Assert.AreEqual(readIllustrationPoints, calculation.Output.HasIllustrationPoints); @@ -245,7 +242,7 @@ } [Test] - public void Calculate_ValidDesignWaterLevelCalculationButInvalidIllustrationPointResults_StartsCalculationWithRightParametersAndLogsWarning() + public void Calculate_ValidDesignWaterLevelCalculationButInvalidIllustrationPointResults_IllustrationPointsNotSetAndLogs() { // Setup string validFilePath = Path.Combine(testDataPath, validFile); @@ -296,10 +293,6 @@ Assert.IsInstanceOf(tupleArray[1].Item3); }); - - AssessmentLevelCalculationInput expectedInput = CreateInput(id, norm); - AssertInput(expectedInput, calculator.ReceivedInputs.Single()); - Assert.IsFalse(calculator.IsCanceled); Assert.IsNotNull(calculation.Output); Assert.IsFalse(calculation.Output.HasIllustrationPoints); } @@ -484,16 +477,24 @@ }; // Assert - TestHelper.AssertLogMessages(call, messages => + TestHelper.AssertLogMessagesAndLoggedExceptions(call, messages => { - string[] msgs = messages.ToArray(); + Tuple[] generatedMessages = messages.ToArray(); + + string[] msgs = generatedMessages.Select(msg => msg.Item1).ToArray(); Assert.AreEqual(4, msgs.Length); CalculationServiceTestHelper.AssertCalculationStartMessage(msgs[0]); Assert.AreEqual(calculationFailedMessage, msgs[1]); Assert.AreEqual($"Golfhoogte berekening is uitgevoerd op de tijdelijke locatie '{calculator.OutputDirectory}'. " + "Gedetailleerde invoer en uitvoer kan in de bestanden op deze locatie worden gevonden.", msgs[2]); CalculationServiceTestHelper.AssertCalculationEndMessage(msgs[3]); + + if (!endInFailure && string.IsNullOrEmpty(lastErrorFileContent)) + { + Assert.IsInstanceOf(generatedMessages[1].Item3); + } }); + Assert.IsInstanceOf(exception); } mockRepository.VerifyAll(); Index: Ringtoets/HydraRing/test/Ringtoets.HydraRing.Calculation.TestUtil.Test/IllustrationPoints/TestGeneralResultTest.cs =================================================================== diff -u -r797860a90e2e806327a86f77e20a368eaf25d6ed -re6e0f3a201a644070997b531763b63f19d44df0e --- Ringtoets/HydraRing/test/Ringtoets.HydraRing.Calculation.TestUtil.Test/IllustrationPoints/TestGeneralResultTest.cs (.../TestGeneralResultTest.cs) (revision 797860a90e2e806327a86f77e20a368eaf25d6ed) +++ Ringtoets/HydraRing/test/Ringtoets.HydraRing.Calculation.TestUtil.Test/IllustrationPoints/TestGeneralResultTest.cs (.../TestGeneralResultTest.cs) (revision e6e0f3a201a644070997b531763b63f19d44df0e) @@ -68,6 +68,28 @@ Assert.IsInstanceOf(topLevelIllustrationPoint.Value.Data); } + [Test] + public void CreateGeneralResultWithSubMechanismIllustrationPoints_ExpectedProperties() + { + // Call + TestGeneralResult generalResult = TestGeneralResult.CreateGeneralResultWithSubMechanismIllustrationPoints(); + + // Assert + Assert.IsInstanceOf(generalResult); + Assert.AreEqual(0, generalResult.Beta); + + var expectedWindDirection = new TestWindDirection(); + AssertWindDirection(expectedWindDirection, generalResult.GoverningWindDirection); + CollectionAssert.IsEmpty(generalResult.Stochasts); + + KeyValuePair topLevelIllustrationPoint = + generalResult.IllustrationPoints.Single(); + WindDirectionClosingSituation actualWindDirectionClosingSituation = topLevelIllustrationPoint.Key; + AssertWindDirection(expectedWindDirection, actualWindDirectionClosingSituation.WindDirection); + Assert.AreEqual("closing situation", actualWindDirectionClosingSituation.ClosingSituation); + Assert.IsInstanceOf(topLevelIllustrationPoint.Value.Data); + } + private static void AssertWindDirection(WindDirection expected, WindDirection actual) { Assert.AreEqual(expected.Name, actual.Name); Index: Ringtoets/HydraRing/test/Ringtoets.HydraRing.Calculation.TestUtil/IllustrationPoints/TestGeneralResult.cs =================================================================== diff -u -r797860a90e2e806327a86f77e20a368eaf25d6ed -re6e0f3a201a644070997b531763b63f19d44df0e --- Ringtoets/HydraRing/test/Ringtoets.HydraRing.Calculation.TestUtil/IllustrationPoints/TestGeneralResult.cs (.../TestGeneralResult.cs) (revision 797860a90e2e806327a86f77e20a368eaf25d6ed) +++ Ringtoets/HydraRing/test/Ringtoets.HydraRing.Calculation.TestUtil/IllustrationPoints/TestGeneralResult.cs (.../TestGeneralResult.cs) (revision e6e0f3a201a644070997b531763b63f19d44df0e) @@ -53,5 +53,19 @@ return generalResult; } + + /// + /// Creates a new instance of with only sub mechanism + /// illustration points. + /// + /// A with sub mechanism illustration points. + public static TestGeneralResult CreateGeneralResultWithSubMechanismIllustrationPoints() + { + var generalResult = new TestGeneralResult(); + generalResult.IllustrationPoints.Add(new WindDirectionClosingSituation(new TestWindDirection(), "closing situation"), + new IllustrationPointTreeNode(new TestSubMechanismIllustrationPoint())); + + return generalResult; + } } } \ No newline at end of file