Beispiel #1
0
        public void Run_ErrorInCalculation_ActivityStateSetToFailed(bool endInFailure, string lastErrorFileContent)
        {
            // Setup
            const string locationName = "locationName";

            var calculator = new TestDunesBoundaryConditionsCalculator
            {
                EndInFailure         = endInFailure,
                LastErrorFileContent = lastErrorFileContent
            };

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

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

            var activity = new DuneLocationCalculationActivity(new DuneLocationCalculation(new TestDuneLocation(locationName)),
                                                               CreateCalculationSettings(),
                                                               0.01,
                                                               "1/100");

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

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

            mockRepository.VerifyAll();
        }
        public void Calculate_ValidData_CalculationStartedWithRightParameters(bool usePreprocessor)
        {
            // Setup
            const double targetProbability     = 1.0 / 30;
            string       preprocessorDirectory = usePreprocessor
                                               ? validPreprocessorDirectory
                                               : string.Empty;
            var calculationSettings = new HydraulicBoundaryCalculationSettings(validHydraulicBoundaryDatabaseFilePath,
                                                                               validHlcdFilePath,
                                                                               false,
                                                                               preprocessorDirectory);

            var calculator = new TestDunesBoundaryConditionsCalculator
            {
                Converged = true
            };

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

            calculatorFactory.Expect(cf => cf.CreateDunesBoundaryConditionsCalculator(Arg <HydraRingCalculationSettings> .Is.NotNull))
            .WhenCalled(invocation =>
            {
                HydraRingCalculationSettingsTestHelper.AssertHydraRingCalculationSettings(
                    calculationSettings, (HydraRingCalculationSettings)invocation.Arguments[0]);
            })
            .Return(calculator);
            var calculationMessageProvider = mockRepository.StrictMock <ICalculationMessageProvider>();

            mockRepository.ReplayAll();

            var duneLocation = new DuneLocation(1300001, "test", new Point2D(0, 0),
                                                new DuneLocation.ConstructionProperties
            {
                CoastalAreaId = 0,
                Offset        = 0,
                Orientation   = 0,
                D50           = 0.000007
            });

            using (new HydraRingCalculatorFactoryConfig(calculatorFactory))
            {
                // Call
                new DuneLocationCalculationService().Calculate(new DuneLocationCalculation(duneLocation),
                                                               targetProbability,
                                                               calculationSettings,
                                                               calculationMessageProvider);

                // Assert
                DunesBoundaryConditionsCalculationInput expectedInput = CreateInput(duneLocation, targetProbability);
                DunesBoundaryConditionsCalculationInput actualInput   = calculator.ReceivedInputs.Single();
                AssertInput(expectedInput, actualInput);
                Assert.AreEqual(usePreprocessor, actualInput.PreprocessorSetting.RunPreprocessor);
            }

            mockRepository.VerifyAll();
        }
        public void Calculate_CalculationRanNotConverged_LogMessage()
        {
            // Setup
            const double targetProbability        = 1.0 / 30;
            const string locationName             = "locationName";
            const string failedConvergenceMessage = "failedConvergenceMessage";

            var calculator = new TestDunesBoundaryConditionsCalculator
            {
                ReliabilityIndex = 0.01
            };

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

            calculatorFactory.Expect(cf => cf.CreateDunesBoundaryConditionsCalculator(null))
            .IgnoreArguments()
            .Return(calculator);
            var calculationMessageProvider = mockRepository.StrictMock <ICalculationMessageProvider>();

            calculationMessageProvider.Expect(c => c.GetCalculatedNotConvergedMessage(locationName)).Return(failedConvergenceMessage);
            mockRepository.ReplayAll();

            var duneLocation            = new TestDuneLocation(locationName);
            var duneLocationCalculation = new DuneLocationCalculation(duneLocation);

            using (new HydraRingCalculatorFactoryConfig(calculatorFactory))
            {
                // Call
                Action test = () => new DuneLocationCalculationService().Calculate(duneLocationCalculation,
                                                                                   targetProbability,
                                                                                   CreateCalculationSettings(),
                                                                                   calculationMessageProvider);

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

                    CalculationServiceTestHelper.AssertCalculationStartMessage(msgs[0]);
                    Assert.AreEqual(failedConvergenceMessage, msgs[1]);
                    StringAssert.StartsWith("Hydraulische belastingenberekening is uitgevoerd op de tijdelijke locatie", msgs[2]);
                    CalculationServiceTestHelper.AssertCalculationEndMessage(msgs[3]);
                });
            }

            mockRepository.VerifyAll();
        }
