Exemplo n.º 1
0
        private static void AssertWaveImpactAsphaltCoverWaveConditionsCalculationActivity(Activity activity,
                                                                                          WaveImpactAsphaltCoverWaveConditionsCalculation calculation,
                                                                                          RoundedDouble assessmentLevel,
                                                                                          HydraulicBoundaryDatabase hydraulicBoundaryDatabase)
        {
            var mocks             = new MockRepository();
            var testCalculator    = new TestWaveConditionsCosineCalculator();
            var calculatorFactory = mocks.StrictMock <IHydraRingCalculatorFactory>();
            int nrOfCalculations  = calculation.InputParameters.GetWaterLevels(assessmentLevel).Count();

            calculatorFactory.Expect(cf => cf.CreateWaveConditionsCosineCalculator(Arg <HydraRingCalculationSettings> .Is.NotNull))
            .WhenCalled(invocation =>
            {
                HydraRingCalculationSettingsTestHelper.AssertHydraRingCalculationSettings(
                    HydraulicBoundaryCalculationSettingsFactory.CreateSettings(hydraulicBoundaryDatabase),
                    (HydraRingCalculationSettings)invocation.Arguments[0]);
            })
            .Return(testCalculator)
            .Repeat
            .Times(nrOfCalculations);
            mocks.ReplayAll();

            using (new HydraRingCalculatorFactoryConfig(calculatorFactory))
            {
                activity.Run();

                Assert.AreEqual(nrOfCalculations, testCalculator.ReceivedInputs.Count());
                foreach (WaveConditionsCosineCalculationInput input in testCalculator.ReceivedInputs)
                {
                    Assert.AreEqual(calculation.InputParameters.BreakWater.Height, input.BreakWater.Height);
                }
            }

            mocks.VerifyAll();
        }
        public void Calculate_VariousHydraulicBoundaryDatabaseConfigurations_StartsCalculationWithRightParameters(
            HydraulicBoundaryDatabase hydraulicBoundaryDatabase)
        {
            // Setup
            var          waterLevel        = (RoundedDouble)4.20;
            var          a                 = (RoundedDouble)1.0;
            var          b                 = (RoundedDouble)0.8;
            var          c                 = (RoundedDouble)0.4;
            const double targetProbability = 0.2;
            var          input             = new WaveConditionsInput
            {
                HydraulicBoundaryLocation = new TestHydraulicBoundaryLocation(),
                ForeshoreProfile          = new TestForeshoreProfile(true),
                UpperBoundaryRevetment    = (RoundedDouble)4,
                LowerBoundaryRevetment    = (RoundedDouble)3,
                StepSize    = WaveConditionsInputStepSize.Two,
                Orientation = (RoundedDouble)0
            };

            var calculator      = new TestWaveConditionsCosineCalculator();
            int nrOfCalculators = input.GetWaterLevels(waterLevel).Count();

            var mockRepository    = new MockRepository();
            var calculatorFactory = mockRepository.StrictMock <IHydraRingCalculatorFactory>();

            calculatorFactory.Expect(cf => cf.CreateWaveConditionsCosineCalculator(Arg <HydraRingCalculationSettings> .Is.NotNull))
            .WhenCalled(invocation =>
            {
                HydraRingCalculationSettingsTestHelper.AssertHydraRingCalculationSettings(
                    HydraulicBoundaryCalculationSettingsFactory.CreateSettings(hydraulicBoundaryDatabase),
                    (HydraRingCalculationSettings)invocation.Arguments[0]);
            })
            .Return(calculator)
            .Repeat
            .Times(nrOfCalculators);
            mockRepository.ReplayAll();

            using (new HydraRingCalculatorFactoryConfig(calculatorFactory))
            {
                // Call
                new TestWaveConditionsCalculationService().PublicCalculate(a,
                                                                           b,
                                                                           c,
                                                                           targetProbability,
                                                                           input,
                                                                           waterLevel,
                                                                           hydraulicBoundaryDatabase);

                // Assert
                for (var i = 0; i < nrOfCalculators; i++)
                {
                    Assert.AreEqual(hydraulicBoundaryDatabase.HydraulicLocationConfigurationSettings.UsePreprocessor,
                                    calculator.ReceivedInputs.ElementAt(i).PreprocessorSetting.RunPreprocessor);
                }
            }

            mockRepository.VerifyAll();
        }
