Пример #1
0
        public void ContextMenuStrip_HydraulicBoundaryDatabaseLinkedToInvalidFile_ContextMenuItemValidateAllDisabledAndTooltipSet()
        {
            // Setup
            var failureMechanism = new GrassCoverErosionInwardsFailureMechanism();

            failureMechanism.CalculationsGroup.Children.Add(new GrassCoverErosionInwardsCalculation());

            IAssessmentSection assessmentSection = AssessmentSectionTestHelper.CreateAssessmentSectionStub(null, mocksRepository, "invalidFilePath");

            var nodeData    = new GrassCoverErosionInwardsFailureMechanismContext(failureMechanism, assessmentSection);
            var menuBuilder = new CustomItemsOnlyContextMenuBuilder();

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

                plugin.Gui = gui;

                // Call
                using (ContextMenuStrip contextMenu = info.ContextMenuStrip(nodeData, null, treeViewControl))
                {
                    // Assert
                    ToolStripItem contextMenuItem = contextMenu.Items[contextMenuValidateAllIndex];

                    Assert.AreEqual("Alles &valideren", contextMenuItem.Text);
                    StringAssert.Contains("Herstellen van de verbinding met de hydraulische belastingendatabase is mislukt.", contextMenuItem.ToolTipText);
                    TestHelper.AssertImagesAreEqual(RiskeerCommonFormsResources.ValidateAllIcon, contextMenuItem.Image);
                    Assert.IsFalse(contextMenuItem.Enabled);
                }
            }
        }
Пример #2
0
        public void ContextMenuStrip_HydraulicBoundaryDatabaseNotLinked_CalculateAllDisabled()
        {
            // Setup
            using (var treeViewControl = new TreeViewControl())
            {
                var failureMechanism = new WaveImpactAsphaltCoverFailureMechanism();
                failureMechanism.CalculationsGroup.Children.Add(new WaveImpactAsphaltCoverWaveConditionsCalculation());

                IAssessmentSection assessmentSection = AssessmentSectionTestHelper.CreateAssessmentSectionStub(mocks);
                var nodeData = new WaveImpactAsphaltCoverFailureMechanismContext(failureMechanism, assessmentSection);

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

                plugin.Gui = gui;

                // Call
                using (ContextMenuStrip contextMenu = info.ContextMenuStrip(nodeData, null, treeViewControl))
                {
                    // Assert
                    ToolStripItem calculateItem = contextMenu.Items[contextMenuCalculateAllIndex];
                    Assert.IsFalse(calculateItem.Enabled);
                    Assert.AreEqual("Er is geen hydraulische belastingendatabase geïmporteerd.", calculateItem.ToolTipText);
                }
            }
        }
Пример #3
0
        public void ContextMenuStrip_HydraulicBoundaryDatabaseNotLinked_ContextMenuItemValidateAllDisabledAndTooltipSet()
        {
            // Setup
            var failureMechanism = new GrassCoverErosionInwardsFailureMechanism();

            failureMechanism.CalculationsGroup.Children.Add(new GrassCoverErosionInwardsCalculation());

            IAssessmentSection assessmentSection = AssessmentSectionTestHelper.CreateAssessmentSectionStub(mocksRepository);

            var nodeData    = new GrassCoverErosionInwardsFailureMechanismContext(failureMechanism, assessmentSection);
            var menuBuilder = new CustomItemsOnlyContextMenuBuilder();

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

                plugin.Gui = gui;

                // Call
                using (ContextMenuStrip contextMenu = info.ContextMenuStrip(nodeData, null, treeViewControl))
                {
                    // Assert
                    TestHelper.AssertContextMenuStripContainsItem(contextMenu, contextMenuValidateAllIndex,
                                                                  "Alles &valideren",
                                                                  "Er is geen hydraulische belastingendatabase geïmporteerd.",
                                                                  RiskeerCommonFormsResources.ValidateAllIcon,
                                                                  false);
                }
            }
        }
Пример #4
0
        private static void SetPropertyAndVerifyNotificationsForCalculation(Action <MacroStabilityInwardsWaterStressesProperties> setProperty,
                                                                            MacroStabilityInwardsCalculation calculation)
        {
            // Setup
            var mocks      = new MockRepository();
            var observable = mocks.StrictMock <IObservable>();

            observable.Expect(o => o.NotifyObservers());
            mocks.ReplayAll();

            MacroStabilityInwardsInput input = calculation.InputParameters;

            var propertyChangeHandler = new SetPropertyValueAfterConfirmationParameterTester(new[]
            {
                observable
            });

            var properties = new MacroStabilityInwardsWaterStressesProperties(input,
                                                                              new GeneralMacroStabilityInwardsInput(),
                                                                              AssessmentSectionTestHelper.GetTestAssessmentLevel(),
                                                                              propertyChangeHandler);

            // Call
            setProperty(properties);

            // Assert
            Assert.IsTrue(propertyChangeHandler.Called);
            mocks.VerifyAll();
        }
