Exemple #1
0
        public void Run_HydraulicBoundaryDatabaseWithCanUsePreprocessorFalse_CreateWaveConditionsCosineCalculatorAsExpected()
        {
            // 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>();

            calculatorFactory.Expect(cf => cf.CreateWaveConditionsCosineCalculator(Arg <HydraRingCalculationSettings> .Is.NotNull))
            .WhenCalled(invocation =>
            {
                HydraRingCalculationSettingsTestHelper.AssertHydraRingCalculationSettings(
                    HydraulicBoundaryCalculationSettingsFactory.CreateSettings(assessmentSection.HydraulicBoundaryDatabase),
                    (HydraRingCalculationSettings)invocation.Arguments[0]);
            })
            .Return(new TestWaveConditionsCosineCalculator())
            .Repeat
            .Times(GetWaterLevels(calculation, assessmentSection).Count() * 2);
            mockRepository.ReplayAll();

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

            // Assert
            mockRepository.VerifyAll();
        }
        public void CalculateWaveHeights_ValidPathOneCalculation_LogsMessages()
        {
            // Setup
            const string hydraulicLocationName = "name";
            const string calculationIdentifier = "1/100";

            var mocks = new MockRepository();
            IAssessmentSection assessmentSection = AssessmentSectionTestHelper.CreateAssessmentSectionStub(mocks);

            var calculatorFactory = mocks.StrictMock <IHydraRingCalculatorFactory>();

            calculatorFactory.Expect(cf => cf.CreateWaveHeightCalculator(Arg <HydraRingCalculationSettings> .Is.NotNull))
            .WhenCalled(invocation =>
            {
                HydraRingCalculationSettingsTestHelper.AssertHydraRingCalculationSettings(
                    HydraulicBoundaryCalculationSettingsFactory.CreateSettings(assessmentSection.HydraulicBoundaryDatabase),
                    (HydraRingCalculationSettings)invocation.Arguments[0]);
            })
            .Return(new TestWaveHeightCalculator());
            mocks.ReplayAll();

            assessmentSection.HydraulicBoundaryDatabase.FilePath = validFilePath;
            HydraulicBoundaryDatabaseTestHelper.SetHydraulicBoundaryLocationConfigurationSettings(assessmentSection.HydraulicBoundaryDatabase);

            DialogBoxHandler = (name, wnd) =>
            {
                // Expect an activity dialog which is automatically closed
            };

            using (var viewParent = new TestViewParentForm())
                using (new HydraRingCalculatorFactoryConfig(calculatorFactory))
                {
                    var guiService = new HydraulicBoundaryLocationCalculationGuiService(viewParent);

                    // Call
                    void Call() =>
                    guiService.CalculateWaveHeights(new[]
                    {
                        new HydraulicBoundaryLocationCalculation(new TestHydraulicBoundaryLocation(hydraulicLocationName))
                    }, assessmentSection, 0.01, calculationIdentifier);

                    // Assert
                    TestHelper.AssertLogMessages(Call, messages =>
                    {
                        string[] msgs = messages.ToArray();
                        Assert.AreEqual(8, msgs.Length);
                        string activityDescription = GetWaveHeightCalculationActivityDescription(hydraulicLocationName, calculationIdentifier);
                        Assert.AreEqual($"{activityDescription} is gestart.", msgs[0]);
                        CalculationServiceTestHelper.AssertValidationStartMessage(msgs[1]);
                        CalculationServiceTestHelper.AssertValidationEndMessage(msgs[2]);
                        CalculationServiceTestHelper.AssertCalculationStartMessage(msgs[3]);
                        Assert.AreEqual($"Golfhoogte berekening voor locatie 'name' ({calculationIdentifier}) is niet geconvergeerd.", msgs[4]);
                        StringAssert.StartsWith("Golfhoogte berekening is uitgevoerd op de tijdelijke locatie", msgs[5]);
                        CalculationServiceTestHelper.AssertCalculationEndMessage(msgs[6]);
                        Assert.AreEqual($"{activityDescription} is gelukt.", msgs[7]);
                    });
                }

            mocks.VerifyAll();
        }
        private static void AssertDesignWaterLevelCalculationActivity(Activity activity,
                                                                      HydraulicBoundaryLocation hydraulicBoundaryLocation,
                                                                      string calculationIdentifier,
                                                                      double targetProbability,
                                                                      HydraulicBoundaryDatabase hydraulicBoundaryDatabase)
        {
            var mocks             = new MockRepository();
            var calculator        = new TestDesignWaterLevelCalculator();
            var calculatorFactory = mocks.StrictMock <IHydraRingCalculatorFactory>();

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

            using (new HydraRingCalculatorFactoryConfig(calculatorFactory))
            {
                Action call = activity.Run;

                string expectedLogMessage = $"Waterstand berekenen voor locatie '{hydraulicBoundaryLocation.Name}' ({calculationIdentifier}) is gestart.";

                TestHelper.AssertLogMessageIsGenerated(call, expectedLogMessage);
                AssessmentLevelCalculationInput designWaterLevelCalculationInput = calculator.ReceivedInputs.Single();
                Assert.AreEqual(hydraulicBoundaryLocation.Id, designWaterLevelCalculationInput.HydraulicBoundaryLocationId);
                Assert.AreEqual(StatisticsConverter.ProbabilityToReliability(targetProbability), designWaterLevelCalculationInput.Beta);
            }

            mocks.VerifyAll();
        }
Exemple #4
0
        private static void AssertStabilityPointStructuresCalculationActivity(Activity activity,
                                                                              ICalculation <StabilityPointStructuresInput> calculation,
                                                                              HydraulicBoundaryDatabase hydraulicBoundaryDatabase)
        {
            var mocks             = new MockRepository();
            var testCalculator    = new TestStructuresCalculator <StructuresStabilityPointCalculationInput>();
            var calculatorFactory = mocks.StrictMock <IHydraRingCalculatorFactory>();

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

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

                StructuresStabilityPointCalculationInput actualInput = testCalculator.ReceivedInputs.Single();
                Assert.AreEqual(calculation.InputParameters.FailureProbabilityStructureWithErosion,
                                actualInput.Variables.Single(v => v.VariableId == 105).Value);
            }

            mocks.VerifyAll();
        }
