Exemplo n.º 1
0
        public void GetViewName_WithContext_ReturnsExpectedViewName(
            Func <IAssessmentSection, IObservableEnumerable <HydraulicBoundaryLocationCalculation> > getCalculationsFunc,
            double maximumAllowableFloodingProbability, double signalFloodingProbability, string expectedProbabilityText)
        {
            // Setup
            var assessmentSection = new AssessmentSectionStub
            {
                FailureMechanismContribution =
                {
                    MaximumAllowableFloodingProbability = maximumAllowableFloodingProbability,
                    SignalFloodingProbability           = signalFloodingProbability
                }
            };
            var context = new WaterLevelCalculationsForNormTargetProbabilityContext(getCalculationsFunc(assessmentSection),
                                                                                    assessmentSection,
                                                                                    () => 0.01);

            using (var plugin = new RiskeerPlugin())
            {
                ViewInfo info = GetViewInfo(plugin);

                // Call
                string viewName = info.GetViewName(null, context);

                // Assert
                Assert.AreEqual($"Waterstanden bij vaste doelkans - {expectedProbabilityText}", viewName);
            }
        }
Exemplo n.º 2
0
        public void CreateFileExporter_WithContext_ReturnFileExporter()
        {
            // Setup
            var mocks             = new MockRepository();
            var assessmentSection = mocks.Stub <IAssessmentSection>();

            mocks.ReplayAll();

            var context = new WaterLevelCalculationsForNormTargetProbabilityContext(
                new ObservableList <HydraulicBoundaryLocationCalculation>(), assessmentSection, () => 0.1);

            const string filePath = "test";

            using (var plugin = new RiskeerPlugin())
            {
                ExportInfo info = GetExportInfo(plugin);

                // Call
                IFileExporter fileExporter = info.CreateFileExporter(context, filePath);

                // Assert
                Assert.IsInstanceOf <HydraulicBoundaryLocationCalculationsForTargetProbabilityExporter>(fileExporter);
            }

            mocks.VerifyAll();
        }
        public void CreateInstance_WithContext_SetsDataCorrectly()
        {
            // Setup
            var mockRepository    = new MockRepository();
            var assessmentSection = mockRepository.Stub <IAssessmentSection>();

            mockRepository.ReplayAll();

            var hydraulicBoundaryLocationCalculations = new ObservableList <HydraulicBoundaryLocationCalculation>();

            double GetNormFunc() => 0.01;

            var context = new WaterLevelCalculationsForNormTargetProbabilityContext(hydraulicBoundaryLocationCalculations,
                                                                                    assessmentSection,
                                                                                    GetNormFunc);

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

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

                // Assert
                Assert.IsInstanceOf <WaterLevelCalculationsForNormTargetProbabilityProperties>(objectProperties);
                Assert.AreSame(hydraulicBoundaryLocationCalculations, objectProperties.Data);
                Assert.AreEqual(GetNormFunc(), ((WaterLevelCalculationsForNormTargetProbabilityProperties)objectProperties).TargetProbability);
            }

            mockRepository.VerifyAll();
        }
Exemplo n.º 4
0
        public void CreateInstance_WithContext_SetsExpectedViewProperties()
        {
            // Setup
            var assessmentSection = new AssessmentSectionStub();
            var context           = new WaterLevelCalculationsForNormTargetProbabilityContext(new ObservableList <HydraulicBoundaryLocationCalculation>(),
                                                                                              assessmentSection,
                                                                                              () => 0.01);

            using (var plugin = new RiskeerPlugin())
            {
                ViewInfo info = GetViewInfo(plugin);

                // Call
                var view = (DesignWaterLevelCalculationsView)info.CreateInstance(context);

                // Assert
                Assert.AreSame(assessmentSection, view.AssessmentSection);
            }
        }
