Index: Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Service.Test/ClosingStructuresCalculationServiceTest.cs =================================================================== diff -u -r83024e3b1086e1dba93b83df874bd4781f67aa63 -r8245c9add5586e4e544ab41195fb0af2b2a459e9 --- Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Service.Test/ClosingStructuresCalculationServiceTest.cs (.../ClosingStructuresCalculationServiceTest.cs) (revision 83024e3b1086e1dba93b83df874bd4781f67aa63) +++ Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Service.Test/ClosingStructuresCalculationServiceTest.cs (.../ClosingStructuresCalculationServiceTest.cs) (revision 8245c9add5586e4e544ab41195fb0af2b2a459e9) @@ -20,6 +20,7 @@ // All rights reserved. using System; +using System.IO; using System.Linq; using Core.Common.Base.Geometry; using Core.Common.TestUtil; @@ -45,7 +46,86 @@ { private static readonly string testDataPath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Integration.Service, "HydraRingCalculation"); + [Test] + public void Validate_ValidCalculationInvalidHydraulicBoundaryDatabase_ReturnsFalse() + { + // Setup + var mockRepository = new MockRepository(); + var assessmentSectionStub = CreateAssessmentSectionStub(new ClosingStructuresFailureMechanism(), mockRepository); + mockRepository.ReplayAll(); + + assessmentSectionStub.HydraulicBoundaryDatabase.FilePath = Path.Combine(testDataPath, "notexisting.sqlite"); + + const string name = ""; + + ClosingStructuresCalculation calculation = new ClosingStructuresCalculation + { + Name = name, + InputParameters = + { + HydraulicBoundaryLocation = new HydraulicBoundaryLocation(1, "name", 2, 2), + } + }; + + // Call + bool isValid = false; + Action call = () => isValid = new ClosingStructuresCalculationService().Validate(calculation, assessmentSectionStub); + + // 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); + + mockRepository.VerifyAll(); + } + + [Test] + public void Validate_CalculationInputWithoutHydraulicBoundaryLocationValidHydraulicBoundaryDatabase_LogsErrorAndReturnsFalse() + { + // Setup + var mockRepository = new MockRepository(); + var assessmentSectionStub = CreateAssessmentSectionStub(new ClosingStructuresFailureMechanism(), mockRepository); + mockRepository.ReplayAll(); + + assessmentSectionStub.HydraulicBoundaryDatabase.FilePath = Path.Combine(testDataPath, "HRD dutch coast south.sqlite"); + + const string name = ""; + + ClosingStructuresCalculation calculation = new TestClosingStructuresCalculation() + { + Name = name, + InputParameters = + { + HydraulicBoundaryLocation = null + } + }; + + // Call + bool isValid = false; + Action call = () => isValid = new ClosingStructuresCalculationService().Validate(calculation, assessmentSectionStub); + + // 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 randvoorwaardenlocatie geselecteerd.", msgs[1]); + StringAssert.StartsWith(string.Format("Validatie van '{0}' beƫindigd om: ", name), msgs[2]); + }); + Assert.IsFalse(isValid); + + mockRepository.VerifyAll(); + } + + [Test] public void Calculate_InvalidInFlowModelType_ThrowsNotSupportedException() { // Setup