Exemple #5
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();
        }
        private static void AssertGrassCoverErosionInwardsCalculationActivity(Activity activity,
                                                                              GrassCoverErosionInwardsCalculation calculation,
                                                                              HydraulicBoundaryDatabase hydraulicBoundaryDatabase)
        {
            var mocks             = new MockRepository();
            var testCalculator    = new TestOvertoppingCalculator();
            var calculatorFactory = mocks.StrictMock <IHydraRingCalculatorFactory>();

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

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

                Assert.AreEqual(calculation.InputParameters.BreakWater.Height, testCalculator.ReceivedInputs.Single().BreakWater.Height);
            }

            mocks.VerifyAll();
        }
        public void Run_HydraulicBoundaryDatabaseWithUsePreprocessorFalse_ExpectedPreprocessorDirectorySetToCalculator()
        {
            // Setup
            var assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike)
            {
                HydraulicBoundaryDatabase =
                {
                    FilePath  = validFilePath,
                    Locations =
                    {
                        new HydraulicBoundaryLocation(1300001, string.Empty, 0, 0)
                    },
                    HydraulicLocationConfigurationSettings =
                    {
                        CanUsePreprocessor    = true,
                        UsePreprocessor       = false,
                        PreprocessorDirectory = "InvalidPreprocessorDirectory"
                    }
                }
            };

            HydraulicBoundaryDatabaseTestHelper.SetHydraulicBoundaryLocationConfigurationSettings(assessmentSection.HydraulicBoundaryDatabase);

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

            calculatorFactory.Expect(cf => cf.CreateStructuresCalculator <StructuresOvertoppingCalculationInput>(
                                         Arg <HydraRingCalculationSettings> .Is.NotNull))
            .WhenCalled(invocation =>
            {
                HydraRingCalculationSettingsTestHelper.AssertHydraRingCalculationSettings(
                    HydraulicBoundaryCalculationSettingsFactory.CreateSettings(assessmentSection.HydraulicBoundaryDatabase),
                    (HydraRingCalculationSettings)invocation.Arguments[0]);
            })
            .Return(new TestStructuresCalculator <StructuresOvertoppingCalculationInput>());
            mockRepository.ReplayAll();

            var failureMechanism = new HeightStructuresFailureMechanism();
            var calculation      = new TestHeightStructuresCalculationScenario
            {
                InputParameters =
                {
                    HydraulicBoundaryLocation = assessmentSection.HydraulicBoundaryDatabase.Locations.First(hl => hl.Id == 1300001)
                }
            };

            CalculatableActivity activity = HeightStructuresCalculationActivityFactory.CreateCalculationActivity(calculation,
                                                                                                                 failureMechanism,
                                                                                                                 assessmentSection);

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

            // Assert
            mockRepository.VerifyAll();
        }
Exemple #8
0
        protected override void PerformCalculation()
        {
            calculation.ClearOutput();

            calculationService.Calculate(calculation,
                                         failureMechanism.GeneralInput,
                                         HydraulicBoundaryCalculationSettingsFactory.CreateSettings(assessmentSection.HydraulicBoundaryDatabase));
        }
        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();
        }
        public void GivenValidCalculations_WhenCalculatingAllFromContextMenu_ThenAllCalculationsScheduled()
        {
            // Given
            var failureMechanism = new StabilityStoneCoverFailureMechanism();
            IAssessmentSection assessmentSection = CreateAssessmentSectionWithHydraulicBoundaryOutput();

            HydraulicBoundaryLocation hydraulicBoundaryLocation       = assessmentSection.HydraulicBoundaryDatabase.Locations.First();
            StabilityStoneCoverWaveConditionsCalculation calculationA = GetValidCalculation(hydraulicBoundaryLocation);
            StabilityStoneCoverWaveConditionsCalculation calculationB = GetValidCalculation(hydraulicBoundaryLocation);
            List <ICalculationBase> calculations = failureMechanism.CalculationsGroup.Children;

            calculations.AddRange(new[]
            {
                calculationA,
                calculationB
            });

            var nodeData = new StabilityStoneCoverFailureMechanismContext(failureMechanism, assessmentSection);

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

                var gui = mocks.Stub <IGui>();
                gui.Stub(g => g.Get(nodeData, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder());
                gui.Stub(g => g.MainWindow).Return(mainWindow);

                var calculatorFactory = mocks.Stub <IHydraRingCalculatorFactory>();
                calculatorFactory.Expect(cf => cf.CreateWaveConditionsCosineCalculator(Arg <HydraRingCalculationSettings> .Is.NotNull))
                .WhenCalled(invocation =>
                {
                    HydraRingCalculationSettingsTestHelper.AssertHydraRingCalculationSettings(
                        HydraulicBoundaryCalculationSettingsFactory.CreateSettings(assessmentSection.HydraulicBoundaryDatabase),
                        (HydraRingCalculationSettings)invocation.Arguments[0]);
                })
                .Return(new TestWaveConditionsCosineCalculator())
                .Repeat
                .Times(12);
                mocks.ReplayAll();

                plugin.Gui = gui;

                using (new HydraRingCalculatorFactoryConfig(calculatorFactory))
                    using (ContextMenuStrip contextMenu = info.ContextMenuStrip(nodeData, null, treeViewControl))
                    {
                        // When
                        contextMenu.Items[contextMenuCalculateAllIndex].PerformClick();

                        // Then
                        Assert.AreEqual(3, calculationA.Output.BlocksOutput.Count());
                        Assert.AreEqual(3, calculationA.Output.ColumnsOutput.Count());
                        Assert.AreEqual(3, calculationB.Output.BlocksOutput.Count());
                        Assert.AreEqual(3, calculationB.Output.ColumnsOutput.Count());
                    }
            }
        }
Exemple #11
0
        public void CreateSettings_WithHydraulicBoundaryDatabaseWithVariousPreprocessorConfigurations_ReturnsExpectedSettings(
            HydraulicBoundaryDatabase database,
            string expectedPreprocessorDirectory)
        {
            // Call
            HydraulicBoundaryCalculationSettings settings = HydraulicBoundaryCalculationSettingsFactory.CreateSettings(database);

            // Assert
            Assert.AreEqual(expectedPreprocessorDirectory, settings.PreprocessorDirectory);
        }
Exemple #12
0
        public void CreateSettings_HydraulicBoundaryDatabaseNull_ThrowsArgumentNullException()
        {
            // Call
            TestDelegate call = () => HydraulicBoundaryCalculationSettingsFactory.CreateSettings(null);

            // Assert
            var exception = Assert.Throws <ArgumentNullException>(call);

            Assert.AreEqual("hydraulicBoundaryDatabase", exception.ParamName);
        }
Exemple #13
0
        protected override void PerformCalculation()
        {
            calculation.ClearOutput();

            FailureMechanismSection section = failureMechanism.Sections.Single(
                s => calculation.IsSurfaceLineIntersectionWithReferenceLineInSection(
                    Math2D.ConvertPointsToLineSegments(s.Points)));

            service.Calculate(calculation, failureMechanism.GeneralInput,
                              HydraulicBoundaryCalculationSettingsFactory.CreateSettings(assessmentSection.HydraulicBoundaryDatabase),
                              section.Length);
        }
Exemple #14
0
        public void Run_HydraulicBoundaryDatabaseWithUsePreprocessorTrue_ExpectedPreprocessorDirectorySetToCalculator()
        {
            // Setup
            var assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike)
            {
                HydraulicBoundaryDatabase =
                {
                    FilePath                               = validFilePath,
                    HydraulicLocationConfigurationSettings =
                    {
                        CanUsePreprocessor    = true,
                        UsePreprocessor       = true,
                        PreprocessorDirectory = validPreprocessorDirectory
                    }
                }
            };

            HydraulicBoundaryDatabaseTestHelper.SetHydraulicBoundaryLocationConfigurationSettings(assessmentSection.HydraulicBoundaryDatabase);

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

            calculatorFactory.Expect(cf => cf.CreateStructuresCalculator <StructuresClosureCalculationInput>(
                                         Arg <HydraRingCalculationSettings> .Is.NotNull))
            .WhenCalled(invocation =>
            {
                HydraRingCalculationSettingsTestHelper.AssertHydraRingCalculationSettings(
                    HydraulicBoundaryCalculationSettingsFactory.CreateSettings(assessmentSection.HydraulicBoundaryDatabase),
                    (HydraRingCalculationSettings)invocation.Arguments[0]);
            })
            .Return(new TestStructuresCalculator <StructuresClosureCalculationInput>());
            mockRepository.ReplayAll();

            var failureMechanism = new ClosingStructuresFailureMechanism();
            var calculation      = new TestClosingStructuresCalculationScenario();

            CalculatableActivity activity = ClosingStructuresCalculationActivityFactory.CreateCalculationActivity(calculation,
                                                                                                                  failureMechanism,
                                                                                                                  assessmentSection);

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

            // Assert
            mockRepository.VerifyAll();
        }
        public void Run_HydraulicBoundaryDatabaseWithUsePreprocessorFalse_CreateWaveConditionsCosineCalculatorAsExpected()
        {
            // Setup
            AssessmentSectionStub assessmentSection = CreateAssessmentSection();

            ConfigureAssessmentSectionWithHydraulicBoundaryOutput(assessmentSection);

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

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

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

            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(new TestWaveConditionsCosineCalculator())
            .Repeat
            .Times(nrOfCalculators);
            mockRepository.ReplayAll();

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

            // Assert
            mockRepository.VerifyAll();
        }