Пример #5
0
        public void Constructor_ExpectedValues()
        {
            // Setup
            var mocks = new MockRepository();
            var propertyChangeHandler = mocks.Stub <IObservablePropertyChangeHandler>();

            mocks.ReplayAll();

            var input = new MacroStabilityInwardsInput(new MacroStabilityInwardsInput.ConstructionProperties());

            // Call
            var properties = new MacroStabilityInwardsWaterStressesProperties(input,
                                                                              new GeneralMacroStabilityInwardsInput(),
                                                                              AssessmentSectionTestHelper.GetTestAssessmentLevel(),
                                                                              propertyChangeHandler);

            // Assert
            Assert.IsInstanceOf <ObjectProperties <MacroStabilityInwardsInput> >(properties);
            Assert.AreSame(input, properties.Data);

            TestHelper.AssertTypeConverter <MacroStabilityInwardsWaterStressesProperties, ExpandableObjectConverter>(
                nameof(MacroStabilityInwardsWaterStressesProperties.Drainage));
            TestHelper.AssertTypeConverter <MacroStabilityInwardsWaterStressesProperties, ExpandableObjectConverter>(
                nameof(MacroStabilityInwardsWaterStressesProperties.LocationDaily));
            TestHelper.AssertTypeConverter <MacroStabilityInwardsWaterStressesProperties, ExpandableObjectConverter>(
                nameof(MacroStabilityInwardsWaterStressesProperties.LocationExtreme));
            TestHelper.AssertTypeConverter <MacroStabilityInwardsWaterStressesProperties, ExpandableObjectConverter>(
                nameof(MacroStabilityInwardsWaterStressesProperties.WaterStressLines));

            mocks.VerifyAll();
        }
        public void CreateInstance_ValidData_NewPropertiesWithOutputAsData()
        {
            // Setup
            var failureMechanism = new MacroStabilityInwardsFailureMechanism();

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

            mocks.ReplayAll();

            var scenario = new MacroStabilityInwardsCalculationScenario
            {
                Output = MacroStabilityInwardsOutputTestFactory.CreateOutput()
            };

            var context = new MacroStabilityInwardsOutputContext(scenario, failureMechanism, assessmentSection);

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

            // Assert
            Assert.IsInstanceOf <MacroStabilityInwardsOutputProperties>(objectProperties);
            Assert.AreSame(scenario.Output, objectProperties.Data);
            mocks.VerifyAll();
        }
Пример #7
0
        public void DynamicReadOnlyValidationMethod_OtherDikeSoilScenario_ReturnsExpectedReadOnly(MacroStabilityInwardsDikeSoilScenario dikeSoilScenario)
        {
            // Setup
            var mocks = new MockRepository();
            var propertyChangeHandler = mocks.Stub <IObservablePropertyChangeHandler>();

            mocks.ReplayAll();

            var input = new MacroStabilityInwardsInput(new MacroStabilityInwardsInput.ConstructionProperties())
            {
                DikeSoilScenario = dikeSoilScenario
            };
            var properties = new MacroStabilityInwardsWaterStressesProperties(input,
                                                                              new GeneralMacroStabilityInwardsInput(),
                                                                              AssessmentSectionTestHelper.GetTestAssessmentLevel(),
                                                                              propertyChangeHandler);

            // Call & Assert
            Assert.IsFalse(properties.DynamicReadOnlyValidationMethod(nameof(MacroStabilityInwardsWaterStressesProperties.AdjustPhreaticLine3And4ForUplift)));
            Assert.IsFalse(properties.DynamicReadOnlyValidationMethod(nameof(MacroStabilityInwardsWaterStressesProperties.LeakageLengthInwardsPhreaticLine3)));
            Assert.IsFalse(properties.DynamicReadOnlyValidationMethod(nameof(MacroStabilityInwardsWaterStressesProperties.LeakageLengthOutwardsPhreaticLine3)));
            Assert.IsFalse(properties.DynamicReadOnlyValidationMethod(nameof(MacroStabilityInwardsWaterStressesProperties.LeakageLengthInwardsPhreaticLine4)));
            Assert.IsFalse(properties.DynamicReadOnlyValidationMethod(nameof(MacroStabilityInwardsWaterStressesProperties.LeakageLengthOutwardsPhreaticLine4)));
            Assert.IsFalse(properties.DynamicReadOnlyValidationMethod(nameof(MacroStabilityInwardsWaterStressesProperties.PiezometricHeadPhreaticLine2Inwards)));
            Assert.IsFalse(properties.DynamicReadOnlyValidationMethod(nameof(MacroStabilityInwardsWaterStressesProperties.PiezometricHeadPhreaticLine2Outwards)));
            Assert.IsFalse(properties.DynamicReadOnlyValidationMethod(nameof(MacroStabilityInwardsWaterStressesProperties.WaterLevelRiverAverage)));
            Assert.IsFalse(properties.DynamicReadOnlyValidationMethod(nameof(MacroStabilityInwardsWaterStressesProperties.MinimumLevelPhreaticLineAtDikeTopPolder)));
            Assert.IsFalse(properties.DynamicReadOnlyValidationMethod(nameof(MacroStabilityInwardsWaterStressesProperties.MinimumLevelPhreaticLineAtDikeTopRiver)));
        }
