Example #1
0
        public void NormativeProbabilityType_Always_HandlerCalledAndPropertySet()
        {
            // Setup
            FailureMechanismContribution failureMechanismContribution = FailureMechanismContributionTestFactory.CreateFailureMechanismContribution();

            var mocks = new MockRepository();
            var failureMechanismContributionNormChangeHandler = mocks.StrictMock <IFailureMechanismContributionNormChangeHandler>();

            failureMechanismContributionNormChangeHandler.Expect(h => h.ChangeNormativeProbabilityType(null))
            .IgnoreArguments()
            .WhenCalled(invocation =>
            {
                var actionToPerform = (Action)invocation.Arguments[0];
                actionToPerform();
            });
            mocks.ReplayAll();

            var properties = new NormProperties(failureMechanismContribution, failureMechanismContributionNormChangeHandler);

            const NormativeProbabilityType newValue = NormativeProbabilityType.SignalFloodingProbability;

            // Call
            properties.NormativeProbabilityType = newValue;

            // Assert
            Assert.AreEqual(newValue, failureMechanismContribution.NormativeProbabilityType);
            mocks.VerifyAll();
        }
Example #2
0
        public void Constructor_ValidData_ExpectedValues()
        {
            // Setup
            var mocks = new MockRepository();
            var failureMechanismContributionNormChangeHandler = mocks.Stub <IFailureMechanismContributionNormChangeHandler>();

            mocks.ReplayAll();

            FailureMechanismContribution failureMechanismContribution = FailureMechanismContributionTestFactory.CreateFailureMechanismContribution();

            // Call
            var properties = new NormProperties(failureMechanismContribution, failureMechanismContributionNormChangeHandler);

            // Assert
            Assert.IsInstanceOf <ObjectProperties <FailureMechanismContribution> >(properties);
            Assert.AreSame(failureMechanismContribution, properties.Data);

            TestHelper.AssertTypeConverter <NormProperties, NoProbabilityValueDoubleConverter>(
                nameof(NormProperties.SignalFloodingProbability));
            TestHelper.AssertTypeConverter <NormProperties, NoProbabilityValueDoubleConverter>(
                nameof(NormProperties.MaximumAllowableFloodingProbability));
            TestHelper.AssertTypeConverter <NormProperties, EnumTypeConverter>(
                nameof(NormProperties.NormativeProbabilityType));
            mocks.VerifyAll();
        }
Example #3
0
        public void GivenNormativeProbabilityTypeIsMaximumAllowableFloodingProbability_WhenChangingSignalFloodingProbability_ThenHandlerCalledAndPropertySet()
        {
            // Given
            FailureMechanismContribution failureMechanismContribution = FailureMechanismContributionTestFactory.CreateFailureMechanismContribution();

            var mocks = new MockRepository();
            var failureMechanismContributionNormChangeHandler = mocks.StrictMock <IFailureMechanismContributionNormChangeHandler>();

            failureMechanismContributionNormChangeHandler.Expect(h => h.ChangeProbability(null))
            .IgnoreArguments()
            .WhenCalled(invocation =>
            {
                var actionToPerform = (Action)invocation.Arguments[0];
                actionToPerform();
            });
            mocks.ReplayAll();

            var properties = new NormProperties(failureMechanismContribution, failureMechanismContributionNormChangeHandler);

            const double newValue = 0.00001;

            // When
            properties.SignalFloodingProbability = newValue;

            // Then
            Assert.AreEqual(newValue, failureMechanismContribution.SignalFloodingProbability);
            mocks.VerifyAll();
        }