Exemple #16
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();
        }
        private static void AssertDuneLocationCalculationActivity(Activity activity,
                                                                  string calculationIdentifier,
                                                                  string locationName,
                                                                  long locationId,
                                                                  double targetProbability,
                                                                  HydraulicBoundaryDatabase hydraulicBoundaryDatabase)
        {
            var calculator = new TestDunesBoundaryConditionsCalculator();

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

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

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

            var expectedLogMessage = $"Hydraulische belastingen berekenen voor locatie '{locationName}' ({calculationIdentifier}) is gestart.";

            TestHelper.AssertLogMessageIsGenerated(Call, expectedLogMessage);
            DunesBoundaryConditionsCalculationInput dunesBoundaryConditionsCalculationInput = calculator.ReceivedInputs.Last();

            Assert.AreEqual(locationId, dunesBoundaryConditionsCalculationInput.HydraulicBoundaryLocationId);
            Assert.AreEqual(StatisticsConverter.ProbabilityToReliability(targetProbability), dunesBoundaryConditionsCalculationInput.Beta);

            mocks.VerifyAll();
        }
Exemple #18
0
        /// <summary>
        /// Creates a collection of <see cref="CalculatableActivity"/> based on <paramref name="calculations"/>.
        /// </summary>
        /// <param name="calculations">The calculations to create activities for.</param>
        /// <param name="assessmentSection">The assessment section the calculations belong to.</param>
        /// <param name="targetProbability">The target probability to use during the calculations.</param>
        /// <param name="calculationIdentifier">The calculation identifier to use in all messages.</param>
        /// <returns>A collection of <see cref="CalculatableActivity"/>.</returns>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="calculations"/> or
        /// <paramref name="assessmentSection"/> is <c>null</c>.</exception>
        /// <exception cref="ArgumentException">Thrown when <paramref name="calculationIdentifier"/> is <c>null</c> or empty.</exception>
        public static IEnumerable <CalculatableActivity> CreateCalculationActivities(IEnumerable <DuneLocationCalculation> calculations,
                                                                                     IAssessmentSection assessmentSection,
                                                                                     double targetProbability,
                                                                                     string calculationIdentifier)
        {
            if (calculations == null)
            {
                throw new ArgumentNullException(nameof(calculations));
            }

            if (assessmentSection == null)
            {
                throw new ArgumentNullException(nameof(assessmentSection));
            }

            HydraulicBoundaryCalculationSettings settings = HydraulicBoundaryCalculationSettingsFactory.CreateSettings(assessmentSection.HydraulicBoundaryDatabase);

            return(calculations.Select(calculation => new DuneLocationCalculationActivity(calculation,
                                                                                          settings,
                                                                                          targetProbability,
                                                                                          calculationIdentifier)).ToArray());
        }