Пример #8
0
        public void GetUniqueDisplayNameForWaterLevelCalculations_ValidParameters_ReturnsExpectedDisplayNameForMaximumAllowableFloodingProbability(
            double maximumAllowableFloodingProbability, double signalFloodingProbability, double userDefinedTargetProbability1, double userDefinedTargetProbability2, string expectedName)
        {
            // Setup
            var hydraulicBoundaryLocationCalculations = new ObservableList <HydraulicBoundaryLocationCalculation>();

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

            assessmentSection.Stub(a => a.FailureMechanismContribution).Return(new FailureMechanismContribution(maximumAllowableFloodingProbability, signalFloodingProbability));
            assessmentSection.Stub(a => a.WaterLevelCalculationsForMaximumAllowableFloodingProbability).Return(hydraulicBoundaryLocationCalculations);
            assessmentSection.Stub(a => a.WaterLevelCalculationsForSignalFloodingProbability).Return(new ObservableList <HydraulicBoundaryLocationCalculation>());
            assessmentSection.Stub(a => a.WaterLevelCalculationsForUserDefinedTargetProbabilities).Return(
                new ObservableList <HydraulicBoundaryLocationCalculationsForTargetProbability>
            {
                new HydraulicBoundaryLocationCalculationsForTargetProbability(userDefinedTargetProbability1),
                new HydraulicBoundaryLocationCalculationsForTargetProbability(userDefinedTargetProbability2)
            });

            mockRepository.ReplayAll();

            // Call
            string name = TargetProbabilityCalculationsDisplayNameHelper.GetUniqueDisplayNameForWaterLevelCalculations(hydraulicBoundaryLocationCalculations,
                                                                                                                       assessmentSection);

            // Assert
            Assert.AreEqual(expectedName, name);

            mockRepository.VerifyAll();
        }
        public void Constructor_ValidData_PropertiesHaveExpectedAttributeValues()
        {
            // Setup
            var input = new MacroStabilityInwardsInput(new MacroStabilityInwardsInput.ConstructionProperties());

            // Call
            var properties = new MacroStabilityInwardsWaterStressLinesProperties(input,
                                                                                 new GeneralMacroStabilityInwardsInput(),
                                                                                 AssessmentSectionTestHelper.GetTestAssessmentLevel());

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

            Assert.AreEqual(2, dynamicProperties.Count);

            const string waterStressesCategoryName = "Waterspanningen";

            PropertyDescriptor waternetExtremeProperty = dynamicProperties[0];

            PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(waternetExtremeProperty,
                                                                            waterStressesCategoryName,
                                                                            "Extreme omstandigheden",
                                                                            "Eigenschappen van de waterspanningslijnen bij extreme omstandigheden.",
                                                                            true);

            PropertyDescriptor waternetDailyProperty = dynamicProperties[1];

            PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(waternetDailyProperty,
                                                                            waterStressesCategoryName,
                                                                            "Dagelijkse omstandigheden",
                                                                            "Eigenschappen van de waterspanningslijnen bij dagelijkse omstandigheden.",
                                                                            true);
        }
        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();
        }
        public void CalculateWaveHeights_ValidPathEmptyCalculationList_NoLog()
        {
            // Setup
            var mocks = new MockRepository();
            IAssessmentSection assessmentSection = AssessmentSectionTestHelper.CreateAssessmentSectionStub(mocks);

            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())
            {
                var guiService = new HydraulicBoundaryLocationCalculationGuiService(viewParent);

                // Call
                void Call() => guiService.CalculateWaveHeights(Enumerable.Empty <HydraulicBoundaryLocationCalculation>(), assessmentSection, 0.01, "1/100");

                // Assert
                TestHelper.AssertLogMessagesCount(Call, 0);
            }

            mocks.VerifyAll();
        }
        public void CalculateWaveHeights_HydraulicDatabaseDoesNotExist_LogsError()
        {
            // Setup
            var mocks      = new MockRepository();
            var viewParent = mocks.Stub <IViewParent>();
            IAssessmentSection assessmentSection = AssessmentSectionTestHelper.CreateAssessmentSectionStub(mocks);

            mocks.ReplayAll();

            assessmentSection.HydraulicBoundaryDatabase.FilePath = "Does not exist";
            HydraulicBoundaryDatabaseTestHelper.SetHydraulicBoundaryLocationConfigurationSettings(assessmentSection.HydraulicBoundaryDatabase);

            var guiService = new HydraulicBoundaryLocationCalculationGuiService(viewParent);

            // Call
            void Call() => guiService.CalculateWaveHeights(Enumerable.Empty <HydraulicBoundaryLocationCalculation>(), assessmentSection, 0.01, "1/100");

            // Assert
            TestHelper.AssertLogMessages(Call, messages =>
            {
                string[] msgs = messages.ToArray();
                Assert.AreEqual(1, msgs.Length);
                StringAssert.StartsWith("Berekeningen konden niet worden gestart. ", msgs.First());
            });
            mocks.VerifyAll();
        }
        public void Run_ValidPipingCalculation_PerformPipingValidationAndCalculationAndLogStartAndEnd()
        {
            // Setup
            var validPipingCalculation =
                SemiProbabilisticPipingCalculationTestFactory.CreateCalculationWithValidInput <TestSemiProbabilisticPipingCalculation>(
                    new TestHydraulicBoundaryLocation());

            var activity = new SemiProbabilisticPipingCalculationActivity(validPipingCalculation,
                                                                          new GeneralPipingInput(),
                                                                          AssessmentSectionTestHelper.GetTestAssessmentLevel());

            // Call
            Action call = () => activity.Run();

            // Assert
            TestHelper.AssertLogMessages(call, messages =>
            {
                string[] msgs = messages.ToArray();
                Assert.AreEqual(5, msgs.Length);
                Assert.AreEqual($"Uitvoeren van berekening '{validPipingCalculation.Name}' is gestart.", msgs[0]);
                CalculationServiceTestHelper.AssertValidationStartMessage(msgs[1]);
                CalculationServiceTestHelper.AssertValidationEndMessage(msgs[2]);
                CalculationServiceTestHelper.AssertCalculationStartMessage(msgs[3]);
                CalculationServiceTestHelper.AssertCalculationEndMessage(msgs[4]);
            });
            Assert.AreEqual(ActivityState.Executed, activity.State);
            Assert.IsNotNull(validPipingCalculation.Output);
        }
        public void Finish_ValidPipingCalculationAndRan_NotifyObserversOfPipingCalculation()
        {
            // Setup
            var mocks    = new MockRepository();
            var observer = mocks.StrictMock <IObserver>();

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

            var validPipingCalculation =
                SemiProbabilisticPipingCalculationTestFactory.CreateCalculationWithValidInput <TestSemiProbabilisticPipingCalculation>(
                    new TestHydraulicBoundaryLocation());

            validPipingCalculation.Output = null;
            validPipingCalculation.Attach(observer);

            var activity = new SemiProbabilisticPipingCalculationActivity(validPipingCalculation,
                                                                          new GeneralPipingInput(),
                                                                          AssessmentSectionTestHelper.GetTestAssessmentLevel());

            activity.Run();

            // Call
            activity.Finish();

            // Assert
            mocks.VerifyAll();
        }
