Index: Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Integration.Test/GrassCoverErosionInwardsCalculationActivityIntegrationTest.cs =================================================================== diff -u -r445fd3483c7414e0c4dc546b82c73479d7fa1d79 -r438c91039ce53124dd58150090f858d0d21e72dd --- Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Integration.Test/GrassCoverErosionInwardsCalculationActivityIntegrationTest.cs (.../GrassCoverErosionInwardsCalculationActivityIntegrationTest.cs) (revision 445fd3483c7414e0c4dc546b82c73479d7fa1d79) +++ Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Integration.Test/GrassCoverErosionInwardsCalculationActivityIntegrationTest.cs (.../GrassCoverErosionInwardsCalculationActivityIntegrationTest.cs) (revision 438c91039ce53124dd58150090f858d0d21e72dd) @@ -92,6 +92,58 @@ } [Test] + public void Run_InvalidOvertoppingCalculation_PerformValidationAndCalculationAndLogStartAndEndWithErrorAndDoNotPerformHydraulicLoadsCalculations() + { + // 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 = new HydraulicBoundaryLocation(1, "test", 1, 1), + DikeProfile = CreateDikeProfile(), + DikeHeightCalculationType = DikeHeightCalculationType.CalculateByAssessmentSectionNorm, + OvertoppingRateCalculationType = OvertoppingRateCalculationType.CalculateByProfileSpecificRequiredProbability + } + }; + + calculation.Attach(observerMock); + + var activity = new GrassCoverErosionInwardsCalculationActivity(calculation, validFile, assessmentSection.GrassCoverErosionInwards, assessmentSection); + + using (new HydraRingCalculatorFactoryConfig()) + { + TestOvertoppingCalculator calculator = ((TestHydraRingCalculatorFactory) HydraRingCalculatorFactory.Instance).OvertoppingCalculator; + calculator.EndInFailure = true; + + // 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.", 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_ValidOvertoppingCalculation_PerformValidationAndCalculationAndLogStartAndEnd() { // Setup @@ -131,11 +183,12 @@ } [Test] - public void Run_InvalidOvertoppingCalculation_PerformValidationAndCalculationAndLogStartAndEndWithErrorAndDoNotPerformHydraulicLoadsCalculations() + public void Finish_ValidOvertoppingCalculation_SetsOutputAndNotifyObserversOfCalculation() { // Setup var mocks = new MockRepository(); var observerMock = mocks.StrictMock(); + observerMock.Expect(o => o.UpdateObserver()); mocks.ReplayAll(); var assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike); @@ -146,10 +199,8 @@ { InputParameters = { - HydraulicBoundaryLocation = new HydraulicBoundaryLocation(1, "test", 1, 1), - DikeProfile = CreateDikeProfile(), - DikeHeightCalculationType = DikeHeightCalculationType.CalculateByAssessmentSectionNorm, - OvertoppingRateCalculationType = OvertoppingRateCalculationType.CalculateByProfileSpecificRequiredProbability + HydraulicBoundaryLocation = assessmentSection.HydraulicBoundaryDatabase.Locations.First(hl => hl.Id == 1300001), + DikeProfile = CreateDikeProfile() } }; @@ -159,33 +210,24 @@ using (new HydraRingCalculatorFactoryConfig()) { - TestOvertoppingCalculator calculator = ((TestHydraRingCalculatorFactory) HydraRingCalculatorFactory.Instance).OvertoppingCalculator; - calculator.EndInFailure = true; + activity.Run(); + } - // Call - Action call = () => activity.Run(); + // Call + activity.Finish(); - // 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.", 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 - } + // Assert + Assert.IsNotNull(calculation.Output); + Assert.IsFalse(double.IsNaN(calculation.Output.ProbabilityAssessmentOutput.Reliability)); + Assert.IsNull(calculation.Output.DikeHeightOutput); + Assert.IsNull(calculation.Output.OvertoppingRateOutput); + mocks.VerifyAll(); } [Test] [TestCase(DikeHeightCalculationType.CalculateByAssessmentSectionNorm)] [TestCase(DikeHeightCalculationType.CalculateByProfileSpecificRequiredProbability)] - public void Run_ValidOvertoppingCalculationAndInvalidDikeHeightCalculation_PerformValidationAndCalculationAndLogStartAndEndWithError( + public void Run_InvalidDikeHeightCalculation_PerformValidationAndCalculationAndLogStartAndEndWithError( DikeHeightCalculationType dikeHeightCalculationType) { // Setup @@ -245,16 +287,11 @@ } [Test] - [TestCase(OvertoppingRateCalculationType.CalculateByAssessmentSectionNorm)] - [TestCase(OvertoppingRateCalculationType.CalculateByProfileSpecificRequiredProbability)] - public void Run_ValidOvertoppingCalculationAndInvalidOvertoppingRateCalculation_PerformValidationAndCalculationAndLogStartAndEndWithError( - OvertoppingRateCalculationType overtoppingRateCalculationType) + [TestCase(DikeHeightCalculationType.CalculateByAssessmentSectionNorm)] + [TestCase(DikeHeightCalculationType.CalculateByProfileSpecificRequiredProbability)] + public void Run_ValidDikeHeightCalculation_PerformValidationAndCalculationAndLogStartAndEndError(DikeHeightCalculationType dikeHeightCalculationType) { // Setup - var mocks = new MockRepository(); - var observerMock = mocks.StrictMock(); - mocks.ReplayAll(); - var assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike) { FailureMechanismContribution = @@ -271,19 +308,17 @@ { HydraulicBoundaryLocation = assessmentSection.HydraulicBoundaryDatabase.Locations.First(hl => hl.Id == 1300001), DikeProfile = CreateDikeProfile(), - OvertoppingRateCalculationType = overtoppingRateCalculationType + DikeHeightCalculationType = dikeHeightCalculationType } }; - 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; + TestHydraulicLoadsCalculator calculator = ((TestHydraRingCalculatorFactory) HydraRingCalculatorFactory.Instance).DikeHeightCalculator; + calculator.Value = 2; + calculator.ReliabilityIndex = -1; // Call Action call = () => activity.Run(); @@ -297,25 +332,32 @@ 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("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); - mocks.VerifyAll(); // Expect no calls on the observer } } [Test] - [Combinatorial] - public void Run_SpecificCombinationOfCalculations_ProgressTextSetAccordingly([Values(DikeHeightCalculationType.CalculateByAssessmentSectionNorm, - DikeHeightCalculationType.CalculateByProfileSpecificRequiredProbability, - DikeHeightCalculationType.NoCalculation)] DikeHeightCalculationType dikeHeightCalculationType, - [Values(OvertoppingRateCalculationType.CalculateByAssessmentSectionNorm, - OvertoppingRateCalculationType.CalculateByProfileSpecificRequiredProbability, - OvertoppingRateCalculationType.NoCalculation)] OvertoppingRateCalculationType overtoppingRateCalculationType) + [TestCase(OvertoppingRateCalculationType.CalculateByAssessmentSectionNorm)] + [TestCase(OvertoppingRateCalculationType.CalculateByProfileSpecificRequiredProbability)] + public void Run_InvalidOvertoppingRateCalculation_PerformValidationAndCalculationAndLogStartAndEndWithError( + OvertoppingRateCalculationType overtoppingRateCalculationType) { - var assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike); + // Setup + var mocks = new MockRepository(); + var observerMock = mocks.StrictMock(); + mocks.ReplayAll(); + + var assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike) + { + FailureMechanismContribution = + { + Norm = 1 + } + }; ImportHydraulicBoundaryDatabase(assessmentSection); AddSectionToAssessmentSection(assessmentSection); @@ -325,51 +367,45 @@ { 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); - var progressTexts = ""; - - activity.ProgressChanged += (s, e) => progressTexts += activity.ProgressText + Environment.NewLine; - using (new HydraRingCalculatorFactoryConfig()) { + TestHydraulicLoadsCalculator calculator = ((TestHydraRingCalculatorFactory) HydraRingCalculatorFactory.Instance).OvertoppingRateCalculator; + calculator.Value = double.NaN; + calculator.EndInFailure = true; + // Call - activity.Run(); - } + Action 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; + // 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 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("Berekening van '{0}' beëindigd om: ", calculation.Name), msgs[6]); + }); + Assert.AreEqual(ActivityState.Executed, activity.State); + mocks.VerifyAll(); // Expect no calls on the observer } - - if (overtoppingRateCalculationType != OvertoppingRateCalculationType.NoCalculation) - { - expectedProgressTexts += $"Stap {totalNumberOfCalculations} van {totalNumberOfCalculations} | Uitvoeren overslagdebiet berekening" + Environment.NewLine; - } - - Assert.AreEqual(expectedProgressTexts, progressTexts); } [Test] - [TestCase(DikeHeightCalculationType.CalculateByAssessmentSectionNorm, TestName = "Run_CalculateWithDikeHeightRan_PerformValidationCalculationLogStartEndError(AssessmentSectionNorm)")] - [TestCase(DikeHeightCalculationType.CalculateByProfileSpecificRequiredProbability, TestName = "Run_CalculateWithDikeHeightRan_PerformValidationCalculationLogStartEndError(ProfileProbability)")] - public void Run_CalculateWithDikeHeightAndRan_PerformValidationAndCalculationAndLogStartAndEndError(DikeHeightCalculationType dikeHeightCalculationType) + [TestCase(OvertoppingRateCalculationType.CalculateByAssessmentSectionNorm)] + [TestCase(OvertoppingRateCalculationType.CalculateByProfileSpecificRequiredProbability)] + public void Run_ValidDikeHeightCalculation_PerformValidationAndCalculationAndLogStartAndEndError(OvertoppingRateCalculationType overtoppingRateCalculationType) { // Setup var assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike) @@ -388,15 +424,15 @@ { 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; + TestHydraulicLoadsCalculator calculator = ((TestHydraRingCalculatorFactory) HydraRingCalculatorFactory.Instance).OvertoppingRateCalculator; calculator.Value = 2; calculator.ReliabilityIndex = -1; @@ -412,23 +448,23 @@ 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("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 Finish_CalculateDikeHeightFalseAndValidCalculationAndRan_SetsOutputAndNotifyObserversOfCalculation() + [Combinatorial] + public void Run_CombinationOfCalculations_ProgressTextSetAccordingly([Values(DikeHeightCalculationType.CalculateByAssessmentSectionNorm, + DikeHeightCalculationType.CalculateByProfileSpecificRequiredProbability, + DikeHeightCalculationType.NoCalculation)] DikeHeightCalculationType dikeHeightCalculationType, + [Values(OvertoppingRateCalculationType.CalculateByAssessmentSectionNorm, + OvertoppingRateCalculationType.CalculateByProfileSpecificRequiredProbability, + OvertoppingRateCalculationType.NoCalculation)] 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); @@ -439,27 +475,45 @@ { HydraulicBoundaryLocation = assessmentSection.HydraulicBoundaryDatabase.Locations.First(hl => hl.Id == 1300001), DikeProfile = CreateDikeProfile(), - DikeHeightCalculationType = DikeHeightCalculationType.NoCalculation + DikeHeightCalculationType = dikeHeightCalculationType, + OvertoppingRateCalculationType = overtoppingRateCalculationType } }; - calculation.Attach(observerMock); - 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(); } - // Call - activity.Finish(); - // Assert - Assert.IsNotNull(calculation.Output); - Assert.IsFalse(double.IsNaN(calculation.Output.ProbabilityAssessmentOutput.Reliability)); - Assert.IsNull(calculation.Output.DikeHeightOutput); - mocks.VerifyAll(); + 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]