Exemple #19
0
        public void CreateSettings_WithHydraulicBoundaryDatabaseWithFilePath_ReturnsExpectedSettings()
        {
            // Setup
            const string hydraulicBoundaryDatabaseFilePath = "some//FilePath//HRD dutch coast south.sqlite";
            const string hlcdFilePath           = "some//FilePath//HLCD dutch coast south.sqlite";
            bool         usePreprocessorClosure = new Random(21).NextBoolean();

            var database = new HydraulicBoundaryDatabase
            {
                FilePath = hydraulicBoundaryDatabaseFilePath
            };

            database.HydraulicLocationConfigurationSettings.SetValues(hlcdFilePath, string.Empty, 10, string.Empty,
                                                                      usePreprocessorClosure, null, null, null, null, null, null);

            // Call
            HydraulicBoundaryCalculationSettings settings = HydraulicBoundaryCalculationSettingsFactory.CreateSettings(database);

            // Assert
            Assert.AreEqual(hydraulicBoundaryDatabaseFilePath, settings.HydraulicBoundaryDatabaseFilePath);
            Assert.AreEqual(hlcdFilePath, settings.HlcdFilePath);
            Assert.AreEqual(usePreprocessorClosure, settings.UsePreprocessorClosure);
        }
        public void Calculate_ValidPathOneCalculation_LogsMessages()
        {
            // Setup
            var hydraulicBoundaryDatabase = new HydraulicBoundaryDatabase
            {
                FilePath = validFilePath,
                HydraulicLocationConfigurationSettings =
                {
                    CanUsePreprocessor    = true,
                    UsePreprocessor       = true,
                    PreprocessorDirectory = validPreprocessorDirectory
                }
            };

            HydraulicBoundaryDatabaseTestHelper.SetHydraulicBoundaryLocationConfigurationSettings(hydraulicBoundaryDatabase);

            const string calculationIdentifier = "1/100";
            const string duneLocationName      = "duneLocationName";

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

            calculatorFactory.Expect(cf => cf.CreateDunesBoundaryConditionsCalculator(Arg <HydraRingCalculationSettings> .Is.NotNull))
            .WhenCalled(invocation =>
            {
                HydraRingCalculationSettingsTestHelper.AssertHydraRingCalculationSettings(
                    HydraulicBoundaryCalculationSettingsFactory.CreateSettings(hydraulicBoundaryDatabase),
                    (HydraRingCalculationSettings)invocation.Arguments[0]);
            })
            .Return(new TestDunesBoundaryConditionsCalculator());
            var assessmentSection = mocks.Stub <IAssessmentSection>();

            assessmentSection.Stub(a => a.HydraulicBoundaryDatabase)
            .Return(hydraulicBoundaryDatabase);
            mocks.ReplayAll();

            using (var viewParent = new TestViewParentForm())
                using (new HydraRingCalculatorFactoryConfig(calculatorFactory))
                {
                    var guiService = new DuneLocationCalculationGuiService(viewParent);

                    // Call
                    void Call() =>
                    guiService.Calculate(new[]
                    {
                        new DuneLocationCalculation(new TestDuneLocation(duneLocationName))
                    }, assessmentSection, 0.01, calculationIdentifier);

                    // Assert
                    TestHelper.AssertLogMessages(Call, messages =>
                    {
                        string[] msgs = messages.ToArray();
                        Assert.AreEqual(8, msgs.Length);
                        Assert.AreEqual($"Hydraulische belastingen berekenen voor locatie '{duneLocationName}' ({calculationIdentifier}) is gestart.", msgs[0]);
                        CalculationServiceTestHelper.AssertValidationStartMessage(msgs[1]);
                        CalculationServiceTestHelper.AssertValidationEndMessage(msgs[2]);
                        CalculationServiceTestHelper.AssertCalculationStartMessage(msgs[3]);
                        Assert.AreEqual($"Hydraulische belastingenberekening voor locatie '{duneLocationName}' ({calculationIdentifier}) is niet geconvergeerd.", msgs[4]);
                        StringAssert.StartsWith("Hydraulische belastingenberekening is uitgevoerd op de tijdelijke locatie", msgs[5]);
                        CalculationServiceTestHelper.AssertCalculationEndMessage(msgs[6]);
                        Assert.AreEqual($"Hydraulische belastingen berekenen voor locatie '{duneLocationName}' ({calculationIdentifier}) is gelukt.", msgs[7]);
                    });
                }

            mocks.VerifyAll();
        }
        /// <summary>
        /// Performs a grass cover erosion inwards calculation based on the supplied <see cref="GrassCoverErosionInwardsCalculation"/>
        /// and sets <see cref="GrassCoverErosionInwardsCalculation.Output"/> if the calculation was successful. Error and status
        /// information is logged during the execution of the operation.
        /// </summary>
        /// <param name="calculation">The <see cref="GrassCoverErosionInwardsCalculation"/> that holds all the information required to perform the calculation.</param>
        /// <param name="assessmentSection">The <see cref="IAssessmentSection"/> that holds information about the target probability used in the calculation.</param>
        /// <param name="generalInput">Calculation input parameters that apply to all <see cref="GrassCoverErosionInwardsCalculation"/> instances.</param>
        /// <exception cref="ArgumentNullException">Thrown when one of the following parameters is <c>null</c>:
        /// <list type="bullet">
        /// <item><paramref name="calculation"/></item>
        /// <item><paramref name="assessmentSection"/></item>
        /// <item><paramref name="generalInput"/></item>
        /// </list></exception>
        /// <exception cref="ArgumentException">Thrown when the hydraulic boundary database file path contains invalid characters.</exception>
        /// <exception cref="CriticalFileReadException">Thrown when:
        /// <list type="bullet">
        /// <item>No settings database file could be found at the location of the hydraulic boundary database file path
        /// with the same name.</item>
        /// <item>Unable to open settings database file.</item>
        /// <item>Unable to read required data from database file.</item>
        /// </list>
        /// </exception>
        /// <exception cref="SecurityException">Thrown when the temporary working directory can't be accessed due to missing permissions.</exception>
        /// <exception cref="IOException">Thrown when the specified path is not valid, the network name is not known
        /// or an I/O error occurred while opening the file.</exception>
        /// <exception cref="UnauthorizedAccessException">Thrown when the directory can't be created due to missing
        /// the required permissions.</exception>
        /// <exception cref="NotSupportedException">Thrown when <see cref="HydraRingCalculationInput.FailureMechanismType"/>
        /// is not the same with already added input.</exception>
        /// <exception cref="Win32Exception">Thrown when there was an error in opening the associated file
        /// or the wait setting could not be accessed.</exception>
        /// <exception cref="HydraRingFileParserException">Thrown when an error occurs during parsing of the Hydra-Ring output.</exception>
        /// <exception cref="HydraRingCalculationException">Thrown when an error occurs during the calculation.</exception>
        internal void Calculate(GrassCoverErosionInwardsCalculation calculation,
                                IAssessmentSection assessmentSection,
                                GeneralGrassCoverErosionInwardsInput generalInput)
        {
            if (calculation == null)
            {
                throw new ArgumentNullException(nameof(calculation));
            }

            if (assessmentSection == null)
            {
                throw new ArgumentNullException(nameof(assessmentSection));
            }

            if (generalInput == null)
            {
                throw new ArgumentNullException(nameof(generalInput));
            }

            HydraulicBoundaryCalculationSettings calculationSettings =
                HydraulicBoundaryCalculationSettingsFactory.CreateSettings(assessmentSection.HydraulicBoundaryDatabase);
            int numberOfCalculators = CreateCalculators(calculation, calculationSettings);

            string hydraulicBoundaryDatabaseFilePath = calculationSettings.HydraulicBoundaryDatabaseFilePath;
            bool   usePreprocessor = !string.IsNullOrEmpty(calculationSettings.PreprocessorDirectory);

            CalculationServiceHelper.LogCalculationBegin();

            try
            {
                OvertoppingOutput overtoppingOutput = CalculateOvertopping(calculation,
                                                                           generalInput,
                                                                           hydraulicBoundaryDatabaseFilePath,
                                                                           usePreprocessor,
                                                                           numberOfCalculators);

                if (canceled)
                {
                    return;
                }

                DikeHeightOutput dikeHeightOutput = CalculateDikeHeight(calculation,
                                                                        generalInput,
                                                                        hydraulicBoundaryDatabaseFilePath,
                                                                        usePreprocessor,
                                                                        numberOfCalculators);
                if (canceled)
                {
                    return;
                }

                OvertoppingRateOutput overtoppingRateOutput = CalculateOvertoppingRate(calculation,
                                                                                       generalInput,
                                                                                       hydraulicBoundaryDatabaseFilePath,
                                                                                       usePreprocessor,
                                                                                       numberOfCalculators);

                if (canceled)
                {
                    return;
                }

                calculation.Output = new GrassCoverErosionInwardsOutput(
                    overtoppingOutput,
                    dikeHeightOutput,
                    overtoppingRateOutput);
            }
            finally
            {
                CalculationServiceHelper.LogCalculationEnd();

                overtoppingCalculator     = null;
                dikeHeightCalculator      = null;
                overtoppingRateCalculator = null;
            }
        }
        public void CreateHydraulicLoadCalculationActivities_WithValidDataAndAllFailureMechanismsRelevant_ExpectedActivitiesCreated()
        {
            // Setup
            AssessmentSection assessmentSection = CreateAssessmentSection();

            var hydraulicBoundaryLocation = new TestHydraulicBoundaryLocation();
            IEnumerable <HydraulicBoundaryLocation> hydraulicBoundaryLocations = new[]
            {
                hydraulicBoundaryLocation
            };

            assessmentSection.WaterLevelCalculationsForUserDefinedTargetProbabilities.AddRange(
                new[]
            {
                new HydraulicBoundaryLocationCalculationsForTargetProbability(0.1),
                new HydraulicBoundaryLocationCalculationsForTargetProbability(0.01)
            });

            assessmentSection.WaveHeightCalculationsForUserDefinedTargetProbabilities.AddRange(
                new[]
            {
                new HydraulicBoundaryLocationCalculationsForTargetProbability(0.025),
                new HydraulicBoundaryLocationCalculationsForTargetProbability(0.0025)
            });

            assessmentSection.SetHydraulicBoundaryLocationCalculations(hydraulicBoundaryLocations);

            AddStabilityStoneCoverCalculation(assessmentSection, hydraulicBoundaryLocation);
            AddWaveImpactAsphaltCoverCalculation(assessmentSection, hydraulicBoundaryLocation);
            AddGrassCoverErosionOutwardsCalculation(assessmentSection, hydraulicBoundaryLocation);
            AddDuneLocationCalculation(assessmentSection);

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

            HydraulicBoundaryCalculationSettings expectedCalculationSettings =
                HydraulicBoundaryCalculationSettingsFactory.CreateSettings(assessmentSection.HydraulicBoundaryDatabase);

            using (mocks.Ordered())
            {
                calculatorFactory.Expect(cf => cf.CreateDesignWaterLevelCalculator(Arg <HydraRingCalculationSettings> .Is.NotNull))
                .WhenCalled(invocation =>
                {
                    HydraRingCalculationSettingsTestHelper.AssertHydraRingCalculationSettings(
                        expectedCalculationSettings, (HydraRingCalculationSettings)invocation.Arguments[0]);
                })
                .Return(new TestDesignWaterLevelCalculator
                {
                    DesignWaterLevel = 2.0
                }).Repeat.Times(4);
                calculatorFactory.Expect(cf => cf.CreateWaveHeightCalculator(Arg <HydraRingCalculationSettings> .Is.NotNull))
                .WhenCalled(invocation =>
                {
                    HydraRingCalculationSettingsTestHelper.AssertHydraRingCalculationSettings(
                        expectedCalculationSettings, (HydraRingCalculationSettings)invocation.Arguments[0]);
                })
                .Return(new TestWaveHeightCalculator()).Repeat.Times(2);

                calculatorFactory.Expect(cf => cf.CreateWaveConditionsCosineCalculator(Arg <HydraRingCalculationSettings> .Is.NotNull))
                .WhenCalled(invocation =>
                {
                    HydraRingCalculationSettingsTestHelper.AssertHydraRingCalculationSettings(
                        expectedCalculationSettings, (HydraRingCalculationSettings)invocation.Arguments[0]);
                })
                .Return(new TestWaveConditionsCosineCalculator()).Repeat.Times(9);

                calculatorFactory.Expect(cf => cf.CreateWaveConditionsCosineCalculator(Arg <HydraRingCalculationSettings> .Is.NotNull))
                .WhenCalled(invocation =>
                {
                    HydraRingCalculationSettingsTestHelper.AssertHydraRingCalculationSettings(
                        expectedCalculationSettings, (HydraRingCalculationSettings)invocation.Arguments[0]);
                })
                .Return(new TestWaveConditionsCosineCalculator()).Repeat.Times(6);

                calculatorFactory.Expect(cf => cf.CreateDunesBoundaryConditionsCalculator(Arg <HydraRingCalculationSettings> .Is.NotNull))
                .WhenCalled(invocation =>
                {
                    HydraRingCalculationSettingsTestHelper.AssertHydraRingCalculationSettings(
                        expectedCalculationSettings, (HydraRingCalculationSettings)invocation.Arguments[0]);
                })
                .Return(new TestDunesBoundaryConditionsCalculator()).Repeat.Once();
            }

            mocks.ReplayAll();

            // Call
            IEnumerable <CalculatableActivity> activities =
                AssessmentSectionCalculationActivityFactory.CreateHydraulicLoadCalculationActivities(assessmentSection);

            // Assert
            Assert.AreEqual(10, activities.Count());

            using (new HydraRingCalculatorFactoryConfig(calculatorFactory))
            {
                activities.ForEachElementDo(activity => activity.Run());
            }

            mocks.VerifyAll();
        }
        public void CalculateForSelectedButton_HydraulicBoundaryDatabaseWithUsePreprocessorFalse_CreateDunesBoundaryConditionsCalculatorCalledAsExpected()
        {
            // Setup
            const double targetProbability         = 0.01;
            var          hydraulicBoundaryDatabase = new HydraulicBoundaryDatabase
            {
                FilePath = hydraulicBoundaryDatabaseFilePath,
                HydraulicLocationConfigurationSettings =
                {
                    CanUsePreprocessor    = true,
                    UsePreprocessor       = false,
                    PreprocessorDirectory = "InvalidPreprocessorDirectory"
                }
            };

            HydraulicBoundaryDatabaseTestHelper.SetHydraulicBoundaryLocationConfigurationSettings(hydraulicBoundaryDatabase);

            var assessmentSection = mocks.Stub <IAssessmentSection>();

            assessmentSection.Stub(a => a.Id).Return("1");
            assessmentSection.Stub(a => a.FailureMechanismContribution)
            .Return(FailureMechanismContributionTestFactory.CreateFailureMechanismContribution());
            assessmentSection.Stub(a => a.HydraulicBoundaryDatabase).Return(hydraulicBoundaryDatabase);
            assessmentSection.Stub(a => a.Attach(null)).IgnoreArguments();
            assessmentSection.Stub(a => a.Detach(null)).IgnoreArguments();

            var calculatorFactory = mocks.StrictMock <IHydraRingCalculatorFactory>();
            var dunesBoundaryConditionsCalculator = new TestDunesBoundaryConditionsCalculator();

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

            var failureMechanism = new DuneErosionFailureMechanism();

            using (var view = new DuneLocationCalculationsView(GenerateDuneLocationCalculations(),
                                                               failureMechanism,
                                                               assessmentSection,
                                                               () => targetProbability,
                                                               () => "1/100"))
            {
                testForm.Controls.Add(view);
                testForm.Show();
                var dataGridView = (DataGridView)view.Controls.Find("dataGridView", true)[0];
                DataGridViewRowCollection rows = dataGridView.Rows;
                rows[0].Cells[calculateColumnIndex].Value = true;

                var buttonTester = new ButtonTester("CalculateForSelectedButton", testForm);

                using (var viewParent = new TestViewParentForm())
                    using (new HydraRingCalculatorFactoryConfig(calculatorFactory))
                    {
                        view.CalculationGuiService = new DuneLocationCalculationGuiService(viewParent);

                        // Call
                        buttonTester.Click();

                        // Assert
                        DunesBoundaryConditionsCalculationInput dunesBoundaryConditionsCalculationInput = dunesBoundaryConditionsCalculator.ReceivedInputs.First();

                        Assert.AreEqual(1, dunesBoundaryConditionsCalculationInput.HydraulicBoundaryLocationId);
                        Assert.AreEqual(StatisticsConverter.ProbabilityToReliability(targetProbability), dunesBoundaryConditionsCalculationInput.Beta);
                    }
            }
        }
