Index: Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Integration.Test/HeightStructuresCalculationServiceIntegrationTest.cs =================================================================== diff -u -re568165b751acf8d72cdf0d128f76d7792dadb56 -r0a51f20ac93373a43f79bb4c6327bce1d46545c6 --- Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Integration.Test/HeightStructuresCalculationServiceIntegrationTest.cs (.../HeightStructuresCalculationServiceIntegrationTest.cs) (revision e568165b751acf8d72cdf0d128f76d7792dadb56) +++ Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Integration.Test/HeightStructuresCalculationServiceIntegrationTest.cs (.../HeightStructuresCalculationServiceIntegrationTest.cs) (revision 0a51f20ac93373a43f79bb4c6327bce1d46545c6) @@ -39,9 +39,122 @@ [TestFixture] public class HeightStructuresCalculationServiceIntegrationTest { - private readonly string testDataPath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.HeightStructures.Integration, "HeightStructuresCalculation"); + private readonly string testDataPath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Integration.Service, "HydraRingCalculation"); [Test] + public void Validate_InvalidCalculationInputValidHydraulicBoundaryDatabase_LogsErrorAndReturnsFalse() + { + // Setup + var assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike); + string validFilePath = Path.Combine(testDataPath, "HRD dutch coast south.sqlite"); + using (var importer = new HydraulicBoundaryDatabaseImporter()) + { + importer.Import(assessmentSection, validFilePath); + } + + const string name = ""; + + HeightStructuresCalculation calculation = new HeightStructuresCalculation + { + Name = name + }; + + + // Call + bool isValid = false; + Action call = () => isValid = HeightStructuresCalculationService.Validate(calculation, assessmentSection); + + // Assert + TestHelper.AssertLogMessages(call, messages => + { + var msgs = messages.ToArray(); + Assert.AreEqual(3, msgs.Length); + StringAssert.StartsWith(string.Format("Validatie van '{0}' gestart om: ", name), msgs[0]); + StringAssert.StartsWith("Validatie mislukt: Er is geen hydraulische randvoorwaarde locatie geselecteerd.", msgs[1]); + StringAssert.StartsWith(string.Format("Validatie van '{0}' beëindigd om: ", name), msgs[2]); + }); + Assert.IsFalse(isValid); + } + + [Test] + public void Validate_ValidCalculationInputAndInvalidHydraulicBoundaryDatabase_ReturnsFalse() + { + // Setup + var assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike) + { + HydraulicBoundaryDatabase = new HydraulicBoundaryDatabase + { + FilePath = Path.Combine(testDataPath, "notexisting.sqlite") + } + }; + + const string name = ""; + + HeightStructuresCalculation calculation = new HeightStructuresCalculation + { + Name = name, + InputParameters = + { + HydraulicBoundaryLocation = new HydraulicBoundaryLocation(1, "name", 2, 2) + } + }; + + + // Call + bool isValid = false; + Action call = () => isValid = HeightStructuresCalculationService.Validate(calculation, assessmentSection); + + // Assert + TestHelper.AssertLogMessages(call, messages => + { + var msgs = messages.ToArray(); + Assert.AreEqual(3, msgs.Length); + StringAssert.StartsWith(string.Format("Validatie van '{0}' gestart om: ", name), msgs[0]); + StringAssert.StartsWith("Validatie mislukt: Fout bij het lezen van bestand", msgs[1]); + StringAssert.StartsWith(string.Format("Validatie van '{0}' beëindigd om: ", name), msgs[2]); + }); + Assert.IsFalse(isValid); + } + + [Test] + public void Validate_ValidCalculationInputAndHydraulicBoundaryDatabase_ReturnsTrue() + { + // Setup + var assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike); + string validFilePath = Path.Combine(testDataPath, "HRD dutch coast south.sqlite"); + using (var importer = new HydraulicBoundaryDatabaseImporter()) + { + importer.Import(assessmentSection, validFilePath); + } + + const string name = ""; + + HeightStructuresCalculation calculation = new HeightStructuresCalculation + { + Name = name, + InputParameters = + { + HydraulicBoundaryLocation = new HydraulicBoundaryLocation(1, "name", 2, 2) + } + }; + + + // Call + bool isValid = false; + Action call = () => isValid = HeightStructuresCalculationService.Validate(calculation, assessmentSection); + + // Assert + TestHelper.AssertLogMessages(call, messages => + { + var msgs = messages.ToArray(); + Assert.AreEqual(2, msgs.Length); + StringAssert.StartsWith(string.Format("Validatie van '{0}' gestart om: ", name), msgs[0]); + StringAssert.StartsWith(string.Format("Validatie van '{0}' beëindigd om: ", name), msgs[1]); + }); + Assert.IsTrue(isValid); + } + + [Test] public void Calculate_ValidCalculation_LogStartAndEndAndReturnOutput() { // Setup @@ -80,8 +193,8 @@ { var msgs = messages.ToArray(); Assert.AreEqual(2, msgs.Length); - StringAssert.StartsWith(String.Format("Berekening van '{0}' gestart om: ", calculation.Name), msgs[0]); - StringAssert.StartsWith(String.Format("Berekening van '{0}' beëindigd om: ", calculation.Name), msgs[1]); + StringAssert.StartsWith(string.Format("Berekening van '{0}' gestart om: ", calculation.Name), msgs[0]); + StringAssert.StartsWith(string.Format("Berekening van '{0}' beëindigd om: ", calculation.Name), msgs[1]); }); Assert.IsNotNull(output); } @@ -125,9 +238,9 @@ { var msgs = messages.ToArray(); Assert.AreEqual(3, msgs.Length); - StringAssert.StartsWith(String.Format("Berekening van '{0}' gestart om: ", calculation.Name), msgs[0]); - StringAssert.StartsWith(String.Format("Hoogte kunstwerk '{0}' niet gelukt.", calculation.Name), msgs[1]); - StringAssert.StartsWith(String.Format("Berekening van '{0}' beëindigd om: ", calculation.Name), msgs[2]); + StringAssert.StartsWith(string.Format("Berekening van '{0}' gestart om: ", calculation.Name), msgs[0]); + StringAssert.StartsWith(string.Format("Hoogte kunstwerk '{0}' niet gelukt.", calculation.Name), msgs[1]); + StringAssert.StartsWith(string.Format("Berekening van '{0}' beëindigd om: ", calculation.Name), msgs[2]); }); Assert.IsNull(output); }