Index: Ringtoets/DuneErosion/test/Ringtoets.DuneErosion.Service.Test/DuneErosionBoundaryCalculationServiceTest.cs =================================================================== diff -u -r9779d1ab6b555c557e8fd18f4430ad207bd003da -rb633ec894f0b9c1878e978b24a0c870480fd604b --- Ringtoets/DuneErosion/test/Ringtoets.DuneErosion.Service.Test/DuneErosionBoundaryCalculationServiceTest.cs (.../DuneErosionBoundaryCalculationServiceTest.cs) (revision 9779d1ab6b555c557e8fd18f4430ad207bd003da) +++ Ringtoets/DuneErosion/test/Ringtoets.DuneErosion.Service.Test/DuneErosionBoundaryCalculationServiceTest.cs (.../DuneErosionBoundaryCalculationServiceTest.cs) (revision b633ec894f0b9c1878e978b24a0c870480fd604b) @@ -45,6 +45,61 @@ private static readonly string validFilePath = Path.Combine(testDataPath, "HRD dutch coast south.sqlite"); [Test] + public void Validate_ValidHydraulicBoundaryDatabasePath_ReturnsTrue() + { + // Setup + var valid = false; + + // Call + Action call = () => valid = DuneErosionBoundaryCalculationService.Validate(validFilePath); + + // Assert + TestHelper.AssertLogMessagesCount(call, 0); + Assert.IsTrue(valid); + } + + [Test] + public void Validate_InvalidHydraulicBoundaryDatabasePath_LogsErrorAndReturnsFalse() + { + // Setup + string notValidFilePath = Path.Combine(testDataPath, "notexisting.sqlite"); + var valid = false; + + // Call + Action call = () => valid = DuneErosionBoundaryCalculationService.Validate(notValidFilePath); + + // Assert + TestHelper.AssertLogMessagesWithLevelAreGenerated(call, new[] + { + Tuple.Create("Herstellen van de verbinding met de hydraulische randvoorwaardendatabase is mislukt. " + + $"Fout bij het lezen van bestand '{notValidFilePath}': het bestand bestaat niet.", + LogLevelConstant.Error) + }, 1); + Assert.IsFalse(valid); + } + + [Test] + public void Validate_ValidHydraulicBoundaryDatabaseWithoutSettings_LogsErrorAndReturnsFalse() + { + // Setup + string notValidFilePath = Path.Combine(testDataPath, "HRD nosettings.sqlite"); + string missingConfigFilePath = Path.Combine(testDataPath, "HRD nosettings.config.sqlite"); + var valid = false; + + // Call + Action call = () => valid = DuneErosionBoundaryCalculationService.Validate(notValidFilePath); + + // Assert + TestHelper.AssertLogMessagesWithLevelAreGenerated(call, new[] + { + Tuple.Create("Herstellen van de verbinding met de hydraulische randvoorwaardendatabase is mislukt. " + + $"Fout bij het lezen van bestand '{missingConfigFilePath}': het bestand bestaat niet.", + LogLevelConstant.Error) + }, 1); + Assert.IsFalse(valid); + } + + [Test] public void Calculate_DuneLocationNull_ThrowArgumentNullException() { // Call @@ -172,9 +227,11 @@ { string[] msgs = messages.ToArray(); Assert.AreEqual(3, msgs.Length); - CalculationServiceTestHelper.AssertCalculationStartMessage(duneLocation.Name, msgs[0]); + + string calculationName = GetCalculationName(duneLocation.Name); + CalculationServiceTestHelper.AssertCalculationStartMessage(calculationName, msgs[0]); StringAssert.StartsWith("Hydraulische randvoorwaarden berekening is uitgevoerd op de tijdelijke locatie", msgs[1]); - CalculationServiceTestHelper.AssertCalculationEndMessage(duneLocation.Name, msgs[2]); + CalculationServiceTestHelper.AssertCalculationEndMessage(calculationName, msgs[2]); }); double targetReliability = StatisticsConverter.ProbabilityToReliability(mechanismSpecificNorm); double calculatedProbability = StatisticsConverter.ReliabilityToProbability(calculator.ReliabilityIndex); @@ -237,10 +294,12 @@ { string[] msgs = messages.ToArray(); Assert.AreEqual(4, msgs.Length); - CalculationServiceTestHelper.AssertCalculationStartMessage(duneLocation.Name, msgs[0]); + + string calculationName = GetCalculationName(duneLocation.Name); + CalculationServiceTestHelper.AssertCalculationStartMessage(calculationName, msgs[0]); Assert.AreEqual($"Hydraulische randvoorwaarden berekening voor locatie '{duneLocation.Name}' is niet geconvergeerd.", msgs[1]); StringAssert.StartsWith("Hydraulische randvoorwaarden berekening is uitgevoerd op de tijdelijke locatie", msgs[2]); - CalculationServiceTestHelper.AssertCalculationEndMessage(duneLocation.Name, msgs[3]); + CalculationServiceTestHelper.AssertCalculationEndMessage(calculationName, msgs[3]); }); } @@ -350,10 +409,12 @@ { string[] msgs = messages.ToArray(); Assert.AreEqual(4, msgs.Length); - CalculationServiceTestHelper.AssertCalculationStartMessage(duneLocation.Name, msgs[0]); + + string calculationName = GetCalculationName(duneLocation.Name); + CalculationServiceTestHelper.AssertCalculationStartMessage(calculationName, msgs[0]); StringAssert.StartsWith($"Hydraulische randvoorwaarden berekening voor locatie '{duneLocation.Name}' is niet gelukt. Bekijk het foutrapport door op details te klikken.", msgs[1]); StringAssert.StartsWith("Hydraulische randvoorwaarden berekening is uitgevoerd op de tijdelijke locatie", msgs[2]); - CalculationServiceTestHelper.AssertCalculationEndMessage(duneLocation.Name, msgs[3]); + CalculationServiceTestHelper.AssertCalculationEndMessage(calculationName, msgs[3]); }); Assert.IsTrue(exceptionThrown); Assert.IsNull(duneLocation.Output); @@ -419,10 +480,12 @@ { string[] msgs = messages.ToArray(); Assert.AreEqual(4, msgs.Length); - CalculationServiceTestHelper.AssertCalculationStartMessage(duneLocation.Name, msgs[0]); + + string calculationName = GetCalculationName(duneLocation.Name); + CalculationServiceTestHelper.AssertCalculationStartMessage(calculationName, msgs[0]); Assert.AreEqual($"Hydraulische randvoorwaarden berekening voor locatie '{duneLocation.Name}' is niet gelukt. Er is geen foutrapport beschikbaar.", msgs[1]); StringAssert.StartsWith("Hydraulische randvoorwaarden berekening is uitgevoerd op de tijdelijke locatie", msgs[2]); - CalculationServiceTestHelper.AssertCalculationEndMessage(duneLocation.Name, msgs[3]); + CalculationServiceTestHelper.AssertCalculationEndMessage(calculationName, msgs[3]); }); Assert.IsTrue(exceptionThrown); Assert.IsNull(duneLocation.Output); @@ -491,10 +554,12 @@ { string[] msgs = messages.ToArray(); Assert.AreEqual(4, msgs.Length); - CalculationServiceTestHelper.AssertCalculationStartMessage(duneLocation.Name, msgs[0]); + + string calculationName = GetCalculationName(duneLocation.Name); + CalculationServiceTestHelper.AssertCalculationStartMessage(calculationName, msgs[0]); StringAssert.StartsWith($"Hydraulische randvoorwaarden berekening voor locatie '{duneLocation.Name}' is niet gelukt. Bekijk het foutrapport door op details te klikken.", msgs[1]); StringAssert.StartsWith("Hydraulische randvoorwaarden berekening is uitgevoerd op de tijdelijke locatie", msgs[2]); - CalculationServiceTestHelper.AssertCalculationEndMessage(duneLocation.Name, msgs[3]); + CalculationServiceTestHelper.AssertCalculationEndMessage(calculationName, msgs[3]); }); Assert.IsTrue(exceptionThrown); Assert.IsNull(duneLocation.Output); @@ -504,6 +569,11 @@ mockRepository.VerifyAll(); } + private static string GetCalculationName(string duneLocationName) + { + return $"Hydraulische belasting berekenen voor locatie '{duneLocationName}'"; + } + private static void AssertInput(DunesBoundaryConditionsCalculationInput expectedInput, DunesBoundaryConditionsCalculationInput actualInput) { Assert.AreEqual(expectedInput.Section.SectionId, actualInput.Section.SectionId);