Example #4
0
        public void CreateInstance_WithContext_SetsFailureMechanismContributionAsData()
        {
            // Setup
            var  mocks             = new MockRepository();
            var  assessmentSection = mocks.Stub <IAssessmentSection>();
            var  viewCommands      = mocks.Stub <IViewCommands>();
            IGui gui = StubFactory.CreateGuiStub(mocks);

            gui.Stub(g => g.ViewCommands).Return(viewCommands);
            mocks.ReplayAll();

            using (var plugin = new RiskeerPlugin())
            {
                plugin.Gui = gui;

                FailureMechanismContribution failureMechanismContribution = FailureMechanismContributionTestFactory.CreateFailureMechanismContribution();
                var context = new NormContext(failureMechanismContribution, assessmentSection);

                PropertyInfo info = GetInfo(plugin);

                // Call
                IObjectProperties objectProperties = info.CreateInstance(context);

                // Assert
                Assert.IsInstanceOf <NormProperties>(objectProperties);
                Assert.AreSame(failureMechanismContribution, objectProperties.Data);
            }

            mocks.VerifyAll();
        }
        public void CalculateForSelectedButton_OneCalculationSelected_CalculateForSelectedCalculationAndKeepOriginalSelection()
        {
            // Setup
            var hydraulicBoundaryDatabase = new HydraulicBoundaryDatabase
            {
                FilePath = hydraulicBoundaryDatabaseFilePath
            };

            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 calculationsObserver = mocks.StrictMock <IObserver>();

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

            calculatorFactory.Expect(cf => cf.CreateDunesBoundaryConditionsCalculator(null))
            .IgnoreArguments()
            .Return(new TestDunesBoundaryConditionsCalculator());
            mocks.ReplayAll();

            IObservableEnumerable <DuneLocationCalculation> calculations = GenerateDuneLocationCalculations();
            var failureMechanism = new DuneErosionFailureMechanism();

            using (DuneLocationCalculationsView view = ShowDuneLocationCalculationsView(calculations,
                                                                                        failureMechanism,
                                                                                        assessmentSection))
            {
                var    dataGridView            = (DataGridView)view.Controls.Find("dataGridView", true)[0];
                object originalDataSource      = dataGridView.DataSource;
                DataGridViewRowCollection rows = dataGridView.Rows;
                rows[0].Cells[calculateColumnIndex].Value = true;

                calculations.Attach(calculationsObserver);

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

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

                        // Call
                        buttonTester.Click();

                        // Assert
                        Assert.AreSame(originalDataSource, dataGridView.DataSource);

                        Assert.IsTrue((bool)rows[0].Cells[calculateColumnIndex].Value);
                        Assert.IsFalse((bool)rows[1].Cells[calculateColumnIndex].Value);
                    }
            }
        }
Example #6
0
        public void Constructor_AssessmentSectionIsNull_ThrowArgumentNullException()
        {
            // Setup
            FailureMechanismContribution contribution = FailureMechanismContributionTestFactory.CreateFailureMechanismContribution();

            // Call
            TestDelegate call = () => new NormContext(contribution, null);

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

            Assert.AreEqual("assessmentSection", exception.ParamName);
        }
Example #7
0
        public void Constructor_NormChangeHandlerNull_ThrowsArgumentNullException()
        {
            // Setup
            FailureMechanismContribution failureMechanismContribution = FailureMechanismContributionTestFactory.CreateFailureMechanismContribution();

            // Call
            void Call() => new NormProperties(failureMechanismContribution, null);

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

            Assert.AreEqual("normChangeHandler", exception.ParamName);
        }
Example #8
0
        public void Constructor_Always_PropertiesHaveExpectedAttributesValues()
        {
            // Setup
            var mocks = new MockRepository();
            var failureMechanismContributionNormChangeHandler = mocks.Stub <IFailureMechanismContributionNormChangeHandler>();

            mocks.ReplayAll();

            FailureMechanismContribution failureMechanismContribution = FailureMechanismContributionTestFactory.CreateFailureMechanismContribution();

            // Call
            var properties = new NormProperties(failureMechanismContribution, failureMechanismContributionNormChangeHandler);

            // Assert
            PropertyDescriptorCollection dynamicProperties = PropertiesTestHelper.GetAllVisiblePropertyDescriptors(properties);

            Assert.AreEqual(3, dynamicProperties.Count);

            const string expectedCategory = "Algemeen";

            PropertyDescriptor maximumAllowableFloodingProbabilityProperty = dynamicProperties[0];

            PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(maximumAllowableFloodingProbabilityProperty,
                                                                            expectedCategory,
                                                                            "Omgevingswaarde [1/jaar]",
                                                                            "De maximale toelaatbare overstromingskans van het traject.");

            PropertyDescriptor signalFloodingProbabilityProperty = dynamicProperties[1];

            PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(signalFloodingProbabilityProperty,
                                                                            expectedCategory,
                                                                            "Signaleringsparameter [1/jaar]",
                                                                            "De overstromingskans voor de signalering over de veiligheid van het traject.");

            PropertyDescriptor normativeProbabilityTypeProperty = dynamicProperties[2];

            PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(normativeProbabilityTypeProperty,
                                                                            expectedCategory,
                                                                            "Rekenwaarde voor waterstanden",
                                                                            "De doelkans die wordt gebruikt om de lokale waterstand te bepalen voor de semi-probabilistische toets voor 'Piping' en 'Macrostabiliteit binnenwaarts'.");

            mocks.VerifyAll();
        }