Exemplo n.º 3
0
        public void Calculate_Always_InputPropertiesCorrectlySentToCalculator(BreakWaterType breakWaterType)
        {
            // Setup
            IAssessmentSection assessmentSection = CreateAssessmentSectionWithHydraulicBoundaryOutput();
            WaveImpactAsphaltCoverWaveConditionsCalculation calculation = GetValidCalculation(assessmentSection.HydraulicBoundaryDatabase.Locations.First());

            calculation.InputParameters.BreakWater.Type = breakWaterType;

            var waveImpactAsphaltCoverFailureMechanism = new WaveImpactAsphaltCoverFailureMechanism();

            var calculator = new TestWaveConditionsCosineCalculator();

            var mockRepository    = new MockRepository();
            var calculatorFactory = mockRepository.StrictMock <IHydraRingCalculatorFactory>();

            calculatorFactory.Expect(cf => cf.CreateWaveConditionsCosineCalculator(null))
            .IgnoreArguments()
            .Return(calculator)
            .Repeat
            .Times(3);
            mockRepository.ReplayAll();

            using (new HydraRingCalculatorFactoryConfig(calculatorFactory))
            {
                // Call
                new WaveImpactAsphaltCoverWaveConditionsCalculationService().Calculate(
                    calculation,
                    assessmentSection,
                    waveImpactAsphaltCoverFailureMechanism.GeneralInput);

                // Assert
                WaveConditionsCosineCalculationInput[] waveConditionsInputs = calculator.ReceivedInputs.ToArray();
                Assert.AreEqual(3, waveConditionsInputs.Length);

                var waterLevelIndex = 0;
                foreach (WaveConditionsCosineCalculationInput actualInput in waveConditionsInputs)
                {
                    GeneralWaveConditionsInput generalInput = waveImpactAsphaltCoverFailureMechanism.GeneralInput;

                    WaveConditionsInput input = calculation.InputParameters;
                    var expectedInput         = new WaveConditionsCosineCalculationInput(1,
                                                                                         input.Orientation,
                                                                                         input.HydraulicBoundaryLocation.Id,
                                                                                         assessmentSection.FailureMechanismContribution.MaximumAllowableFloodingProbability,
                                                                                         input.ForeshoreProfile.Geometry.Select(c => new HydraRingForelandPoint(c.X, c.Y)),
                                                                                         new HydraRingBreakWater(BreakWaterTypeHelper.GetHydraRingBreakWaterType(breakWaterType), input.BreakWater.Height),
                                                                                         GetWaterLevels(calculation, assessmentSection).ElementAt(waterLevelIndex++),
                                                                                         generalInput.A,
                                                                                         generalInput.B,
                                                                                         generalInput.C);

                    HydraRingDataEqualityHelper.AreEqual(expectedInput, actualInput);
                }
            }

            mockRepository.VerifyAll();
        }
        public void Calculate_WithoutBreakWater_StartsCalculationWithRightParameters(bool useForeshore)
        {
            // Setup
            var          waterLevel        = (RoundedDouble)4.20;
            var          a                 = (RoundedDouble)1.0;
            var          b                 = (RoundedDouble)0.8;
            var          c                 = (RoundedDouble)0.4;
            const double targetProbability = 0.2;
            var          input             = new WaveConditionsInput
            {
                HydraulicBoundaryLocation = new TestHydraulicBoundaryLocation(),
                ForeshoreProfile          = new TestForeshoreProfile(true),
                UpperBoundaryRevetment    = (RoundedDouble)4,
                LowerBoundaryRevetment    = (RoundedDouble)3,
                StepSize      = WaveConditionsInputStepSize.Two,
                UseBreakWater = false,
                UseForeshore  = useForeshore,
                Orientation   = (RoundedDouble)0
            };

            var calculator = new TestWaveConditionsCosineCalculator();

            RoundedDouble[] waterLevels     = input.GetWaterLevels(waterLevel).ToArray();
            int             nrOfCalculators = waterLevels.Length;

            var mockRepository    = new MockRepository();
            var calculatorFactory = mockRepository.StrictMock <IHydraRingCalculatorFactory>();

            calculatorFactory.Expect(cf => cf.CreateWaveConditionsCosineCalculator(null))
            .IgnoreArguments()
            .Return(calculator)
            .Repeat
            .Times(nrOfCalculators);
            mockRepository.ReplayAll();

            using (new HydraRingCalculatorFactoryConfig(calculatorFactory))
            {
                // Call
                new TestWaveConditionsCalculationService().PublicCalculate(a,
                                                                           b,
                                                                           c,
                                                                           targetProbability,
                                                                           input,
                                                                           waterLevel,
                                                                           GetValidHydraulicBoundaryDatabase());

                // Assert
                for (var i = 0; i < nrOfCalculators; i++)
                {
                    WaveConditionsCosineCalculationInput expectedInput = CreateInput(waterLevels[i], a, b, c, targetProbability, input, useForeshore, false);
                    HydraRingDataEqualityHelper.AreEqual(expectedInput, calculator.ReceivedInputs.ElementAt(i));
                }
            }

            mockRepository.VerifyAll();
        }