Exemplo n.º 5
0
        public void CreateInstance_WithContext_SetsExpectedDataGridViewData()
        {
            // Setup
            var random = new Random();

            var hydraulicBoundaryLocationCalculations = new ObservableList <HydraulicBoundaryLocationCalculation>
            {
                new HydraulicBoundaryLocationCalculation(new TestHydraulicBoundaryLocation())
                {
                    Output = new TestHydraulicBoundaryLocationCalculationOutput(random.NextDouble())
                },
                new HydraulicBoundaryLocationCalculation(new TestHydraulicBoundaryLocation())
                {
                    Output = new TestHydraulicBoundaryLocationCalculationOutput(random.NextDouble())
                }
            };

            var context = new WaterLevelCalculationsForNormTargetProbabilityContext(hydraulicBoundaryLocationCalculations,
                                                                                    new AssessmentSectionStub(),
                                                                                    () => 0.01);

            using (var plugin = new RiskeerPlugin())
            {
                ViewInfo info = GetViewInfo(plugin);

                // Call
                var view = (DesignWaterLevelCalculationsView)info.CreateInstance(context);

                using (var testForm = new Form())
                {
                    testForm.Controls.Add(view);
                    testForm.Show();

                    // Assert
                    DataGridView calculationsDataGridView = ControlTestHelper.GetDataGridView(view, "DataGridView");
                    DataGridViewRowCollection rows        = calculationsDataGridView.Rows;
                    Assert.AreEqual(2, rows.Count);
                    Assert.AreEqual(hydraulicBoundaryLocationCalculations[0].Output.Result.ToString(), rows[0].Cells[waterLevelColumnIndex].FormattedValue);
                    Assert.AreEqual(hydraulicBoundaryLocationCalculations[1].Output.Result.ToString(), rows[1].Cells[waterLevelColumnIndex].FormattedValue);
                }
            }
        }
Exemplo n.º 6
0
        public void AfterCreate_WithGuiSet_SetsSpecificPropertiesToView()
        {
            // Setup
            var  mocks = new MockRepository();
            IGui gui   = StubFactory.CreateGuiStub(mocks);

            gui.Stub(g => g.ViewCommands).Return(mocks.Stub <IViewCommands>());
            gui.Stub(g => g.MainWindow).Return(mocks.Stub <IMainWindow>());
            gui.Stub(g => g.DocumentViewController).Return(mocks.Stub <IDocumentViewController>());
            gui.Stub(g => g.ProjectStore).Return(mocks.Stub <IStoreProject>());
            mocks.ReplayAll();

            double GetNormFunc() => 0.01;

            var assessmentSection = new AssessmentSectionStub();
            var calculations      = new ObservableList <HydraulicBoundaryLocationCalculation>();

            var context = new WaterLevelCalculationsForNormTargetProbabilityContext(calculations,
                                                                                    assessmentSection,
                                                                                    GetNormFunc);

            using (var view = new DesignWaterLevelCalculationsView(new ObservableList <HydraulicBoundaryLocationCalculation>(),
                                                                   new AssessmentSectionStub(),
                                                                   GetNormFunc,
                                                                   () => "1/100"))

                using (var plugin = new RiskeerPlugin())
                {
                    ViewInfo info = GetViewInfo(plugin);
                    plugin.Gui = gui;
                    plugin.Activate();

                    // Call
                    info.AfterCreate(view, context);

                    // Assert
                    Assert.IsInstanceOf <IHydraulicBoundaryLocationCalculationGuiService>(view.CalculationGuiService);
                }

            mocks.VerifyAll();
        }
Exemplo n.º 7
0
        public void GetViewData_Always_ReturnsHydraulicBoundaryLocationCalculations()
        {
            // Setup
            var assessmentSection = new AssessmentSectionStub();
            var calculations      = new ObservableList <HydraulicBoundaryLocationCalculation>();

            var context = new WaterLevelCalculationsForNormTargetProbabilityContext(calculations,
                                                                                    assessmentSection,
                                                                                    () => 0.01);

            using (var plugin = new RiskeerPlugin())
            {
                ViewInfo info = GetViewInfo(plugin);

                // Call
                object viewData = info.GetViewData(context);

                // Assert
                Assert.AreSame(calculations, viewData);
            }
        }