Exemple #24
0
        public void ContextMenuStrip_ClickOnCalculateAllItem_ScheduleAllChildCalculations()
        {
            // Setup
            IMainWindow mainWindow  = MainWindowTestHelper.CreateMainWindowStub(mocksRepository);
            var         menuBuilder = new CustomItemsOnlyContextMenuBuilder();

            var failureMechanism = new GrassCoverErosionInwardsFailureMechanism();

            failureMechanism.CalculationsGroup.Children.Add(new GrassCoverErosionInwardsCalculation
            {
                Name            = "A",
                InputParameters =
                {
                    HydraulicBoundaryLocation = new TestHydraulicBoundaryLocation(),
                    DikeProfile               = DikeProfileTestFactory.CreateDikeProfile()
                }
            });
            failureMechanism.CalculationsGroup.Children.Add(new GrassCoverErosionInwardsCalculation
            {
                Name            = "B",
                InputParameters =
                {
                    HydraulicBoundaryLocation = new TestHydraulicBoundaryLocation(),
                    DikeProfile               = DikeProfileTestFactory.CreateDikeProfile()
                }
            });

            var hydraulicBoundaryDatabase = new HydraulicBoundaryDatabase
            {
                FilePath = Path.Combine(testDataPath, "complete.sqlite")
            };

            HydraulicBoundaryDatabaseTestHelper.SetHydraulicBoundaryLocationConfigurationSettings(hydraulicBoundaryDatabase);

            var assessmentSection = mocksRepository.Stub <IAssessmentSection>();

            assessmentSection.Stub(a => a.Id).Return(string.Empty);
            assessmentSection.Stub(a => a.FailureMechanismContribution)
            .Return(FailureMechanismContributionTestFactory.CreateFailureMechanismContribution());
            assessmentSection.Stub(a => a.HydraulicBoundaryDatabase).Return(hydraulicBoundaryDatabase);

            var context = new GrassCoverErosionInwardsFailureMechanismContext(failureMechanism, assessmentSection);

            using (var treeViewControl = new TreeViewControl())
            {
                var gui = mocksRepository.Stub <IGui>();
                gui.Stub(g => g.Get(context, treeViewControl)).Return(menuBuilder);
                gui.Stub(g => g.MainWindow).Return(mainWindow);
                gui.Stub(g => g.MainWindow).Return(mocksRepository.Stub <IMainWindow>());

                int nrOfCalculators   = failureMechanism.Calculations.Count();
                var calculatorFactory = mocksRepository.Stub <IHydraRingCalculatorFactory>();
                calculatorFactory.Expect(cf => cf.CreateOvertoppingCalculator(Arg <HydraRingCalculationSettings> .Is.NotNull))
                .WhenCalled(invocation =>
                {
                    HydraRingCalculationSettingsTestHelper.AssertHydraRingCalculationSettings(
                        HydraulicBoundaryCalculationSettingsFactory.CreateSettings(hydraulicBoundaryDatabase),
                        (HydraRingCalculationSettings)invocation.Arguments[0]);
                })
                .Return(new TestOvertoppingCalculator())
                .Repeat
                .Times(nrOfCalculators);
                mocksRepository.ReplayAll();

                plugin.Gui = gui;

                DialogBoxHandler = (name, wnd) =>
                {
                    // Expect an activity dialog which is automatically closed
                };

                using (ContextMenuStrip contextMenu = info.ContextMenuStrip(context, null, treeViewControl))
                    using (new HydraRingCalculatorFactoryConfig(calculatorFactory))
                    {
                        // Call
                        TestHelper.AssertLogMessages(() => contextMenu.Items[contextMenuCalculateAllIndex].PerformClick(), messages =>
                        {
                            List <string> messageList = messages.ToList();

                            // Assert
                            Assert.AreEqual(14, messageList.Count);
                            Assert.AreEqual("Uitvoeren van berekening 'A' is gestart.", messageList[0]);
                            CalculationServiceTestHelper.AssertValidationStartMessage(messageList[1]);
                            CalculationServiceTestHelper.AssertValidationEndMessage(messageList[2]);
                            CalculationServiceTestHelper.AssertCalculationStartMessage(messageList[3]);
                            StringAssert.StartsWith("De overloop en overslag berekening is uitgevoerd op de tijdelijke locatie", messageList[4]);
                            CalculationServiceTestHelper.AssertCalculationEndMessage(messageList[5]);
                            Assert.AreEqual("Uitvoeren van berekening 'A' is gelukt.", messageList[6]);

                            Assert.AreEqual("Uitvoeren van berekening 'B' is gestart.", messageList[7]);
                            CalculationServiceTestHelper.AssertValidationStartMessage(messageList[8]);
                            CalculationServiceTestHelper.AssertValidationEndMessage(messageList[9]);
                            CalculationServiceTestHelper.AssertCalculationStartMessage(messageList[10]);
                            StringAssert.StartsWith("De overloop en overslag berekening is uitgevoerd op de tijdelijke locatie", messageList[11]);
                            CalculationServiceTestHelper.AssertCalculationEndMessage(messageList[12]);
                            Assert.AreEqual("Uitvoeren van berekening 'B' is gelukt.", messageList[13]);
                        });
                    }
            }
        }
        public void CreateCalculationActivities_WithValidDataAndAllFailureMechanismsRelevant_ExpectedActivitiesCreated()
        {
            // Setup
            AssessmentSection assessmentSection = CreateAssessmentSection();

            var hydraulicBoundaryLocation = new TestHydraulicBoundaryLocation();
            IEnumerable <HydraulicBoundaryLocation> hydraulicBoundaryLocations = new[]
            {
                hydraulicBoundaryLocation
            };

            assessmentSection.SetHydraulicBoundaryLocationCalculations(hydraulicBoundaryLocations);

            AddSemiProbabilisticPipingCalculationScenario(assessmentSection, hydraulicBoundaryLocation);
            AddProbabilisticPipingCalculationScenario(assessmentSection, hydraulicBoundaryLocation);
            AddGrassCoverErosionInwardsCalculation(assessmentSection, hydraulicBoundaryLocation);
            AddMacroStabilityInwardsCalculationScenario(assessmentSection, hydraulicBoundaryLocation);
            AddHeightStructuresCalculation(assessmentSection, hydraulicBoundaryLocation);
            AddClosingStructuresCalculation(assessmentSection, hydraulicBoundaryLocation);
            AddStabilityPointStructuresCalculation(assessmentSection, hydraulicBoundaryLocation);

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

            HydraulicBoundaryCalculationSettings expectedCalculationSettings =
                HydraulicBoundaryCalculationSettingsFactory.CreateSettings(assessmentSection.HydraulicBoundaryDatabase);

            using (mocks.Ordered())
            {
                calculatorFactory.Expect(cf => cf.CreatePipingCalculator(Arg <HydraRingCalculationSettings> .Is.NotNull))
                .WhenCalled(invocation =>
                {
                    HydraRingCalculationSettingsTestHelper.AssertHydraRingCalculationSettings(
                        expectedCalculationSettings, (HydraRingCalculationSettings)invocation.Arguments[0]);
                })
                .Return(new TestPipingCalculator());

                calculatorFactory.Expect(cf => cf.CreateOvertoppingCalculator(Arg <HydraRingCalculationSettings> .Is.NotNull))
                .WhenCalled(invocation =>
                {
                    HydraRingCalculationSettingsTestHelper.AssertHydraRingCalculationSettings(
                        expectedCalculationSettings, (HydraRingCalculationSettings)invocation.Arguments[0]);
                })
                .Return(new TestOvertoppingCalculator());

                calculatorFactory.Expect(cf => cf.CreateStructuresCalculator <StructuresOvertoppingCalculationInput>(
                                             Arg <HydraRingCalculationSettings> .Is.NotNull))
                .WhenCalled(invocation =>
                {
                    HydraRingCalculationSettingsTestHelper.AssertHydraRingCalculationSettings(
                        expectedCalculationSettings, (HydraRingCalculationSettings)invocation.Arguments[0]);
                })
                .Return(new TestStructuresCalculator <StructuresOvertoppingCalculationInput>());

                calculatorFactory.Expect(cf => cf.CreateStructuresCalculator <StructuresClosureCalculationInput>(
                                             Arg <HydraRingCalculationSettings> .Is.NotNull))
                .WhenCalled(invocation =>
                {
                    HydraRingCalculationSettingsTestHelper.AssertHydraRingCalculationSettings(
                        expectedCalculationSettings, (HydraRingCalculationSettings)invocation.Arguments[0]);
                })
                .Return(new TestStructuresCalculator <StructuresClosureCalculationInput>());

                calculatorFactory.Expect(cf => cf.CreateStructuresCalculator <StructuresStabilityPointCalculationInput>(
                                             Arg <HydraRingCalculationSettings> .Is.NotNull))
                .WhenCalled(invocation =>
                {
                    HydraRingCalculationSettingsTestHelper.AssertHydraRingCalculationSettings(
                        expectedCalculationSettings, (HydraRingCalculationSettings)invocation.Arguments[0]);
                })
                .Return(new TestStructuresCalculator <StructuresStabilityPointCalculationInput>());
            }

            mocks.ReplayAll();

            // Call
            IEnumerable <CalculatableActivity> activities =
                AssessmentSectionCalculationActivityFactory.CreateCalculationActivities(assessmentSection);

            // Assert
            Assert.AreEqual(7, activities.Count());

            using (new HydraRingCalculatorFactoryConfig(calculatorFactory))
                using (new PipingSubCalculatorFactoryConfig())
                    using (new MacroStabilityInwardsCalculatorFactoryConfig())
                    {
                        var pipingTestFactory         = (TestPipingSubCalculatorFactory)PipingSubCalculatorFactory.Instance;
                        var macroStabilityTestFactory = (TestMacroStabilityInwardsCalculatorFactory)MacroStabilityInwardsCalculatorFactory.Instance;

                        Assert.IsFalse(pipingTestFactory.LastCreatedUpliftCalculator.Calculated);
                        Assert.IsFalse(macroStabilityTestFactory.LastCreatedUpliftVanCalculator.Calculated);

                        activities.ForEachElementDo(activity => activity.Run());

                        Assert.IsTrue(pipingTestFactory.LastCreatedUpliftCalculator.Calculated);
                        Assert.IsTrue(macroStabilityTestFactory.LastCreatedUpliftVanCalculator.Calculated);
                    }

            mocks.VerifyAll();
        }
