Index: Ringtoets/Common/test/Ringtoets.Common.Service.Test/Structures/StructuresCalculationServiceBaseTest.cs =================================================================== diff -u -r4997c48d331087a7f1fa40a7874a6f7d6ab1abd4 -r59afdb7983d1fe07862e126bb209c6eb93beee23 --- Ringtoets/Common/test/Ringtoets.Common.Service.Test/Structures/StructuresCalculationServiceBaseTest.cs (.../StructuresCalculationServiceBaseTest.cs) (revision 4997c48d331087a7f1fa40a7874a6f7d6ab1abd4) +++ Ringtoets/Common/test/Ringtoets.Common.Service.Test/Structures/StructuresCalculationServiceBaseTest.cs (.../StructuresCalculationServiceBaseTest.cs) (revision 59afdb7983d1fe07862e126bb209c6eb93beee23) @@ -218,6 +218,99 @@ mocks.VerifyAll(); } + [Test] + public void Validate_InputInvalidAccordingToValidationRule_LogErrorAndReturnFalse() + { + // Setup + var failureMechanism = new TestFailureMechanism(); + failureMechanism.AddSection(new FailureMechanismSection("test section", new[] + { + new Point2D(0, 0), + new Point2D(1, 1) + })); + + var mocks = new MockRepository(); + IAssessmentSection assessmentSectionStub = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mocks); + assessmentSectionStub.HydraulicBoundaryDatabase.FilePath = validFilePath; + mocks.ReplayAll(); + + const string name = ""; + var calculation = new TestStructuresCalculation + { + Name = name, + InputParameters = + { + Structure = new TestStructure(), + HydraulicBoundaryLocation = new TestHydraulicBoundaryLocation(), + IsValid = false + } + }; + + var isValid = false; + + // Call + Action call = () => isValid = TestStructuresCalculationService.Validate(calculation, assessmentSectionStub); + + // Assert + TestHelper.AssertLogMessages(call, messages => + { + string[] msgs = messages.ToArray(); + Assert.AreEqual(3, msgs.Length); + CalculationServiceTestHelper.AssertValidationStartMessage(msgs[0]); + Assert.AreEqual("Validatie mislukt: Error message", msgs[1]); + CalculationServiceTestHelper.AssertValidationEndMessage(msgs[2]); + }); + Assert.IsFalse(isValid); + + mocks.VerifyAll(); + } + + [Test] + public void Validate_InputValidAccordingToValidationRule_ReturnTrue() + { + // Setup + var failureMechanism = new TestFailureMechanism(); + failureMechanism.AddSection(new FailureMechanismSection("test section", new[] + { + new Point2D(0, 0), + new Point2D(1, 1) + })); + + var mocks = new MockRepository(); + IAssessmentSection assessmentSectionStub = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mocks); + assessmentSectionStub.HydraulicBoundaryDatabase.FilePath = validFilePath; + mocks.ReplayAll(); + + const string name = ""; + var calculation = new TestStructuresCalculation + { + Name = name, + InputParameters = + { + Structure = new TestStructure(), + HydraulicBoundaryLocation = new TestHydraulicBoundaryLocation(), + IsValid = true + } + }; + + var isValid = false; + + // Call + Action call = () => isValid = TestStructuresCalculationService.Validate(calculation, assessmentSectionStub); + + // Assert + TestHelper.AssertLogMessages(call, messages => + { + string[] msgs = messages.ToArray(); + Assert.AreEqual(2, msgs.Length); + CalculationServiceTestHelper.AssertValidationStartMessage(msgs[0]); + CalculationServiceTestHelper.AssertValidationEndMessage(msgs[1]); + }); + Assert.IsTrue(isValid); + + mocks.VerifyAll(); + } + private class TestStructuresCalculationService : StructuresCalculationServiceBase {}