Index: Application/Ringtoets/test/Application.Ringtoets.Storage.TestUtil.Test/RingtoetsProjectTestHelperTest.cs =================================================================== diff -u -r57b198a3f80256e02b871d8de11c05d9f2dcf311 -r2be62a16f4a6d90a76ebb53967a7b7ea3a445cd1 --- Application/Ringtoets/test/Application.Ringtoets.Storage.TestUtil.Test/RingtoetsProjectTestHelperTest.cs (.../RingtoetsProjectTestHelperTest.cs) (revision 57b198a3f80256e02b871d8de11c05d9f2dcf311) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.TestUtil.Test/RingtoetsProjectTestHelperTest.cs (.../RingtoetsProjectTestHelperTest.cs) (revision 2be62a16f4a6d90a76ebb53967a7b7ea3a445cd1) @@ -515,7 +515,7 @@ Assert.AreEqual(120, actualGoverningWindDirection.Angle, actualGoverningWindDirection.Angle.GetAccuracy()); Stochast stochast = generalResult.Stochasts.Single(); - Assert.AreEqual("Name of stochast", stochast.Name); + Assert.AreEqual("Name of a stochast", stochast.Name); Assert.AreEqual(37, stochast.Alpha, stochast.Alpha.GetAccuracy()); Assert.AreEqual(13, stochast.Duration, stochast.Duration.GetAccuracy()); @@ -531,7 +531,7 @@ Assert.AreEqual(3, illustrationPoint.Beta, illustrationPoint.Beta.GetAccuracy()); SubMechanismIllustrationPointStochast illustrationPointStochast = illustrationPoint.Stochasts.Single(); - Assert.AreEqual("Name of a submechanism stochast", illustrationPointStochast.Name); + Assert.AreEqual("Name of a stochast", illustrationPointStochast.Name); Assert.AreEqual(10, illustrationPointStochast.Duration, illustrationPointStochast.Duration.GetAccuracy()); Assert.AreEqual(9, illustrationPointStochast.Alpha, illustrationPointStochast.Alpha.GetAccuracy()); Assert.AreEqual(8, illustrationPointStochast.Realization, illustrationPointStochast.Realization.GetAccuracy()); Index: Application/Ringtoets/test/Application.Ringtoets.Storage.TestUtil/RingtoetsProjectTestHelper.cs =================================================================== diff -u -r57b198a3f80256e02b871d8de11c05d9f2dcf311 -r2be62a16f4a6d90a76ebb53967a7b7ea3a445cd1 --- Application/Ringtoets/test/Application.Ringtoets.Storage.TestUtil/RingtoetsProjectTestHelper.cs (.../RingtoetsProjectTestHelper.cs) (revision 57b198a3f80256e02b871d8de11c05d9f2dcf311) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.TestUtil/RingtoetsProjectTestHelper.cs (.../RingtoetsProjectTestHelper.cs) (revision 2be62a16f4a6d90a76ebb53967a7b7ea3a445cd1) @@ -385,7 +385,7 @@ private static GeneralResult GetConfiguredGeneralResultTopLevelSubMechanismIllustrationPoint() { var illustrationPointResult = new IllustrationPointResult("Description of result", 5); - var subMechanismIllustrationPointStochast = new SubMechanismIllustrationPointStochast("Name of a submechanism stochast", 10, 9, 8); + var subMechanismIllustrationPointStochast = new SubMechanismIllustrationPointStochast("Name of a stochast", 10, 9, 8); var illustrationPoint = new SubMechanismIllustrationPoint("Name of illustrationPoint", 3, new[] { @@ -401,7 +401,7 @@ illustrationPoint); var governingWindDirection = new WindDirection("SSE", 120); - var stochast = new Stochast("Name of stochast", 13, 37); + var stochast = new Stochast("Name of a stochast", 13, 37); return new GeneralResult(governingWindDirection, new[] { Index: Ringtoets/Common/src/Ringtoets.Common.Data/IllustrationPoints/GeneralResult.cs =================================================================== diff -u -ra4bd5433cf68976014c17b17cd9cfb766b135c74 -r2be62a16f4a6d90a76ebb53967a7b7ea3a445cd1 --- Ringtoets/Common/src/Ringtoets.Common.Data/IllustrationPoints/GeneralResult.cs (.../GeneralResult.cs) (revision a4bd5433cf68976014c17b17cd9cfb766b135c74) +++ Ringtoets/Common/src/Ringtoets.Common.Data/IllustrationPoints/GeneralResult.cs (.../GeneralResult.cs) (revision 2be62a16f4a6d90a76ebb53967a7b7ea3a445cd1) @@ -45,7 +45,7 @@ /// Thrown when any of the input /// parameters is null. /// Thrown when one of the input parameters - /// is invalid (duplicate items, missing items) + /// is invalid (duplicate items, missing items). public GeneralResult(WindDirection governingWindDirection, IEnumerable stochasts, IEnumerable topLevelIllustrationPoints) @@ -63,11 +63,7 @@ throw new ArgumentNullException(nameof(topLevelIllustrationPoints)); } - IEnumerable points = topLevelIllustrationPoints.OfType(); - if (points.Any()) - { - ValidateStochastInChildren(points, stochasts); - } + ValidateStochastInChildren(topLevelIllustrationPoints, stochasts); ValidateStochasts(stochasts); ValidateTopLevelIllustrationPoints(topLevelIllustrationPoints); @@ -102,14 +98,26 @@ return clone; } - private void ValidateStochastInChildren(IEnumerable topLevelFaultTreeIllustrationPoints, IEnumerable stochasts) + private void ValidateStochastInChildren(IEnumerable topLevelillustrationPoints, IEnumerable stochasts) { var childStochastNames = new List(); - foreach (TopLevelFaultTreeIllustrationPoint topLevelFaultTreeIllustrationPoint in topLevelFaultTreeIllustrationPoints) + foreach (T topLevelIllustrationPoint in topLevelillustrationPoints) { - IllustrationPointNode nodeRoot = topLevelFaultTreeIllustrationPoint.FaultTreeNodeRoot; - childStochastNames.AddRange(GetStochastNamesFromChildren(nodeRoot)); + var topLevelFaultTreeIllustrationPoint = topLevelIllustrationPoint as TopLevelFaultTreeIllustrationPoint; + if (topLevelFaultTreeIllustrationPoint != null) + { + IllustrationPointNode nodeRoot = topLevelFaultTreeIllustrationPoint.FaultTreeNodeRoot; + childStochastNames.AddRange(GetStochastNamesFromChildren(nodeRoot)); + continue; + } + + var topLevelSubMechanismIllustrationPoint = topLevelIllustrationPoint as TopLevelSubMechanismIllustrationPoint; + if (topLevelSubMechanismIllustrationPoint != null) + { + SubMechanismIllustrationPoint nodeRoot = topLevelSubMechanismIllustrationPoint.SubMechanismIllustrationPoint; + childStochastNames.AddRange(nodeRoot.Stochasts.Select(s => s.Name)); + } } childStochastNames = childStochastNames.Distinct().ToList(); IEnumerable topLevelStochastNames = stochasts.Select(s => s.Name); Index: Ringtoets/Common/src/Ringtoets.Common.Service/DesignWaterLevelCalculationService.cs =================================================================== diff -u -r19d976fb7e64bc4c23ca6a601eb47d876b1fecff -r2be62a16f4a6d90a76ebb53967a7b7ea3a445cd1 --- Ringtoets/Common/src/Ringtoets.Common.Service/DesignWaterLevelCalculationService.cs (.../DesignWaterLevelCalculationService.cs) (revision 19d976fb7e64bc4c23ca6a601eb47d876b1fecff) +++ Ringtoets/Common/src/Ringtoets.Common.Service/DesignWaterLevelCalculationService.cs (.../DesignWaterLevelCalculationService.cs) (revision 2be62a16f4a6d90a76ebb53967a7b7ea3a445cd1) @@ -188,9 +188,17 @@ return; } - GeneralResult generalResult = designWaterLevelCalculation.CalculateIllustrationPoints - ? GetGeneralResult(calculator.IllustrationPointsResult) - : null; + GeneralResult generalResult = null; + try + { + generalResult = designWaterLevelCalculation.CalculateIllustrationPoints + ? GetGeneralResult(calculator.IllustrationPointsResult) + : null; + } + catch (ArgumentException e) + { + log.Error(string.Format(Resources.SetGeneralResult_Error_while_converting_generalresult, designWaterLevelCalculation.Name) + " " + e.Message); + } HydraulicBoundaryLocationOutput hydraulicBoundaryLocationOutput = CreateHydraulicBoundaryLocationOutput( messageProvider, designWaterLevelCalculation.Name, calculationInput.Beta, norm, calculator.Converged, generalResult); Index: Ringtoets/Common/src/Ringtoets.Common.Service/Structures/StructuresCalculationServiceBase.cs =================================================================== diff -u -r57b198a3f80256e02b871d8de11c05d9f2dcf311 -r2be62a16f4a6d90a76ebb53967a7b7ea3a445cd1 --- Ringtoets/Common/src/Ringtoets.Common.Service/Structures/StructuresCalculationServiceBase.cs (.../StructuresCalculationServiceBase.cs) (revision 57b198a3f80256e02b871d8de11c05d9f2dcf311) +++ Ringtoets/Common/src/Ringtoets.Common.Service/Structures/StructuresCalculationServiceBase.cs (.../StructuresCalculationServiceBase.cs) (revision 2be62a16f4a6d90a76ebb53967a7b7ea3a445cd1) @@ -283,7 +283,7 @@ } catch (ArgumentException e) { - log.Warn(string.Format(Resources.SetGeneralResult_Error_while_converting_generalresult, calculation.Name) + " " + e.Message); + log.Error(string.Format(Resources.SetGeneralResult_Error_while_converting_generalresult, calculation.Name) + " " + e.Message); } calculation.Output = new StructuresOutput(probabilityAssessmentOutput, generalResult); Index: Ringtoets/Common/src/Ringtoets.Common.Service/WaveHeightCalculationService.cs =================================================================== diff -u -r19d976fb7e64bc4c23ca6a601eb47d876b1fecff -r2be62a16f4a6d90a76ebb53967a7b7ea3a445cd1 --- Ringtoets/Common/src/Ringtoets.Common.Service/WaveHeightCalculationService.cs (.../WaveHeightCalculationService.cs) (revision 19d976fb7e64bc4c23ca6a601eb47d876b1fecff) +++ Ringtoets/Common/src/Ringtoets.Common.Service/WaveHeightCalculationService.cs (.../WaveHeightCalculationService.cs) (revision 2be62a16f4a6d90a76ebb53967a7b7ea3a445cd1) @@ -189,9 +189,17 @@ return; } - GeneralResult generalResult = waveHeightCalculation.CalculateIllustrationPoints - ? GetGeneralResult(calculator.IllustrationPointsResult) - : null; + GeneralResult generalResult = null; + try + { + generalResult = waveHeightCalculation.CalculateIllustrationPoints + ? GetGeneralResult(calculator.IllustrationPointsResult) + : null; + } + catch (ArgumentException e) + { + log.Error(string.Format(Resources.SetGeneralResult_Error_while_converting_generalresult, waveHeightCalculation.Name) + " " + e.Message); + } HydraulicBoundaryLocationOutput hydraulicBoundaryLocationOutput = CreateHydraulicBoundaryLocationOutput( messageProvider, waveHeightCalculation.Name, calculationInput.Beta, norm, calculator.Converged, generalResult); Index: Ringtoets/Common/test/Ringtoets.Common.Service.Test/DesignWaterLevelCalculationServiceTest.cs =================================================================== diff -u -r889e8e4ee8267b316e00e8f8a1035c60afb200a0 -r2be62a16f4a6d90a76ebb53967a7b7ea3a445cd1 --- Ringtoets/Common/test/Ringtoets.Common.Service.Test/DesignWaterLevelCalculationServiceTest.cs (.../DesignWaterLevelCalculationServiceTest.cs) (revision 889e8e4ee8267b316e00e8f8a1035c60afb200a0) +++ Ringtoets/Common/test/Ringtoets.Common.Service.Test/DesignWaterLevelCalculationServiceTest.cs (.../DesignWaterLevelCalculationServiceTest.cs) (revision 2be62a16f4a6d90a76ebb53967a7b7ea3a445cd1) @@ -241,7 +241,7 @@ } [Test] - public void Calculate_ValidDesignWaterLevelCalculationButInvalidIllustrationPointResults_IllustrationPointNotSetAndLog() + public void Calculate_ValidDesignWaterLevelCalculationButIllustrationPointResultsOfIncorrectType_IllustrationPointNotSetAndLog() { // Setup string validFilePath = Path.Combine(testDataPath, validFile); @@ -295,6 +295,222 @@ } [Test] + public void Calculate_ValidDesignWaterLevelCalculationButIllustrationPointResultsWithNonDistinctStochasts_IllustrationPointNotSetAndLog() + { + // Setup + string validFilePath = Path.Combine(testDataPath, validFile); + + var calculator = new TestDesignWaterLevelCalculator + { + IllustrationPointsResult = GeneralResultTestFactory.CreateGeneralResultWithNonDistinctStochasts(), + Converged = true + }; + + var mockRepository = new MockRepository(); + var calculatorFactory = mockRepository.StrictMock(); + calculatorFactory.Expect(cf => cf.CreateDesignWaterLevelCalculator(testDataPath)).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(); + + using (new HydraRingCalculatorFactoryConfig(calculatorFactory)) + { + // Call + Action call = () => new DesignWaterLevelCalculationService().Calculate(calculation, + validFilePath, + 1.0 / 30, + calculationMessageProvider); + + // Assert + TestHelper.AssertLogMessagesWithLevelAndLoggedExceptions(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("Fout bij het uitlezen van de illustratiepunten voor berekening punt_flw_ 1: " + + "Een of meerdere stochasten hebben dezelfde naam. " + + "Het uitlezen van illustratiepunten wordt overgeslagen.", 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]); + }); + Assert.IsNotNull(calculation.Output); + Assert.IsFalse(calculation.Output.HasGeneralResult); + } + mockRepository.VerifyAll(); + } + + [Test] + public void Calculate_ValidDesignWaterLevelCalculationButIllustrationPointResultsWithIncorrectTopLevelStochasts_IllustrationPointNotSetAndLog() + { + // Setup + string validFilePath = Path.Combine(testDataPath, validFile); + + var calculator = new TestDesignWaterLevelCalculator + { + IllustrationPointsResult = GeneralResultTestFactory.CreateGeneralResultSubMechanismWithIncorrectTopLevelStochasts(), + Converged = true + }; + + var mockRepository = new MockRepository(); + var calculatorFactory = mockRepository.StrictMock(); + calculatorFactory.Expect(cf => cf.CreateDesignWaterLevelCalculator(testDataPath)).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(); + + using (new HydraRingCalculatorFactoryConfig(calculatorFactory)) + { + // Call + Action call = () => new DesignWaterLevelCalculationService().Calculate(calculation, + validFilePath, + 1.0 / 30, + calculationMessageProvider); + + // Assert + TestHelper.AssertLogMessagesWithLevelAndLoggedExceptions(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("Fout bij het uitlezen van de illustratiepunten voor berekening punt_flw_ 1: " + + "De stochasten van een illustratiepunt bevatten niet dezelfde stochasten als de illustratiepunten die het punt bevat. " + + "Het uitlezen van illustratiepunten wordt overgeslagen.", 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]); + }); + Assert.IsNotNull(calculation.Output); + Assert.IsFalse(calculation.Output.HasGeneralResult); + } + mockRepository.VerifyAll(); + } + + [Test] + public void Calculate_ValidDesignWaterLevelCalculationButIllustrationPointResultsWithNonDistinctIllustrationPoints_IllustrationPointNotSetAndLog() + { + // Setup + string validFilePath = Path.Combine(testDataPath, validFile); + + var calculator = new TestDesignWaterLevelCalculator + { + IllustrationPointsResult = GeneralResultTestFactory.CreateGeneralResultSubMechanismWithNonDistinctIllustrationPoints(), + Converged = true + }; + + var mockRepository = new MockRepository(); + var calculatorFactory = mockRepository.StrictMock(); + calculatorFactory.Expect(cf => cf.CreateDesignWaterLevelCalculator(testDataPath)).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(); + + using (new HydraRingCalculatorFactoryConfig(calculatorFactory)) + { + // Call + Action call = () => new DesignWaterLevelCalculationService().Calculate(calculation, + validFilePath, + 1.0 / 30, + calculationMessageProvider); + + // Assert + TestHelper.AssertLogMessagesWithLevelAndLoggedExceptions(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("Fout bij het uitlezen van de illustratiepunten voor berekening punt_flw_ 1: " + + "Een of meerdere illustratiepunten hebben dezelfde sluitscenario en windrichting. " + + "Het uitlezen van illustratiepunten wordt overgeslagen.", 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]); + }); + Assert.IsNotNull(calculation.Output); + Assert.IsFalse(calculation.Output.HasGeneralResult); + } + mockRepository.VerifyAll(); + } + + [Test] + public void Calculate_ValidDesignWaterLevelCalculationButIllustrationPointResultsWithNonDistinctIllustrationPointResults_IllustrationPointNotSetAndLog() + { + // Setup + string validFilePath = Path.Combine(testDataPath, validFile); + + var calculator = new TestDesignWaterLevelCalculator + { + IllustrationPointsResult = GeneralResultTestFactory.CreateGeneralResultSubMechanismWithNonDistinctIllustrationPointResults(), + Converged = true + }; + + var mockRepository = new MockRepository(); + var calculatorFactory = mockRepository.StrictMock(); + calculatorFactory.Expect(cf => cf.CreateDesignWaterLevelCalculator(testDataPath)).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(); + + using (new HydraRingCalculatorFactoryConfig(calculatorFactory)) + { + // Call + Action call = () => new DesignWaterLevelCalculationService().Calculate(calculation, + validFilePath, + 1.0 / 30, + calculationMessageProvider); + + // Assert + TestHelper.AssertLogMessagesWithLevelAndLoggedExceptions(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("Fout bij het uitlezen van de illustratiepunten voor berekening punt_flw_ 1: " + + "Een of meerdere resultaten hebben dezelfde naam. " + + "Het uitlezen van illustratiepunten wordt overgeslagen.", 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]); + }); + Assert.IsNotNull(calculation.Output); + Assert.IsFalse(calculation.Output.HasGeneralResult); + } + mockRepository.VerifyAll(); + } + + [Test] public void Calculate_ValidDesignWaterLevelCalculationThrowsException_ThrowsHydraRingFileParserException() { // Setup Index: Ringtoets/Common/test/Ringtoets.Common.Service.Test/Structures/StructuresCalculationServiceBaseTest.cs =================================================================== diff -u -r57b198a3f80256e02b871d8de11c05d9f2dcf311 -r2be62a16f4a6d90a76ebb53967a7b7ea3a445cd1 --- Ringtoets/Common/test/Ringtoets.Common.Service.Test/Structures/StructuresCalculationServiceBaseTest.cs (.../StructuresCalculationServiceBaseTest.cs) (revision 57b198a3f80256e02b871d8de11c05d9f2dcf311) +++ Ringtoets/Common/test/Ringtoets.Common.Service.Test/Structures/StructuresCalculationServiceBaseTest.cs (.../StructuresCalculationServiceBaseTest.cs) (revision 2be62a16f4a6d90a76ebb53967a7b7ea3a445cd1) @@ -20,7 +20,6 @@ // All rights reserved. using System; -using System.Collections.Generic; using System.IO; using System.Linq; using Core.Common.Base.Geometry; @@ -38,7 +37,6 @@ using Ringtoets.HydraRing.Calculation.Calculator.Factory; using Ringtoets.HydraRing.Calculation.Data; using Ringtoets.HydraRing.Calculation.Data.Input; -using Ringtoets.HydraRing.Calculation.Data.Output.IllustrationPoints; using Ringtoets.HydraRing.Calculation.Exceptions; using Ringtoets.HydraRing.Calculation.TestUtil; using Ringtoets.HydraRing.Calculation.TestUtil.Calculator; @@ -603,16 +601,66 @@ { // Setup var mocks = new MockRepository(); - var stochasts = new[] + var calculator = new TestStructuresCalculator { - new Stochast("Stochast A", 0, 0), - new Stochast("Stochast A", 0, 0) + OutputDirectory = validFilePath, + IllustrationPointsResult = GeneralResultTestFactory.CreateGeneralResultWithNonDistinctStochasts() }; - var illustrationPoints = new Dictionary(); + var calculatorFactory = mocks.StrictMock(); + calculatorFactory.Expect(cf => cf.CreateStructuresCalculator(testDataPath)) + .Return(calculator); + + const string performedCalculationMessage = "Calculation successful"; + 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.AssertLogMessagesWithLevelAndLoggedExceptions(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("Fout bij het uitlezen van de illustratiepunten voor berekening Nieuwe berekening: " + + "Een of meerdere stochasten hebben dezelfde naam. Het uitlezen van illustratiepunten wordt overgeslagen.", msgs[1]); + Assert.AreEqual(performedCalculationMessage, msgs[2]); + CalculationServiceTestHelper.AssertCalculationEndMessage(msgs[3]); + }); + Assert.IsNotNull(calculation.Output); + Assert.IsFalse(calculation.Output.HasGeneralResult); + } + mocks.VerifyAll(); + } + + [Test] + public void Calculate_ValidInputButIllustrationPointResultsWithIncorrectTopLevelStochasts_IllustrationPointsNotSetAndLogsWarning() + { + // Setup + var mocks = new MockRepository(); var calculator = new TestStructuresCalculator { OutputDirectory = validFilePath, - IllustrationPointsResult = new GeneralResult(0.5, new TestWindDirection(), stochasts, illustrationPoints) + IllustrationPointsResult = GeneralResultTestFactory.CreateGeneralResultFaultTreeWithIncorrectTopLevelStochasts() }; var calculatorFactory = mocks.StrictMock(); calculatorFactory.Expect(cf => cf.CreateStructuresCalculator(testDataPath)) @@ -650,7 +698,8 @@ CalculationServiceTestHelper.AssertCalculationStartMessage(msgs[0]); Assert.AreEqual("Fout bij het uitlezen van de illustratiepunten voor berekening Nieuwe berekening: " + - "Een of meerdere stochasten hebben dezelfde naam. Het uitlezen van illustratiepunten wordt overgeslagen.", msgs[1]); + "De stochasten van een illustratiepunt bevatten niet dezelfde stochasten als de illustratiepunten die het punt bevat. " + + "Het uitlezen van illustratiepunten wordt overgeslagen.", msgs[1]); Assert.AreEqual(performedCalculationMessage, msgs[2]); CalculationServiceTestHelper.AssertCalculationEndMessage(msgs[3]); }); @@ -661,25 +710,185 @@ } [Test] + public void Calculate_ValidInputButIllustrationPointResultsWithIncorrectStochastsInChildren_IllustrationPointsNotSetAndLogsWarning() + { + // Setup + var mocks = new MockRepository(); + var calculator = new TestStructuresCalculator + { + OutputDirectory = validFilePath, + IllustrationPointsResult = GeneralResultTestFactory.CreateGeneralResultWithIncorrectStochastsInChildren() + }; + var calculatorFactory = mocks.StrictMock(); + calculatorFactory.Expect(cf => cf.CreateStructuresCalculator(testDataPath)) + .Return(calculator); + + const string performedCalculationMessage = "Calculation successful"; + 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.AssertLogMessagesWithLevelAndLoggedExceptions(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("Fout bij het uitlezen van de illustratiepunten voor berekening Nieuwe berekening: " + + "De stochasten van een illustratiepunt bevatten niet dezelfde stochasten als de illustratiepunten die het punt bevat. " + + "Het uitlezen van illustratiepunten wordt overgeslagen.", msgs[1]); + Assert.AreEqual(performedCalculationMessage, msgs[2]); + CalculationServiceTestHelper.AssertCalculationEndMessage(msgs[3]); + }); + Assert.IsNotNull(calculation.Output); + Assert.IsFalse(calculation.Output.HasGeneralResult); + } + mocks.VerifyAll(); + } + + [Test] public void Calculate_ValidInputButIllustrationPointResultsWithNonDistinctIllustrationPoints_IllustrationPointsNotSetAndLogsWarning() { // Setup var mocks = new MockRepository(); - var illustrationPoints = new Dictionary + var calculator = new TestStructuresCalculator { + OutputDirectory = validFilePath, + IllustrationPointsResult = GeneralResultTestFactory.CreateGeneralResultFaultTreeWithNonDistinctIllustrationPoints() + }; + var calculatorFactory = mocks.StrictMock(); + calculatorFactory.Expect(cf => cf.CreateStructuresCalculator(testDataPath)) + .Return(calculator); + + const string performedCalculationMessage = "Calculation successful"; + var messageProvider = mocks.StrictMock(); + messageProvider.Expect(mp => mp.GetCalculationPerformedMessage(validFilePath)).Return(performedCalculationMessage); + mocks.ReplayAll(); + + var hydraulicBoundaryLocation = new TestHydraulicBoundaryLocation(); + var calculation = new TestStructuresCalculation + { + InputParameters = { - new WindDirectionClosingSituation(new WindDirection("N", 0.0), "closing A"), - new IllustrationPointTreeNode(new TestFaultTreeIllustrationPoint()) - }, + 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.AssertLogMessagesWithLevelAndLoggedExceptions(call, messages => { - new WindDirectionClosingSituation(new WindDirection("S", 0.0), "closing A"), - new IllustrationPointTreeNode(new TestFaultTreeIllustrationPoint()) + Tuple[] tupleArray = messages.ToArray(); + + string[] msgs = tupleArray.Select(tuple => tuple.Item1).ToArray(); + Assert.AreEqual(4, msgs.Length); + + CalculationServiceTestHelper.AssertCalculationStartMessage(msgs[0]); + Assert.AreEqual("Fout bij het uitlezen van de illustratiepunten voor berekening Nieuwe berekening: " + + "Een of meerdere illustratiepunten hebben dezelfde sluitscenario en windrichting. " + + "Het uitlezen van illustratiepunten wordt overgeslagen.", msgs[1]); + Assert.AreEqual(performedCalculationMessage, msgs[2]); + CalculationServiceTestHelper.AssertCalculationEndMessage(msgs[3]); + }); + Assert.IsNotNull(calculation.Output); + Assert.IsFalse(calculation.Output.HasGeneralResult); + } + mocks.VerifyAll(); + } + + [Test] + public void Calculate_ValidInputButIllustrationPointResultsWithNonDistinctIllustrationPointResults_IllustrationPointsNotSetAndLogsWarning() + { + // Setup + var mocks = new MockRepository(); + var calculator = new TestStructuresCalculator + { + OutputDirectory = validFilePath, + IllustrationPointsResult = GeneralResultTestFactory.CreateGeneralResultFaultTreeWithNonDistinctIllustrationPointResults() + }; + var calculatorFactory = mocks.StrictMock(); + calculatorFactory.Expect(cf => cf.CreateStructuresCalculator(testDataPath)) + .Return(calculator); + + const string performedCalculationMessage = "Calculation successful"; + 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.AssertLogMessagesWithLevelAndLoggedExceptions(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("Fout bij het uitlezen van de illustratiepunten voor berekening Nieuwe berekening: " + + "Een of meerdere resultaten hebben dezelfde naam. " + + "Het uitlezen van illustratiepunten wordt overgeslagen.", msgs[1]); + Assert.AreEqual(performedCalculationMessage, msgs[2]); + CalculationServiceTestHelper.AssertCalculationEndMessage(msgs[3]); + }); + Assert.IsNotNull(calculation.Output); + Assert.IsFalse(calculation.Output.HasGeneralResult); + } + mocks.VerifyAll(); + } + + [Test] + public void Calculate_ValidInputButIllustrationPointResultsWithNonDistinctNamesInChildren_IllustrationPointsNotSetAndLogsWarning() + { + // Setup + var mocks = new MockRepository(); var calculator = new TestStructuresCalculator { OutputDirectory = validFilePath, - IllustrationPointsResult = new GeneralResult(0.5, new TestWindDirection(), Enumerable.Empty(), illustrationPoints) + IllustrationPointsResult = GeneralResultTestFactory.CreateGeneralResultWithNonDistinctNamesInChildren() }; var calculatorFactory = mocks.StrictMock(); calculatorFactory.Expect(cf => cf.CreateStructuresCalculator(testDataPath)) @@ -717,7 +926,7 @@ CalculationServiceTestHelper.AssertCalculationStartMessage(msgs[0]); Assert.AreEqual("Fout bij het uitlezen van de illustratiepunten voor berekening Nieuwe berekening: " + - "Een of meerdere illustratiepunten hebben dezelfde sluitscenario en windrichting. " + + "Een of meerdere illustratiepunten bevatten illustratiepunten met dezelfde naam. " + "Het uitlezen van illustratiepunten wordt overgeslagen.", msgs[1]); Assert.AreEqual(performedCalculationMessage, msgs[2]); CalculationServiceTestHelper.AssertCalculationEndMessage(msgs[3]); Index: Ringtoets/Common/test/Ringtoets.Common.Service.Test/WaveHeightCalculationServiceTest.cs =================================================================== diff -u -r889e8e4ee8267b316e00e8f8a1035c60afb200a0 -r2be62a16f4a6d90a76ebb53967a7b7ea3a445cd1 --- Ringtoets/Common/test/Ringtoets.Common.Service.Test/WaveHeightCalculationServiceTest.cs (.../WaveHeightCalculationServiceTest.cs) (revision 889e8e4ee8267b316e00e8f8a1035c60afb200a0) +++ Ringtoets/Common/test/Ringtoets.Common.Service.Test/WaveHeightCalculationServiceTest.cs (.../WaveHeightCalculationServiceTest.cs) (revision 2be62a16f4a6d90a76ebb53967a7b7ea3a445cd1) @@ -236,7 +236,7 @@ } [Test] - public void Calculate_ValidDesignWaterLevelCalculationButInvalidIllustrationPointResults_IllustrationPointsNotSetAndLogs() + public void Calculate_ValidWaveHeightCalculationButIllustrationPointResultsOfIncorrectType_IllustrationPointsNotSetAndLogs() { // Setup string validFilePath = Path.Combine(testDataPath, validFile); @@ -290,6 +290,222 @@ } [Test] + public void Calculate_ValidWaveHeightCalculationButIllustrationPointResultsWithNonDistinctStochasts_IllustrationPointNotSetAndLog() + { + // Setup + string validFilePath = Path.Combine(testDataPath, validFile); + + var calculator = new TestWaveHeightCalculator + { + IllustrationPointsResult = GeneralResultTestFactory.CreateGeneralResultWithNonDistinctStochasts(), + Converged = true + }; + + var mockRepository = new MockRepository(); + var calculatorFactory = mockRepository.StrictMock(); + calculatorFactory.Expect(cf => cf.CreateWaveHeightCalculator(testDataPath)).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(); + + using (new HydraRingCalculatorFactoryConfig(calculatorFactory)) + { + // Call + Action call = () => new WaveHeightCalculationService().Calculate(calculation, + validFilePath, + 1.0 / 30, + calculationMessageProvider); + + // Assert + TestHelper.AssertLogMessagesWithLevelAndLoggedExceptions(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("Fout bij het uitlezen van de illustratiepunten voor berekening punt_flw_ 1: " + + "Een of meerdere stochasten hebben dezelfde naam. " + + "Het uitlezen van illustratiepunten wordt overgeslagen.", 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]); + }); + Assert.IsNotNull(calculation.Output); + Assert.IsFalse(calculation.Output.HasGeneralResult); + } + mockRepository.VerifyAll(); + } + + [Test] + public void Calculate_ValidWaveHeightCalculationButIllustrationPointResultsWithIncorrectTopLevelStochasts_IllustrationPointNotSetAndLog() + { + // Setup + string validFilePath = Path.Combine(testDataPath, validFile); + + var calculator = new TestWaveHeightCalculator + { + IllustrationPointsResult = GeneralResultTestFactory.CreateGeneralResultSubMechanismWithIncorrectTopLevelStochasts(), + Converged = true + }; + + var mockRepository = new MockRepository(); + var calculatorFactory = mockRepository.StrictMock(); + calculatorFactory.Expect(cf => cf.CreateWaveHeightCalculator(testDataPath)).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(); + + using (new HydraRingCalculatorFactoryConfig(calculatorFactory)) + { + // Call + Action call = () => new WaveHeightCalculationService().Calculate(calculation, + validFilePath, + 1.0 / 30, + calculationMessageProvider); + + // Assert + TestHelper.AssertLogMessagesWithLevelAndLoggedExceptions(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("Fout bij het uitlezen van de illustratiepunten voor berekening punt_flw_ 1: " + + "De stochasten van een illustratiepunt bevatten niet dezelfde stochasten als de illustratiepunten die het punt bevat. " + + "Het uitlezen van illustratiepunten wordt overgeslagen.", 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]); + }); + Assert.IsNotNull(calculation.Output); + Assert.IsFalse(calculation.Output.HasGeneralResult); + } + mockRepository.VerifyAll(); + } + + [Test] + public void Calculate_ValidWaveHeightCalculationButIllustrationPointResultsWithNonDistinctIllustrationPoints_IllustrationPointNotSetAndLog() + { + // Setup + string validFilePath = Path.Combine(testDataPath, validFile); + + var calculator = new TestWaveHeightCalculator + { + IllustrationPointsResult = GeneralResultTestFactory.CreateGeneralResultSubMechanismWithNonDistinctIllustrationPoints(), + Converged = true + }; + + var mockRepository = new MockRepository(); + var calculatorFactory = mockRepository.StrictMock(); + calculatorFactory.Expect(cf => cf.CreateWaveHeightCalculator(testDataPath)).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(); + + using (new HydraRingCalculatorFactoryConfig(calculatorFactory)) + { + // Call + Action call = () => new WaveHeightCalculationService().Calculate(calculation, + validFilePath, + 1.0 / 30, + calculationMessageProvider); + + // Assert + TestHelper.AssertLogMessagesWithLevelAndLoggedExceptions(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("Fout bij het uitlezen van de illustratiepunten voor berekening punt_flw_ 1: " + + "Een of meerdere illustratiepunten hebben dezelfde sluitscenario en windrichting. " + + "Het uitlezen van illustratiepunten wordt overgeslagen.", 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]); + }); + Assert.IsNotNull(calculation.Output); + Assert.IsFalse(calculation.Output.HasGeneralResult); + } + mockRepository.VerifyAll(); + } + + [Test] + public void Calculate_ValidWaveHeightCalculationButIllustrationPointResultsWithNonDistinctIllustrationPointResults_IllustrationPointNotSetAndLog() + { + // Setup + string validFilePath = Path.Combine(testDataPath, validFile); + + var calculator = new TestWaveHeightCalculator + { + IllustrationPointsResult = GeneralResultTestFactory.CreateGeneralResultSubMechanismWithNonDistinctIllustrationPointResults(), + Converged = true + }; + + var mockRepository = new MockRepository(); + var calculatorFactory = mockRepository.StrictMock(); + calculatorFactory.Expect(cf => cf.CreateWaveHeightCalculator(testDataPath)).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(); + + using (new HydraRingCalculatorFactoryConfig(calculatorFactory)) + { + // Call + Action call = () => new WaveHeightCalculationService().Calculate(calculation, + validFilePath, + 1.0 / 30, + calculationMessageProvider); + + // Assert + TestHelper.AssertLogMessagesWithLevelAndLoggedExceptions(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("Fout bij het uitlezen van de illustratiepunten voor berekening punt_flw_ 1: " + + "Een of meerdere resultaten hebben dezelfde naam. " + + "Het uitlezen van illustratiepunten wordt overgeslagen.", 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]); + }); + Assert.IsNotNull(calculation.Output); + Assert.IsFalse(calculation.Output.HasGeneralResult); + } + mockRepository.VerifyAll(); + } + + [Test] public void Calculate_ValidWaveHeightCalculationThrowsException_ThrowsHydraRingFileParserException() { // Setup Index: Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Service/GrassCoverErosionInwardsCalculationService.cs =================================================================== diff -u -r57b198a3f80256e02b871d8de11c05d9f2dcf311 -r2be62a16f4a6d90a76ebb53967a7b7ea3a445cd1 --- Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Service/GrassCoverErosionInwardsCalculationService.cs (.../GrassCoverErosionInwardsCalculationService.cs) (revision 57b198a3f80256e02b871d8de11c05d9f2dcf311) +++ Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Service/GrassCoverErosionInwardsCalculationService.cs (.../GrassCoverErosionInwardsCalculationService.cs) (revision 2be62a16f4a6d90a76ebb53967a7b7ea3a445cd1) @@ -277,7 +277,7 @@ } catch (ArgumentException e) { - log.Warn(string.Format(Resources.SetGeneralResult_Error_while_converting_generalresult_overtopping, calculation.Name) + " " + e.Message); + log.Error(string.Format(Resources.SetGeneralResult_Error_while_converting_generalresult_overtopping, calculation.Name) + " " + e.Message); } var overtoppingOutput = new OvertoppingOutput(overtoppingCalculator.WaveHeight, @@ -676,7 +676,7 @@ } catch (ArgumentException e) { - log.Warn(string.Format(Resources.SetGeneralResult_Error_while_converting_generalresult_dike_height, calculationName) + " " + e.Message); + log.Error(string.Format(Resources.SetGeneralResult_Error_while_converting_generalresult_dike_height, calculationName) + " " + e.Message); } return new DikeHeightOutput(dikeHeight, targetProbability, @@ -726,7 +726,7 @@ } catch (ArgumentException e) { - log.Warn(string.Format(Resources.SetGeneralResult_Error_while_converting_generalresult_overtopping_rate, calculationName) + " " + e.Message); + log.Error(string.Format(Resources.SetGeneralResult_Error_while_converting_generalresult_overtopping_rate, calculationName) + " " + e.Message); } return new OvertoppingRateOutput(overtoppingRate, targetProbability, Index: Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Service.Test/GrassCoverErosionInwardsCalculationServiceTest.cs =================================================================== diff -u -ra4bd5433cf68976014c17b17cd9cfb766b135c74 -r2be62a16f4a6d90a76ebb53967a7b7ea3a445cd1 --- Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Service.Test/GrassCoverErosionInwardsCalculationServiceTest.cs (.../GrassCoverErosionInwardsCalculationServiceTest.cs) (revision a4bd5433cf68976014c17b17cd9cfb766b135c74) +++ Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Service.Test/GrassCoverErosionInwardsCalculationServiceTest.cs (.../GrassCoverErosionInwardsCalculationServiceTest.cs) (revision 2be62a16f4a6d90a76ebb53967a7b7ea3a445cd1) @@ -20,7 +20,6 @@ // All rights reserved. using System; -using System.Collections.Generic; using System.IO; using System.Linq; using Core.Common.Base.Data; @@ -39,7 +38,6 @@ using Ringtoets.GrassCoverErosionInwards.Data; using Ringtoets.GrassCoverErosionInwards.Service.TestUtil; using Ringtoets.HydraRing.Calculation.Calculator.Factory; -using Ringtoets.HydraRing.Calculation.Data.Output.IllustrationPoints; using Ringtoets.HydraRing.Calculation.Exceptions; using Ringtoets.HydraRing.Calculation.TestUtil.Calculator; using Ringtoets.HydraRing.Calculation.TestUtil.IllustrationPoints; @@ -2260,7 +2258,7 @@ validFile); var overtoppingCalculator = new TestOvertoppingCalculator { - IllustrationPointsResult = GeneralResultTestFactory.CreateGeneralResultWithIncorrectTopLevelStochasts() + IllustrationPointsResult = GeneralResultTestFactory.CreateGeneralResultFaultTreeWithIncorrectTopLevelStochasts() }; var dikeHeightCalculator = new TestHydraulicLoadsCalculator { @@ -2428,7 +2426,7 @@ validFile); var overtoppingCalculator = new TestOvertoppingCalculator { - IllustrationPointsResult = GeneralResultTestFactory.CreateGeneralResultWithNonDistinctIllustrationPoints() + IllustrationPointsResult = GeneralResultTestFactory.CreateGeneralResultFaultTreeWithNonDistinctIllustrationPoints() }; var dikeHeightCalculator = new TestHydraulicLoadsCalculator { @@ -2512,7 +2510,7 @@ validFile); var overtoppingCalculator = new TestOvertoppingCalculator { - IllustrationPointsResult = GeneralResultTestFactory.CreateGeneralResultWithNonDistinctIllustrationPointResults() + IllustrationPointsResult = GeneralResultTestFactory.CreateGeneralResultFaultTreeWithNonDistinctIllustrationPointResults() }; var dikeHeightCalculator = new TestHydraulicLoadsCalculator { @@ -2856,7 +2854,7 @@ }; var overtoppingRateCalculator = new TestHydraulicLoadsCalculator { - IllustrationPointsResult = GeneralResultTestFactory.CreateGeneralResultWithIncorrectTopLevelStochasts() + IllustrationPointsResult = GeneralResultTestFactory.CreateGeneralResultFaultTreeWithIncorrectTopLevelStochasts() }; var calculatorFactory = mockRepository.StrictMock(); calculatorFactory.Expect(cf => cf.CreateOvertoppingCalculator(testDataPath)).Return(overtoppingCalculator); @@ -3024,7 +3022,7 @@ }; var overtoppingRateCalculator = new TestHydraulicLoadsCalculator { - IllustrationPointsResult = GeneralResultTestFactory.CreateGeneralResultWithNonDistinctIllustrationPoints() + IllustrationPointsResult = GeneralResultTestFactory.CreateGeneralResultFaultTreeWithNonDistinctIllustrationPoints() }; var calculatorFactory = mockRepository.StrictMock(); calculatorFactory.Expect(cf => cf.CreateOvertoppingCalculator(testDataPath)).Return(overtoppingCalculator); @@ -3108,7 +3106,7 @@ }; var overtoppingRateCalculator = new TestHydraulicLoadsCalculator { - IllustrationPointsResult = GeneralResultTestFactory.CreateGeneralResultWithNonDistinctIllustrationPointResults() + IllustrationPointsResult = GeneralResultTestFactory.CreateGeneralResultFaultTreeWithNonDistinctIllustrationPointResults() }; var calculatorFactory = mockRepository.StrictMock(); calculatorFactory.Expect(cf => cf.CreateOvertoppingCalculator(testDataPath)).Return(overtoppingCalculator); @@ -3440,7 +3438,7 @@ }; var dikeHeightCalculator = new TestHydraulicLoadsCalculator { - IllustrationPointsResult = GeneralResultTestFactory.CreateGeneralResultWithIncorrectTopLevelStochasts() + IllustrationPointsResult = GeneralResultTestFactory.CreateGeneralResultFaultTreeWithIncorrectTopLevelStochasts() }; var overtoppingRateCalculator = new TestHydraulicLoadsCalculator { @@ -3608,7 +3606,7 @@ }; var dikeHeightCalculator = new TestHydraulicLoadsCalculator { - IllustrationPointsResult = GeneralResultTestFactory.CreateGeneralResultWithNonDistinctIllustrationPoints() + IllustrationPointsResult = GeneralResultTestFactory.CreateGeneralResultFaultTreeWithNonDistinctIllustrationPoints() }; var overtoppingRateCalculator = new TestHydraulicLoadsCalculator { @@ -3692,7 +3690,7 @@ }; var dikeHeightCalculator = new TestHydraulicLoadsCalculator { - IllustrationPointsResult = GeneralResultTestFactory.CreateGeneralResultWithNonDistinctIllustrationPointResults() + IllustrationPointsResult = GeneralResultTestFactory.CreateGeneralResultFaultTreeWithNonDistinctIllustrationPointResults() }; var overtoppingRateCalculator = new TestHydraulicLoadsCalculator { Index: Ringtoets/HydraRing/test/Ringtoets.HydraRing.Calculation.TestUtil.Test/IllustrationPoints/GeneralResultTestFactoryTest.cs =================================================================== diff -u -ra4bd5433cf68976014c17b17cd9cfb766b135c74 -r2be62a16f4a6d90a76ebb53967a7b7ea3a445cd1 --- Ringtoets/HydraRing/test/Ringtoets.HydraRing.Calculation.TestUtil.Test/IllustrationPoints/GeneralResultTestFactoryTest.cs (.../GeneralResultTestFactoryTest.cs) (revision a4bd5433cf68976014c17b17cd9cfb766b135c74) +++ Ringtoets/HydraRing/test/Ringtoets.HydraRing.Calculation.TestUtil.Test/IllustrationPoints/GeneralResultTestFactoryTest.cs (.../GeneralResultTestFactoryTest.cs) (revision 2be62a16f4a6d90a76ebb53967a7b7ea3a445cd1) @@ -51,10 +51,10 @@ } [Test] - public void CreateGeneralResultWithIncorrectTopLevelStochasts_ExpectedProperties() + public void CreateGeneralResultFaultTreeWithIncorrectTopLevelStochasts_ExpectedProperties() { // Call - GeneralResult generalResult = GeneralResultTestFactory.CreateGeneralResultWithIncorrectTopLevelStochasts(); + GeneralResult generalResult = GeneralResultTestFactory.CreateGeneralResultFaultTreeWithIncorrectTopLevelStochasts(); // Assert Assert.IsInstanceOf(generalResult); @@ -82,6 +82,37 @@ } [Test] + public void CreateGeneralResultSubMechanismWithIncorrectTopLevelStochasts_ExpectedProperties() + { + // Call + GeneralResult generalResult = GeneralResultTestFactory.CreateGeneralResultSubMechanismWithIncorrectTopLevelStochasts(); + + // Assert + Assert.IsInstanceOf(generalResult); + Assert.AreEqual(0.5, generalResult.Beta); + + var expectedWindDirection = new TestWindDirection(); + AssertWindDirection(expectedWindDirection, generalResult.GoverningWindDirection); + Assert.AreEqual(2, generalResult.Stochasts.Count()); + Stochast[] stochasts = generalResult.Stochasts.ToArray(); + Assert.AreEqual("Stochast A", stochasts[0].Name); + Assert.AreEqual("Stochast B", stochasts[1].Name); + + KeyValuePair topLevelIllustrationPoint = + generalResult.IllustrationPoints.Single(); + + WindDirectionClosingSituation actualWindDirectionClosingSituation = topLevelIllustrationPoint.Key; + AssertWindDirection(expectedWindDirection, actualWindDirectionClosingSituation.WindDirection); + Assert.AreEqual("closing A", actualWindDirectionClosingSituation.ClosingSituation); + + Assert.IsInstanceOf(topLevelIllustrationPoint.Value.Data); + Assert.AreEqual("Point A", ((SubMechanismIllustrationPoint) topLevelIllustrationPoint.Value.Data).Name); + + Stochast topLevelIllustrationPointStochast = ((SubMechanismIllustrationPoint) topLevelIllustrationPoint.Value.Data).Stochasts.Single(); + Assert.AreEqual("Stochast C", topLevelIllustrationPointStochast.Name); + } + + [Test] public void CreateGeneralResultWithIncorrectStochastsInChildren_ExpectedProperties() { // Call @@ -119,10 +150,10 @@ } [Test] - public void CreateGeneralResultWithNonDistinctIllustrationPoints_ExpectedProperties() + public void CreateGeneralResultFaultTreeWithNonDistinctIllustrationPoints_ExpectedProperties() { // Call - GeneralResult generalResult = GeneralResultTestFactory.CreateGeneralResultWithNonDistinctIllustrationPoints(); + GeneralResult generalResult = GeneralResultTestFactory.CreateGeneralResultFaultTreeWithNonDistinctIllustrationPoints(); // Assert Assert.IsInstanceOf(generalResult); @@ -133,7 +164,7 @@ KeyValuePair[] topLevelIllustrationPoints = generalResult.IllustrationPoints.ToArray(); Assert.AreEqual(2, topLevelIllustrationPoints.Length); - + AssertWindDirection(new WindDirection("N", 0.0), topLevelIllustrationPoints[0].Key.WindDirection); Assert.AreEqual("closing A", topLevelIllustrationPoints[0].Key.ClosingSituation); @@ -145,15 +176,41 @@ } [Test] - public void CreateGeneralResultWithNonDistinctIllustrationPointResults_ExpectedProperties() + public void CreateGeneralResultSubMechanismWithNonDistinctIllustrationPoints_ExpectedProperties() { // Call - GeneralResult generalResult = GeneralResultTestFactory.CreateGeneralResultWithNonDistinctIllustrationPointResults(); + GeneralResult generalResult = GeneralResultTestFactory.CreateGeneralResultSubMechanismWithNonDistinctIllustrationPoints(); // Assert Assert.IsInstanceOf(generalResult); Assert.AreEqual(0.5, generalResult.Beta); + AssertWindDirection(new TestWindDirection(), generalResult.GoverningWindDirection); + + KeyValuePair[] topLevelIllustrationPoints = + generalResult.IllustrationPoints.ToArray(); + Assert.AreEqual(2, topLevelIllustrationPoints.Length); + + AssertWindDirection(new WindDirection("N", 0.0), topLevelIllustrationPoints[0].Key.WindDirection); + Assert.AreEqual("closing A", topLevelIllustrationPoints[0].Key.ClosingSituation); + + AssertWindDirection(new WindDirection("S", 0.0), topLevelIllustrationPoints[1].Key.WindDirection); + Assert.AreEqual("closing A", topLevelIllustrationPoints[1].Key.ClosingSituation); + + Assert.IsInstanceOf(topLevelIllustrationPoints[0].Value.Data); + Assert.IsInstanceOf(topLevelIllustrationPoints[1].Value.Data); + } + + [Test] + public void CreateGeneralResultFaultTreeWithNonDistinctIllustrationPointResults_ExpectedProperties() + { + // Call + GeneralResult generalResult = GeneralResultTestFactory.CreateGeneralResultFaultTreeWithNonDistinctIllustrationPointResults(); + + // Assert + Assert.IsInstanceOf(generalResult); + Assert.AreEqual(0.5, generalResult.Beta); + var expectedWindDirection = new TestWindDirection(); AssertWindDirection(expectedWindDirection, generalResult.GoverningWindDirection); @@ -165,11 +222,11 @@ Assert.AreEqual("closing A", actualWindDirectionClosingSituation.ClosingSituation); Assert.IsInstanceOf(topLevelIllustrationPoint.Value.Data); - Assert.AreEqual("Point A", ((FaultTreeIllustrationPoint)topLevelIllustrationPoint.Value.Data).Name); + Assert.AreEqual("Point A", ((FaultTreeIllustrationPoint) topLevelIllustrationPoint.Value.Data).Name); IllustrationPointTreeNode[] children = topLevelIllustrationPoint.Value.Children.ToArray(); Assert.IsInstanceOf(children[0].Data); - IllustrationPointResult[] illustrationPointResults = ((SubMechanismIllustrationPoint)children[0].Data).Results.ToArray(); + IllustrationPointResult[] illustrationPointResults = ((SubMechanismIllustrationPoint) children[0].Data).Results.ToArray(); Assert.AreEqual("Result A", illustrationPointResults[0].Description); Assert.AreEqual(0.0, illustrationPointResults[0].Value); Assert.AreEqual("Result A", illustrationPointResults[1].Description); @@ -178,6 +235,37 @@ } [Test] + public void CreateGeneralResultSubMechanismWithNonDistinctIllustrationPointResults_ExpectedProperties() + { + // Call + GeneralResult generalResult = GeneralResultTestFactory.CreateGeneralResultSubMechanismWithNonDistinctIllustrationPointResults(); + + // Assert + Assert.IsInstanceOf(generalResult); + Assert.AreEqual(0.5, generalResult.Beta); + + var expectedWindDirection = new TestWindDirection(); + AssertWindDirection(expectedWindDirection, generalResult.GoverningWindDirection); + + KeyValuePair topLevelIllustrationPoint = + generalResult.IllustrationPoints.Single(); + + WindDirectionClosingSituation actualWindDirectionClosingSituation = topLevelIllustrationPoint.Key; + AssertWindDirection(expectedWindDirection, actualWindDirectionClosingSituation.WindDirection); + Assert.AreEqual("closing A", actualWindDirectionClosingSituation.ClosingSituation); + + Assert.IsInstanceOf(topLevelIllustrationPoint.Value.Data); + var subMechanismIllustrationPoint = (SubMechanismIllustrationPoint) topLevelIllustrationPoint.Value.Data; + Assert.AreEqual("Point SA", subMechanismIllustrationPoint.Name); + + IllustrationPointResult[] illustrationPointResults = subMechanismIllustrationPoint.Results.ToArray(); + Assert.AreEqual("Result A", illustrationPointResults[0].Description); + Assert.AreEqual(0.0, illustrationPointResults[0].Value); + Assert.AreEqual("Result A", illustrationPointResults[1].Description); + Assert.AreEqual(1.0, illustrationPointResults[1].Value); + } + + [Test] public void CreateGeneralResultWithNonDistinctNamesInChildren_ExpectedProperties() { // Call @@ -194,9 +282,9 @@ generalResult.IllustrationPoints.Single(); Assert.IsInstanceOf(topLevelIllustrationPoint.Value.Data); - var children = topLevelIllustrationPoint.Value.Children.ToArray(); - Assert.AreEqual("Point B", ((SubMechanismIllustrationPoint)children[0].Data).Name); - Assert.AreEqual("Point B", ((SubMechanismIllustrationPoint)children[1].Data).Name); + IllustrationPointTreeNode[] children = topLevelIllustrationPoint.Value.Children.ToArray(); + Assert.AreEqual("Point B", ((SubMechanismIllustrationPoint) children[0].Data).Name); + Assert.AreEqual("Point B", ((SubMechanismIllustrationPoint) children[1].Data).Name); Assert.IsInstanceOf(children[0].Data); Assert.IsInstanceOf(children[1].Data); Index: Ringtoets/HydraRing/test/Ringtoets.HydraRing.Calculation.TestUtil/IllustrationPoints/GeneralResultTestFactory.cs =================================================================== diff -u -ra4bd5433cf68976014c17b17cd9cfb766b135c74 -r2be62a16f4a6d90a76ebb53967a7b7ea3a445cd1 --- Ringtoets/HydraRing/test/Ringtoets.HydraRing.Calculation.TestUtil/IllustrationPoints/GeneralResultTestFactory.cs (.../GeneralResultTestFactory.cs) (revision a4bd5433cf68976014c17b17cd9cfb766b135c74) +++ Ringtoets/HydraRing/test/Ringtoets.HydraRing.Calculation.TestUtil/IllustrationPoints/GeneralResultTestFactory.cs (.../GeneralResultTestFactory.cs) (revision 2be62a16f4a6d90a76ebb53967a7b7ea3a445cd1) @@ -29,9 +29,9 @@ { /// /// Creates a new instance of - /// with non distinct stochasts + /// with non distinct stochasts. /// - /// A with non distinct stochasts + /// A with non distinct stochasts. public static GeneralResult CreateGeneralResultWithNonDistinctStochasts() { var stochasts = new[] @@ -44,11 +44,11 @@ } /// - /// Creates a new instance of - /// with an incomplete list of top level stochasts + /// Creates a new instance of containing a fault tree + /// with an incomplete list of top level stochasts. /// - /// A with an incomplete list of top level stochasts - public static GeneralResult CreateGeneralResultWithIncorrectTopLevelStochasts() + /// A with an incomplete list of top level stochasts. + public static GeneralResult CreateGeneralResultFaultTreeWithIncorrectTopLevelStochasts() { var stochasts = new[] { @@ -72,11 +72,39 @@ } /// + /// Creates a new instance of containing a sub mechanism + /// with an incomplete list of top level stochasts. + /// + /// A with an incomplete list of top level stochasts. + public static GeneralResult CreateGeneralResultSubMechanismWithIncorrectTopLevelStochasts() + { + var stochasts = new[] + { + new Stochast("Stochast A", 0, 0), + new Stochast("Stochast B", 0, 0) + }; + + var faultTreeNode1 = new IllustrationPointTreeNode(new SubMechanismIllustrationPoint("Point A", new[] + { + new SubMechanismIllustrationPointStochast("Stochast C", 0, 0, 0) + }, Enumerable.Empty(), 0.0)); + + var illustrationPoints = new Dictionary + { + { + new WindDirectionClosingSituation(new TestWindDirection(), "closing A"), + faultTreeNode1 + } + }; + return new GeneralResult(0.5, new TestWindDirection(), stochasts, illustrationPoints); + } + + /// /// Creates a new instance of - /// with an incomplete list of stochasts in a fault tree illustration point in the tree + /// with an incomplete list of stochasts in a fault tree illustration point in the tree. /// /// A with an incomplete list of stochasts - /// in a fault tree illustration point in the tree + /// in a fault tree illustration point in the tree. public static GeneralResult CreateGeneralResultWithIncorrectStochastsInChildren() { var stochasts = new[] @@ -110,11 +138,11 @@ } /// - /// Creates a new instance of - /// with non distinct illustration points + /// Creates a new instance of containing a fault tree + /// with non distinct illustration points. /// - /// A with non distinct illustration points - public static GeneralResult CreateGeneralResultWithNonDistinctIllustrationPoints() + /// A with non distinct illustration points. + public static GeneralResult CreateGeneralResultFaultTreeWithNonDistinctIllustrationPoints() { var illustrationPoints = new Dictionary { @@ -131,12 +159,33 @@ } /// - /// Creates a new instance of - /// with non distinct illustration point results + /// Creates a new instance of containing a sub mechanism + /// with non distinct illustration points. /// - /// A with non distinct illustration point results - public static GeneralResult CreateGeneralResultWithNonDistinctIllustrationPointResults() + /// A with non distinct illustration points. + public static GeneralResult CreateGeneralResultSubMechanismWithNonDistinctIllustrationPoints() { + var illustrationPoints = new Dictionary + { + { + new WindDirectionClosingSituation(new WindDirection("N", 0.0), "closing A"), + new IllustrationPointTreeNode(new TestSubMechanismIllustrationPoint()) + }, + { + new WindDirectionClosingSituation(new WindDirection("S", 0.0), "closing A"), + new IllustrationPointTreeNode(new TestSubMechanismIllustrationPoint()) + } + }; + return new GeneralResult(0.5, new TestWindDirection(), Enumerable.Empty(), illustrationPoints); + } + + /// + /// Creates a new instance of containing a fault tree + /// with non distinct illustration point results. + /// + /// A with non distinct illustration point results. + public static GeneralResult CreateGeneralResultFaultTreeWithNonDistinctIllustrationPointResults() + { var illustrationPointNode = new IllustrationPointTreeNode(new FaultTreeIllustrationPoint("Point A", 0.5, Enumerable.Empty(), @@ -165,10 +214,35 @@ } /// + /// Creates a new instance of containing a fault tree + /// with non distinct illustration point results. + /// + /// A with non distinct illustration point results. + public static GeneralResult CreateGeneralResultSubMechanismWithNonDistinctIllustrationPointResults() + { + var illustrationPointNode = new IllustrationPointTreeNode(new SubMechanismIllustrationPoint("Point SA", + Enumerable.Empty(), + new[] + { + new IllustrationPointResult("Result A", 0.0), + new IllustrationPointResult("Result A", 1.0) + }, 0.0)); + + var illustrationPoints = new Dictionary + { + { + new WindDirectionClosingSituation(new TestWindDirection(), "closing A"), + illustrationPointNode + } + }; + return new GeneralResult(0.5, new TestWindDirection(), Enumerable.Empty(), illustrationPoints); + } + + /// /// Creates a new instance of - /// with non distinct illustration point names + /// with non distinct illustration point names. /// - /// A with non distinct illustration point names + /// A with non distinct illustration point names. public static GeneralResult CreateGeneralResultWithNonDistinctNamesInChildren() { var illustrationPointNode = new IllustrationPointTreeNode(new FaultTreeIllustrationPoint("Point A",