Example #9
0
        public void GetProperties_WithData_ReturnExpectedValues()
        {
            // Setup
            var mocks = new MockRepository();
            var failureMechanismContributionNormChangeHandler = mocks.Stub <IFailureMechanismContributionNormChangeHandler>();

            mocks.ReplayAll();

            FailureMechanismContribution failureMechanismContribution = FailureMechanismContributionTestFactory.CreateFailureMechanismContribution();

            // Call
            var properties = new NormProperties(failureMechanismContribution, failureMechanismContributionNormChangeHandler);

            // Assert
            Assert.AreEqual(failureMechanismContribution.MaximumAllowableFloodingProbability, properties.MaximumAllowableFloodingProbability);
            Assert.AreEqual(failureMechanismContribution.SignalFloodingProbability, properties.SignalFloodingProbability);
            Assert.AreEqual(failureMechanismContribution.NormativeProbabilityType, properties.NormativeProbabilityType);
            mocks.VerifyAll();
        }
Example #10
0
        public void Constructor_ExpectedValues()
        {
            // Setup
            var mocks             = new MockRepository();
            var assessmentSection = mocks.Stub <IAssessmentSection>();

            mocks.ReplayAll();

            FailureMechanismContribution contribution = FailureMechanismContributionTestFactory.CreateFailureMechanismContribution();

            // Call
            var context = new NormContext(contribution, assessmentSection);

            // Assert
            Assert.IsInstanceOf <ObservableWrappedObjectContextBase <FailureMechanismContribution> >(context);
            Assert.AreSame(contribution, context.WrappedData);
            Assert.AreSame(assessmentSection, context.AssessmentSection);
            mocks.VerifyAll();
        }
        public void GivenViewWithFailureMechanismContribution_WhenFailureMechanismContributionUpdated_ThenDataTableUpdated()
        {
            // Given
            var random = new Random(21);

            var mocks    = new MockRepository();
            var observer = mocks.StrictMock <IObserver>();

            observer.Expect(o => o.UpdateObserver());
            mocks.ReplayAll();

            FailureMechanismContribution failureMechanismContribution = FailureMechanismContributionTestFactory.CreateFailureMechanismContribution();

            failureMechanismContribution.Attach(observer);

            using (new AssemblyToolCalculatorFactoryConfig())
                using (var view = new AssessmentSectionAssemblyGroupsView(failureMechanismContribution))
                {
                    var calculatorFactory = (TestAssemblyToolCalculatorFactory)AssemblyToolCalculatorFactory.Instance;
                    AssessmentSectionAssemblyGroupBoundariesCalculatorStub calculator = calculatorFactory.LastCreatedAssessmentSectionAssemblyGroupBoundariesCalculator;

                    AssemblyGroupsTable <AssessmentSectionAssemblyGroup> groupsTable = GetCategoriesTable(view);

                    // Precondition
                    Assert.AreEqual(calculator.AssessmentSectionAssemblyGroupBoundariesOutput.Count(), groupsTable.Rows.Count);

                    // When
                    var newOutput = new[]
                    {
                        new AssessmentSectionAssemblyGroupBoundaries(random.NextDouble(),
                                                                     random.NextDouble(),
                                                                     random.NextEnumValue <AssessmentSectionAssemblyGroup>())
                    };
                    calculator.AssessmentSectionAssemblyGroupBoundariesOutput = newOutput;
                    failureMechanismContribution.NotifyObservers();

                    // Then
                    Assert.AreEqual(newOutput.Length, groupsTable.Rows.Count);
                }

            mocks.VerifyAll();
        }
        public void ContextMenuStrip_Always_CallsContextMenuBuilderMethods()
        {
            // Setup
            var mocks             = new MockRepository();
            var assessmentSection = mocks.Stub <IAssessmentSection>();
            var context           = new NormContext(FailureMechanismContributionTestFactory.CreateFailureMechanismContribution(),
                                                    assessmentSection);

            var menuBuilder = mocks.StrictMock <IContextMenuBuilder>();

            using (mocks.Ordered())
            {
                menuBuilder.Expect(mb => mb.AddPropertiesItem()).Return(menuBuilder);
                menuBuilder.Expect(mb => mb.Build()).Return(null);
            }

            using (var treeViewControl = new TreeViewControl())
            {
                IGui gui = StubFactory.CreateGuiStub(mocks);
                gui.Stub(cmp => cmp.Get(context, treeViewControl)).Return(menuBuilder);
                mocks.ReplayAll();

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

                    plugin.Gui = gui;

                    // Call
                    info.ContextMenuStrip(context, null, treeViewControl);
                }
            }

            // Assert
            mocks.VerifyAll();
        }
        public void Constructor_WithFailureMechanismContribution_CreatesViewAndTableWithData()
        {
            // Setup
            FailureMechanismContribution failureMechanismContribution = FailureMechanismContributionTestFactory.CreateFailureMechanismContribution();

            // Call
            using (new AssemblyToolCalculatorFactoryConfig())
                using (var view = new AssessmentSectionAssemblyGroupsView(failureMechanismContribution))
                {
                    // Assert
                    Assert.IsInstanceOf <UserControl>(view);
                    Assert.IsInstanceOf <IView>(view);
                    Assert.IsNull(view.Data);
                    Assert.AreEqual(1, view.Controls.Count);
                    Assert.AreSame(failureMechanismContribution, view.FailureMechanismContribution);

                    AssemblyGroupsTable <AssessmentSectionAssemblyGroup> tableControl = GetCategoriesTable(view);
                    Assert.AreEqual(DockStyle.Fill, tableControl.Dock);

                    var calculatorFactory = (TestAssemblyToolCalculatorFactory)AssemblyToolCalculatorFactory.Instance;
                    AssessmentSectionAssemblyGroupBoundariesCalculatorStub calculator = calculatorFactory.LastCreatedAssessmentSectionAssemblyGroupBoundariesCalculator;
                    Assert.AreEqual(calculator.AssessmentSectionAssemblyGroupBoundariesOutput.Count(), tableControl.Rows.Count);
                }
        }
        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);
                    }
            }
        }
        public void CalculateForSelectedButton_OneCalculationSelected_CalculateForSelectedCalculationAndLogsMessages()
        {
            // Setup
            var hydraulicBoundaryDatabase = new HydraulicBoundaryDatabase
            {
                FilePath = hydraulicBoundaryDatabaseFilePath
            };

            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 calculationsObserver = mocks.StrictMock <IObserver>();

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

            calculatorFactory.Expect(cf => cf.CreateDunesBoundaryConditionsCalculator(null))
            .IgnoreArguments()
            .Return(new TestDunesBoundaryConditionsCalculator());
            mocks.ReplayAll();

            IObservableEnumerable <DuneLocationCalculation> calculations = GenerateDuneLocationCalculations();
            var failureMechanism = new DuneErosionFailureMechanism();

            using (DuneLocationCalculationsView view = ShowDuneLocationCalculationsView(calculations,
                                                                                        failureMechanism,
                                                                                        assessmentSection))
            {
                var dataGridView = (DataGridView)view.Controls.Find("dataGridView", true)[0];
                DataGridViewRowCollection rows = dataGridView.Rows;
                rows[0].Cells[calculateColumnIndex].Value = true;

                calculations.Attach(calculationsObserver);

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

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

                        // Call
                        void Call() => buttonTester.Click();

                        // Assert
                        string expectedDuneLocationName = calculations.ElementAt(0).DuneLocation.Name;

                        TestHelper.AssertLogMessages(Call,
                                                     messages =>
                        {
                            List <string> messageList = messages.ToList();

                            // Assert
                            Assert.AreEqual(8, messageList.Count);
                            Assert.AreEqual($"Hydraulische belastingen berekenen voor locatie '{expectedDuneLocationName}' (1/100) is gestart.", messageList[0]);
                            CalculationServiceTestHelper.AssertValidationStartMessage(messageList[1]);
                            CalculationServiceTestHelper.AssertValidationEndMessage(messageList[2]);
                            CalculationServiceTestHelper.AssertCalculationStartMessage(messageList[3]);
                            Assert.AreEqual($"Hydraulische belastingenberekening voor locatie '{expectedDuneLocationName}' (1/100) is niet geconvergeerd.", messageList[4]);
                            StringAssert.StartsWith("Hydraulische belastingenberekening is uitgevoerd op de tijdelijke locatie", messageList[5]);
                            CalculationServiceTestHelper.AssertCalculationEndMessage(messageList[6]);
                            Assert.AreEqual($"Hydraulische belastingen berekenen voor locatie '{expectedDuneLocationName}' (1/100) is gelukt.", messageList[7]);
                        });
                    }
            }
        }
