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]);