Exemple #26
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));
                        });
                    }
            }
        }
        /// <summary>
        /// Performs a wave conditions calculation based on the supplied <see cref="WaveConditionsInput"/>
        /// and returns the output. Error and status information is logged during the execution
        /// of the operation.
        /// </summary>
        /// <param name="waveConditionsInput">The <see cref="WaveConditionsInput"/> that holds all the information
        /// required to perform the calculation.</param>
        /// <param name="assessmentLevel">The assessment level to use for determining water levels.</param>
        /// <param name="a">The 'a' factor decided on failure mechanism level.</param>
        /// <param name="b">The 'b' factor decided on failure mechanism level.</param>
        /// <param name="c">The 'c' factor decided on failure mechanism level.</param>
        /// <param name="targetProbability">The target probability to use.</param>
        /// <param name="hydraulicBoundaryDatabase">The hydraulic boundary database to perform the calculations with.</param>
        /// <returns>An <see cref="IEnumerable{T}"/> of <see cref="WaveConditionsOutput"/>.</returns>
        /// <remarks>Preprocessing is disabled when the preprocessor directory equals <see cref="string.Empty"/>.</remarks>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="waveConditionsInput"/> or
        /// <paramref name="hydraulicBoundaryDatabase"/> is <c>null</c>.</exception>
        /// <exception cref="ArgumentException">Thrown when the hydraulic boundary database file path
        /// contains invalid characters.</exception>
        /// <exception cref="CriticalFileReadException">Thrown when:
        /// <list type="bullet">
        /// <item>No settings database file could be found at the location of the hydraulic boundary database file path
        /// with the same name.</item>
        /// <item>Unable to open settings database file.</item>
        /// <item>Unable to read required data from database file.</item>
        /// </list>
        /// </exception>
        /// <exception cref="HydraRingCalculationException">Thrown when an error occurs during
        /// the calculations.</exception>
        protected IEnumerable <WaveConditionsOutput> CalculateWaveConditions(WaveConditionsInput waveConditionsInput,
                                                                             RoundedDouble assessmentLevel,
                                                                             RoundedDouble a,
                                                                             RoundedDouble b,
                                                                             RoundedDouble c,
                                                                             double targetProbability,
                                                                             HydraulicBoundaryDatabase hydraulicBoundaryDatabase)
        {
            if (waveConditionsInput == null)
            {
                throw new ArgumentNullException(nameof(waveConditionsInput));
            }

            if (hydraulicBoundaryDatabase == null)
            {
                throw new ArgumentNullException(nameof(hydraulicBoundaryDatabase));
            }

            var calculationsFailed = 0;
            var outputs            = new List <WaveConditionsOutput>();

            RoundedDouble[] waterLevels = waveConditionsInput.GetWaterLevels(assessmentLevel).ToArray();
            foreach (RoundedDouble waterLevel in waterLevels.TakeWhile(waterLevel => !Canceled))
            {
                try
                {
                    log.Info(string.Format(CultureInfo.CurrentCulture,
                                           Resources.WaveConditionsCalculationService_OnRun_Calculation_for_waterlevel_0_started,
                                           waterLevel));

                    NotifyProgress(waterLevel, currentStep++, TotalWaterLevelCalculations);

                    WaveConditionsOutput output = CalculateWaterLevel(waterLevel,
                                                                      a, b, c, targetProbability,
                                                                      waveConditionsInput,
                                                                      HydraulicBoundaryCalculationSettingsFactory.CreateSettings(hydraulicBoundaryDatabase));

                    if (output != null)
                    {
                        outputs.Add(output);
                    }
                    else
                    {
                        calculationsFailed++;
                        outputs.Add(WaveConditionsOutputFactory.CreateFailedOutput(waterLevel, targetProbability));
                    }
                }
                finally
                {
                    log.Info(string.Format(CultureInfo.CurrentCulture,
                                           Resources.WaveConditionsCalculationService_OnRun_Calculation_for_waterlevel_0_ended,
                                           waterLevel));
                }
            }

            if (calculationsFailed == waterLevels.Length)
            {
                string message = string.Format(CultureInfo.CurrentCulture,
                                               Resources.WaveConditionsCalculationService_CalculateWaterLevel_Error_in_wave_conditions_calculation_for_all_waterlevels);
                log.Error(message);
                throw new HydraRingCalculationException(message);
            }

            return(outputs);
        }