Exemplo n.º 8
0
        public void Constructor_ExpectedValues()
        {
            // Setup
            var mockRepository    = new MockRepository();
            var assessmentSection = mockRepository.Stub <IAssessmentSection>();

            mockRepository.ReplayAll();

            var           calculations = new ObservableList <HydraulicBoundaryLocationCalculation>();
            Func <double> getNormFunc  = () => 0.01;

            // Call
            var context = new WaterLevelCalculationsForNormTargetProbabilityContext(calculations,
                                                                                    assessmentSection,
                                                                                    getNormFunc);

            // Assert
            Assert.IsInstanceOf <ObservableWrappedObjectContextBase <IObservableEnumerable <HydraulicBoundaryLocationCalculation> > >(context);
            Assert.AreSame(calculations, context.WrappedData);
            Assert.AreSame(assessmentSection, context.AssessmentSection);
            Assert.AreSame(getNormFunc, context.GetNormFunc);
            mockRepository.VerifyAll();
        }
Exemplo n.º 9
0
        public void Name_WithContext_ReturnsName()
        {
            // Setup
            var mocks             = new MockRepository();
            var assessmentSection = mocks.Stub <IAssessmentSection>();

            mocks.ReplayAll();

            var context = new WaterLevelCalculationsForNormTargetProbabilityContext(
                new ObservableList <HydraulicBoundaryLocationCalculation>(), assessmentSection, () => 0.1);

            using (var plugin = new RiskeerPlugin())
            {
                ExportInfo info = GetExportInfo(plugin);

                // Call
                string name = info.Name(context);

                // Assert
                Assert.AreEqual("Waterstanden (1/10)", name);
            }

            mocks.VerifyAll();
        }
Exemplo n.º 10
0
        public void CreateInstance_WithContext_SetsExpectedCalculationData(
            Func <IAssessmentSection, IObservableEnumerable <HydraulicBoundaryLocationCalculation> > getCalculationsFunc)
        {
            // Setup
            double GetNormFunc() => 0.01;

            var assessmentSection = new AssessmentSectionStub();

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

            IObservableEnumerable <HydraulicBoundaryLocationCalculation> calculations = getCalculationsFunc(assessmentSection);
            var context = new WaterLevelCalculationsForNormTargetProbabilityContext(calculations,
                                                                                    assessmentSection,
                                                                                    GetNormFunc);

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

            double actualNormValue = double.NaN;
            IEnumerable <HydraulicBoundaryLocationCalculation> performedCalculations = null;

            guiService.Expect(ch => ch.CalculateDesignWaterLevels(null, null, int.MinValue, null)).IgnoreArguments().WhenCalled(
                invocation =>
            {
                performedCalculations = (IEnumerable <HydraulicBoundaryLocationCalculation>)invocation.Arguments[0];
                actualNormValue       = (double)invocation.Arguments[2];
            });

            mockRepository.ReplayAll();

            using (var plugin = new RiskeerPlugin())
            {
                ViewInfo info = GetViewInfo(plugin);

                // Call
                var view = (DesignWaterLevelCalculationsView)info.CreateInstance(context);

                using (var testForm = new Form())
                {
                    view.CalculationGuiService = guiService;
                    testForm.Controls.Add(view);
                    testForm.Show();

                    DataGridView calculationsDataGridView = ControlTestHelper.GetDataGridView(view, "DataGridView");
                    DataGridViewRowCollection rows        = calculationsDataGridView.Rows;
                    rows[0].Cells[calculateColumnIndex].Value = true;

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

                    button.Click();

                    // Assert
                    Assert.AreEqual(GetNormFunc(), actualNormValue);
                    Assert.AreSame(calculations.Single(), performedCalculations.Single());
                }
            }

            mockRepository.VerifyAll();
        }