Beispiel #4
0
        public void Run_ValidInput_PerformValidationAndCalculationAndLogStartAndEnd()
        {
            // Setup
            const double targetProbability     = 0.01;
            const string calculationIdentifier = "1/100";
            const string locationName          = "locationName";

            var calculator = new TestDunesBoundaryConditionsCalculator
            {
                Converged = true
            };

            HydraulicBoundaryCalculationSettings calculationSettings = CreateCalculationSettings();

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

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

            var duneLocation = new TestDuneLocation(locationName);

            var activity = new DuneLocationCalculationActivity(new DuneLocationCalculation(duneLocation),
                                                               calculationSettings,
                                                               targetProbability,
                                                               calculationIdentifier);

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

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

            Assert.AreEqual(ActivityState.Executed, activity.State);
            mockRepository.VerifyAll();
        }
Beispiel #5
0
        public void Run_VariousValidInputs_PerformsCalculationWithCorrectInput(bool usePreprocessor)
        {
            // Setup
            const double targetProbability     = 0.01;
            const string calculationIdentifier = "1/100";
            const string locationName          = "locationName";

            var calculator = new TestDunesBoundaryConditionsCalculator
            {
                Converged = true
            };

            string preprocessorDirectory = usePreprocessor ? validPreprocessorDirectory : string.Empty;
            var    calculationSettings   = new HydraulicBoundaryCalculationSettings(validHydraulicBoundaryDatabaseFilePath,
                                                                                    validHlcdFilePath,
                                                                                    false,
                                                                                    preprocessorDirectory);

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

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

            var duneLocation = new TestDuneLocation(locationName);

            var activity = new DuneLocationCalculationActivity(new DuneLocationCalculation(duneLocation),
                                                               calculationSettings,
                                                               targetProbability,
                                                               calculationIdentifier);

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

                // Assert
                DunesBoundaryConditionsCalculationInput calculationInput = calculator.ReceivedInputs.Single();
                Assert.AreEqual(duneLocation.Id, calculationInput.HydraulicBoundaryLocationId);
                Assert.AreEqual(StatisticsConverter.ProbabilityToReliability(targetProbability), calculationInput.Beta);
            }

            mockRepository.VerifyAll();
        }
Beispiel #6
0
        public void Run_ValidCalculationAndRun_SetsOutput()
        {
            // Setup
            var    random                   = new Random(123);
            double expectedWaterLevel       = random.NextDouble();
            double expectedWaveHeight       = random.NextDouble();
            double expectedWavePeriod       = random.NextDouble();
            double expectedReliabilityIndex = random.NextDouble();

            var duneLocationCalculation = new DuneLocationCalculation(new TestDuneLocation());
            var calculator = new TestDunesBoundaryConditionsCalculator
            {
                WaterLevel       = expectedWaterLevel,
                WaveHeight       = expectedWaveHeight,
                WavePeriod       = expectedWavePeriod,
                ReliabilityIndex = expectedReliabilityIndex,
                Converged        = true
            };

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

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

            var activity = new DuneLocationCalculationActivity(duneLocationCalculation,
                                                               CreateCalculationSettings(),
                                                               0.01,
                                                               "1/100");

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

            // Assert
            DuneLocationCalculationOutput actualCalculationOutput = duneLocationCalculation.Output;

            Assert.IsNotNull(actualCalculationOutput);
            Assert.AreEqual(expectedWaterLevel, actualCalculationOutput.WaterLevel, actualCalculationOutput.WaterLevel.GetAccuracy());
            Assert.AreEqual(expectedWaveHeight, actualCalculationOutput.WaveHeight, actualCalculationOutput.WaveHeight.GetAccuracy());
            Assert.AreEqual(expectedWavePeriod, actualCalculationOutput.WavePeriod, actualCalculationOutput.WavePeriod.GetAccuracy());
            Assert.AreEqual(expectedReliabilityIndex, actualCalculationOutput.CalculatedReliability, actualCalculationOutput.CalculatedReliability.GetAccuracy());
            Assert.AreEqual(CalculationConvergence.CalculatedConverged, actualCalculationOutput.CalculationConvergence);
            mockRepository.VerifyAll();
        }
