Index: Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Service.Test/ClosingStructuresCalculationServiceTest.cs =================================================================== diff -u -rbd73023d5f8926a411da214fb5ce522056a0e30a -rce5d60b8a5c520faec45cce64de6957dce747449 --- Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Service.Test/ClosingStructuresCalculationServiceTest.cs (.../ClosingStructuresCalculationServiceTest.cs) (revision bd73023d5f8926a411da214fb5ce522056a0e30a) +++ Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Service.Test/ClosingStructuresCalculationServiceTest.cs (.../ClosingStructuresCalculationServiceTest.cs) (revision ce5d60b8a5c520faec45cce64de6957dce747449) @@ -940,6 +940,195 @@ } } + [Test] + public void Calculate_CalculationFailedWithExceptionAndLastErrorPresent_LogErrorAndThrowException() + { + // Setup + var closingStructuresFailureMechanism = new ClosingStructuresFailureMechanism(); + + var mockRepository = new MockRepository(); + IAssessmentSection assessmentSectionStub = AssessmentSectionHelper.CreateAssessmentSectionStub(closingStructuresFailureMechanism, + mockRepository); + mockRepository.ReplayAll(); + + closingStructuresFailureMechanism.AddSection(new FailureMechanismSection("test section", new[] + { + new Point2D(0, 0), + new Point2D(1, 1) + })); + + var calculation = new TestClosingStructuresCalculation + { + InputParameters = + { + HydraulicBoundaryLocation = assessmentSectionStub.HydraulicBoundaryDatabase.Locations.First(hl => hl.Id == 1300001) + } + }; + + using (new HydraRingCalculatorFactoryConfig()) + { + var calculator = ((TestHydraRingCalculatorFactory) HydraRingCalculatorFactory.Instance).StructuresClosureCalculator; + calculator.LastErrorContent = "An error occured"; + calculator.EndInFailure = true; + + var exceptionThrown = false; + + // Call + Action call = () => + { + try + { + new ClosingStructuresCalculationService().Calculate(calculation, + assessmentSectionStub, + closingStructuresFailureMechanism, + testDataPath); + } + catch (HydraRingFileParserException) + { + exceptionThrown = true; + } + }; + // Assert + TestHelper.AssertLogMessages(call, messages => + { + var msgs = messages.ToArray(); + Assert.AreEqual(4, msgs.Length); + StringAssert.StartsWith(string.Format("Berekening van '{0}' gestart om: ", calculation.Name), msgs[0]); + StringAssert.StartsWith(string.Format("De berekening voor kunstwerk sluiten '{0}' is niet gelukt. Bekijk het foutrapport door op details te klikken.", calculation.Name), msgs[1]); + StringAssert.StartsWith("Betrouwbaarheid sluiting kunstwerk berekening is uitgevoerd op de tijdelijke locatie:", msgs[2]); + StringAssert.StartsWith(string.Format("Berekening van '{0}' beëindigd om: ", calculation.Name), msgs[3]); + }); + Assert.IsTrue(exceptionThrown); + } + } + + [Test] + public void Calculate_CalculationFailedWithExceptionAndNoLastErrorPresent_LogErrorAndThrowException() + { + // Setup + var closingStructuresFailureMechanism = new ClosingStructuresFailureMechanism(); + + var mockRepository = new MockRepository(); + IAssessmentSection assessmentSectionStub = AssessmentSectionHelper.CreateAssessmentSectionStub(closingStructuresFailureMechanism, + mockRepository); + mockRepository.ReplayAll(); + + closingStructuresFailureMechanism.AddSection(new FailureMechanismSection("test section", new[] + { + new Point2D(0, 0), + new Point2D(1, 1) + })); + + var calculation = new TestClosingStructuresCalculation + { + InputParameters = + { + HydraulicBoundaryLocation = assessmentSectionStub.HydraulicBoundaryDatabase.Locations.First(hl => hl.Id == 1300001) + } + }; + + using (new HydraRingCalculatorFactoryConfig()) + { + var calculator = ((TestHydraRingCalculatorFactory) HydraRingCalculatorFactory.Instance).StructuresClosureCalculator; + calculator.EndInFailure = true; + + var exceptionThrown = false; + + // Call + Action call = () => + { + try + { + new ClosingStructuresCalculationService().Calculate(calculation, + assessmentSectionStub, + closingStructuresFailureMechanism, + testDataPath); + } + catch (HydraRingFileParserException) + { + exceptionThrown = true; + } + }; + // Assert + TestHelper.AssertLogMessages(call, messages => + { + var msgs = messages.ToArray(); + Assert.AreEqual(4, msgs.Length); + StringAssert.StartsWith(string.Format("Berekening van '{0}' gestart om: ", calculation.Name), msgs[0]); + StringAssert.StartsWith(string.Format("De berekening voor kunstwerk sluiten '{0}' is niet gelukt. Er is geen foutrapport beschikbaar.", calculation.Name), msgs[1]); + StringAssert.StartsWith("Betrouwbaarheid sluiting kunstwerk berekening is uitgevoerd op de tijdelijke locatie:", msgs[2]); + StringAssert.StartsWith(string.Format("Berekening van '{0}' beëindigd om: ", calculation.Name), msgs[3]); + }); + Assert.IsTrue(exceptionThrown); + } + } + + [Test] + public void Calculate_CalculationFailedWithoutExceptionAndWithLastErrorPresent_LogErrorAndThrowException() + { + // Setup + var closingStructuresFailureMechanism = new ClosingStructuresFailureMechanism(); + + var mockRepository = new MockRepository(); + IAssessmentSection assessmentSectionStub = AssessmentSectionHelper.CreateAssessmentSectionStub(closingStructuresFailureMechanism, + mockRepository); + mockRepository.ReplayAll(); + + closingStructuresFailureMechanism.AddSection(new FailureMechanismSection("test section", new[] + { + new Point2D(0, 0), + new Point2D(1, 1) + })); + + var calculation = new TestClosingStructuresCalculation + { + InputParameters = + { + HydraulicBoundaryLocation = assessmentSectionStub.HydraulicBoundaryDatabase.Locations.First(hl => hl.Id == 1300001) + } + }; + + using (new HydraRingCalculatorFactoryConfig()) + { + var calculator = ((TestHydraRingCalculatorFactory) HydraRingCalculatorFactory.Instance).StructuresClosureCalculator; + calculator.EndInFailure = false; + calculator.LastErrorContent = "An error occured"; + + var exceptionThrown = false; + var exceptionMessage = string.Empty; + + // Call + Action call = () => + { + try + { + new ClosingStructuresCalculationService().Calculate(calculation, + assessmentSectionStub, + closingStructuresFailureMechanism, + testDataPath); + } + catch (HydraRingFileParserException e) + { + exceptionThrown = true; + exceptionMessage = e.Message; + } + }; + // Assert + TestHelper.AssertLogMessages(call, messages => + { + var msgs = messages.ToArray(); + Assert.AreEqual(4, msgs.Length); + StringAssert.StartsWith(string.Format("Berekening van '{0}' gestart om: ", calculation.Name), msgs[0]); + StringAssert.StartsWith(string.Format("De berekening voor kunstwerk sluiten '{0}' is niet gelukt. Bekijk het foutrapport door op details te klikken.", + calculation.Name), msgs[1]); + StringAssert.StartsWith("Betrouwbaarheid sluiting kunstwerk berekening is uitgevoerd op de tijdelijke locatie:", msgs[2]); + StringAssert.StartsWith(string.Format("Berekening van '{0}' beëindigd om: ", calculation.Name), msgs[3]); + }); + Assert.IsTrue(exceptionThrown); + Assert.AreEqual(calculator.LastErrorContent, exceptionMessage); + } + } + /// /// Sets all input parameters of to invalid values. ///