Пример #15
0
        public void CreateFileImporter_Always_ReturnFileImporter()
        {
            // Setup
            var mocks = new MockRepository();
            IAssessmentSection assessmentSection = AssessmentSectionTestHelper.CreateAssessmentSectionStub(mocks);

            mocks.ReplayAll();

            var context = new StabilityPointStructuresCalculationGroupContext(new CalculationGroup(),
                                                                              null,
                                                                              new StabilityPointStructuresFailureMechanism(),
                                                                              assessmentSection);

            using (var plugin = new StabilityPointStructuresPlugin())
            {
                ImportInfo info = GetImportInfo(plugin);

                // Call
                IFileImporter fileImporter = info.CreateFileImporter(context, "test");

                // Assert
                Assert.IsInstanceOf <StabilityPointStructuresCalculationConfigurationImporter>(fileImporter);
            }

            mocks.VerifyAll();
        }
Пример #16
0
        public void Run_InvalidMacroStabilityInwardsCalculation_LogValidationStartAndEndWithErrors()
        {
            // Setup
            MacroStabilityInwardsCalculationScenario invalidMacroStabilityInwardsCalculation = MacroStabilityInwardsCalculationScenarioTestFactory.CreateMacroStabilityInwardsCalculationScenarioWithInvalidInput();

            var activity = new MacroStabilityInwardsCalculationActivity(invalidMacroStabilityInwardsCalculation,
                                                                        new GeneralMacroStabilityInwardsInput(),
                                                                        AssessmentSectionTestHelper.GetTestAssessmentLevel());

            // Call
            Action call = () => activity.Run();

            // Assert
            TestHelper.AssertLogMessagesWithLevelAndLoggedExceptions(call, messages =>
            {
                Tuple <string, Level, Exception>[] tupleArray = messages.ToArray();
                string[] msgs = tupleArray.Select(tuple => tuple.Item1).ToArray();

                Assert.AreEqual(6, msgs.Length);
                Assert.AreEqual($"Uitvoeren van berekening '{invalidMacroStabilityInwardsCalculation.Name}' is gestart.", msgs[0]);
                CalculationServiceTestHelper.AssertValidationStartMessage(msgs[1]);
                Assert.AreEqual(Level.Error, tupleArray[2].Item2);
                Assert.AreEqual(Level.Error, tupleArray[3].Item2);
                Assert.AreEqual(Level.Error, tupleArray[4].Item2);
                CalculationServiceTestHelper.AssertValidationEndMessage(msgs[5]);
            });
            Assert.AreEqual(ActivityState.Failed, activity.State);
        }
        public void Validate_ValidCalculationInputAndHydraulicBoundaryDatabase_ReturnsTrue()
        {
            // Setup
            var mockRepository = new MockRepository();
            IAssessmentSection assessmentSection = AssessmentSectionTestHelper.CreateAssessmentSectionStub(new HeightStructuresFailureMechanism(),
                                                                                                           mockRepository,
                                                                                                           validHydraulicBoundaryDatabaseFilePath);

            mockRepository.ReplayAll();

            var calculation = new TestHeightStructuresCalculationScenario
            {
                InputParameters =
                {
                    HydraulicBoundaryLocation = new HydraulicBoundaryLocation(1, "name", 2, 2)
                }
            };

            // Call
            var    isValid = false;
            Action call    = () => isValid = HeightStructuresCalculationService.Validate(calculation, assessmentSection);

            // Assert
            TestHelper.AssertLogMessages(call, messages =>
            {
                string[] msgs = messages.ToArray();
                Assert.AreEqual(2, msgs.Length);
                CalculationServiceTestHelper.AssertValidationStartMessage(msgs[0]);
                CalculationServiceTestHelper.AssertValidationEndMessage(msgs[1]);
            });
            Assert.IsTrue(isValid);

            mockRepository.VerifyAll();
        }
