Index: Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Integration.Test/GrassCoverErosionInwardsCalculationActivityIntegrationTest.cs =================================================================== diff -u -rfbb5151e17328fe78696f78c8e71d1a2d513d655 -rb46e7362cfbeafe2ea25d7d3c36e7d25e5cfdb65 --- Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Integration.Test/GrassCoverErosionInwardsCalculationActivityIntegrationTest.cs (.../GrassCoverErosionInwardsCalculationActivityIntegrationTest.cs) (revision fbb5151e17328fe78696f78c8e71d1a2d513d655) +++ Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Integration.Test/GrassCoverErosionInwardsCalculationActivityIntegrationTest.cs (.../GrassCoverErosionInwardsCalculationActivityIntegrationTest.cs) (revision b46e7362cfbeafe2ea25d7d3c36e7d25e5cfdb65) @@ -92,13 +92,136 @@ } [Test] - public void Run_InvalidOvertoppingCalculation_PerformValidationAndCalculationAndLogStartAndEndWithErrorAndDoNotPerformHydraulicLoadsCalculations() + [Combinatorial] + public void Run_CombinationOfCalculations_ProgressTextSetAccordingly([Values(DikeHeightCalculationType.CalculateByAssessmentSectionNorm, + DikeHeightCalculationType.CalculateByProfileSpecificRequiredProbability, + DikeHeightCalculationType.NoCalculation)] DikeHeightCalculationType dikeHeightCalculationType, + [Values(OvertoppingRateCalculationType.CalculateByAssessmentSectionNorm, + OvertoppingRateCalculationType.CalculateByProfileSpecificRequiredProbability, + OvertoppingRateCalculationType.NoCalculation)] OvertoppingRateCalculationType overtoppingRateCalculationType) { + var assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike); + ImportHydraulicBoundaryDatabase(assessmentSection); + AddSectionToAssessmentSection(assessmentSection); + + var calculation = new GrassCoverErosionInwardsCalculation + { + InputParameters = + { + HydraulicBoundaryLocation = assessmentSection.HydraulicBoundaryDatabase.Locations.First(hl => hl.Id == 1300001), + DikeProfile = CreateDikeProfile(), + DikeHeightCalculationType = dikeHeightCalculationType, + OvertoppingRateCalculationType = overtoppingRateCalculationType + } + }; + + var activity = new GrassCoverErosionInwardsCalculationActivity(calculation, validFile, assessmentSection.GrassCoverErosionInwards, assessmentSection); + + var progressTexts = ""; + + activity.ProgressChanged += (s, e) => progressTexts += activity.ProgressText + Environment.NewLine; + + using (new HydraRingCalculatorFactoryConfig()) + { + // Call + activity.Run(); + } + + // Assert + int totalNumberOfCalculations = dikeHeightCalculationType != DikeHeightCalculationType.NoCalculation + ? overtoppingRateCalculationType != OvertoppingRateCalculationType.NoCalculation + ? 3 + : 2 + : overtoppingRateCalculationType != OvertoppingRateCalculationType.NoCalculation + ? 2 + : 1; + + string expectedProgressTexts = $"Stap 1 van {totalNumberOfCalculations} | Uitvoeren overloop en overslag berekening" + Environment.NewLine; + + if (dikeHeightCalculationType != DikeHeightCalculationType.NoCalculation) + { + expectedProgressTexts += $"Stap 2 van {totalNumberOfCalculations} | Uitvoeren HBN berekening" + Environment.NewLine; + } + + if (overtoppingRateCalculationType != OvertoppingRateCalculationType.NoCalculation) + { + expectedProgressTexts += $"Stap {totalNumberOfCalculations} van {totalNumberOfCalculations} | Uitvoeren overslagdebiet berekening" + Environment.NewLine; + } + + Assert.AreEqual(expectedProgressTexts, progressTexts); + } + + [Test] + public void Run_ValidOvertoppingCalculation_InputPropertiesCorrectlySendToService() + { // Setup - var mocks = new MockRepository(); - var observerMock = mocks.StrictMock(); - mocks.ReplayAll(); + var assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike); + ImportHydraulicBoundaryDatabase(assessmentSection); + AddSectionToAssessmentSection(assessmentSection); + var calculation = new GrassCoverErosionInwardsCalculation + { + InputParameters = + { + HydraulicBoundaryLocation = assessmentSection.HydraulicBoundaryDatabase.Locations.First(hl => hl.Id == 1300001), + DikeProfile = CreateDikeProfile() + } + }; + + var activity = new GrassCoverErosionInwardsCalculationActivity(calculation, validFile, assessmentSection.GrassCoverErosionInwards, assessmentSection); + + using (new HydraRingCalculatorFactoryConfig()) + { + // Call + activity.Run(); + + // Assert + TestOvertoppingCalculator testOvertoppingCalculator = ((TestHydraRingCalculatorFactory) HydraRingCalculatorFactory.Instance).OvertoppingCalculator; + OvertoppingCalculationInput[] overtoppingCalculationInputs = testOvertoppingCalculator.ReceivedInputs.ToArray(); + Assert.AreEqual(1, overtoppingCalculationInputs.Length); + + OvertoppingCalculationInput actualInput = overtoppingCalculationInputs[0]; + GeneralGrassCoverErosionInwardsInput generalInput = assessmentSection.GrassCoverErosionInwards.GeneralInput; + + GrassCoverErosionInwardsInput input = calculation.InputParameters; + var expectedInput = new OvertoppingCalculationInput(calculation.InputParameters.HydraulicBoundaryLocation.Id, + calculation.InputParameters.Orientation, + calculation.InputParameters.DikeGeometry.Select(roughnessPoint => new HydraRingRoughnessProfilePoint(roughnessPoint.Point.X, roughnessPoint.Point.Y, roughnessPoint.Roughness)), + input.ForeshoreGeometry.Select(c => new HydraRingForelandPoint(c.X, c.Y)), + new HydraRingBreakWater((int) input.BreakWater.Type, input.BreakWater.Height), + calculation.InputParameters.DikeHeight, + generalInput.CriticalOvertoppingModelFactor, + generalInput.FbFactor.Mean, + generalInput.FbFactor.StandardDeviation, + generalInput.FbFactor.LowerBoundary, + generalInput.FbFactor.UpperBoundary, + generalInput.FnFactor.Mean, + generalInput.FnFactor.StandardDeviation, + generalInput.FnFactor.LowerBoundary, + generalInput.FnFactor.UpperBoundary, + generalInput.OvertoppingModelFactor, + calculation.InputParameters.CriticalFlowRate.Mean, + calculation.InputParameters.CriticalFlowRate.StandardDeviation, + generalInput.FrunupModelFactor.Mean, + generalInput.FrunupModelFactor.StandardDeviation, + generalInput.FrunupModelFactor.LowerBoundary, + generalInput.FrunupModelFactor.UpperBoundary, + generalInput.FshallowModelFactor.Mean, + generalInput.FshallowModelFactor.StandardDeviation, + generalInput.FshallowModelFactor.LowerBoundary, + generalInput.FshallowModelFactor.UpperBoundary); + + HydraRingDataEqualityHelper.AreEqual(expectedInput, actualInput); + Assert.AreEqual(testDataPath, testOvertoppingCalculator.HydraulicBoundaryDatabaseDirectory); + } + } + + [Test] + [TestCase(DikeHeightCalculationType.CalculateByAssessmentSectionNorm, TestName = "Run_ValidDikeHeightCalculation_InputPropertiesCorrectlySendToService(AssessmentSectionNorm)")] + [TestCase(DikeHeightCalculationType.CalculateByProfileSpecificRequiredProbability, TestName = "Run_ValidDikeHeightCalculation_InputPropertiesCorrectlySendToService(ProfileProbability)")] + public void Run_ValidDikeHeightCalculation_InputPropertiesCorrectlySendToService(DikeHeightCalculationType dikeHeightCalculationType) + { + // Setup var assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike); ImportHydraulicBoundaryDatabase(assessmentSection); AddSectionToAssessmentSection(assessmentSection); @@ -107,22 +230,135 @@ { InputParameters = { - HydraulicBoundaryLocation = new HydraulicBoundaryLocation(1, "test", 1, 1), + HydraulicBoundaryLocation = assessmentSection.HydraulicBoundaryDatabase.Locations.First(hl => hl.Id == 1300001), DikeProfile = CreateDikeProfile(), - DikeHeightCalculationType = DikeHeightCalculationType.CalculateByAssessmentSectionNorm, - OvertoppingRateCalculationType = OvertoppingRateCalculationType.CalculateByProfileSpecificRequiredProbability + DikeHeightCalculationType = dikeHeightCalculationType } }; - calculation.Attach(observerMock); - var activity = new GrassCoverErosionInwardsCalculationActivity(calculation, validFile, assessmentSection.GrassCoverErosionInwards, assessmentSection); using (new HydraRingCalculatorFactoryConfig()) { + // Call + activity.Run(); + + // Assert + TestHydraulicLoadsCalculator dikeHeightCalculator = ((TestHydraRingCalculatorFactory) HydraRingCalculatorFactory.Instance).DikeHeightCalculator; + HydraulicLoadsCalculationInput[] dikeHeightCalculationInputs = dikeHeightCalculator.ReceivedInputs.ToArray(); + Assert.AreEqual(1, dikeHeightCalculationInputs.Length); + + HydraulicLoadsCalculationInput actualInput = dikeHeightCalculationInputs[0]; + GeneralGrassCoverErosionInwardsInput generalInput = assessmentSection.GrassCoverErosionInwards.GeneralInput; + + GrassCoverErosionInwardsInput input = calculation.InputParameters; + + double norm = dikeHeightCalculationType == DikeHeightCalculationType.CalculateByAssessmentSectionNorm + ? assessmentSection.FailureMechanismContribution.Norm + : RingtoetsCommonDataCalculationService.ProfileSpecificRequiredProbability( + assessmentSection.FailureMechanismContribution.Norm, + assessmentSection.GrassCoverErosionInwards.Contribution, + generalInput.N); + + var expectedInput = new DikeHeightCalculationInput(calculation.InputParameters.HydraulicBoundaryLocation.Id, + norm, + calculation.InputParameters.Orientation, + calculation.InputParameters.DikeGeometry.Select(roughnessPoint => new HydraRingRoughnessProfilePoint(roughnessPoint.Point.X, roughnessPoint.Point.Y, roughnessPoint.Roughness)), + input.ForeshoreGeometry.Select(c => new HydraRingForelandPoint(c.X, c.Y)), + new HydraRingBreakWater((int) input.BreakWater.Type, input.BreakWater.Height), + generalInput.CriticalOvertoppingModelFactor, + generalInput.FbFactor.Mean, + generalInput.FbFactor.StandardDeviation, + generalInput.FbFactor.LowerBoundary, + generalInput.FbFactor.UpperBoundary, + generalInput.FnFactor.Mean, + generalInput.FnFactor.StandardDeviation, + generalInput.FnFactor.LowerBoundary, + generalInput.FnFactor.UpperBoundary, + generalInput.OvertoppingModelFactor, + calculation.InputParameters.CriticalFlowRate.Mean, + calculation.InputParameters.CriticalFlowRate.StandardDeviation, + generalInput.FrunupModelFactor.Mean, + generalInput.FrunupModelFactor.StandardDeviation, + generalInput.FrunupModelFactor.LowerBoundary, + generalInput.FrunupModelFactor.UpperBoundary, + generalInput.FshallowModelFactor.Mean, + generalInput.FshallowModelFactor.StandardDeviation, + generalInput.FshallowModelFactor.LowerBoundary, + generalInput.FshallowModelFactor.UpperBoundary); + + HydraRingDataEqualityHelper.AreEqual(expectedInput, actualInput); + Assert.AreEqual(testDataPath, dikeHeightCalculator.HydraulicBoundaryDatabaseDirectory); + } + } + + private static void AddSectionToAssessmentSection(AssessmentSection assessmentSection) + { + assessmentSection.GrassCoverErosionInwards.AddSection(new FailureMechanismSection("test section", new[] + { + new Point2D(0, 0), + new Point2D(1, 1) + })); + } + + private static void ImportHydraulicBoundaryDatabase(AssessmentSection assessmentSection) + { + string validFilePath = Path.Combine(testDataPath, "HRD dutch coast south.sqlite"); + + using (var importer = new HydraulicBoundaryDatabaseImporter()) + { + importer.Import(assessmentSection, validFilePath); + } + } + + private static DikeProfile CreateDikeProfile() + { + return new DikeProfile(new Point2D(0, 0), + new[] + { + new RoughnessPoint(new Point2D(1.1, 2.2), 0.6), + new RoughnessPoint(new Point2D(3.3, 4.4), 0.7) + }, new[] + { + new Point2D(3.3, 4.4), + new Point2D(5.5, 6.6) + }, + new BreakWater(BreakWaterType.Dam, 10.0), + new DikeProfile.ConstructionProperties + { + Id = "id", + Orientation = 5.5, + DikeHeight = 10 + }); + } + + #region Overtopping calculations + + [Test] + public void Run_InvalidOvertoppingCalculationWithExceptionAndLastErrorPresent_LogErrorAndThrowException() + { + // Setup + var assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike); + ImportHydraulicBoundaryDatabase(assessmentSection); + AddSectionToAssessmentSection(assessmentSection); + + var calculation = new GrassCoverErosionInwardsCalculation + { + InputParameters = + { + HydraulicBoundaryLocation = assessmentSection.HydraulicBoundaryDatabase.Locations.First(hl => hl.Id == 1300001), + DikeProfile = CreateDikeProfile() + } + }; + + using (new HydraRingCalculatorFactoryConfig()) + { TestOvertoppingCalculator calculator = ((TestHydraRingCalculatorFactory) HydraRingCalculatorFactory.Instance).OvertoppingCalculator; + calculator.LastErrorFileContent = "An error occurred"; calculator.EndInFailure = true; + var activity = new GrassCoverErosionInwardsCalculationActivity(calculation, validFile, assessmentSection.GrassCoverErosionInwards, assessmentSection); + // Call Action call = () => activity.Run(); @@ -134,16 +370,103 @@ StringAssert.StartsWith(string.Format("Validatie van '{0}' gestart om: ", calculation.Name), msgs[0]); StringAssert.StartsWith(string.Format("Validatie van '{0}' beëindigd om: ", calculation.Name), msgs[1]); StringAssert.StartsWith(string.Format("Berekening van '{0}' gestart om: ", calculation.Name), msgs[2]); - StringAssert.StartsWith(string.Format("De overloop en overslag berekening voor grasbekleding erosie kruin en binnentalud '{0}' is niet gelukt.", calculation.Name), msgs[3]); + StringAssert.StartsWith(string.Format("De overloop en overslag berekening voor grasbekleding erosie kruin en binnentalud '{0}' is niet gelukt. Bekijk het foutrapport door op details te klikken.", calculation.Name), msgs[3]); StringAssert.StartsWith("De overloop en overslag berekening is uitgevoerd op de tijdelijke locatie", msgs[4]); StringAssert.StartsWith(string.Format("Berekening van '{0}' beëindigd om: ", calculation.Name), msgs[5]); }); Assert.AreEqual(ActivityState.Failed, activity.State); - mocks.VerifyAll(); // Expect no calls on the observer } } [Test] + public void Run_InvalidOvertoppingCalculationWithExceptionAndNoLastErrorPresent_LogErrorAndThrowException() + { + // Setup + var assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike); + ImportHydraulicBoundaryDatabase(assessmentSection); + AddSectionToAssessmentSection(assessmentSection); + + var calculation = new GrassCoverErosionInwardsCalculation + { + InputParameters = + { + HydraulicBoundaryLocation = assessmentSection.HydraulicBoundaryDatabase.Locations.First(hl => hl.Id == 1300001), + DikeProfile = CreateDikeProfile() + } + }; + + using (new HydraRingCalculatorFactoryConfig()) + { + TestOvertoppingCalculator calculator = ((TestHydraRingCalculatorFactory) HydraRingCalculatorFactory.Instance).OvertoppingCalculator; + calculator.EndInFailure = true; + + var activity = new GrassCoverErosionInwardsCalculationActivity(calculation, validFile, assessmentSection.GrassCoverErosionInwards, assessmentSection); + + // Call + Action call = () => activity.Run(); + + // Assert + TestHelper.AssertLogMessages(call, messages => + { + string[] msgs = messages.ToArray(); + Assert.AreEqual(6, msgs.Length); + StringAssert.StartsWith(string.Format("Validatie van '{0}' gestart om: ", calculation.Name), msgs[0]); + StringAssert.StartsWith(string.Format("Validatie van '{0}' beëindigd om: ", calculation.Name), msgs[1]); + StringAssert.StartsWith(string.Format("Berekening van '{0}' gestart om: ", calculation.Name), msgs[2]); + StringAssert.StartsWith(string.Format("De overloop en overslag berekening voor grasbekleding erosie kruin en binnentalud '{0}' is niet gelukt. Er is geen foutrapport beschikbaar.", calculation.Name), msgs[3]); + StringAssert.StartsWith("De overloop en overslag berekening is uitgevoerd op de tijdelijke locatie", msgs[4]); + StringAssert.StartsWith(string.Format("Berekening van '{0}' beëindigd om: ", calculation.Name), msgs[5]); + }); + Assert.AreEqual(ActivityState.Failed, activity.State); + } + } + + [Test] + public void Run_InvalidOvertoppingCalculationWithoutExceptionAndWithLastErrorPresent_LogErrorAndThrowException() + { + // Setup + var assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike); + ImportHydraulicBoundaryDatabase(assessmentSection); + AddSectionToAssessmentSection(assessmentSection); + + var calculation = new GrassCoverErosionInwardsCalculation + { + InputParameters = + { + HydraulicBoundaryLocation = assessmentSection.HydraulicBoundaryDatabase.Locations.First(hl => hl.Id == 1300001), + DikeProfile = CreateDikeProfile() + } + }; + + using (new HydraRingCalculatorFactoryConfig()) + { + TestOvertoppingCalculator calculator = ((TestHydraRingCalculatorFactory) HydraRingCalculatorFactory.Instance).OvertoppingCalculator; + calculator.EndInFailure = false; + calculator.LastErrorFileContent = "An error occurred"; + + var activity = new GrassCoverErosionInwardsCalculationActivity(calculation, validFile, assessmentSection.GrassCoverErosionInwards, assessmentSection); + + // Call + Action call = () => activity.Run(); + + // Assert + TestHelper.AssertLogMessages(call, messages => + { + string[] msgs = messages.ToArray(); + Assert.AreEqual(6, msgs.Length); + StringAssert.StartsWith(string.Format("Validatie van '{0}' gestart om: ", calculation.Name), msgs[0]); + StringAssert.StartsWith(string.Format("Validatie van '{0}' beëindigd om: ", calculation.Name), msgs[1]); + StringAssert.StartsWith(string.Format("Berekening van '{0}' gestart om: ", calculation.Name), msgs[2]); + StringAssert.StartsWith(string.Format("De overloop en overslag berekening voor grasbekleding erosie kruin en binnentalud '{0}' is niet gelukt. Bekijk het foutrapport door op details te klikken.", + calculation.Name), msgs[3]); + StringAssert.StartsWith("De overloop en overslag berekening is uitgevoerd op de tijdelijke locatie", msgs[4]); + StringAssert.StartsWith(string.Format("Berekening van '{0}' beëindigd om: ", calculation.Name), msgs[5]); + }); + Assert.AreEqual(ActivityState.Failed, activity.State); + } + } + + [Test] public void Run_ValidOvertoppingCalculation_PerformValidationAndCalculationAndLogStartAndEnd() { // Setup @@ -265,24 +588,17 @@ mocks.VerifyAll(); } + #endregion + + #region Dike height calculations + [Test] [TestCase(DikeHeightCalculationType.CalculateByAssessmentSectionNorm)] [TestCase(DikeHeightCalculationType.CalculateByProfileSpecificRequiredProbability)] - public void Run_InvalidDikeHeightCalculation_PerformValidationAndCalculationAndLogStartAndEndWithError( - DikeHeightCalculationType dikeHeightCalculationType) + public void Run_InvalidDikeHeightCalculationWithExceptionAndLastErrorPresent_LogError(DikeHeightCalculationType dikeHeightCalculationType) { // Setup - var mocks = new MockRepository(); - var observerMock = mocks.StrictMock(); - mocks.ReplayAll(); - - var assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike) - { - FailureMechanismContribution = - { - Norm = 1 - } - }; + var assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike); ImportHydraulicBoundaryDatabase(assessmentSection); AddSectionToAssessmentSection(assessmentSection); @@ -296,16 +612,14 @@ } }; - calculation.Attach(observerMock); - - var activity = new GrassCoverErosionInwardsCalculationActivity(calculation, validFile, assessmentSection.GrassCoverErosionInwards, assessmentSection); - using (new HydraRingCalculatorFactoryConfig()) { TestHydraulicLoadsCalculator calculator = ((TestHydraRingCalculatorFactory) HydraRingCalculatorFactory.Instance).DikeHeightCalculator; - calculator.Value = double.NaN; + calculator.LastErrorFileContent = "An error occurred"; calculator.EndInFailure = true; + var activity = new GrassCoverErosionInwardsCalculationActivity(calculation, validFile, assessmentSection.GrassCoverErosionInwards, assessmentSection); + // Call Action call = () => activity.Run(); @@ -318,28 +632,21 @@ StringAssert.StartsWith(string.Format("Validatie van '{0}' beëindigd om: ", calculation.Name), msgs[1]); StringAssert.StartsWith(string.Format("Berekening van '{0}' gestart om: ", calculation.Name), msgs[2]); StringAssert.StartsWith("De overloop en overslag berekening is uitgevoerd op de tijdelijke locatie", msgs[3]); - StringAssert.StartsWith(string.Format("De HBN berekening voor grasbekleding erosie kruin en binnentalud '{0}' is niet gelukt.", calculation.Name), msgs[4]); + StringAssert.StartsWith(string.Format("De HBN berekening voor grasbekleding erosie kruin en binnentalud '{0}' is niet gelukt. Bekijk het foutrapport door op details te klikken.", calculation.Name), msgs[4]); StringAssert.StartsWith("De HBN berekening is uitgevoerd op de tijdelijke locatie", msgs[5]); StringAssert.StartsWith(string.Format("Berekening van '{0}' beëindigd om: ", calculation.Name), msgs[6]); }); Assert.AreEqual(ActivityState.Executed, activity.State); - mocks.VerifyAll(); // Expect no calls on the observer } } [Test] [TestCase(DikeHeightCalculationType.CalculateByAssessmentSectionNorm)] [TestCase(DikeHeightCalculationType.CalculateByProfileSpecificRequiredProbability)] - public void Run_ValidDikeHeightCalculation_PerformValidationAndCalculationAndLogStartAndEndError(DikeHeightCalculationType dikeHeightCalculationType) + public void Run_InvalidDikeHeightCalculationWithExceptionAndNoLastErrorPresent_LogError(DikeHeightCalculationType dikeHeightCalculationType) { // Setup - var assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike) - { - FailureMechanismContribution = - { - Norm = 1 - } - }; + var assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike); ImportHydraulicBoundaryDatabase(assessmentSection); AddSectionToAssessmentSection(assessmentSection); @@ -353,14 +660,13 @@ } }; - var activity = new GrassCoverErosionInwardsCalculationActivity(calculation, validFile, assessmentSection.GrassCoverErosionInwards, assessmentSection); - using (new HydraRingCalculatorFactoryConfig()) { TestHydraulicLoadsCalculator calculator = ((TestHydraRingCalculatorFactory) HydraRingCalculatorFactory.Instance).DikeHeightCalculator; - calculator.Value = 2; - calculator.ReliabilityIndex = -1; + calculator.EndInFailure = true; + var activity = new GrassCoverErosionInwardsCalculationActivity(calculation, validFile, assessmentSection.GrassCoverErosionInwards, assessmentSection); + // Call Action call = () => activity.Run(); @@ -373,8 +679,8 @@ StringAssert.StartsWith(string.Format("Validatie van '{0}' beëindigd om: ", calculation.Name), msgs[1]); StringAssert.StartsWith(string.Format("Berekening van '{0}' gestart om: ", calculation.Name), msgs[2]); StringAssert.StartsWith("De overloop en overslag berekening is uitgevoerd op de tijdelijke locatie", msgs[3]); - StringAssert.StartsWith("De HBN berekening is uitgevoerd op de tijdelijke locatie", msgs[4]); - StringAssert.StartsWith(string.Format("De HBN berekening voor grasbekleding erosie kruin en binnentalud '{0}' is niet geconvergeerd.", calculation.Name), msgs[5]); + StringAssert.StartsWith(string.Format("De HBN berekening voor grasbekleding erosie kruin en binnentalud '{0}' is niet gelukt. Er is geen foutrapport beschikbaar.", calculation.Name), msgs[4]); + StringAssert.StartsWith("De HBN berekening is uitgevoerd op de tijdelijke locatie", msgs[5]); StringAssert.StartsWith(string.Format("Berekening van '{0}' beëindigd om: ", calculation.Name), msgs[6]); }); Assert.AreEqual(ActivityState.Executed, activity.State); @@ -384,14 +690,9 @@ [Test] [TestCase(DikeHeightCalculationType.CalculateByAssessmentSectionNorm)] [TestCase(DikeHeightCalculationType.CalculateByProfileSpecificRequiredProbability)] - public void Finish_InvalidDikeHeightCalculation_OutputSetAndObserversNotified(DikeHeightCalculationType dikeHeightCalculationType) + public void Run_InvalidDikeHeightCalculationWithoutExceptionAndWithLastErrorPresent_LogError(DikeHeightCalculationType dikeHeightCalculationType) { // Setup - var mocks = new MockRepository(); - var observerMock = mocks.StrictMock(); - observerMock.Expect(o => o.UpdateObserver()); - mocks.ReplayAll(); - var assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike); ImportHydraulicBoundaryDatabase(assessmentSection); AddSectionToAssessmentSection(assessmentSection); @@ -406,116 +707,14 @@ } }; - calculation.Attach(observerMock); - - var activity = new GrassCoverErosionInwardsCalculationActivity(calculation, validFile, assessmentSection.GrassCoverErosionInwards, assessmentSection); - using (new HydraRingCalculatorFactoryConfig()) { TestHydraulicLoadsCalculator calculator = ((TestHydraRingCalculatorFactory) HydraRingCalculatorFactory.Instance).DikeHeightCalculator; - calculator.Value = double.NaN; - calculator.EndInFailure = true; + calculator.EndInFailure = false; + calculator.LastErrorFileContent = "An error occurred"; - activity.Run(); - } + var activity = new GrassCoverErosionInwardsCalculationActivity(calculation, validFile, assessmentSection.GrassCoverErosionInwards, assessmentSection); - // Call - activity.Finish(); - - // Assert - Assert.IsNotNull(calculation.Output); - Assert.IsNull(calculation.Output.DikeHeightOutput); - mocks.VerifyAll(); - } - - [Test] - [TestCase(DikeHeightCalculationType.CalculateByAssessmentSectionNorm)] - [TestCase(DikeHeightCalculationType.CalculateByProfileSpecificRequiredProbability)] - public void Finish_ValidDikeHeightCalculation_OutputSetAndObserversNotified(DikeHeightCalculationType dikeHeightCalculationType) - { - // Setup - var mocks = new MockRepository(); - var observerMock = mocks.StrictMock(); - observerMock.Expect(o => o.UpdateObserver()); - mocks.ReplayAll(); - - var assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike); - ImportHydraulicBoundaryDatabase(assessmentSection); - AddSectionToAssessmentSection(assessmentSection); - - var calculation = new GrassCoverErosionInwardsCalculation - { - InputParameters = - { - HydraulicBoundaryLocation = assessmentSection.HydraulicBoundaryDatabase.Locations.First(hl => hl.Id == 1300001), - DikeProfile = CreateDikeProfile(), - DikeHeightCalculationType = dikeHeightCalculationType - } - }; - - calculation.Attach(observerMock); - - var activity = new GrassCoverErosionInwardsCalculationActivity(calculation, validFile, assessmentSection.GrassCoverErosionInwards, assessmentSection); - - using (new HydraRingCalculatorFactoryConfig()) - { - activity.Run(); - } - - // Call - activity.Finish(); - - // Assert - Assert.IsNotNull(calculation.Output); - ProbabilityAssessmentOutput probabilisticAssessmentOutput = calculation.Output.ProbabilityAssessmentOutput; - Assert.IsFalse(double.IsNaN(probabilisticAssessmentOutput.Reliability)); - HydraulicLoadsOutput dikeHeightOutput = calculation.Output.DikeHeightOutput; - Assert.IsNotNull(dikeHeightOutput); - Assert.IsFalse(double.IsNaN(dikeHeightOutput.Result)); - mocks.VerifyAll(); - } - - [Test] - [TestCase(OvertoppingRateCalculationType.CalculateByAssessmentSectionNorm)] - [TestCase(OvertoppingRateCalculationType.CalculateByProfileSpecificRequiredProbability)] - public void Run_InvalidOvertoppingRateCalculation_PerformValidationAndCalculationAndLogStartAndEndWithError( - OvertoppingRateCalculationType overtoppingRateCalculationType) - { - // Setup - var mocks = new MockRepository(); - var observerMock = mocks.StrictMock(); - mocks.ReplayAll(); - - var assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike) - { - FailureMechanismContribution = - { - Norm = 1 - } - }; - ImportHydraulicBoundaryDatabase(assessmentSection); - AddSectionToAssessmentSection(assessmentSection); - - var calculation = new GrassCoverErosionInwardsCalculation - { - InputParameters = - { - HydraulicBoundaryLocation = assessmentSection.HydraulicBoundaryDatabase.Locations.First(hl => hl.Id == 1300001), - DikeProfile = CreateDikeProfile(), - OvertoppingRateCalculationType = overtoppingRateCalculationType - } - }; - - calculation.Attach(observerMock); - - var activity = new GrassCoverErosionInwardsCalculationActivity(calculation, validFile, assessmentSection.GrassCoverErosionInwards, assessmentSection); - - using (new HydraRingCalculatorFactoryConfig()) - { - TestHydraulicLoadsCalculator calculator = ((TestHydraRingCalculatorFactory) HydraRingCalculatorFactory.Instance).OvertoppingRateCalculator; - calculator.Value = double.NaN; - calculator.EndInFailure = true; - // Call Action call = () => activity.Run(); @@ -528,19 +727,18 @@ StringAssert.StartsWith(string.Format("Validatie van '{0}' beëindigd om: ", calculation.Name), msgs[1]); StringAssert.StartsWith(string.Format("Berekening van '{0}' gestart om: ", calculation.Name), msgs[2]); StringAssert.StartsWith("De overloop en overslag berekening is uitgevoerd op de tijdelijke locatie", msgs[3]); - StringAssert.StartsWith(string.Format("De overslagdebiet berekening voor grasbekleding erosie kruin en binnentalud '{0}' is niet gelukt.", calculation.Name), msgs[4]); - StringAssert.StartsWith("De overslagdebiet berekening is uitgevoerd op de tijdelijke locatie", msgs[5]); + StringAssert.StartsWith(string.Format("De HBN berekening voor grasbekleding erosie kruin en binnentalud '{0}' is niet gelukt. Bekijk het foutrapport door op details te klikken.", calculation.Name), msgs[4]); + StringAssert.StartsWith("De HBN berekening is uitgevoerd op de tijdelijke locatie", msgs[5]); StringAssert.StartsWith(string.Format("Berekening van '{0}' beëindigd om: ", calculation.Name), msgs[6]); }); Assert.AreEqual(ActivityState.Executed, activity.State); - mocks.VerifyAll(); // Expect no calls on the observer } } [Test] - [TestCase(OvertoppingRateCalculationType.CalculateByAssessmentSectionNorm)] - [TestCase(OvertoppingRateCalculationType.CalculateByProfileSpecificRequiredProbability)] - public void Run_ValidOvertoppingRateCalculation_PerformValidationAndCalculationAndLogStartAndEndError(OvertoppingRateCalculationType overtoppingRateCalculationType) + [TestCase(DikeHeightCalculationType.CalculateByAssessmentSectionNorm)] + [TestCase(DikeHeightCalculationType.CalculateByProfileSpecificRequiredProbability)] + public void Run_ValidDikeHeightCalculation_PerformValidationAndCalculationAndLogStartAndEndError(DikeHeightCalculationType dikeHeightCalculationType) { // Setup var assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike) @@ -559,15 +757,15 @@ { HydraulicBoundaryLocation = assessmentSection.HydraulicBoundaryDatabase.Locations.First(hl => hl.Id == 1300001), DikeProfile = CreateDikeProfile(), - OvertoppingRateCalculationType = overtoppingRateCalculationType + DikeHeightCalculationType = dikeHeightCalculationType } }; var activity = new GrassCoverErosionInwardsCalculationActivity(calculation, validFile, assessmentSection.GrassCoverErosionInwards, assessmentSection); using (new HydraRingCalculatorFactoryConfig()) { - TestHydraulicLoadsCalculator calculator = ((TestHydraRingCalculatorFactory) HydraRingCalculatorFactory.Instance).OvertoppingRateCalculator; + TestHydraulicLoadsCalculator calculator = ((TestHydraRingCalculatorFactory) HydraRingCalculatorFactory.Instance).DikeHeightCalculator; calculator.Value = 2; calculator.ReliabilityIndex = -1; @@ -583,18 +781,18 @@ StringAssert.StartsWith(string.Format("Validatie van '{0}' beëindigd om: ", calculation.Name), msgs[1]); StringAssert.StartsWith(string.Format("Berekening van '{0}' gestart om: ", calculation.Name), msgs[2]); StringAssert.StartsWith("De overloop en overslag berekening is uitgevoerd op de tijdelijke locatie", msgs[3]); - StringAssert.StartsWith("De overslagdebiet berekening is uitgevoerd op de tijdelijke locatie", msgs[4]); - StringAssert.StartsWith(string.Format("De overslagdebiet berekening voor grasbekleding erosie kruin en binnentalud '{0}' is niet geconvergeerd.", calculation.Name), msgs[5]); + StringAssert.StartsWith("De HBN berekening is uitgevoerd op de tijdelijke locatie", msgs[4]); + StringAssert.StartsWith(string.Format("De HBN berekening voor grasbekleding erosie kruin en binnentalud '{0}' is niet geconvergeerd.", calculation.Name), msgs[5]); StringAssert.StartsWith(string.Format("Berekening van '{0}' beëindigd om: ", calculation.Name), msgs[6]); }); Assert.AreEqual(ActivityState.Executed, activity.State); } } [Test] - [TestCase(OvertoppingRateCalculationType.CalculateByAssessmentSectionNorm)] - [TestCase(OvertoppingRateCalculationType.CalculateByProfileSpecificRequiredProbability)] - public void Finish_InvalidOvertoppingRateCalculation_OutputSetAndObserversNotified(OvertoppingRateCalculationType overtoppingRateCalculationType) + [TestCase(DikeHeightCalculationType.CalculateByAssessmentSectionNorm)] + [TestCase(DikeHeightCalculationType.CalculateByProfileSpecificRequiredProbability)] + public void Finish_InvalidDikeHeightCalculation_OutputSetAndObserversNotified(DikeHeightCalculationType dikeHeightCalculationType) { // Setup var mocks = new MockRepository(); @@ -612,7 +810,7 @@ { HydraulicBoundaryLocation = assessmentSection.HydraulicBoundaryDatabase.Locations.First(hl => hl.Id == 1300001), DikeProfile = CreateDikeProfile(), - OvertoppingRateCalculationType = overtoppingRateCalculationType + DikeHeightCalculationType = dikeHeightCalculationType } }; @@ -622,7 +820,7 @@ using (new HydraRingCalculatorFactoryConfig()) { - TestHydraulicLoadsCalculator calculator = ((TestHydraRingCalculatorFactory) HydraRingCalculatorFactory.Instance).OvertoppingRateCalculator; + TestHydraulicLoadsCalculator calculator = ((TestHydraRingCalculatorFactory) HydraRingCalculatorFactory.Instance).DikeHeightCalculator; calculator.Value = double.NaN; calculator.EndInFailure = true; @@ -639,9 +837,9 @@ } [Test] - [TestCase(OvertoppingRateCalculationType.CalculateByAssessmentSectionNorm)] - [TestCase(OvertoppingRateCalculationType.CalculateByProfileSpecificRequiredProbability)] - public void Finish_ValidOvertoppingRateCalculation_OutputSetAndObserversNotified(OvertoppingRateCalculationType overtoppingRateCalculationType) + [TestCase(DikeHeightCalculationType.CalculateByAssessmentSectionNorm)] + [TestCase(DikeHeightCalculationType.CalculateByProfileSpecificRequiredProbability)] + public void Finish_ValidDikeHeightCalculation_OutputSetAndObserversNotified(DikeHeightCalculationType dikeHeightCalculationType) { // Setup var mocks = new MockRepository(); @@ -659,7 +857,7 @@ { HydraulicBoundaryLocation = assessmentSection.HydraulicBoundaryDatabase.Locations.First(hl => hl.Id == 1300001), DikeProfile = CreateDikeProfile(), - OvertoppingRateCalculationType = overtoppingRateCalculationType + DikeHeightCalculationType = dikeHeightCalculationType } }; @@ -679,76 +877,20 @@ Assert.IsNotNull(calculation.Output); ProbabilityAssessmentOutput probabilisticAssessmentOutput = calculation.Output.ProbabilityAssessmentOutput; Assert.IsFalse(double.IsNaN(probabilisticAssessmentOutput.Reliability)); - HydraulicLoadsOutput overtoppingRateOutput = calculation.Output.OvertoppingRateOutput; - Assert.IsNotNull(overtoppingRateOutput); - Assert.IsFalse(double.IsNaN(overtoppingRateOutput.Result)); + HydraulicLoadsOutput dikeHeightOutput = calculation.Output.DikeHeightOutput; + Assert.IsNotNull(dikeHeightOutput); + Assert.IsFalse(double.IsNaN(dikeHeightOutput.Result)); mocks.VerifyAll(); } - [Test] - [Combinatorial] - public void Run_CombinationOfCalculations_ProgressTextSetAccordingly([Values(DikeHeightCalculationType.CalculateByAssessmentSectionNorm, - DikeHeightCalculationType.CalculateByProfileSpecificRequiredProbability, - DikeHeightCalculationType.NoCalculation)] DikeHeightCalculationType dikeHeightCalculationType, - [Values(OvertoppingRateCalculationType.CalculateByAssessmentSectionNorm, - OvertoppingRateCalculationType.CalculateByProfileSpecificRequiredProbability, - OvertoppingRateCalculationType.NoCalculation)] OvertoppingRateCalculationType overtoppingRateCalculationType) - { - var assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike); - ImportHydraulicBoundaryDatabase(assessmentSection); - AddSectionToAssessmentSection(assessmentSection); + #endregion - var calculation = new GrassCoverErosionInwardsCalculation - { - InputParameters = - { - HydraulicBoundaryLocation = assessmentSection.HydraulicBoundaryDatabase.Locations.First(hl => hl.Id == 1300001), - DikeProfile = CreateDikeProfile(), - DikeHeightCalculationType = dikeHeightCalculationType, - OvertoppingRateCalculationType = overtoppingRateCalculationType - } - }; + #region Overtopping rate calculations - var activity = new GrassCoverErosionInwardsCalculationActivity(calculation, validFile, assessmentSection.GrassCoverErosionInwards, assessmentSection); - - var progressTexts = ""; - - activity.ProgressChanged += (s, e) => progressTexts += activity.ProgressText + Environment.NewLine; - - using (new HydraRingCalculatorFactoryConfig()) - { - // Call - activity.Run(); - } - - // Assert - int totalNumberOfCalculations = dikeHeightCalculationType != DikeHeightCalculationType.NoCalculation - ? overtoppingRateCalculationType != OvertoppingRateCalculationType.NoCalculation - ? 3 - : 2 - : overtoppingRateCalculationType != OvertoppingRateCalculationType.NoCalculation - ? 2 - : 1; - - string expectedProgressTexts = $"Stap 1 van {totalNumberOfCalculations} | Uitvoeren overloop en overslag berekening" + Environment.NewLine; - - if (dikeHeightCalculationType != DikeHeightCalculationType.NoCalculation) - { - expectedProgressTexts += $"Stap 2 van {totalNumberOfCalculations} | Uitvoeren HBN berekening" + Environment.NewLine; - } - - if (overtoppingRateCalculationType != OvertoppingRateCalculationType.NoCalculation) - { - expectedProgressTexts += $"Stap {totalNumberOfCalculations} van {totalNumberOfCalculations} | Uitvoeren overslagdebiet berekening" + Environment.NewLine; - } - - Assert.AreEqual(expectedProgressTexts, progressTexts); - } - [Test] - [TestCase(DikeHeightCalculationType.CalculateByAssessmentSectionNorm, TestName = "Run_OvertoppingCalculationFailedExceptionLastError_LogErrorThrowException(AssessmentSectionNorm)")] - [TestCase(DikeHeightCalculationType.CalculateByProfileSpecificRequiredProbability, TestName = "Run_OvertoppingCalculationFailedExceptionLastError_LogErrorThrowException(ProfileProbability)")] - public void Run_OvertoppingCalculationFailedWithExceptionAndLastErrorPresent_LogErrorAndThrowException(DikeHeightCalculationType dikeHeightCalculationType) + [TestCase(OvertoppingRateCalculationType.CalculateByAssessmentSectionNorm)] + [TestCase(OvertoppingRateCalculationType.CalculateByProfileSpecificRequiredProbability)] + public void Run_InvalidOvertoppingRateCalculationWithExceptionAndLastErrorPresent_LogError(OvertoppingRateCalculationType overtoppingRateCalculationType) { // Setup var assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike); @@ -761,13 +903,13 @@ { HydraulicBoundaryLocation = assessmentSection.HydraulicBoundaryDatabase.Locations.First(hl => hl.Id == 1300001), DikeProfile = CreateDikeProfile(), - DikeHeightCalculationType = dikeHeightCalculationType + OvertoppingRateCalculationType = overtoppingRateCalculationType } }; using (new HydraRingCalculatorFactoryConfig()) { - TestOvertoppingCalculator calculator = ((TestHydraRingCalculatorFactory) HydraRingCalculatorFactory.Instance).OvertoppingCalculator; + TestHydraulicLoadsCalculator calculator = ((TestHydraRingCalculatorFactory) HydraRingCalculatorFactory.Instance).OvertoppingRateCalculator; calculator.LastErrorFileContent = "An error occurred"; calculator.EndInFailure = true; @@ -780,22 +922,23 @@ TestHelper.AssertLogMessages(call, messages => { string[] msgs = messages.ToArray(); - Assert.AreEqual(6, msgs.Length); + Assert.AreEqual(7, msgs.Length); StringAssert.StartsWith(string.Format("Validatie van '{0}' gestart om: ", calculation.Name), msgs[0]); StringAssert.StartsWith(string.Format("Validatie van '{0}' beëindigd om: ", calculation.Name), msgs[1]); StringAssert.StartsWith(string.Format("Berekening van '{0}' gestart om: ", calculation.Name), msgs[2]); - StringAssert.StartsWith(string.Format("De overloop en overslag berekening voor grasbekleding erosie kruin en binnentalud '{0}' is niet gelukt. Bekijk het foutrapport door op details te klikken.", calculation.Name), msgs[3]); - StringAssert.StartsWith("De overloop en overslag berekening is uitgevoerd op de tijdelijke locatie", msgs[4]); - StringAssert.StartsWith(string.Format("Berekening van '{0}' beëindigd om: ", calculation.Name), msgs[5]); + StringAssert.StartsWith("De overloop en overslag berekening is uitgevoerd op de tijdelijke locatie", msgs[3]); + StringAssert.StartsWith(string.Format("De overslagdebiet berekening voor grasbekleding erosie kruin en binnentalud '{0}' is niet gelukt. Bekijk het foutrapport door op details te klikken.", calculation.Name), msgs[4]); + StringAssert.StartsWith("De overslagdebiet berekening is uitgevoerd op de tijdelijke locatie", msgs[5]); + StringAssert.StartsWith(string.Format("Berekening van '{0}' beëindigd om: ", calculation.Name), msgs[6]); }); - Assert.AreEqual(ActivityState.Failed, activity.State); + Assert.AreEqual(ActivityState.Executed, activity.State); } } [Test] - [TestCase(DikeHeightCalculationType.CalculateByAssessmentSectionNorm, TestName = "Run_OvertoppingCalculationFailedExceptionNoLastError_LogErrorThrowException(AssessmentSectionNorm)")] - [TestCase(DikeHeightCalculationType.CalculateByProfileSpecificRequiredProbability, TestName = "Run_OvertoppingCalculationFailedExceptionNoLastError_LogErrorThrowException(ProfileProbability)")] - public void Run_OvertoppingCalculationFailedWithExceptionAndNoLastErrorPresent_LogErrorAndThrowException(DikeHeightCalculationType dikeHeightCalculationType) + [TestCase(OvertoppingRateCalculationType.CalculateByAssessmentSectionNorm)] + [TestCase(OvertoppingRateCalculationType.CalculateByProfileSpecificRequiredProbability)] + public void Run_InvalidOvertoppingRateCalculationWithExceptionAndNoLastErrorPresent_LogError(OvertoppingRateCalculationType overtoppingRateCalculationType) { // Setup var assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike); @@ -808,13 +951,13 @@ { HydraulicBoundaryLocation = assessmentSection.HydraulicBoundaryDatabase.Locations.First(hl => hl.Id == 1300001), DikeProfile = CreateDikeProfile(), - DikeHeightCalculationType = dikeHeightCalculationType + OvertoppingRateCalculationType = overtoppingRateCalculationType } }; using (new HydraRingCalculatorFactoryConfig()) { - TestOvertoppingCalculator calculator = ((TestHydraRingCalculatorFactory) HydraRingCalculatorFactory.Instance).OvertoppingCalculator; + TestHydraulicLoadsCalculator calculator = ((TestHydraRingCalculatorFactory) HydraRingCalculatorFactory.Instance).OvertoppingRateCalculator; calculator.EndInFailure = true; var activity = new GrassCoverErosionInwardsCalculationActivity(calculation, validFile, assessmentSection.GrassCoverErosionInwards, assessmentSection); @@ -826,22 +969,23 @@ TestHelper.AssertLogMessages(call, messages => { string[] msgs = messages.ToArray(); - Assert.AreEqual(6, msgs.Length); + Assert.AreEqual(7, msgs.Length); StringAssert.StartsWith(string.Format("Validatie van '{0}' gestart om: ", calculation.Name), msgs[0]); StringAssert.StartsWith(string.Format("Validatie van '{0}' beëindigd om: ", calculation.Name), msgs[1]); StringAssert.StartsWith(string.Format("Berekening van '{0}' gestart om: ", calculation.Name), msgs[2]); - StringAssert.StartsWith(string.Format("De overloop en overslag berekening voor grasbekleding erosie kruin en binnentalud '{0}' is niet gelukt. Er is geen foutrapport beschikbaar.", calculation.Name), msgs[3]); - StringAssert.StartsWith("De overloop en overslag berekening is uitgevoerd op de tijdelijke locatie", msgs[4]); - StringAssert.StartsWith(string.Format("Berekening van '{0}' beëindigd om: ", calculation.Name), msgs[5]); + StringAssert.StartsWith("De overloop en overslag berekening is uitgevoerd op de tijdelijke locatie", msgs[3]); + StringAssert.StartsWith(string.Format("De overslagdebiet berekening voor grasbekleding erosie kruin en binnentalud '{0}' is niet gelukt. Er is geen foutrapport beschikbaar.", calculation.Name), msgs[4]); + StringAssert.StartsWith("De overslagdebiet berekening is uitgevoerd op de tijdelijke locatie", msgs[5]); + StringAssert.StartsWith(string.Format("Berekening van '{0}' beëindigd om: ", calculation.Name), msgs[6]); }); - Assert.AreEqual(ActivityState.Failed, activity.State); + Assert.AreEqual(ActivityState.Executed, activity.State); } } [Test] - [TestCase(DikeHeightCalculationType.CalculateByAssessmentSectionNorm, TestName = "Run_OvertoppingCalculationFailedNoExceptionLastError_LogErrorThrowException(AssessmentSectionNorm)")] - [TestCase(DikeHeightCalculationType.CalculateByProfileSpecificRequiredProbability, TestName = "Run_OvertoppingCalculationFailedNoExceptionLastError_LogErrorThrowException(ProfileProbability)")] - public void Run_OvertoppingCalculationFailedWithoutExceptionAndWithLastErrorPresent_LogErrorAndThrowException(DikeHeightCalculationType dikeHeightCalculationType) + [TestCase(OvertoppingRateCalculationType.CalculateByAssessmentSectionNorm)] + [TestCase(OvertoppingRateCalculationType.CalculateByProfileSpecificRequiredProbability)] + public void Run_InvalidOvertoppingRateCalculationWithoutExceptionAndWithLastErrorPresent_LogError(OvertoppingRateCalculationType overtoppingRateCalculationType) { // Setup var assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike); @@ -854,13 +998,13 @@ { HydraulicBoundaryLocation = assessmentSection.HydraulicBoundaryDatabase.Locations.First(hl => hl.Id == 1300001), DikeProfile = CreateDikeProfile(), - DikeHeightCalculationType = dikeHeightCalculationType + OvertoppingRateCalculationType = overtoppingRateCalculationType } }; using (new HydraRingCalculatorFactoryConfig()) { - TestOvertoppingCalculator calculator = ((TestHydraRingCalculatorFactory) HydraRingCalculatorFactory.Instance).OvertoppingCalculator; + TestHydraulicLoadsCalculator calculator = ((TestHydraRingCalculatorFactory) HydraRingCalculatorFactory.Instance).OvertoppingRateCalculator; calculator.EndInFailure = false; calculator.LastErrorFileContent = "An error occurred"; @@ -873,121 +1017,32 @@ TestHelper.AssertLogMessages(call, messages => { string[] msgs = messages.ToArray(); - Assert.AreEqual(6, msgs.Length); - StringAssert.StartsWith(string.Format("Validatie van '{0}' gestart om: ", calculation.Name), msgs[0]); - StringAssert.StartsWith(string.Format("Validatie van '{0}' beëindigd om: ", calculation.Name), msgs[1]); - StringAssert.StartsWith(string.Format("Berekening van '{0}' gestart om: ", calculation.Name), msgs[2]); - StringAssert.StartsWith(string.Format("De overloop en overslag berekening voor grasbekleding erosie kruin en binnentalud '{0}' is niet gelukt. Bekijk het foutrapport door op details te klikken.", - calculation.Name), msgs[3]); - StringAssert.StartsWith("De overloop en overslag berekening is uitgevoerd op de tijdelijke locatie", msgs[4]); - StringAssert.StartsWith(string.Format("Berekening van '{0}' beëindigd om: ", calculation.Name), msgs[5]); - }); - Assert.AreEqual(ActivityState.Failed, activity.State); - } - } - - [Test] - [TestCase(DikeHeightCalculationType.CalculateByAssessmentSectionNorm, TestName = "Run_DikeHeightCalculationFailedWithExceptionLastError_LogError(AssessmentSectionNorm)")] - [TestCase(DikeHeightCalculationType.CalculateByProfileSpecificRequiredProbability, TestName = "Run_DikeHeightCalculationFailedWithExceptionLastError_LogError(ProfileProbability)")] - public void Run_DikeHeightCalculationFailedWithExceptionAndLastErrorPresent_LogError(DikeHeightCalculationType dikeHeightCalculationType) - { - // Setup - var assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike); - ImportHydraulicBoundaryDatabase(assessmentSection); - AddSectionToAssessmentSection(assessmentSection); - - var calculation = new GrassCoverErosionInwardsCalculation - { - InputParameters = - { - HydraulicBoundaryLocation = assessmentSection.HydraulicBoundaryDatabase.Locations.First(hl => hl.Id == 1300001), - DikeProfile = CreateDikeProfile(), - DikeHeightCalculationType = dikeHeightCalculationType - } - }; - - using (new HydraRingCalculatorFactoryConfig()) - { - TestHydraulicLoadsCalculator calculator = ((TestHydraRingCalculatorFactory) HydraRingCalculatorFactory.Instance).DikeHeightCalculator; - calculator.LastErrorFileContent = "An error occurred"; - calculator.EndInFailure = true; - - var activity = new GrassCoverErosionInwardsCalculationActivity(calculation, validFile, assessmentSection.GrassCoverErosionInwards, assessmentSection); - - // Call - Action call = () => activity.Run(); - - // Assert - TestHelper.AssertLogMessages(call, messages => - { - string[] msgs = messages.ToArray(); Assert.AreEqual(7, msgs.Length); StringAssert.StartsWith(string.Format("Validatie van '{0}' gestart om: ", calculation.Name), msgs[0]); StringAssert.StartsWith(string.Format("Validatie van '{0}' beëindigd om: ", calculation.Name), msgs[1]); StringAssert.StartsWith(string.Format("Berekening van '{0}' gestart om: ", calculation.Name), msgs[2]); StringAssert.StartsWith("De overloop en overslag berekening is uitgevoerd op de tijdelijke locatie", msgs[3]); - StringAssert.StartsWith(string.Format("De HBN berekening voor grasbekleding erosie kruin en binnentalud '{0}' is niet gelukt. Bekijk het foutrapport door op details te klikken.", calculation.Name), msgs[4]); - StringAssert.StartsWith("De HBN berekening is uitgevoerd op de tijdelijke locatie", msgs[5]); + StringAssert.StartsWith(string.Format("De overslagdebiet berekening voor grasbekleding erosie kruin en binnentalud '{0}' is niet gelukt. Bekijk het foutrapport door op details te klikken.", calculation.Name), msgs[4]); + StringAssert.StartsWith("De overslagdebiet berekening is uitgevoerd op de tijdelijke locatie", msgs[5]); StringAssert.StartsWith(string.Format("Berekening van '{0}' beëindigd om: ", calculation.Name), msgs[6]); }); Assert.AreEqual(ActivityState.Executed, activity.State); } } [Test] - [TestCase(DikeHeightCalculationType.CalculateByAssessmentSectionNorm, TestName = "Run_DikeHeightCalculationFailedWithExceptionNoLastError_LogError(AssessmentSectionNorm)")] - [TestCase(DikeHeightCalculationType.CalculateByProfileSpecificRequiredProbability, TestName = "Run_DikeHeightCalculationFailedWithExceptionNoLastError_LogError(ProfileProbability)")] - public void Run_DikeHeightCalculationFailedWithExceptionAndNoLastErrorPresent_LogError(DikeHeightCalculationType dikeHeightCalculationType) + [TestCase(OvertoppingRateCalculationType.CalculateByAssessmentSectionNorm)] + [TestCase(OvertoppingRateCalculationType.CalculateByProfileSpecificRequiredProbability)] + public void Run_ValidOvertoppingRateCalculation_PerformValidationAndCalculationAndLogStartAndEndError(OvertoppingRateCalculationType overtoppingRateCalculationType) { // Setup - var assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike); - ImportHydraulicBoundaryDatabase(assessmentSection); - AddSectionToAssessmentSection(assessmentSection); - - var calculation = new GrassCoverErosionInwardsCalculation + var assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike) { - InputParameters = + FailureMechanismContribution = { - HydraulicBoundaryLocation = assessmentSection.HydraulicBoundaryDatabase.Locations.First(hl => hl.Id == 1300001), - DikeProfile = CreateDikeProfile(), - DikeHeightCalculationType = dikeHeightCalculationType + Norm = 1 } }; - - using (new HydraRingCalculatorFactoryConfig()) - { - TestHydraulicLoadsCalculator calculator = ((TestHydraRingCalculatorFactory) HydraRingCalculatorFactory.Instance).DikeHeightCalculator; - calculator.EndInFailure = true; - - var activity = new GrassCoverErosionInwardsCalculationActivity(calculation, validFile, assessmentSection.GrassCoverErosionInwards, assessmentSection); - - // Call - Action call = () => activity.Run(); - - // Assert - TestHelper.AssertLogMessages(call, messages => - { - string[] msgs = messages.ToArray(); - Assert.AreEqual(7, msgs.Length); - StringAssert.StartsWith(string.Format("Validatie van '{0}' gestart om: ", calculation.Name), msgs[0]); - StringAssert.StartsWith(string.Format("Validatie van '{0}' beëindigd om: ", calculation.Name), msgs[1]); - StringAssert.StartsWith(string.Format("Berekening van '{0}' gestart om: ", calculation.Name), msgs[2]); - StringAssert.StartsWith("De overloop en overslag berekening is uitgevoerd op de tijdelijke locatie", msgs[3]); - StringAssert.StartsWith(string.Format("De HBN berekening voor grasbekleding erosie kruin en binnentalud '{0}' is niet gelukt. Er is geen foutrapport beschikbaar.", calculation.Name), msgs[4]); - StringAssert.StartsWith("De HBN berekening is uitgevoerd op de tijdelijke locatie", msgs[5]); - StringAssert.StartsWith(string.Format("Berekening van '{0}' beëindigd om: ", calculation.Name), msgs[6]); - }); - Assert.AreEqual(ActivityState.Executed, activity.State); - } - } - - [Test] - [TestCase(DikeHeightCalculationType.CalculateByAssessmentSectionNorm, TestName = "Run_DikeHeightCalculationFailedWithoutExceptionWithLastError_LogError(AssessmentSectionNorm)")] - [TestCase(DikeHeightCalculationType.CalculateByProfileSpecificRequiredProbability, TestName = "Run_DikeHeightCalculationFailedWithoutExceptionWithLastError_LogError(ProfileProbability)")] - public void Run_DikeHeightCalculationFailedWithoutExceptionAndWithLastErrorPresent_LogError(DikeHeightCalculationType dikeHeightCalculationType) - { - // Setup - var assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike); ImportHydraulicBoundaryDatabase(assessmentSection); AddSectionToAssessmentSection(assessmentSection); @@ -997,18 +1052,18 @@ { HydraulicBoundaryLocation = assessmentSection.HydraulicBoundaryDatabase.Locations.First(hl => hl.Id == 1300001), DikeProfile = CreateDikeProfile(), - DikeHeightCalculationType = dikeHeightCalculationType + OvertoppingRateCalculationType = overtoppingRateCalculationType } }; + var activity = new GrassCoverErosionInwardsCalculationActivity(calculation, validFile, assessmentSection.GrassCoverErosionInwards, assessmentSection); + using (new HydraRingCalculatorFactoryConfig()) { - TestHydraulicLoadsCalculator calculator = ((TestHydraRingCalculatorFactory) HydraRingCalculatorFactory.Instance).DikeHeightCalculator; - calculator.EndInFailure = false; - calculator.LastErrorFileContent = "An error occurred"; + TestHydraulicLoadsCalculator calculator = ((TestHydraRingCalculatorFactory) HydraRingCalculatorFactory.Instance).OvertoppingRateCalculator; + calculator.Value = 2; + calculator.ReliabilityIndex = -1; - var activity = new GrassCoverErosionInwardsCalculationActivity(calculation, validFile, assessmentSection.GrassCoverErosionInwards, assessmentSection); - // Call Action call = () => activity.Run(); @@ -1021,18 +1076,25 @@ StringAssert.StartsWith(string.Format("Validatie van '{0}' beëindigd om: ", calculation.Name), msgs[1]); StringAssert.StartsWith(string.Format("Berekening van '{0}' gestart om: ", calculation.Name), msgs[2]); StringAssert.StartsWith("De overloop en overslag berekening is uitgevoerd op de tijdelijke locatie", msgs[3]); - StringAssert.StartsWith(string.Format("De HBN berekening voor grasbekleding erosie kruin en binnentalud '{0}' is niet gelukt. Bekijk het foutrapport door op details te klikken.", calculation.Name), msgs[4]); - StringAssert.StartsWith("De HBN berekening is uitgevoerd op de tijdelijke locatie", msgs[5]); + StringAssert.StartsWith("De overslagdebiet berekening is uitgevoerd op de tijdelijke locatie", msgs[4]); + StringAssert.StartsWith(string.Format("De overslagdebiet berekening voor grasbekleding erosie kruin en binnentalud '{0}' is niet geconvergeerd.", calculation.Name), msgs[5]); StringAssert.StartsWith(string.Format("Berekening van '{0}' beëindigd om: ", calculation.Name), msgs[6]); }); Assert.AreEqual(ActivityState.Executed, activity.State); } } [Test] - public void Run_ValidOvertoppingCalculation_InputPropertiesCorrectlySendToService() + [TestCase(OvertoppingRateCalculationType.CalculateByAssessmentSectionNorm)] + [TestCase(OvertoppingRateCalculationType.CalculateByProfileSpecificRequiredProbability)] + public void Finish_InvalidOvertoppingRateCalculation_OutputSetAndObserversNotified(OvertoppingRateCalculationType overtoppingRateCalculationType) { // Setup + var mocks = new MockRepository(); + var observerMock = mocks.StrictMock(); + observerMock.Expect(o => o.UpdateObserver()); + mocks.ReplayAll(); + var assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike); ImportHydraulicBoundaryDatabase(assessmentSection); AddSectionToAssessmentSection(assessmentSection); @@ -1042,64 +1104,44 @@ InputParameters = { HydraulicBoundaryLocation = assessmentSection.HydraulicBoundaryDatabase.Locations.First(hl => hl.Id == 1300001), - DikeProfile = CreateDikeProfile() + DikeProfile = CreateDikeProfile(), + OvertoppingRateCalculationType = overtoppingRateCalculationType } }; + calculation.Attach(observerMock); + var activity = new GrassCoverErosionInwardsCalculationActivity(calculation, validFile, assessmentSection.GrassCoverErosionInwards, assessmentSection); using (new HydraRingCalculatorFactoryConfig()) { - // Call + TestHydraulicLoadsCalculator calculator = ((TestHydraRingCalculatorFactory) HydraRingCalculatorFactory.Instance).OvertoppingRateCalculator; + calculator.Value = double.NaN; + calculator.EndInFailure = true; + activity.Run(); + } - // Assert - TestOvertoppingCalculator testOvertoppingCalculator = ((TestHydraRingCalculatorFactory) HydraRingCalculatorFactory.Instance).OvertoppingCalculator; - OvertoppingCalculationInput[] overtoppingCalculationInputs = testOvertoppingCalculator.ReceivedInputs.ToArray(); - Assert.AreEqual(1, overtoppingCalculationInputs.Length); + // Call + activity.Finish(); - OvertoppingCalculationInput actualInput = overtoppingCalculationInputs[0]; - GeneralGrassCoverErosionInwardsInput generalInput = assessmentSection.GrassCoverErosionInwards.GeneralInput; - - GrassCoverErosionInwardsInput input = calculation.InputParameters; - var expectedInput = new OvertoppingCalculationInput(calculation.InputParameters.HydraulicBoundaryLocation.Id, - calculation.InputParameters.Orientation, - calculation.InputParameters.DikeGeometry.Select(roughnessPoint => new HydraRingRoughnessProfilePoint(roughnessPoint.Point.X, roughnessPoint.Point.Y, roughnessPoint.Roughness)), - input.ForeshoreGeometry.Select(c => new HydraRingForelandPoint(c.X, c.Y)), - new HydraRingBreakWater((int) input.BreakWater.Type, input.BreakWater.Height), - calculation.InputParameters.DikeHeight, - generalInput.CriticalOvertoppingModelFactor, - generalInput.FbFactor.Mean, - generalInput.FbFactor.StandardDeviation, - generalInput.FbFactor.LowerBoundary, - generalInput.FbFactor.UpperBoundary, - generalInput.FnFactor.Mean, - generalInput.FnFactor.StandardDeviation, - generalInput.FnFactor.LowerBoundary, - generalInput.FnFactor.UpperBoundary, - generalInput.OvertoppingModelFactor, - calculation.InputParameters.CriticalFlowRate.Mean, - calculation.InputParameters.CriticalFlowRate.StandardDeviation, - generalInput.FrunupModelFactor.Mean, - generalInput.FrunupModelFactor.StandardDeviation, - generalInput.FrunupModelFactor.LowerBoundary, - generalInput.FrunupModelFactor.UpperBoundary, - generalInput.FshallowModelFactor.Mean, - generalInput.FshallowModelFactor.StandardDeviation, - generalInput.FshallowModelFactor.LowerBoundary, - generalInput.FshallowModelFactor.UpperBoundary); - - HydraRingDataEqualityHelper.AreEqual(expectedInput, actualInput); - Assert.AreEqual(testDataPath, testOvertoppingCalculator.HydraulicBoundaryDatabaseDirectory); - } + // Assert + Assert.IsNotNull(calculation.Output); + Assert.IsNull(calculation.Output.OvertoppingRateOutput); + mocks.VerifyAll(); } [Test] - [TestCase(DikeHeightCalculationType.CalculateByAssessmentSectionNorm, TestName = "Run_ValidDikeHeightCalculation_InputPropertiesCorrectlySendToService(AssessmentSectionNorm)")] - [TestCase(DikeHeightCalculationType.CalculateByProfileSpecificRequiredProbability, TestName = "Run_ValidDikeHeightCalculation_InputPropertiesCorrectlySendToService(ProfileProbability)")] - public void Run_ValidDikeHeightCalculation_InputPropertiesCorrectlySendToService(DikeHeightCalculationType dikeHeightCalculationType) + [TestCase(OvertoppingRateCalculationType.CalculateByAssessmentSectionNorm)] + [TestCase(OvertoppingRateCalculationType.CalculateByProfileSpecificRequiredProbability)] + public void Finish_ValidOvertoppingRateCalculation_OutputSetAndObserversNotified(OvertoppingRateCalculationType overtoppingRateCalculationType) { // Setup + var mocks = new MockRepository(); + var observerMock = mocks.StrictMock(); + observerMock.Expect(o => o.UpdateObserver()); + mocks.ReplayAll(); + var assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike); ImportHydraulicBoundaryDatabase(assessmentSection); AddSectionToAssessmentSection(assessmentSection); @@ -1110,104 +1152,32 @@ { HydraulicBoundaryLocation = assessmentSection.HydraulicBoundaryDatabase.Locations.First(hl => hl.Id == 1300001), DikeProfile = CreateDikeProfile(), - DikeHeightCalculationType = dikeHeightCalculationType + OvertoppingRateCalculationType = overtoppingRateCalculationType } }; + calculation.Attach(observerMock); + var activity = new GrassCoverErosionInwardsCalculationActivity(calculation, validFile, assessmentSection.GrassCoverErosionInwards, assessmentSection); using (new HydraRingCalculatorFactoryConfig()) { - // Call activity.Run(); - - // Assert - TestHydraulicLoadsCalculator dikeHeightCalculator = ((TestHydraRingCalculatorFactory) HydraRingCalculatorFactory.Instance).DikeHeightCalculator; - HydraulicLoadsCalculationInput[] dikeHeightCalculationInputs = dikeHeightCalculator.ReceivedInputs.ToArray(); - Assert.AreEqual(1, dikeHeightCalculationInputs.Length); - - HydraulicLoadsCalculationInput actualInput = dikeHeightCalculationInputs[0]; - GeneralGrassCoverErosionInwardsInput generalInput = assessmentSection.GrassCoverErosionInwards.GeneralInput; - - GrassCoverErosionInwardsInput input = calculation.InputParameters; - - double norm = dikeHeightCalculationType == DikeHeightCalculationType.CalculateByAssessmentSectionNorm - ? assessmentSection.FailureMechanismContribution.Norm - : RingtoetsCommonDataCalculationService.ProfileSpecificRequiredProbability( - assessmentSection.FailureMechanismContribution.Norm, - assessmentSection.GrassCoverErosionInwards.Contribution, - generalInput.N); - - var expectedInput = new DikeHeightCalculationInput(calculation.InputParameters.HydraulicBoundaryLocation.Id, - norm, - calculation.InputParameters.Orientation, - calculation.InputParameters.DikeGeometry.Select(roughnessPoint => new HydraRingRoughnessProfilePoint(roughnessPoint.Point.X, roughnessPoint.Point.Y, roughnessPoint.Roughness)), - input.ForeshoreGeometry.Select(c => new HydraRingForelandPoint(c.X, c.Y)), - new HydraRingBreakWater((int) input.BreakWater.Type, input.BreakWater.Height), - generalInput.CriticalOvertoppingModelFactor, - generalInput.FbFactor.Mean, - generalInput.FbFactor.StandardDeviation, - generalInput.FbFactor.LowerBoundary, - generalInput.FbFactor.UpperBoundary, - generalInput.FnFactor.Mean, - generalInput.FnFactor.StandardDeviation, - generalInput.FnFactor.LowerBoundary, - generalInput.FnFactor.UpperBoundary, - generalInput.OvertoppingModelFactor, - calculation.InputParameters.CriticalFlowRate.Mean, - calculation.InputParameters.CriticalFlowRate.StandardDeviation, - generalInput.FrunupModelFactor.Mean, - generalInput.FrunupModelFactor.StandardDeviation, - generalInput.FrunupModelFactor.LowerBoundary, - generalInput.FrunupModelFactor.UpperBoundary, - generalInput.FshallowModelFactor.Mean, - generalInput.FshallowModelFactor.StandardDeviation, - generalInput.FshallowModelFactor.LowerBoundary, - generalInput.FshallowModelFactor.UpperBoundary); - - HydraRingDataEqualityHelper.AreEqual(expectedInput, actualInput); - Assert.AreEqual(testDataPath, dikeHeightCalculator.HydraulicBoundaryDatabaseDirectory); } - } - private static void AddSectionToAssessmentSection(AssessmentSection assessmentSection) - { - assessmentSection.GrassCoverErosionInwards.AddSection(new FailureMechanismSection("test section", new[] - { - new Point2D(0, 0), - new Point2D(1, 1) - })); - } + // Call + activity.Finish(); - private static void ImportHydraulicBoundaryDatabase(AssessmentSection assessmentSection) - { - string validFilePath = Path.Combine(testDataPath, "HRD dutch coast south.sqlite"); - - using (var importer = new HydraulicBoundaryDatabaseImporter()) - { - importer.Import(assessmentSection, validFilePath); - } + // Assert + Assert.IsNotNull(calculation.Output); + ProbabilityAssessmentOutput probabilisticAssessmentOutput = calculation.Output.ProbabilityAssessmentOutput; + Assert.IsFalse(double.IsNaN(probabilisticAssessmentOutput.Reliability)); + HydraulicLoadsOutput overtoppingRateOutput = calculation.Output.OvertoppingRateOutput; + Assert.IsNotNull(overtoppingRateOutput); + Assert.IsFalse(double.IsNaN(overtoppingRateOutput.Result)); + mocks.VerifyAll(); } - private static DikeProfile CreateDikeProfile() - { - return new DikeProfile(new Point2D(0, 0), - new[] - { - new RoughnessPoint(new Point2D(1.1, 2.2), 0.6), - new RoughnessPoint(new Point2D(3.3, 4.4), 0.7) - }, new[] - { - new Point2D(3.3, 4.4), - new Point2D(5.5, 6.6) - }, - new BreakWater(BreakWaterType.Dam, 10.0), - new DikeProfile.ConstructionProperties - { - Id = "id", - Orientation = 5.5, - DikeHeight = 10 - }); - } + #endregion } } \ No newline at end of file