Exemplo n.º 5
0
        public void Cancel_WhenPerformingCalculationForBlocks_CurrentCalculationForWaterLevelCompletesAndSubsequentCalculationsDidNotRun()
        {
            // Setup
            IAssessmentSection assessmentSection = CreateAssessmentSectionWithHydraulicBoundaryOutput();
            StabilityStoneCoverWaveConditionsCalculation calculation = CreateValidCalculation(assessmentSection.HydraulicBoundaryDatabase.Locations.First());

            CalculatableActivity activity = StabilityStoneCoverWaveConditionsCalculationActivityFactory.CreateCalculationActivity(
                calculation,
                new StabilityStoneCoverFailureMechanism(),
                assessmentSection);

            var mockRepository    = new MockRepository();
            var calculatorFactory = mockRepository.StrictMock <IHydraRingCalculatorFactory>();
            var calculator        = new TestWaveConditionsCosineCalculator();

            calculatorFactory.Expect(cf => cf.CreateWaveConditionsCosineCalculator(null))
            .IgnoreArguments()
            .Return(calculator);
            mockRepository.ReplayAll();

            using (new HydraRingCalculatorFactoryConfig(calculatorFactory))
            {
                activity.ProgressChanged += (sender, args) =>
                {
                    if (activity.State != ActivityState.Canceled && activity.ProgressText.Contains("Stap 1 van 6"))
                    {
                        // Call
                        activity.Cancel();
                    }
                };

                // Assert
                TestHelper.AssertLogMessages(() => activity.Run(), messages =>
                {
                    string[] msgs = messages.ToArray();
                    RoundedDouble firstWaterLevel = GetWaterLevels(calculation, assessmentSection).First();

                    Assert.AreEqual(10, msgs.Length);
                    Assert.AreEqual($"Golfcondities berekenen voor '{calculation.Name}' is gestart.", msgs[0]);
                    CalculationServiceTestHelper.AssertValidationStartMessage(msgs[1]);
                    CalculationServiceTestHelper.AssertValidationEndMessage(msgs[2]);
                    CalculationServiceTestHelper.AssertCalculationStartMessage(msgs[3]);
                    Assert.AreEqual("Berekening voor blokken is gestart.", msgs[4]);
                    Assert.AreEqual($"Berekening voor waterstand '{firstWaterLevel}' is gestart.", msgs[5]);
                    StringAssert.StartsWith("Golfcondities berekening is uitgevoerd op de tijdelijke locatie", msgs[6]);
                    Assert.AreEqual($"Berekening voor waterstand '{firstWaterLevel}' is beëindigd.", msgs[7]);
                    Assert.AreEqual("Berekening voor blokken is beëindigd.", msgs[8]);
                    CalculationServiceTestHelper.AssertCalculationEndMessage(msgs[9]);
                });

                Assert.AreEqual(ActivityState.Canceled, activity.State);
            }

            mockRepository.VerifyAll();
        }
        public void Calculate_CancelCalculationWithValidInput_CancelsCalculator()
        {
            // Setup
            var          waterLevel        = (RoundedDouble)4.2;
            var          a                 = (RoundedDouble)1.0;
            var          b                 = (RoundedDouble)0.8;
            var          c                 = (RoundedDouble)0.4;
            const double targetProbability = 0.2;
            var          input             = new WaveConditionsInput
            {
                HydraulicBoundaryLocation = new TestHydraulicBoundaryLocation(),
                ForeshoreProfile          = new TestForeshoreProfile(),
                UpperBoundaryRevetment    = waterLevel,
                LowerBoundaryRevetment    = (RoundedDouble)3
            };
            var calculator        = new TestWaveConditionsCosineCalculator();
            var mockRepository    = new MockRepository();
            var calculatorFactory = mockRepository.Stub <IHydraRingCalculatorFactory>();

            calculatorFactory.Expect(cf => cf.CreateWaveConditionsCosineCalculator(null))
            .IgnoreArguments()
            .Return(calculator);
            mockRepository.ReplayAll();

            using (new HydraRingCalculatorFactoryConfig(calculatorFactory))
            {
                var service = new TestWaveConditionsCalculationService();
                calculator.CalculationFinishedHandler += (s, e) => service.Cancel();

                // Call
                service.PublicCalculate(a,
                                        b,
                                        c,
                                        targetProbability,
                                        input,
                                        waterLevel,
                                        GetValidHydraulicBoundaryDatabase());

                // Assert
                Assert.IsTrue(calculator.IsCanceled);
            }

            mockRepository.VerifyAll();
        }
        public void Run_CalculationFailed_OutputNull(bool endInFailure, string lastErrorFileContent)
        {
            // Setup
            AssessmentSectionStub assessmentSection = CreateAssessmentSection();

            ConfigureAssessmentSectionWithHydraulicBoundaryOutput(assessmentSection);

            GrassCoverErosionOutwardsWaveConditionsCalculation calculation = CreateValidCalculation(assessmentSection.HydraulicBoundaryDatabase.Locations.First());

            var failureMechanism          = new GrassCoverErosionOutwardsFailureMechanism();
            CalculatableActivity activity = GrassCoverErosionOutwardsCalculationActivityFactory.CreateWaveConditionsCalculationActivity(calculation,
                                                                                                                                        failureMechanism,
                                                                                                                                        assessmentSection);

            var waveConditionsCosineCalculator = new TestWaveConditionsCosineCalculator
            {
                EndInFailure         = endInFailure,
                LastErrorFileContent = lastErrorFileContent
            };

            int nrOfCalculators = GetWaterLevels(calculation, assessmentSection).Count();

            var mockRepository    = new MockRepository();
            var calculatorFactory = mockRepository.StrictMock <IHydraRingCalculatorFactory>();

            calculatorFactory.Expect(cf => cf.CreateWaveConditionsCosineCalculator(null))
            .IgnoreArguments()
            .Return(waveConditionsCosineCalculator)
            .Repeat
            .Times(nrOfCalculators);
            mockRepository.ReplayAll();

            using (new HydraRingCalculatorFactoryConfig(calculatorFactory))
            {
                // Call
                activity.Run();

                // Assert
                Assert.IsNull(calculation.Output);
            }

            mockRepository.VerifyAll();
        }
Exemplo n.º 8
0
        public void Calculate_HydraulicBoundaryDatabaseWithUsePreprocessorFalse_ExpectedPreprocessorDirectorySetToCalculator()
        {
            // Setup
            IAssessmentSection assessmentSection = CreateAssessmentSectionWithHydraulicBoundaryOutput();

            assessmentSection.HydraulicBoundaryDatabase.HydraulicLocationConfigurationSettings.CanUsePreprocessor    = true;
            assessmentSection.HydraulicBoundaryDatabase.HydraulicLocationConfigurationSettings.UsePreprocessor       = false;
            assessmentSection.HydraulicBoundaryDatabase.HydraulicLocationConfigurationSettings.PreprocessorDirectory = "InvalidPreprocessorDirectory";

            WaveImpactAsphaltCoverWaveConditionsCalculation calculation = GetValidCalculation(assessmentSection.HydraulicBoundaryDatabase.Locations.First());

            var waveImpactAsphaltCoverFailureMechanism = new WaveImpactAsphaltCoverFailureMechanism();

            var calculator = new TestWaveConditionsCosineCalculator();

            var mockRepository    = new MockRepository();
            var calculatorFactory = mockRepository.StrictMock <IHydraRingCalculatorFactory>();

            calculatorFactory.Expect(cf => cf.CreateWaveConditionsCosineCalculator(Arg <HydraRingCalculationSettings> .Is.NotNull))
            .WhenCalled(invocation =>
            {
                HydraRingCalculationSettingsTestHelper.AssertHydraRingCalculationSettings(
                    HydraulicBoundaryCalculationSettingsFactory.CreateSettings(assessmentSection.HydraulicBoundaryDatabase),
                    (HydraRingCalculationSettings)invocation.Arguments[0]);
            })
            .Return(calculator)
            .Repeat
            .Times(3);
            mockRepository.ReplayAll();

            using (new HydraRingCalculatorFactoryConfig(calculatorFactory))
            {
                // Call
                new WaveImpactAsphaltCoverWaveConditionsCalculationService().Calculate(
                    calculation,
                    assessmentSection,
                    waveImpactAsphaltCoverFailureMechanism.GeneralInput);
            }

            // Assert
            mockRepository.VerifyAll();
        }
        public void Run_ErrorInCalculation_ActivityStateFailed(bool endInFailure, string lastErrorFileContent)
        {
            // Setup
            IAssessmentSection assessmentSection = CreateAssessmentSectionWithHydraulicBoundaryOutput();
            WaveImpactAsphaltCoverWaveConditionsCalculation calculation = CreateValidCalculation(assessmentSection.HydraulicBoundaryDatabase.Locations.First());

            CalculatableActivity activity = WaveImpactAsphaltCoverWaveConditionsCalculationActivityFactory.CreateCalculationActivity(
                calculation,
                new WaveImpactAsphaltCoverFailureMechanism(),
                assessmentSection);

            var mockRepository    = new MockRepository();
            var calculatorFactory = mockRepository.StrictMock <IHydraRingCalculatorFactory>();
            var calculator        = new TestWaveConditionsCosineCalculator
            {
                EndInFailure         = endInFailure,
                LastErrorFileContent = lastErrorFileContent
            };

            calculatorFactory.Expect(cf => cf.CreateWaveConditionsCosineCalculator(null))
            .IgnoreArguments()
            .Return(calculator)
            .Repeat
            .Times(GetWaterLevels(calculation, assessmentSection).Count());
            mockRepository.ReplayAll();

            using (new HydraRingCalculatorFactoryConfig(calculatorFactory))
            {
                // Call
                activity.Run();

                // Assert
                Assert.AreEqual(ActivityState.Failed, activity.State);
            }

            mockRepository.VerifyAll();
        }
