Exemplo n.º 1
0
        public void Calculate_Canceled_HasNoOutput()
        {
            // Setup
            IAssessmentSection assessmentSection = CreateAssessmentSectionWithHydraulicBoundaryOutput();
            WaveImpactAsphaltCoverWaveConditionsCalculation calculation = GetDefaultCalculation(assessmentSection.HydraulicBoundaryDatabase.Locations.First());

            var waveImpactAsphaltCoverFailureMechanism = new WaveImpactAsphaltCoverFailureMechanism();

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

            mockRepository.ReplayAll();

            using (new HydraRingCalculatorFactoryConfig(calculatorFactory))
            {
                var waveImpactAsphaltCoverWaveConditionsCalculationService = new WaveImpactAsphaltCoverWaveConditionsCalculationService();
                waveImpactAsphaltCoverWaveConditionsCalculationService.Cancel();

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

                // Assert
                Assert.IsFalse(calculation.HasOutput);
            }

            mockRepository.VerifyAll();
        }
Exemplo n.º 2
0
        public void Constructor_ReturnsNewInstance()
        {
            // Call
            var service = new WaveImpactAsphaltCoverWaveConditionsCalculationService();

            // Assert
            Assert.IsInstanceOf <WaveConditionsCalculationServiceBase>(service);
        }
Exemplo n.º 3
0
        public void Calculate_Always_SendsProgressNotifications()
        {
            // Setup
            IAssessmentSection assessmentSection = CreateAssessmentSectionWithHydraulicBoundaryOutput();
            WaveImpactAsphaltCoverWaveConditionsCalculation calculation = GetValidCalculation(assessmentSection.HydraulicBoundaryDatabase.Locations.First());

            var failureMechanism = new WaveImpactAsphaltCoverFailureMechanism();

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

            RoundedDouble[] waterLevels = GetWaterLevels(calculation, assessmentSection).ToArray();
            calculatorFactory.Stub(cf => cf.CreateWaveConditionsCosineCalculator(null))
            .IgnoreArguments()
            .Return(new TestWaveConditionsCosineCalculator());
            mockRepository.ReplayAll();

            int nrOfCalculators = waterLevels.Length;

            using (new HydraRingCalculatorFactoryConfig(calculatorFactory))
            {
                var currentStep = 1;
                var stabilityStoneCoverWaveConditionsCalculationService = new WaveImpactAsphaltCoverWaveConditionsCalculationService();
                stabilityStoneCoverWaveConditionsCalculationService.OnProgressChanged += (description, step, steps) =>
                {
                    // Assert
                    var text = $"Waterstand '{waterLevels[(step - 1) % waterLevels.Length]}' [m+NAP] voor asfalt berekenen.";
                    Assert.AreEqual(text, description);
                    Assert.AreEqual(currentStep++, step);
                    Assert.AreEqual(nrOfCalculators, steps);
                };

                // Call
                stabilityStoneCoverWaveConditionsCalculationService.Calculate(calculation,
                                                                              assessmentSection,
                                                                              failureMechanism.GeneralInput);
            }

            mockRepository.VerifyAll();
        }
Exemplo n.º 4
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();
        }
Exemplo n.º 5
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();
        }