Exemple #28
0
        public void GivenValidCalculations_WhenCalculatingAllFromContextMenu_ThenAllCalculationsScheduled()
        {
            // Given
            var assessmentSection = new AssessmentSectionStub
            {
                HydraulicBoundaryDatabase =
                {
                    FilePath = validFilePath
                }
            };

            HydraulicBoundaryDatabaseTestHelper.SetHydraulicBoundaryLocationConfigurationSettings(assessmentSection.HydraulicBoundaryDatabase);

            var failureMechanism = new DuneErosionFailureMechanism
            {
                DuneLocationCalculationsForUserDefinedTargetProbabilities =
                {
                    new DuneLocationCalculationsForTargetProbability(0.1),
                    new DuneLocationCalculationsForTargetProbability(0.01)
                }
            };

            var duneLocation = new TestDuneLocation("Test");

            failureMechanism.SetDuneLocations(new[]
            {
                duneLocation
            });

            var groupContext = new DuneLocationCalculationsForUserDefinedTargetProbabilitiesGroupContext(failureMechanism.DuneLocationCalculationsForUserDefinedTargetProbabilities,
                                                                                                         failureMechanism,
                                                                                                         assessmentSection);

            var mocks = new MockRepository();

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

                var gui = mocks.Stub <IGui>();
                gui.Stub(g => g.MainWindow).Return(mainWindow);
                gui.Stub(cmp => cmp.Get(groupContext, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder());
                gui.Stub(g => g.DocumentViewController).Return(mocks.Stub <IDocumentViewController>());
                gui.Stub(g => g.ViewHost).Return(mocks.Stub <IViewHost>());

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

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

                using (var plugin = new DuneErosionPlugin())
                {
                    TreeNodeInfo info = GetInfo(plugin);

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

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

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

                                const string calculationTypeDisplayName = "Hydraulische belastingen";
                                const string calculationDisplayName     = "Hydraulische belastingenberekening";

                                HydraulicBoundaryLocationCalculationActivityLogTestHelper.AssertHydraulicBoundaryLocationCalculationMessages(
                                    duneLocation.Name, calculationTypeDisplayName, calculationDisplayName, "1/10", msgs, 0);
                                HydraulicBoundaryLocationCalculationActivityLogTestHelper.AssertHydraulicBoundaryLocationCalculationMessages(
                                    duneLocation.Name, calculationTypeDisplayName, calculationDisplayName, "1/100", msgs, 8);
                            });
                        }
                }
            }

            mocks.VerifyAll();
        }