Exemplo n.º 10
0
        public void Calculate_CancelCalculationWithValidInput_CancelsCalculatorAndHasNullOutput()
        {
            // Setup
            IAssessmentSection assessmentSection = CreateAssessmentSectionWithHydraulicBoundaryOutput();
            WaveImpactAsphaltCoverWaveConditionsCalculation calculation = GetDefaultCalculation(assessmentSection.HydraulicBoundaryDatabase.Locations.First());

            var waveImpactAsphaltCoverFailureMechanism = new WaveImpactAsphaltCoverFailureMechanism();

            var calculator = new TestWaveConditionsCosineCalculator();

            var mockRepository    = new MockRepository();
            var calculatorFactory = mockRepository.StrictMock <IHydraRingCalculatorFactory>();

            calculatorFactory.Expect(cf => cf.CreateWaveConditionsCosineCalculator(null))
            .IgnoreArguments()
            .Return(calculator);
            mockRepository.ReplayAll();

            using (new HydraRingCalculatorFactoryConfig(calculatorFactory))
            {
                var waveImpactAsphaltCoverWaveConditionsCalculationService = new WaveImpactAsphaltCoverWaveConditionsCalculationService();
                calculator.CalculationFinishedHandler += (s, e) => waveImpactAsphaltCoverWaveConditionsCalculationService.Cancel();

                // Call
                waveImpactAsphaltCoverWaveConditionsCalculationService.Calculate(
                    calculation,
                    assessmentSection,
                    waveImpactAsphaltCoverFailureMechanism.GeneralInput);

                // Assert
                Assert.IsNull(calculation.Output);
                Assert.IsTrue(calculator.IsCanceled);
            }

            mockRepository.VerifyAll();
        }
        public void Run_Always_InputPropertiesCorrectlySentToService(BreakWaterType breakWaterType)
        {
            // Setup
            AssessmentSectionStub assessmentSection = CreateAssessmentSection();

            ConfigureAssessmentSectionWithHydraulicBoundaryOutput(assessmentSection);

            GrassCoverErosionOutwardsWaveConditionsCalculation calculation = CreateValidCalculation(assessmentSection.HydraulicBoundaryDatabase.Locations.First());

            calculation.InputParameters.BreakWater.Type = breakWaterType;

            var failureMechanism          = new GrassCoverErosionOutwardsFailureMechanism();
            CalculatableActivity activity = GrassCoverErosionOutwardsCalculationActivityFactory.CreateWaveConditionsCalculationActivity(calculation,
                                                                                                                                        failureMechanism,
                                                                                                                                        assessmentSection);

            var waveConditionsCosineCalculator = new TestWaveConditionsCosineCalculator();

            RoundedDouble[] waterLevels     = GetWaterLevels(calculation, assessmentSection).ToArray();
            int             nrOfCalculators = GetNrOfCalculators(calculation, assessmentSection);

            var mockRepository    = new MockRepository();
            var calculatorFactory = mockRepository.StrictMock <IHydraRingCalculatorFactory>();

            calculatorFactory.Expect(cf => cf.CreateWaveConditionsCosineCalculator(null))
            .IgnoreArguments()
            .Return(waveConditionsCosineCalculator)
            .Repeat
            .Times(nrOfCalculators);
            mockRepository.ReplayAll();

            using (new HydraRingCalculatorFactoryConfig(calculatorFactory))
            {
                // Call
                activity.Run();

                // Assert
                WaveConditionsCosineCalculationInput[] waveConditionsInputs = waveConditionsCosineCalculator.ReceivedInputs.ToArray();
                Assert.AreEqual(nrOfCalculators, waveConditionsInputs.Length);

                WaveConditionsInput input = calculation.InputParameters;
                double targetProbability  = assessmentSection.FailureMechanismContribution.MaximumAllowableFloodingProbability;

                var waterLevelIndex = 0;
                GeneralGrassCoverErosionOutwardsInput generalInput = failureMechanism.GeneralInput;
                for (var i = 0; i < waveConditionsInputs.Length / 2; i++)
                {
                    var expectedInput = new WaveConditionsCosineCalculationInput(1,
                                                                                 input.Orientation,
                                                                                 input.HydraulicBoundaryLocation.Id,
                                                                                 targetProbability,
                                                                                 input.ForeshoreProfile.Geometry.Select(c => new HydraRingForelandPoint(c.X, c.Y)),
                                                                                 new HydraRingBreakWater(BreakWaterTypeHelper.GetHydraRingBreakWaterType(breakWaterType), input.BreakWater.Height),
                                                                                 waterLevels[waterLevelIndex++],
                                                                                 generalInput.GeneralWaveRunUpWaveConditionsInput.A,
                                                                                 generalInput.GeneralWaveRunUpWaveConditionsInput.B,
                                                                                 generalInput.GeneralWaveRunUpWaveConditionsInput.C);

                    HydraRingDataEqualityHelper.AreEqual(expectedInput, waveConditionsInputs[i]);
                }

                waterLevelIndex = 0;
                for (int i = waveConditionsInputs.Length / 2; i < waveConditionsInputs.Length; i++)
                {
                    var expectedInput = new WaveConditionsCosineCalculationInput(1,
                                                                                 input.Orientation,
                                                                                 input.HydraulicBoundaryLocation.Id,
                                                                                 targetProbability,
                                                                                 input.ForeshoreProfile.Geometry.Select(c => new HydraRingForelandPoint(c.X, c.Y)),
                                                                                 new HydraRingBreakWater(BreakWaterTypeHelper.GetHydraRingBreakWaterType(breakWaterType), input.BreakWater.Height),
                                                                                 waterLevels[waterLevelIndex++],
                                                                                 generalInput.GeneralWaveImpactWaveConditionsInput.A,
                                                                                 generalInput.GeneralWaveImpactWaveConditionsInput.B,
                                                                                 generalInput.GeneralWaveImpactWaveConditionsInput.C);

                    HydraRingDataEqualityHelper.AreEqual(expectedInput, waveConditionsInputs[i]);
                }
            }

            mockRepository.VerifyAll();
        }
        public void Calculate_OneOutOfThreeCalculationsFails_ReturnsOutputsAndLogError(bool endInFailure,
                                                                                       string lastErrorFileContent,
                                                                                       string detailedReport)
        {
            // Setup
            var calculatorThatFails = new TestWaveConditionsCosineCalculator
            {
                EndInFailure         = endInFailure,
                LastErrorFileContent = lastErrorFileContent
            };
            var mockRepository    = new MockRepository();
            var calculatorFactory = mockRepository.StrictMock <IHydraRingCalculatorFactory>();

            calculatorFactory.Expect(cf => cf.CreateWaveConditionsCosineCalculator(null))
            .IgnoreArguments()
            .Return(calculatorThatFails);
            calculatorFactory.Expect(cf => cf.CreateWaveConditionsCosineCalculator(null))
            .IgnoreArguments()
            .Return(new TestWaveConditionsCosineCalculator())
            .Repeat
            .Twice();
            mockRepository.ReplayAll();

            var          waterLevelUpperBoundary = new RoundedDouble(2, 4.00);
            var          waterLevelLowerBoundary = new RoundedDouble(2, 3.00);
            var          waterLevel        = (RoundedDouble)4.2;
            var          a                 = (RoundedDouble)1.0;
            var          b                 = (RoundedDouble)0.8;
            var          c                 = (RoundedDouble)0.4;
            const double targetProbability = 0.2;
            var          input             = new WaveConditionsInput
            {
                HydraulicBoundaryLocation = new TestHydraulicBoundaryLocation(),
                ForeshoreProfile          = new TestForeshoreProfile(),
                UpperBoundaryRevetment    = waterLevelUpperBoundary,
                LowerBoundaryRevetment    = waterLevelLowerBoundary
            };

            using (new HydraRingCalculatorFactoryConfig(calculatorFactory))
            {
                var service = new TestWaveConditionsCalculationService();

                // Call
                void Call() => service.PublicCalculate(a, b, c, targetProbability, input, waterLevel, GetValidHydraulicBoundaryDatabase());

                // Assert
                TestHelper.AssertLogMessages(Call, messages =>
                {
                    string[] msgs = messages.ToArray();
                    Assert.AreEqual(10, msgs.Length);

                    var waterLevelMiddle = new RoundedDouble(2, 3.50);

                    Assert.AreEqual($"Berekening voor waterstand '{waterLevelUpperBoundary}' is gestart.", msgs[0]);
                    Assert.AreEqual($"Berekening is mislukt voor waterstand '{waterLevelUpperBoundary}'. {detailedReport}", msgs[1]);
                    StringAssert.StartsWith("Golfcondities berekening is uitgevoerd op de tijdelijke locatie", msgs[2]);
                    Assert.AreEqual($"Berekening voor waterstand '{waterLevelUpperBoundary}' is beëindigd.", msgs[3]);

                    Assert.AreEqual($"Berekening voor waterstand '{waterLevelMiddle}' is gestart.", msgs[4]);
                    StringAssert.StartsWith("Golfcondities berekening is uitgevoerd op de tijdelijke locatie", msgs[5]);
                    Assert.AreEqual($"Berekening voor waterstand '{waterLevelMiddle}' is beëindigd.", msgs[6]);

                    Assert.AreEqual($"Berekening voor waterstand '{waterLevelLowerBoundary}' is gestart.", msgs[7]);
                    StringAssert.StartsWith("Golfcondities berekening is uitgevoerd op de tijdelijke locatie", msgs[8]);
                    Assert.AreEqual($"Berekening voor waterstand '{waterLevelLowerBoundary}' is beëindigd.", msgs[9]);
                });

                WaveConditionsOutput[] waveConditionsOutputs = service.Outputs.ToArray();
                Assert.AreEqual(3, waveConditionsOutputs.Length);

                WaveConditionsOutputTestHelper.AssertFailedOutput(waterLevelUpperBoundary,
                                                                  targetProbability,
                                                                  waveConditionsOutputs[0]);
            }

            mockRepository.VerifyAll();
        }
        public void Calculate_ThreeCalculationsFail_ThrowsHydraRingCalculationExceptionAndLogError(bool endInFailure,
                                                                                                   string lastErrorFileContent,
                                                                                                   string detailedReport)
        {
            // Setup
            var waterLevel = (RoundedDouble)4.20;
            var waterLevelUpperBoundaryRevetment = new RoundedDouble(2, 4.00);
            var waterLevelLowerBoundaryRevetment = new RoundedDouble(2, 3.00);

            var input = new WaveConditionsInput
            {
                HydraulicBoundaryLocation = new TestHydraulicBoundaryLocation(),
                ForeshoreProfile          = new TestForeshoreProfile(),
                UpperBoundaryRevetment    = waterLevelUpperBoundaryRevetment,
                LowerBoundaryRevetment    = waterLevelLowerBoundaryRevetment
            };

            int nrOfCalculators = input.GetWaterLevels(waterLevel).Count();

            var calculatorThatFails = new TestWaveConditionsCosineCalculator
            {
                EndInFailure         = endInFailure,
                LastErrorFileContent = lastErrorFileContent
            };

            var mockRepository    = new MockRepository();
            var calculatorFactory = mockRepository.StrictMock <IHydraRingCalculatorFactory>();

            calculatorFactory.Expect(cf => cf.CreateWaveConditionsCosineCalculator(null))
            .IgnoreArguments()
            .Return(calculatorThatFails)
            .Repeat
            .Times(nrOfCalculators);
            mockRepository.ReplayAll();

            var          a = (RoundedDouble)1.0;
            var          b = (RoundedDouble)0.8;
            var          c = (RoundedDouble)0.4;
            const double targetProbability = 0.2;

            HydraRingCalculationException exception = null;

            using (new HydraRingCalculatorFactoryConfig(calculatorFactory))
            {
                // Call
                void Call()
                {
                    try
                    {
                        new TestWaveConditionsCalculationService().PublicCalculate(a, b, c, targetProbability, input, waterLevel,
                                                                                   GetValidHydraulicBoundaryDatabase());
                    }
                    catch (HydraRingCalculationException e)
                    {
                        exception = e;
                    }
                }

                // Assert
                TestHelper.AssertLogMessages(Call, messages =>
                {
                    string[] msgs = messages.ToArray();
                    Assert.AreEqual(13, msgs.Length);

                    var waterLevelMiddleRevetment = new RoundedDouble(2, 3.50);

                    Assert.AreEqual($"Berekening voor waterstand '{waterLevelUpperBoundaryRevetment}' is gestart.", msgs[0]);
                    Assert.AreEqual($"Berekening is mislukt voor waterstand '{waterLevelUpperBoundaryRevetment}'. {detailedReport}", msgs[1]);
                    StringAssert.StartsWith("Golfcondities berekening is uitgevoerd op de tijdelijke locatie", msgs[2]);
                    Assert.AreEqual($"Berekening voor waterstand '{waterLevelUpperBoundaryRevetment}' is beëindigd.", msgs[3]);

                    Assert.AreEqual($"Berekening voor waterstand '{waterLevelMiddleRevetment}' is gestart.", msgs[4]);
                    Assert.AreEqual($"Berekening is mislukt voor waterstand '{waterLevelMiddleRevetment}'. {detailedReport}", msgs[5]);
                    StringAssert.StartsWith("Golfcondities berekening is uitgevoerd op de tijdelijke locatie", msgs[6]);
                    Assert.AreEqual($"Berekening voor waterstand '{waterLevelMiddleRevetment}' is beëindigd.", msgs[7]);

                    Assert.AreEqual($"Berekening voor waterstand '{waterLevelLowerBoundaryRevetment}' is gestart.", msgs[8]);
                    Assert.AreEqual($"Berekening is mislukt voor waterstand '{waterLevelLowerBoundaryRevetment}'. {detailedReport}", msgs[9]);
                    StringAssert.StartsWith("Golfcondities berekening is uitgevoerd op de tijdelijke locatie", msgs[10]);
                    Assert.AreEqual($"Berekening voor waterstand '{waterLevelLowerBoundaryRevetment}' is beëindigd.", msgs[11]);

                    Assert.AreEqual("Berekening is mislukt voor alle waterstanden.", msgs[12]);
                });
                Assert.IsInstanceOf <HydraRingCalculationException>(exception);
                Assert.AreEqual("Berekening is mislukt voor alle waterstanden.", exception.Message);
            }

            mockRepository.VerifyAll();
        }
