Index: Ringtoets/GrassCoverErosionOutwards/src/Ringtoets.GrassCoverErosionOutwards.Service/GrassCoverErosionOutwardsWaveConditionsCalculationActivity.cs =================================================================== diff -u -r2c68fa9dd748870624f45c0f2ae6a30327485a63 -rbecf5cc824acc98fc87209aaec2830a080f1a246 --- Ringtoets/GrassCoverErosionOutwards/src/Ringtoets.GrassCoverErosionOutwards.Service/GrassCoverErosionOutwardsWaveConditionsCalculationActivity.cs (.../GrassCoverErosionOutwardsWaveConditionsCalculationActivity.cs) (revision 2c68fa9dd748870624f45c0f2ae6a30327485a63) +++ Ringtoets/GrassCoverErosionOutwards/src/Ringtoets.GrassCoverErosionOutwards.Service/GrassCoverErosionOutwardsWaveConditionsCalculationActivity.cs (.../GrassCoverErosionOutwardsWaveConditionsCalculationActivity.cs) (revision becf5cc824acc98fc87209aaec2830a080f1a246) @@ -87,7 +87,9 @@ protected override void OnRun() { - PerformRun(() => WaveConditionsCalculationService.Instance.Validate(calculation.InputParameters, assessmentSection.HydraulicBoundaryDatabase, calculation.Name), + PerformRun(() => WaveConditionsCalculationService.Instance.Validate(calculation.InputParameters, + assessmentSection.HydraulicBoundaryDatabase, + calculation.Name), () => GrassCoverErosionOutwardsDataSynchronizationService.ClearWaveConditionsCalculationOutput(calculation), () => { Index: Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.Integration.Test/GrassCoverErosionOutwardsWaveConditionsCalculationActivityIntegrationTest.cs =================================================================== diff -u -r2c68fa9dd748870624f45c0f2ae6a30327485a63 -rbecf5cc824acc98fc87209aaec2830a080f1a246 --- Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.Integration.Test/GrassCoverErosionOutwardsWaveConditionsCalculationActivityIntegrationTest.cs (.../GrassCoverErosionOutwardsWaveConditionsCalculationActivityIntegrationTest.cs) (revision 2c68fa9dd748870624f45c0f2ae6a30327485a63) +++ Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.Integration.Test/GrassCoverErosionOutwardsWaveConditionsCalculationActivityIntegrationTest.cs (.../GrassCoverErosionOutwardsWaveConditionsCalculationActivityIntegrationTest.cs) (revision becf5cc824acc98fc87209aaec2830a080f1a246) @@ -35,6 +35,7 @@ using Ringtoets.GrassCoverErosionOutwards.Service; using Ringtoets.GrassCoverErosionOutwards.Service.Properties; using Ringtoets.HydraRing.Calculation.TestUtil; +using Ringtoets.HydraRing.Data; using Ringtoets.Integration.Data; using Ringtoets.Integration.Plugin.FileImporters; using Ringtoets.Revetment.Data; @@ -49,25 +50,161 @@ private readonly string testDataPath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Integration.Service, "HydraRingCalculation"); [Test] - public void OnRun_NoWaterLevels_LogStartAndEnd() + public void OnRun_NoHydraulicBoundaryDatabase_DoesNotPerformCalculationAndLogsError() { // Setup var assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike); + var calculation = new GrassCoverErosionOutwardsWaveConditionsCalculation() + { + InputParameters = + { + ForeshoreProfile = CreateForeshoreProfile(), + UseForeshore = true, + UseBreakWater = true, + StepSize = WaveConditionsInputStepSize.Half, + LowerBoundaryRevetment = (RoundedDouble) 5.3, + UpperBoundaryRevetment = (RoundedDouble) 10, + UpperBoundaryWaterLevels = (RoundedDouble) 5.4, + LowerBoundaryWaterLevels = (RoundedDouble) 5 + } + }; + + var activity = new GrassCoverErosionOutwardsWaveConditionsCalculationActivity(calculation, + testDataPath, + assessmentSection.GrassCoverErosionOutwards, + assessmentSection); + + using (new HydraRingCalculationServiceConfig()) + { + // Call + Action call = () => activity.Run(); + + // Assert + TestHelper.AssertLogMessages(call, messages => + { + var msgs = messages.ToArray(); + Assert.AreEqual(3, msgs.Length); + StringAssert.StartsWith(string.Format("Validatie van '{0}' gestart om: ", calculation.Name), msgs[0]); + StringAssert.StartsWith("Validatie mislukt: Er is geen hydraulische randvoorwaardendatabase geïmporteerd.", msgs[1]); + StringAssert.StartsWith(string.Format("Validatie van '{0}' beëindigd om: ", calculation.Name), msgs[2]); + }); + Assert.AreEqual(ActivityState.Failed, activity.State); + } + } + + [Test] + public void OnRun_InvalidHydraulicBoundaryDatabase_DoesNotPerformCalculationAndLogsError() + { + // Setup + var assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike); + assessmentSection.HydraulicBoundaryDatabase = new HydraulicBoundaryDatabase() + { + FilePath = Path.Combine(testDataPath, "NonExisting.sqlite") + }; + + var calculation = new GrassCoverErosionOutwardsWaveConditionsCalculation + { + InputParameters = + { + ForeshoreProfile = CreateForeshoreProfile(), + UseForeshore = true, + UseBreakWater = true, + StepSize = WaveConditionsInputStepSize.Half, + LowerBoundaryRevetment = (RoundedDouble) 5.3, + UpperBoundaryRevetment = (RoundedDouble) 10, + UpperBoundaryWaterLevels = (RoundedDouble) 5.4, + LowerBoundaryWaterLevels = (RoundedDouble) 5 + } + }; + + var activity = new GrassCoverErosionOutwardsWaveConditionsCalculationActivity(calculation, + testDataPath, + assessmentSection.GrassCoverErosionOutwards, + assessmentSection); + + using (new HydraRingCalculationServiceConfig()) + { + // Call + Action call = () => activity.Run(); + + // Assert + TestHelper.AssertLogMessages(call, messages => + { + var msgs = messages.ToArray(); + Assert.AreEqual(3, msgs.Length); + StringAssert.StartsWith(string.Format("Validatie van '{0}' gestart om: ", calculation.Name), msgs[0]); + StringAssert.StartsWith("Validatie mislukt: Herstellen van de verbinding met de hydraulische randvoorwaardendatabase is mislukt.", msgs[1]); + StringAssert.StartsWith(string.Format("Validatie van '{0}' beëindigd om: ", calculation.Name), msgs[2]); + }); + Assert.AreEqual(ActivityState.Failed, activity.State); + } + } + + [Test] + public void OnRun_NoHydraulicBoundaryLocation_DoesNotPerformCalculationAndLogsError() + { + // Setup + var assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike); ImportHydraulicBoundaryDatabase(assessmentSection); var calculation = new GrassCoverErosionOutwardsWaveConditionsCalculation { InputParameters = { + ForeshoreProfile = CreateForeshoreProfile(), + UseForeshore = true, + UseBreakWater = true, + StepSize = WaveConditionsInputStepSize.Half, + LowerBoundaryRevetment = (RoundedDouble) 5.3, + UpperBoundaryRevetment = (RoundedDouble) 10, + UpperBoundaryWaterLevels = (RoundedDouble) 5.4, + LowerBoundaryWaterLevels = (RoundedDouble) 5 + } + }; + + var activity = new GrassCoverErosionOutwardsWaveConditionsCalculationActivity(calculation, + testDataPath, + assessmentSection.GrassCoverErosionOutwards, + assessmentSection); + + using (new HydraRingCalculationServiceConfig()) + { + // Call + Action call = () => activity.Run(); + + // Assert + TestHelper.AssertLogMessages(call, messages => + { + var msgs = messages.ToArray(); + Assert.AreEqual(3, msgs.Length); + StringAssert.StartsWith(string.Format("Validatie van '{0}' gestart om: ", calculation.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: ", calculation.Name), msgs[2]); + }); + Assert.AreEqual(ActivityState.Failed, activity.State); + } + } + + [Test] + public void OnRun_NoDesignWaterLevel_DoesNotPerformCalculationAndLogsError() + { + // Setup + var assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike); + ImportHydraulicBoundaryDatabase(assessmentSection); + + var calculation = new GrassCoverErosionOutwardsWaveConditionsCalculation + { + InputParameters = + { HydraulicBoundaryLocation = assessmentSection.HydraulicBoundaryDatabase.Locations.First(hl => hl.Id == 1300001), ForeshoreProfile = CreateForeshoreProfile(), UseForeshore = true, UseBreakWater = true, StepSize = WaveConditionsInputStepSize.Half, - LowerBoundaryRevetment = (RoundedDouble)5.3, - UpperBoundaryRevetment = (RoundedDouble)10, - UpperBoundaryWaterLevels = (RoundedDouble)5.4, - LowerBoundaryWaterLevels = (RoundedDouble)5 + LowerBoundaryRevetment = (RoundedDouble) 5.3, + UpperBoundaryRevetment = (RoundedDouble) 10, + UpperBoundaryWaterLevels = (RoundedDouble) 5.4, + LowerBoundaryWaterLevels = (RoundedDouble) 5 } }; @@ -76,30 +213,81 @@ assessmentSection.GrassCoverErosionOutwards, assessmentSection); - using (new WaveConditionsCalculationServiceConfig()) + using (new HydraRingCalculationServiceConfig()) { // Call + activity.Run(); Action call = () => activity.Run(); // Assert TestHelper.AssertLogMessages(call, messages => { 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]); + Assert.AreEqual(3, msgs.Length); + StringAssert.StartsWith(string.Format("Validatie van '{0}' gestart om: ", calculation.Name), msgs[0]); + StringAssert.StartsWith("Validatie mislukt: Kan het toetspeil niet afleiden op basis van de invoer.", msgs[1]); + StringAssert.StartsWith(string.Format("Validatie van '{0}' beëindigd om: ", calculation.Name), msgs[2]); }); Assert.AreEqual(ActivityState.Failed, activity.State); } } [Test] - public void OnRun_CalculationWithWaterLevels_PerformCalculationAndLogStartAndEnd() + [TestCase(double.NaN, 10.0)] + [TestCase(1.0, double.NaN)] + public void OnRun_NoWaterLevels_DoesNotPerformCalculationAndLogsError(double lowerBoundaryRevetment, double upperBoundaryRevetment) { // Setup var assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike); ImportHydraulicBoundaryDatabase(assessmentSection); + var calculation = new GrassCoverErosionOutwardsWaveConditionsCalculation + { + InputParameters = + { + HydraulicBoundaryLocation = assessmentSection.HydraulicBoundaryDatabase.Locations.First(hl => hl.Id == 1300001), + ForeshoreProfile = CreateForeshoreProfile(), + UseForeshore = true, + UseBreakWater = true, + StepSize = WaveConditionsInputStepSize.Half, + LowerBoundaryRevetment = (RoundedDouble) lowerBoundaryRevetment, + UpperBoundaryRevetment = (RoundedDouble) upperBoundaryRevetment, + UpperBoundaryWaterLevels = (RoundedDouble) 5.4, + LowerBoundaryWaterLevels = (RoundedDouble) 5 + } + }; + calculation.InputParameters.HydraulicBoundaryLocation.DesignWaterLevel = (RoundedDouble) 12.0; + + var activity = new GrassCoverErosionOutwardsWaveConditionsCalculationActivity(calculation, + testDataPath, + assessmentSection.GrassCoverErosionOutwards, + assessmentSection); + + using (new HydraRingCalculationServiceConfig()) + { + // Call + Action call = () => activity.Run(); + + // Assert + TestHelper.AssertLogMessages(call, messages => + { + var msgs = messages.ToArray(); + Assert.AreEqual(3, msgs.Length); + StringAssert.StartsWith(string.Format("Validatie van '{0}' gestart om: ", calculation.Name), msgs[0]); + StringAssert.StartsWith("Validatie mislukt: Kan geen waterstanden afleiden op basis van de invoer. Controleer de opgegeven boven- en ondergrenzen.", msgs[1]); + StringAssert.StartsWith(string.Format("Validatie van '{0}' beëindigd om: ", calculation.Name), msgs[2]); + }); + Assert.AreEqual(ActivityState.Failed, activity.State); + } + } + + [Test] + public void OnRun_CalculationWithValidInputConditions_PerformCalculationAndLogStartAndEnd() + { + // Setup + var assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike); + ImportHydraulicBoundaryDatabase(assessmentSection); + GrassCoverErosionOutwardsWaveConditionsCalculation calculation = GetValidCalculation(assessmentSection); var activity = new GrassCoverErosionOutwardsWaveConditionsCalculationActivity(calculation, @@ -134,7 +322,7 @@ } [Test] - public void OnRun_CalculationWithWaterLevelsCannotPerformCalculation_LogStartAndErrorAndEnd() + public void OnRun_CalculationWitValidCalculationCannotPerformCalculation_LogStartAndErrorAndEnd() { // Setup var assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike); @@ -392,13 +580,13 @@ UseForeshore = true, UseBreakWater = true, StepSize = WaveConditionsInputStepSize.Half, - LowerBoundaryRevetment = (RoundedDouble)4, - UpperBoundaryRevetment = (RoundedDouble)10, - UpperBoundaryWaterLevels = (RoundedDouble)8, - LowerBoundaryWaterLevels = (RoundedDouble)7.1 + LowerBoundaryRevetment = (RoundedDouble) 4, + UpperBoundaryRevetment = (RoundedDouble) 10, + UpperBoundaryWaterLevels = (RoundedDouble) 8, + LowerBoundaryWaterLevels = (RoundedDouble) 7.1 } }; - calculation.InputParameters.HydraulicBoundaryLocation.DesignWaterLevel = (RoundedDouble)9.3; + calculation.InputParameters.HydraulicBoundaryLocation.DesignWaterLevel = (RoundedDouble) 9.3; return calculation; }