Beispiel #7
0
        public void Run_CalculationResultingInNoConvergence_LogWarningNoConvergence()
        {
            // Setup
            const string calculationIdentifier = "1/100";
            const string locationName          = "locationName";

            var calculator = new TestDunesBoundaryConditionsCalculator
            {
                Converged = false
            };

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

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

            var duneLocationCalculation = new DuneLocationCalculation(new TestDuneLocation(locationName));

            var activity = new DuneLocationCalculationActivity(duneLocationCalculation,
                                                               CreateCalculationSettings(),
                                                               0.01,
                                                               calculationIdentifier);

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

                // Assert
                TestHelper.AssertLogMessages(Call, messages =>
                {
                    string[] msgs = messages.ToArray();
                    Assert.AreEqual(7, msgs.Length);
                    Assert.AreEqual($"Hydraulische belastingenberekening voor locatie '{locationName}' ({calculationIdentifier}) is niet geconvergeerd.", msgs[4]);
                });
                Assert.AreEqual(CalculationConvergence.CalculatedNotConverged, duneLocationCalculation.Output.CalculationConvergence);
            }

            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();
        }
Beispiel #9
0
        public void Run_InvalidCalculation_LogsError(bool endInFailure, string lastErrorFileContent)
        {
            // Setup
            const string calculationIdentifier = "1/100";
            const string locationName          = "locationName";

            var calculator = new TestDunesBoundaryConditionsCalculator
            {
                EndInFailure         = endInFailure,
                LastErrorFileContent = lastErrorFileContent
            };

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

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

            var activity = new DuneLocationCalculationActivity(new DuneLocationCalculation(new TestDuneLocation(locationName)),
                                                               CreateCalculationSettings(),
                                                               0.01,
                                                               calculationIdentifier);

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

                // Assert
                string expectedFailureMessage = string.IsNullOrEmpty(lastErrorFileContent)
                                                    ? $"Er is een fout opgetreden tijdens de hydraulische belastingenberekening '{locationName}' ({calculationIdentifier}). Er is geen foutrapport beschikbaar."
                                                    : $"Er is een fout opgetreden tijdens de hydraulische belastingenberekening '{locationName}' ({calculationIdentifier}). Bekijk het foutrapport door op details te klikken.{Environment.NewLine}{lastErrorFileContent}";

                TestHelper.AssertLogMessageIsGenerated(Call, expectedFailureMessage, 7);
            }

            mockRepository.VerifyAll();
        }
        public void Calculate_CancelCalculationWithValidInput_CancelsCalculator()
        {
            // Setup
            const double targetProbability = 1.0 / 30;
            var          calculator        = new TestDunesBoundaryConditionsCalculator
            {
                Converged = true
            };

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

            calculatorFactory.Expect(cf => cf.CreateDunesBoundaryConditionsCalculator(null))
            .IgnoreArguments()
            .Return(calculator);
            var calculationMessageProvider = mockRepository.StrictMock <ICalculationMessageProvider>();

            mockRepository.ReplayAll();

            var duneLocationCalculation = new DuneLocationCalculation(new TestDuneLocation());

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

                // Call
                service.Calculate(duneLocationCalculation,
                                  targetProbability,
                                  CreateCalculationSettings(),
                                  calculationMessageProvider);

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

            mockRepository.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);
                    }
            }
        }
Beispiel #12
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);
                    }
            }
        }