Exemplo n.º 14
0
        public void GivenValidCalculations_WhenCalculatingAllFromContextMenu_ThenAllCalculationsScheduled()
        {
            // Given
            var hydraulicBoundaryLocation = new TestHydraulicBoundaryLocation("Test");
            var assessmentSection         = new AssessmentSectionStub
            {
                HydraulicBoundaryDatabase =
                {
                    FilePath = validFilePath
                }
            };

            assessmentSection.SetHydraulicBoundaryLocationCalculations(new[]
            {
                hydraulicBoundaryLocation
            });
            HydraulicBoundaryDatabaseTestHelper.SetHydraulicBoundaryLocationConfigurationSettings(assessmentSection.HydraulicBoundaryDatabase);

            var failureMechanism = new GrassCoverErosionOutwardsFailureMechanism();

            assessmentSection.WaterLevelCalculationsForSignalFloodingProbability.ElementAt(0).Output =
                new TestHydraulicBoundaryLocationCalculationOutput(2.0);

            GrassCoverErosionOutwardsWaveConditionsCalculation calculation = CreateValidCalculation(hydraulicBoundaryLocation);

            failureMechanism.CalculationsGroup.Children.Add(calculation);

            var context = new GrassCoverErosionOutwardsFailureMechanismContext(failureMechanism, assessmentSection);

            using (var treeViewControl = new TreeViewControl())
            {
                IMainWindow mainWindow = MainWindowTestHelper.CreateMainWindowStub(mocks);

                var gui = mocks.Stub <IGui>();
                gui.Stub(g => g.MainWindow).Return(mainWindow);
                gui.Stub(g => g.ProjectOpened += null).IgnoreArguments();
                gui.Stub(g => g.ProjectOpened -= null).IgnoreArguments();
                gui.Stub(cmp => cmp.Get(context, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder());
                gui.Stub(g => g.DocumentViewController).Return(mocks.Stub <IDocumentViewController>());

                var calculatorFactory        = mocks.Stub <IHydraRingCalculatorFactory>();
                var waveConditionsCalculator = new TestWaveConditionsCosineCalculator
                {
                    Converged = false
                };

                HydraulicBoundaryCalculationSettings expectedCalculationSettings = HydraulicBoundaryCalculationSettingsFactory.CreateSettings(assessmentSection.HydraulicBoundaryDatabase);
                calculatorFactory.Expect(cf => cf.CreateWaveConditionsCosineCalculator(Arg <HydraRingCalculationSettings> .Is.NotNull))
                .WhenCalled(invocation =>
                {
                    HydraRingCalculationSettingsTestHelper.AssertHydraRingCalculationSettings(
                        expectedCalculationSettings,
                        (HydraRingCalculationSettings)invocation.Arguments[0]);
                })
                .Return(waveConditionsCalculator)
                .Repeat
                .Times(6);
                mocks.ReplayAll();

                plugin.Gui = gui;
                plugin.Activate();

                using (ContextMenuStrip contextMenuAdapter = info.ContextMenuStrip(context, null, treeViewControl))
                    using (new HydraRingCalculatorFactoryConfig(calculatorFactory))
                    {
                        // When
                        void Call() => contextMenuAdapter.Items[contextMenuCalculateAllIndex].PerformClick();

                        // Then
                        TestHelper.AssertLogMessages(Call, messages =>
                        {
                            string[] msgs = messages.ToArray();
                            Assert.AreEqual(28, msgs.Length);

                            Assert.AreEqual($"Golfcondities berekenen voor '{calculation.Name}' is gestart.", msgs.ElementAt(0));
                            CalculationServiceTestHelper.AssertValidationStartMessage(msgs.ElementAt(1));
                            CalculationServiceTestHelper.AssertValidationEndMessage(msgs.ElementAt(2));
                            CalculationServiceTestHelper.AssertCalculationStartMessage(msgs.ElementAt(3));

                            IEnumerable <RoundedDouble> waterLevels = calculation.InputParameters.GetWaterLevels(
                                assessmentSection.WaterLevelCalculationsForSignalFloodingProbability.Single().Output.Result);
                            Assert.AreEqual(3, waterLevels.Count());
                            AssertWaveConditionsCalculationMessages(msgs, waterLevels, "golfoploop", 4);
                            AssertWaveConditionsCalculationMessages(msgs, waterLevels, "golfklap", 15);
                            CalculationServiceTestHelper.AssertCalculationEndMessage(msgs.ElementAt(26));
                            Assert.AreEqual($"Golfcondities berekenen voor '{calculation.Name}' is gelukt.", msgs.ElementAt(27));
                        });
                    }
            }
        }
Exemplo n.º 15
0
        public void Calculate_OneOutOfThreeCalculationsFails_ReturnsOutputsAndLogError(bool endInFailure,
                                                                                       string lastErrorFileContent,
                                                                                       string detailedReport)
        {
            // Setup
            var failureMechanism    = new WaveImpactAsphaltCoverFailureMechanism();
            var calculatorThatFails = new TestWaveConditionsCosineCalculator
            {
                EndInFailure         = endInFailure,
                LastErrorFileContent = lastErrorFileContent
            };

            var mockRepository    = new MockRepository();
            var calculatorFactory = mockRepository.StrictMock <IHydraRingCalculatorFactory>();

            calculatorFactory.Expect(cf => cf.CreateWaveConditionsCosineCalculator(null))
            .IgnoreArguments()
            .Return(calculatorThatFails);
            calculatorFactory.Expect(cf => cf.CreateWaveConditionsCosineCalculator(null))
            .IgnoreArguments()
            .Return(new TestWaveConditionsCosineCalculator())
            .Repeat
            .Twice();
            mockRepository.ReplayAll();

            IAssessmentSection assessmentSection = CreateAssessmentSectionWithHydraulicBoundaryOutput();
            WaveImpactAsphaltCoverWaveConditionsCalculation calculation = GetValidCalculation(assessmentSection.HydraulicBoundaryDatabase.Locations.First());

            using (new HydraRingCalculatorFactoryConfig(calculatorFactory))
            {
                var service = new WaveImpactAsphaltCoverWaveConditionsCalculationService();

                // Call
                void Call() => service.Calculate(calculation, assessmentSection, failureMechanism.GeneralInput);

                // Assert
                RoundedDouble[] waterLevels = GetWaterLevels(calculation, assessmentSection).ToArray();
                RoundedDouble   waterLevelUpperBoundaryRevetment = waterLevels[0];
                RoundedDouble   waterLevelMiddleRevetment        = waterLevels[1];
                RoundedDouble   waterLevelLowerBoundaryRevetment = waterLevels[2];

                TestHelper.AssertLogMessages(Call, messages =>
                {
                    string[] msgs = messages.ToArray();
                    Assert.AreEqual(12, msgs.Length);

                    CalculationServiceTestHelper.AssertCalculationStartMessage(msgs[0]);

                    Assert.AreEqual($"Berekening voor waterstand '{waterLevelUpperBoundaryRevetment}' is gestart.", msgs[1]);
                    Assert.AreEqual($"Berekening is mislukt voor waterstand '{waterLevelUpperBoundaryRevetment}'. {detailedReport}", msgs[2]);
                    StringAssert.StartsWith("Golfcondities berekening is uitgevoerd op de tijdelijke locatie", msgs[3]);
                    Assert.AreEqual($"Berekening voor waterstand '{waterLevelUpperBoundaryRevetment}' is beëindigd.", msgs[4]);

                    Assert.AreEqual($"Berekening voor waterstand '{waterLevelMiddleRevetment}' is gestart.", msgs[5]);
                    StringAssert.StartsWith("Golfcondities berekening is uitgevoerd op de tijdelijke locatie", msgs[6]);
                    Assert.AreEqual($"Berekening voor waterstand '{waterLevelMiddleRevetment}' is beëindigd.", msgs[7]);

                    Assert.AreEqual($"Berekening voor waterstand '{waterLevelLowerBoundaryRevetment}' is gestart.", msgs[8]);
                    StringAssert.StartsWith("Golfcondities berekening is uitgevoerd op de tijdelijke locatie", msgs[9]);
                    Assert.AreEqual($"Berekening voor waterstand '{waterLevelLowerBoundaryRevetment}' is beëindigd.", msgs[10]);

                    CalculationServiceTestHelper.AssertCalculationEndMessage(msgs[11]);
                });

                WaveConditionsOutput[] waveConditionsOutputs = calculation.Output.Items.ToArray();
                Assert.AreEqual(3, waveConditionsOutputs.Length);

                WaveConditionsOutputTestHelper.AssertFailedOutput(waterLevelUpperBoundaryRevetment,
                                                                  assessmentSection.FailureMechanismContribution.MaximumAllowableFloodingProbability,
                                                                  waveConditionsOutputs[0]);
            }

            mockRepository.VerifyAll();
        }
Exemplo n.º 16
0
        public void Calculate_ThreeCalculationsFail_ThrowsHydraRingCalculationExceptionAndLogError(bool endInFailure,
                                                                                                   string lastErrorFileContent,
                                                                                                   string detailedReport)
        {
            // Setup
            var failureMechanism    = new WaveImpactAsphaltCoverFailureMechanism();
            var calculatorThatFails = new TestWaveConditionsCosineCalculator
            {
                EndInFailure         = endInFailure,
                LastErrorFileContent = lastErrorFileContent
            };

            var mockRepository    = new MockRepository();
            var calculatorFactory = mockRepository.StrictMock <IHydraRingCalculatorFactory>();

            calculatorFactory.Expect(cf => cf.CreateWaveConditionsCosineCalculator(null))
            .IgnoreArguments()
            .Return(calculatorThatFails)
            .Repeat
            .Times(3);
            mockRepository.ReplayAll();

            IAssessmentSection assessmentSection = CreateAssessmentSectionWithHydraulicBoundaryOutput();
            WaveImpactAsphaltCoverWaveConditionsCalculation calculation = GetValidCalculation(assessmentSection.HydraulicBoundaryDatabase.Locations.First());

            using (new HydraRingCalculatorFactoryConfig(calculatorFactory))
            {
                HydraRingCalculationException exception = null;

                // Call
                void Call()
                {
                    try
                    {
                        new WaveImpactAsphaltCoverWaveConditionsCalculationService().Calculate(calculation, assessmentSection, failureMechanism.GeneralInput);
                    }
                    catch (HydraRingCalculationException e)
                    {
                        exception = e;
                    }
                }

                // Assert
                TestHelper.AssertLogMessages(Call, messages =>
                {
                    string[] msgs = messages.ToArray();
                    Assert.AreEqual(15, msgs.Length);

                    CalculationServiceTestHelper.AssertCalculationStartMessage(msgs[0]);

                    RoundedDouble[] waterLevels = GetWaterLevels(calculation, assessmentSection).ToArray();
                    RoundedDouble waterLevelUpperBoundaryRevetment = waterLevels[0];
                    RoundedDouble waterLevelMiddleRevetment        = waterLevels[1];
                    RoundedDouble waterLevelLowerBoundaryRevetment = waterLevels[2];

                    Assert.AreEqual($"Berekening voor waterstand '{waterLevelUpperBoundaryRevetment}' is gestart.", msgs[1]);
                    Assert.AreEqual($"Berekening is mislukt voor waterstand '{waterLevelUpperBoundaryRevetment}'. {detailedReport}", msgs[2]);
                    StringAssert.StartsWith("Golfcondities berekening is uitgevoerd op de tijdelijke locatie", msgs[3]);
                    Assert.AreEqual($"Berekening voor waterstand '{waterLevelUpperBoundaryRevetment}' is beëindigd.", msgs[4]);

                    Assert.AreEqual($"Berekening voor waterstand '{waterLevelMiddleRevetment}' is gestart.", msgs[5]);
                    Assert.AreEqual($"Berekening is mislukt voor waterstand '{waterLevelMiddleRevetment}'. {detailedReport}", msgs[6]);
                    StringAssert.StartsWith("Golfcondities berekening is uitgevoerd op de tijdelijke locatie", msgs[7]);
                    Assert.AreEqual($"Berekening voor waterstand '{waterLevelMiddleRevetment}' is beëindigd.", msgs[8]);

                    Assert.AreEqual($"Berekening voor waterstand '{waterLevelLowerBoundaryRevetment}' is gestart.", msgs[9]);
                    Assert.AreEqual($"Berekening is mislukt voor waterstand '{waterLevelLowerBoundaryRevetment}'. {detailedReport}", msgs[10]);
                    StringAssert.StartsWith("Golfcondities berekening is uitgevoerd op de tijdelijke locatie", msgs[11]);
                    Assert.AreEqual($"Berekening voor waterstand '{waterLevelLowerBoundaryRevetment}' is beëindigd.", msgs[12]);

                    Assert.AreEqual("Berekening is mislukt voor alle waterstanden.", msgs[13]);
                    CalculationServiceTestHelper.AssertCalculationEndMessage(msgs[14]);
                });
                Assert.IsInstanceOf <HydraRingCalculationException>(exception);
                Assert.AreEqual("Berekening is mislukt voor alle waterstanden.", exception.Message);
                Assert.IsNull(calculation.Output);
            }

            mockRepository.VerifyAll();
        }