Exemple #29
0
        public void PerformDuneLocationCalculationsFromContextMenu_HydraulicBoundaryDatabaseWithUsePreprocessorFalse_SendsRightInputToCalculationService()
        {
            // Setup
            var duneLocationCalculationsForTargetProbability = new DuneLocationCalculationsForTargetProbability(0.01)
            {
                DuneLocationCalculations =
                {
                    new DuneLocationCalculation(new DuneLocation(1300001, "A", new Point2D(0, 0), new DuneLocation.ConstructionProperties
                    {
                        CoastalAreaId = 0,
                        Offset        = 0,
                        Orientation   = 0,
                        D50           = 0.000007
                    }))
                }
            };

            var failureMechanism = new DuneErosionFailureMechanism();

            failureMechanism.DuneLocationCalculationsForUserDefinedTargetProbabilities.Add(duneLocationCalculationsForTargetProbability);

            var hydraulicBoundaryDatabase = new HydraulicBoundaryDatabase
            {
                FilePath = validFilePath,
                HydraulicLocationConfigurationSettings =
                {
                    CanUsePreprocessor    = true,
                    UsePreprocessor       = false,
                    PreprocessorDirectory = "InvalidPreprocessorDirectory"
                }
            };

            HydraulicBoundaryDatabaseTestHelper.SetHydraulicBoundaryLocationConfigurationSettings(hydraulicBoundaryDatabase);

            var assessmentSection = mocks.Stub <IAssessmentSection>();

            assessmentSection.Stub(a => a.HydraulicBoundaryDatabase).Return(hydraulicBoundaryDatabase);
            assessmentSection.Stub(a => a.Id).Return("13-1");
            assessmentSection.Stub(a => a.GetFailureMechanisms()).Return(new[]
            {
                failureMechanism
            });
            assessmentSection.Stub(a => a.FailureMechanismContribution)
            .Return(FailureMechanismContributionTestFactory.CreateFailureMechanismContribution());

            var context = new DuneLocationCalculationsForUserDefinedTargetProbabilityContext(duneLocationCalculationsForTargetProbability,
                                                                                             failureMechanism,
                                                                                             assessmentSection);

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

                var gui = mocks.Stub <IGui>();
                gui.Stub(cmp => cmp.Get(context, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder());
                gui.Stub(g => g.MainWindow).Return(mainWindow);
                gui.Stub(g => g.ViewHost).Return(mocks.Stub <IViewHost>());

                var dunesBoundaryConditionsCalculator = new TestDunesBoundaryConditionsCalculator();
                var calculatorFactory = mocks.Stub <IHydraRingCalculatorFactory>();
                calculatorFactory.Expect(cf => cf.CreateDunesBoundaryConditionsCalculator(Arg <HydraRingCalculationSettings> .Is.NotNull))
                .WhenCalled(invocation =>
                {
                    HydraRingCalculationSettingsTestHelper.AssertHydraRingCalculationSettings(
                        HydraulicBoundaryCalculationSettingsFactory.CreateSettings(hydraulicBoundaryDatabase),
                        (HydraRingCalculationSettings)invocation.Arguments[0]);
                })
                .Return(dunesBoundaryConditionsCalculator);

                mocks.ReplayAll();

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

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

                        // Assert
                        DunesBoundaryConditionsCalculationInput dunesBoundaryConditionsCalculationInput = dunesBoundaryConditionsCalculator.ReceivedInputs.First();

                        Assert.AreEqual(duneLocationCalculationsForTargetProbability.DuneLocationCalculations[0].DuneLocation.Id,
                                        dunesBoundaryConditionsCalculationInput.HydraulicBoundaryLocationId);
                        Assert.AreEqual(StatisticsConverter.ProbabilityToReliability(duneLocationCalculationsForTargetProbability.TargetProbability),
                                        dunesBoundaryConditionsCalculationInput.Beta);
                    }
            }
        }
Exemple #30
0
        public void GivenValidCalculations_WhenCalculatingAllFromContextMenu_ThenLogMessagesAddedOutputSet()
        {
            // Given
            var mockRepository    = new MockRepository();
            var assessmentSection = new AssessmentSectionStub
            {
                HydraulicBoundaryDatabase =
                {
                    FilePath = Path.Combine(testDataPath, "HRD ijsselmeer.sqlite")
                }
            };

            HydraulicBoundaryDatabaseTestHelper.SetHydraulicBoundaryLocationConfigurationSettings(assessmentSection.HydraulicBoundaryDatabase);

            var hydraulicBoundaryLocation = new TestHydraulicBoundaryLocation("locationName");

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

            var context = new WaveHeightCalculationsForUserDefinedTargetProbabilitiesGroupContext(
                assessmentSection.WaveHeightCalculationsForUserDefinedTargetProbabilities,
                assessmentSection);

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

                IGui gui = StubFactory.CreateGuiStub(mockRepository);
                gui.Stub(g => g.MainWindow).Return(mainWindow);
                gui.Stub(cmp => cmp.Get(context, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder());
                gui.Stub(g => g.ProjectStore).Return(mockRepository.Stub <IStoreProject>());
                gui.Stub(g => g.DocumentViewController).Return(mockRepository.Stub <IDocumentViewController>());

                var waveHeightCalculator = new TestWaveHeightCalculator
                {
                    Converged = false
                };
                var calculatorFactory = mockRepository.Stub <IHydraRingCalculatorFactory>();
                calculatorFactory.Expect(cf => cf.CreateWaveHeightCalculator(Arg <HydraRingCalculationSettings> .Is.NotNull))
                .WhenCalled(invocation =>
                {
                    HydraRingCalculationSettingsTestHelper.AssertHydraRingCalculationSettings(
                        HydraulicBoundaryCalculationSettingsFactory.CreateSettings(assessmentSection.HydraulicBoundaryDatabase),
                        (HydraRingCalculationSettings)invocation.Arguments[0]);
                })
                .Return(waveHeightCalculator)
                .Repeat
                .Times(2);
                mockRepository.ReplayAll();

                DialogBoxHandler = (name, wnd) =>
                {
                    // Expect an activity dialog which is automatically closed
                };

                using (var plugin = new RiskeerPlugin())
                {
                    TreeNodeInfo info = GetInfo(plugin);
                    plugin.Gui = gui;
                    plugin.Activate();

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

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

                                const string calculationTypeDisplayName = "Golfhoogte";
                                const string calculationDisplayName     = "Golfhoogte berekening";

                                HydraulicBoundaryLocationCalculationActivityLogTestHelper.AssertHydraulicBoundaryLocationCalculationMessages(
                                    hydraulicBoundaryLocation.Name, calculationTypeDisplayName, calculationDisplayName, "1/4.000", msgs, 0);
                                HydraulicBoundaryLocationCalculationActivityLogTestHelper.AssertHydraulicBoundaryLocationCalculationMessages(
                                    hydraulicBoundaryLocation.Name, calculationTypeDisplayName, calculationDisplayName, "1/40.000", msgs, 8);
                            });

                            AssertHydraulicBoundaryLocationCalculationOutput(waveHeightCalculator, assessmentSection.WaveHeightCalculationsForUserDefinedTargetProbabilities[0].HydraulicBoundaryLocationCalculations[0].Output);
                            AssertHydraulicBoundaryLocationCalculationOutput(waveHeightCalculator, assessmentSection.WaveHeightCalculationsForUserDefinedTargetProbabilities[1].HydraulicBoundaryLocationCalculations[0].Output);
                        }
                }
            }

            mockRepository.VerifyAll();
        }