Пример #18
0
        public void Run_ValidMacroStabilityInwardsCalculation_PerformMacroStabilityInwardsValidationAndCalculationAndLogStartAndEnd()
        {
            // Setup
            MacroStabilityInwardsCalculationScenario validMacroStabilityInwardsCalculation = MacroStabilityInwardsCalculationScenarioTestFactory.CreateMacroStabilityInwardsCalculationScenarioWithValidInput(new TestHydraulicBoundaryLocation());

            using (new MacroStabilityInwardsCalculatorFactoryConfig())
            {
                var activity = new MacroStabilityInwardsCalculationActivity(validMacroStabilityInwardsCalculation,
                                                                            new GeneralMacroStabilityInwardsInput(),
                                                                            AssessmentSectionTestHelper.GetTestAssessmentLevel());

                // Call
                Action call = () => activity.Run();

                // Assert
                TestHelper.AssertLogMessages(call, messages =>
                {
                    string[] msgs = messages.ToArray();
                    Assert.AreEqual(7, msgs.Length);
                    Assert.AreEqual($"Uitvoeren van berekening '{validMacroStabilityInwardsCalculation.Name}' is gestart.", msgs[0]);
                    CalculationServiceTestHelper.AssertValidationStartMessage(msgs[1]);
                    Assert.AreEqual("Validatie van waterspanningen in extreme omstandigheden is gestart.", msgs[2]);
                    Assert.AreEqual("Validatie van waterspanningen in dagelijkse omstandigheden is gestart.", msgs[3]);
                    CalculationServiceTestHelper.AssertValidationEndMessage(msgs[4]);
                    CalculationServiceTestHelper.AssertCalculationStartMessage(msgs[5]);
                    CalculationServiceTestHelper.AssertCalculationEndMessage(msgs[6]);
                });
                Assert.AreEqual(ActivityState.Executed, activity.State);
                Assert.IsNotNull(validMacroStabilityInwardsCalculation.Output);
            }
        }
Пример #19
0
        public void Finish_ValidMacroStabilityInwardsCalculationAndRan_NotifyObserversOfMacroStabilityInwardsCalculation()
        {
            // Setup
            var mocks    = new MockRepository();
            var observer = mocks.StrictMock <IObserver>();

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

            MacroStabilityInwardsCalculationScenario validMacroStabilityInwardsCalculation = MacroStabilityInwardsCalculationScenarioTestFactory.CreateMacroStabilityInwardsCalculationScenarioWithValidInput(new TestHydraulicBoundaryLocation());

            validMacroStabilityInwardsCalculation.Output = null;
            validMacroStabilityInwardsCalculation.Attach(observer);

            var activity = new MacroStabilityInwardsCalculationActivity(validMacroStabilityInwardsCalculation,
                                                                        new GeneralMacroStabilityInwardsInput(),
                                                                        AssessmentSectionTestHelper.GetTestAssessmentLevel());

            activity.Run();

            // Call
            activity.Finish();

            // Assert
            mocks.VerifyAll();
        }
Пример #20
0
        public void Constructor_ExpectedValues()
        {
            // Setup
            var failureMechanism = new PipingFailureMechanism();

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

            mocks.ReplayAll();

            var calculation = new SemiProbabilisticPipingCalculationScenario();
            FailureMechanismSection failureMechanismSection = FailureMechanismSectionTestFactory.CreateFailureMechanismSection();

            // Call
            var row = new SemiProbabilisticPipingScenarioRow(calculation, failureMechanism, failureMechanismSection, assessmentSection);

            // Assert
            Assert.IsInstanceOf <PipingScenarioRow <SemiProbabilisticPipingCalculationScenario> >(row);
            Assert.AreSame(calculation, row.CalculationScenario);

            TestHelper.AssertTypeConverter <SemiProbabilisticPipingScenarioRow, NoProbabilityValueDoubleConverter>(
                nameof(SemiProbabilisticPipingScenarioRow.FailureProbabilityUplift));
            TestHelper.AssertTypeConverter <SemiProbabilisticPipingScenarioRow, NoProbabilityValueDoubleConverter>(
                nameof(SemiProbabilisticPipingScenarioRow.FailureProbabilityHeave));
            TestHelper.AssertTypeConverter <SemiProbabilisticPipingScenarioRow, NoProbabilityValueDoubleConverter>(
                nameof(SemiProbabilisticPipingScenarioRow.FailureProbabilitySellmeijer));
        }