Example #16
0
        public void CalculateForSelectedButton_Always_CalculateWaveHeightsCalledAsExpected()
        {
            // Setup
            const string databaseFilePath      = "DatabaseFilePath";
            const double targetProbability     = 0.01;
            const string calculationIdentifier = "1/100";

            var assessmentSection         = mockRepository.Stub <IAssessmentSection>();
            var hydraulicBoundaryDatabase = new HydraulicBoundaryDatabase
            {
                FilePath = databaseFilePath
            };

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

            var guiService = mockRepository.StrictMock <IHydraulicBoundaryLocationCalculationGuiService>();

            IAssessmentSection assessmentSectionValue = null;

            HydraulicBoundaryLocationCalculation[] performedCalculations = null;
            double targetProbabilityValue     = double.NaN;
            string calculationIdentifierValue = null;

            guiService.Expect(ch => ch.CalculateWaveHeights(null, null, int.MinValue, null)).IgnoreArguments().WhenCalled(
                invocation =>
            {
                performedCalculations      = ((IEnumerable <HydraulicBoundaryLocationCalculation>)invocation.Arguments[0]).ToArray();
                assessmentSectionValue     = (IAssessmentSection)invocation.Arguments[1];
                targetProbabilityValue     = (double)invocation.Arguments[2];
                calculationIdentifierValue = (string)invocation.Arguments[3];
            });

            mockRepository.ReplayAll();

            IObservableEnumerable <HydraulicBoundaryLocationCalculation> hydraulicBoundaryLocationCalculations = GetTestHydraulicBoundaryLocationCalculations();

            WaveHeightCalculationsView view = ShowWaveHeightCalculationsView(hydraulicBoundaryLocationCalculations,
                                                                             assessmentSection,
                                                                             targetProbability,
                                                                             calculationIdentifier,
                                                                             testForm);

            DataGridView calculationsDataGridView = GetCalculationsDataGridView();
            DataGridViewRowCollection rows        = calculationsDataGridView.Rows;

            rows[0].Cells[calculateColumnIndex].Value = true;

            view.CalculationGuiService = guiService;
            var button = new ButtonTester("CalculateForSelectedButton", testForm);

            // Call
            button.Click();

            // Assert
            Assert.AreEqual(calculationIdentifier, calculationIdentifierValue);
            Assert.AreSame(assessmentSection, assessmentSectionValue);
            Assert.AreEqual(targetProbability, targetProbabilityValue);
            Assert.AreEqual(1, performedCalculations.Length);
            Assert.AreSame(hydraulicBoundaryLocationCalculations.First(), performedCalculations.First());
        }