Beispiel #13
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();
        }
        public void Calculate_CalculationFailedWithoutExceptionAndWithLastErrorPresent_LogErrorAndThrowException()
        {
            // Setup
            const double targetProbability    = 1.0 / 30;
            const string locationName         = "locationName";
            const string errorMessage         = "errorMessage";
            const string lastErrorFileContent = "lastErrorFileContent";

            var calculator = new TestDunesBoundaryConditionsCalculator
            {
                EndInFailure         = false,
                LastErrorFileContent = lastErrorFileContent
            };

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

            calculatorFactory.Expect(cf => cf.CreateDunesBoundaryConditionsCalculator(null))
            .IgnoreArguments()
            .Return(calculator);
            var calculationMessageProvider = mockRepository.StrictMock <ICalculationMessageProvider>();

            calculationMessageProvider.Expect(c => c.GetCalculationFailedWithErrorReportMessage(locationName, lastErrorFileContent)).Return(errorMessage);
            mockRepository.ReplayAll();

            var duneLocation            = new TestDuneLocation(locationName);
            var duneLocationCalculation = new DuneLocationCalculation(duneLocation);

            using (new HydraRingCalculatorFactoryConfig(calculatorFactory))
            {
                var    exceptionThrown  = false;
                string exceptionMessage = string.Empty;

                // Call
                Action call = () =>
                {
                    try
                    {
                        new DuneLocationCalculationService().Calculate(duneLocationCalculation,
                                                                       targetProbability,
                                                                       CreateCalculationSettings(),
                                                                       calculationMessageProvider);
                    }
                    catch (HydraRingCalculationException e)
                    {
                        exceptionThrown  = true;
                        exceptionMessage = e.Message;
                    }
                };

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

                    CalculationServiceTestHelper.AssertCalculationStartMessage(msgs[0]);
                    Assert.AreEqual(errorMessage, msgs[1]);
                    StringAssert.StartsWith("Hydraulische belastingenberekening is uitgevoerd op de tijdelijke locatie", msgs[2]);
                    CalculationServiceTestHelper.AssertCalculationEndMessage(msgs[3]);
                });
                Assert.IsTrue(exceptionThrown);
                Assert.IsNull(duneLocationCalculation.Output);
                Assert.AreEqual(calculator.LastErrorFileContent, exceptionMessage);
            }

            mockRepository.VerifyAll();
        }
        public void Calculate_CalculationRan_SetOutput()
        {
            // Setup
            const double targetProbability = 1.0 / 30;
            var          calculator        = new TestDunesBoundaryConditionsCalculator
            {
                ReliabilityIndex = 3.27052,
                WaterLevel       = 4.82912,
                WaveHeight       = 2.88936,
                WavePeriod       = 10.65437,
                Converged        = true
            };

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

            calculatorFactory.Expect(cf => cf.CreateDunesBoundaryConditionsCalculator(null))
            .IgnoreArguments()
            .Return(calculator);
            var calculationMessageProvider = mockRepository.StrictMock <ICalculationMessageProvider>();

            mockRepository.ReplayAll();

            var duneLocationCalculation = new DuneLocationCalculation(new TestDuneLocation());

            // Precondition
            Assert.IsNull(duneLocationCalculation.Output);

            using (new HydraRingCalculatorFactoryConfig(calculatorFactory))
            {
                // Call
                Action test = () => new DuneLocationCalculationService().Calculate(duneLocationCalculation,
                                                                                   targetProbability,
                                                                                   CreateCalculationSettings(),
                                                                                   calculationMessageProvider);

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

                    CalculationServiceTestHelper.AssertCalculationStartMessage(msgs[0]);
                    StringAssert.StartsWith("Hydraulische belastingenberekening is uitgevoerd op de tijdelijke locatie", msgs[1]);
                    CalculationServiceTestHelper.AssertCalculationEndMessage(msgs[2]);
                });
                double targetReliability     = StatisticsConverter.ProbabilityToReliability(targetProbability);
                double calculatedProbability = StatisticsConverter.ReliabilityToProbability(calculator.ReliabilityIndex);

                DuneLocationCalculationOutput actualCalculationOutput = duneLocationCalculation.Output;
                Assert.IsNotNull(actualCalculationOutput);
                Assert.AreEqual(calculator.ReliabilityIndex, actualCalculationOutput.CalculatedReliability.Value);
                Assert.AreEqual(calculatedProbability, actualCalculationOutput.CalculatedProbability);
                Assert.AreEqual(targetProbability, actualCalculationOutput.TargetProbability);
                Assert.AreEqual(targetReliability, actualCalculationOutput.TargetReliability, actualCalculationOutput.TargetReliability.GetAccuracy());
                Assert.AreEqual(calculator.WaterLevel, actualCalculationOutput.WaterLevel, actualCalculationOutput.WaterLevel.GetAccuracy());
                Assert.AreEqual(calculator.WaveHeight, actualCalculationOutput.WaveHeight, actualCalculationOutput.WaveHeight.GetAccuracy());
                Assert.AreEqual(calculator.WavePeriod, actualCalculationOutput.WavePeriod, actualCalculationOutput.WavePeriod.GetAccuracy());
            }

            mockRepository.VerifyAll();
        }