Пример #21
0
        public void Constructor_CalculationWithOutput_ExpectedValues(double sectionLength)
        {
            // Setup
            var failureMechanism = new PipingFailureMechanism();

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

            mocks.ReplayAll();

            var calculation = new SemiProbabilisticPipingCalculationScenario
            {
                Output = PipingTestDataGenerator.GetRandomSemiProbabilisticPipingOutput()
            };
            var failureMechanismSection = new FailureMechanismSection("test", new[]
            {
                new Point2D(0, 0),
                new Point2D(sectionLength, 0)
            });

            // Call
            var row = new SemiProbabilisticPipingScenarioRow(calculation, failureMechanism, failureMechanismSection, assessmentSection);

            // Assert
            DerivedSemiProbabilisticPipingOutput expectedDerivedOutput = DerivedSemiProbabilisticPipingOutputFactory.Create(calculation.Output, assessmentSection.FailureMechanismContribution.NormativeProbability);

            Assert.AreEqual(expectedDerivedOutput.PipingProbability, row.FailureProbability);
            Assert.AreEqual(expectedDerivedOutput.UpliftProbability, row.FailureProbabilityUplift);
            Assert.AreEqual(expectedDerivedOutput.HeaveProbability, row.FailureProbabilityHeave);
            Assert.AreEqual(expectedDerivedOutput.SellmeijerProbability, row.FailureProbabilitySellmeijer);
            Assert.AreEqual(Math.Min(1.0, expectedDerivedOutput.PipingProbability * failureMechanism.PipingProbabilityAssessmentInput.GetN(
                                         failureMechanismSection.Length)),
                            row.SectionFailureProbability);
            mocks.VerifyAll();
        }
Пример #22
0
        public void Validate_ValidCalculationValidHydraulicBoundaryDatabaseNoSettings_LogsErrorAndReturnsFalse()
        {
            // Setup
            var mocks = new MockRepository();
            IAssessmentSection assessmentSection = AssessmentSectionTestHelper.CreateAssessmentSectionStub(new TestCalculatableFailureMechanism(),
                                                                                                           mocks,
                                                                                                           Path.Combine(testDataPath, "HRD nosettings.sqlite"));

            mocks.ReplayAll();

            var calculation = new TestStructuresCalculation();

            var isValid = false;

            // Call
            void Call() => isValid = TestStructuresCalculationService.Validate(calculation, assessmentSection);

            // Assert
            TestHelper.AssertLogMessages(Call, messages =>
            {
                string[] msgs = messages.ToArray();
                Assert.AreEqual(3, msgs.Length);
                CalculationServiceTestHelper.AssertValidationStartMessage(msgs[0]);
                StringAssert.StartsWith("Herstellen van de verbinding met de hydraulische belastingendatabase is mislukt. " +
                                        "Fout bij het lezen van bestand", msgs[1]);
                CalculationServiceTestHelper.AssertValidationEndMessage(msgs[2]);
            });
            Assert.IsFalse(isValid);

            mocks.VerifyAll();
        }
Пример #23
0
        public void Validate_WithoutImportedHydraulicBoundaryDatabase_LogsErrorAndReturnsFalse()
        {
            // Setup
            var mocks = new MockRepository();
            IAssessmentSection assessmentSection = AssessmentSectionTestHelper.CreateAssessmentSectionStub(new TestCalculatableFailureMechanism(),
                                                                                                           mocks);

            mocks.ReplayAll();

            var isValid = false;

            // Call
            void Call() => isValid = TestStructuresCalculationService.Validate(new TestStructuresCalculation(), assessmentSection);

            // Assert
            TestHelper.AssertLogMessages(Call, messages =>
            {
                string[] msgs = messages.ToArray();
                Assert.AreEqual(3, msgs.Length);
                CalculationServiceTestHelper.AssertValidationStartMessage(msgs[0]);
                Assert.AreEqual("Er is geen hydraulische belastingendatabase geïmporteerd.", msgs[1]);
                CalculationServiceTestHelper.AssertValidationEndMessage(msgs[2]);
            });
            Assert.IsFalse(isValid);

            mocks.VerifyAll();
        }