Example #17
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);
                    }
            }
        }
Example #18
0
        public void ContextMenuStrip_ClickOnCalculateAllItem_ScheduleAllCalculationsAndNotifyObservers()
        {
            // Setup
            const string locationName1 = "1";
            const string locationName2 = "2";

            using (var treeViewControl = new TreeViewControl())
            {
                var duneLocationCalculationsForTargetProbability = new DuneLocationCalculationsForTargetProbability(0.01)
                {
                    DuneLocationCalculations =
                    {
                        new DuneLocationCalculation(new DuneLocation(1300001, locationName1, new Point2D(0, 0), new DuneLocation.ConstructionProperties
                        {
                            CoastalAreaId = 0,
                            Offset        = 0,
                            Orientation   = 0,
                            D50           = 0.000007
                        })),
                        new DuneLocationCalculation(new DuneLocation(1300002, locationName2, 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
                };
                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);

                var builder = new CustomItemsOnlyContextMenuBuilder();

                IMainWindow mainWindow = MainWindowTestHelper.CreateMainWindowStub(mocks);

                var gui = mocks.Stub <IGui>();
                gui.Stub(cmp => cmp.Get(context, treeViewControl)).Return(builder);
                gui.Stub(g => g.MainWindow).Return(mainWindow);
                gui.Stub(g => g.ViewHost).Return(mocks.Stub <IViewHost>());
                var calculationObserver = mocks.StrictMock <IObserver>();
                calculationObserver.Expect(o => o.UpdateObserver()).Repeat.Times(2);
                var calculationsObserver = mocks.StrictMock <IObserver>();

                var calculatorFactory = mocks.Stub <IHydraRingCalculatorFactory>();
                calculatorFactory.Expect(cf => cf.CreateDunesBoundaryConditionsCalculator(null))
                .IgnoreArguments()
                .Return(new TestDunesBoundaryConditionsCalculator())
                .Repeat
                .Times(2);
                mocks.ReplayAll();

                duneLocationCalculationsForTargetProbability.DuneLocationCalculations.Attach(calculationsObserver);
                duneLocationCalculationsForTargetProbability.DuneLocationCalculations.ForEachElementDo(location => location.Attach(calculationObserver));

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

                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(16, messageList.Count);
                            Assert.AreEqual($"Hydraulische belastingen berekenen voor locatie '{locationName1}' (1/100) is gestart.", messageList[0]);
                            CalculationServiceTestHelper.AssertValidationStartMessage(messageList[1]);
                            CalculationServiceTestHelper.AssertValidationEndMessage(messageList[2]);
                            CalculationServiceTestHelper.AssertCalculationStartMessage(messageList[3]);
                            Assert.AreEqual($"Hydraulische belastingenberekening voor locatie '{locationName1}' (1/100) is niet geconvergeerd.", messageList[4]);
                            StringAssert.StartsWith("Hydraulische belastingenberekening is uitgevoerd op de tijdelijke locatie", messageList[5]);
                            CalculationServiceTestHelper.AssertCalculationEndMessage(messageList[6]);
                            Assert.AreEqual($"Hydraulische belastingen berekenen voor locatie '{locationName1}' (1/100) is gelukt.", messageList[7]);

                            Assert.AreEqual($"Hydraulische belastingen berekenen voor locatie '{locationName2}' (1/100) is gestart.", messageList[8]);
                            CalculationServiceTestHelper.AssertValidationStartMessage(messageList[9]);
                            CalculationServiceTestHelper.AssertValidationEndMessage(messageList[10]);
                            CalculationServiceTestHelper.AssertCalculationStartMessage(messageList[11]);
                            Assert.AreEqual($"Hydraulische belastingenberekening voor locatie '{locationName2}' (1/100) is niet geconvergeerd.", messageList[12]);
                            StringAssert.StartsWith("Hydraulische belastingenberekening is uitgevoerd op de tijdelijke locatie", messageList[13]);
                            CalculationServiceTestHelper.AssertCalculationEndMessage(messageList[14]);
                            Assert.AreEqual($"Hydraulische belastingen berekenen voor locatie '{locationName2}' (1/100) is gelukt.", messageList[15]);
                        });
                    }
            }
        }
Example #19
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]);
                        });
                    }
            }
        }