Пример #24
0
        public void Validate_ValidCalculationInvalidPreprocessorDirectory_LogsErrorAndReturnsFalse()
        {
            // Setup
            var mocks = new MockRepository();

            IAssessmentSection assessmentSection = AssessmentSectionTestHelper.CreateAssessmentSectionStub(
                new TestCalculatableFailureMechanism(), mocks, validHydraulicBoundaryDatabaseFilePath);

            assessmentSection.HydraulicBoundaryDatabase.HydraulicLocationConfigurationSettings.CanUsePreprocessor    = true;
            assessmentSection.HydraulicBoundaryDatabase.HydraulicLocationConfigurationSettings.UsePreprocessor       = true;
            assessmentSection.HydraulicBoundaryDatabase.HydraulicLocationConfigurationSettings.PreprocessorDirectory = "NonExistingPreprocessorDirectory";

            mocks.ReplayAll();

            var calculation = new TestStructuresCalculation();

            var isValid = true;

            // Call
            void Call() => isValid = TestStructuresCalculationService.Validate(calculation, assessmentSection);

            // Assert
            TestHelper.AssertLogMessages(Call, messages =>
            {
                string[] msgs = messages.ToArray();
                Assert.AreEqual(3, msgs.Length);
                CalculationServiceTestHelper.AssertValidationStartMessage(msgs[0]);
                Assert.AreEqual("De bestandsmap waar de preprocessor bestanden opslaat is ongeldig. De bestandsmap bestaat niet.", msgs[1]);
                CalculationServiceTestHelper.AssertValidationEndMessage(msgs[2]);
            });
            Assert.IsFalse(isValid);

            mocks.VerifyAll();
        }
        public void CreateCalculationActivitiesForFailureMechanism_WithValidCalculations_ReturnsGrassCoverErosionInwardsCalculationActivitiesWithParametersSet()
        {
            // Setup
            var failureMechanism = new GrassCoverErosionInwardsFailureMechanism();

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

            mocks.ReplayAll();

            GrassCoverErosionInwardsCalculation calculation1 = CreateValidCalculation();
            GrassCoverErosionInwardsCalculation calculation2 = CreateValidCalculation();

            failureMechanism.CalculationsGroup.Children.AddRange(new[]
            {
                calculation1,
                calculation2
            });

            // Call
            IEnumerable <CalculatableActivity> activities = GrassCoverErosionInwardsCalculationActivityFactory.CreateCalculationActivities(
                failureMechanism, assessmentSection);

            // Assert
            CollectionAssert.AllItemsAreInstancesOfType(activities, typeof(GrassCoverErosionInwardsCalculationActivity));
            Assert.AreEqual(2, activities.Count());

            HydraulicBoundaryDatabase hydraulicBoundaryDatabase = assessmentSection.HydraulicBoundaryDatabase;

            AssertGrassCoverErosionInwardsCalculationActivity(activities.First(), calculation1, hydraulicBoundaryDatabase);
            AssertGrassCoverErosionInwardsCalculationActivity(activities.ElementAt(1), calculation2, hydraulicBoundaryDatabase);
            mocks.VerifyAll();
        }
Пример #26
0
        public void ContextMenuStrip_HydraulicBoundaryDatabaseLinkedToInvalidFile_ContextMenuItemCalculateAllDisabledAndTooltipSet()
        {
            // Setup
            using (var treeViewControl = new TreeViewControl())
            {
                IAssessmentSection assessmentSection = AssessmentSectionTestHelper.CreateAssessmentSectionStub(null, mocks, "invalidFilePath");

                var context = new DuneLocationCalculationsForUserDefinedTargetProbabilityContext(new DuneLocationCalculationsForTargetProbability(0.1),
                                                                                                 new DuneErosionFailureMechanism(),
                                                                                                 assessmentSection);

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

                mocks.ReplayAll();

                plugin.Gui = gui;

                // Call
                using (ContextMenuStrip menu = info.ContextMenuStrip(context, null, treeViewControl))
                {
                    // Assert
                    ToolStripItem contextMenuItem = menu.Items[contextMenuCalculateAllIndex];

                    Assert.AreEqual("Alles be&rekenen", contextMenuItem.Text);
                    StringAssert.Contains("Herstellen van de verbinding met de hydraulische belastingendatabase is mislukt.", contextMenuItem.ToolTipText);
                    TestHelper.AssertImagesAreEqual(RiskeerCommonFormsResources.CalculateAllIcon, contextMenuItem.Image);
                    Assert.IsFalse(contextMenuItem.Enabled);
                }
            }
        }
        public void Export_NestedCalculationGroupWithGroupsWithCalculationsWithAndWithoutOutput_FolderNotExportedAndReturnsTrue()
        {
            // Setup
            string folderPath = TestHelper.GetScratchPadPath($"{nameof(MacroStabilityInwardsCalculationGroupExporterTest)}.{nameof(Export_NestedCalculationGroupWithGroupsWithCalculationsWithAndWithoutOutput_FolderNotExportedAndReturnsTrue)}");

            Directory.CreateDirectory(folderPath);
            string filePath = Path.Combine(folderPath, "export.zip");

            MacroStabilityInwardsCalculationScenario calculation1 = CreateCalculation("calculation1", false);
            MacroStabilityInwardsCalculationScenario calculation2 = CreateCalculation("calculation2");

            var rootGroup = new CalculationGroup
            {
                Name = "root"
            };
            var nestedGroup1 = new CalculationGroup
            {
                Name = "group1"
            };
            var nestedGroup2 = new CalculationGroup
            {
                Name = "group2"
            };

            nestedGroup2.Children.Add(calculation2);
            nestedGroup2.Children.Add(calculation1);
            nestedGroup1.Children.Add(nestedGroup2);
            rootGroup.Children.Add(nestedGroup1);

            var exporter = new MacroStabilityInwardsCalculationGroupExporter(rootGroup, new GeneralMacroStabilityInwardsInput(),
                                                                             new PersistenceFactory(), filePath, fileExtension,
                                                                             c => AssessmentSectionTestHelper.GetTestAssessmentLevel());

            try
            {
                using (new MacroStabilityInwardsCalculatorFactoryConfig())
                {
                    // Call
                    var exportResult            = false;
                    void Call() => exportResult = exporter.Export();

                    // Assert
                    TestHelper.AssertLogMessagesWithLevelAreGenerated(Call, new[]
                    {
                        new Tuple <string, LogLevelConstant>($"Berekening '{calculation1.Name}' heeft geen uitvoer. Deze berekening wordt overgeslagen.", LogLevelConstant.Warn)
                    });
                    Assert.IsTrue(exportResult);

                    AssertFilesExistInZip(new[]
                    {
                        $"{nestedGroup1.Name}/{nestedGroup2.Name}/{calculation2.Name}.{fileExtension}"
                    }, filePath);
                }
            }
            finally
            {
                DirectoryHelper.TryDelete(folderPath);
            }
        }
        public void Export_CalculationGroupWithNestedGroupsAndCalculations_WritesFilesAndReturnsTrue()
        {
            // Setup
            string folderPath = TestHelper.GetScratchPadPath($"{nameof(MacroStabilityInwardsCalculationGroupExporterTest)}.{nameof(Export_CalculationGroupWithNestedGroupsAndCalculations_WritesFilesAndReturnsTrue)}");

            Directory.CreateDirectory(folderPath);
            string filePath = Path.Combine(folderPath, "export.zip");

            MacroStabilityInwardsCalculationScenario calculation1 = CreateCalculation("calculation1");
            MacroStabilityInwardsCalculationScenario calculation2 = CreateCalculation("calculation2");
            MacroStabilityInwardsCalculationScenario calculation3 = CreateCalculation("calculation3");
            MacroStabilityInwardsCalculationScenario calculation4 = CreateCalculation("calculation4");

            var rootCalculationGroup = new CalculationGroup();
            var nestedGroup1         = new CalculationGroup
            {
                Name = "NestedGroup1"
            };
            var nestedGroup2 = new CalculationGroup
            {
                Name = "NestedGroup2"
            };

            nestedGroup2.Children.Add(calculation4);
            nestedGroup1.Children.Add(calculation3);
            nestedGroup1.Children.Add(nestedGroup2);
            rootCalculationGroup.Children.Add(calculation1);
            rootCalculationGroup.Children.Add(calculation2);
            rootCalculationGroup.Children.Add(nestedGroup1);

            var exporter = new MacroStabilityInwardsCalculationGroupExporter(rootCalculationGroup, new GeneralMacroStabilityInwardsInput(),
                                                                             new PersistenceFactory(), filePath, fileExtension,
                                                                             c => AssessmentSectionTestHelper.GetTestAssessmentLevel());

            try
            {
                using (new MacroStabilityInwardsCalculatorFactoryConfig())
                {
                    // Call
                    bool exportResult = exporter.Export();

                    // Assert
                    Assert.IsTrue(exportResult);
                    AssertFilesExistInZip(new[]
                    {
                        $"{calculation1.Name}.{fileExtension}",
                        $"{calculation2.Name}.{fileExtension}",
                        $"{nestedGroup1.Name}/{calculation3.Name}.{fileExtension}",
                        $"{nestedGroup1.Name}/{nestedGroup2.Name}/{calculation4.Name}.{fileExtension}"
                    }, filePath);
                }
            }
            finally
            {
                DirectoryHelper.TryDelete(folderPath);
            }
        }
Пример #29
0
        public void Validate_ValidInput_ReturnsEmpty()
        {
            // Call
            string[] messages = MacroStabilityInwardsInputValidator.Validate(input,
                                                                             AssessmentSectionTestHelper.GetTestAssessmentLevel()).ToArray();

            // Assert
            CollectionAssert.IsEmpty(messages);
        }
        public void Calculate_PreprocessorDirectorySet_InputPropertiesCorrectlySentToCalculator(bool usePreprocessor)
        {
            // Setup
            string preprocessorDirectory = usePreprocessor
                                               ? validPreprocessorDirectory
                                               : string.Empty;
            var calculationSettings = new HydraulicBoundaryCalculationSettings(validHydraulicBoundaryDatabaseFilePath,
                                                                               validHlcdFilePath,
                                                                               false,
                                                                               preprocessorDirectory);

            var failureMechanism = new HeightStructuresFailureMechanism();

            var mockRepository = new MockRepository();
            IAssessmentSection assessmentSection = AssessmentSectionTestHelper.CreateAssessmentSectionStub(failureMechanism,
                                                                                                           mockRepository);
            var calculator        = new TestStructuresCalculator <StructuresOvertoppingCalculationInput>();
            var calculatorFactory = mockRepository.StrictMock <IHydraRingCalculatorFactory>();

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

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

            using (new HydraRingCalculatorFactoryConfig(calculatorFactory))
            {
                // Call
                new HeightStructuresCalculationService().Calculate(calculation,
                                                                   failureMechanism.GeneralInput,
                                                                   calculationSettings);

                // Assert
                StructuresOvertoppingCalculationInput[] calculationInputs = calculator.ReceivedInputs.ToArray();
                Assert.AreEqual(1, calculationInputs.Length);

                StructuresOvertoppingCalculationInput actualInput = calculationInputs[0];
                Assert.AreEqual(usePreprocessor, actualInput.PreprocessorSetting.RunPreprocessor);
            }

            mockRepository.VerifyAll();
        }