Exemple #1
0
        public void GivenFullyConfiguredView_WhenSelectingCellInRow_ThenSelectionChangedAndPropagatedAccordingly()
        {
            // Given
            var mocks       = new MockRepository();
            var calculation = mocks.Stub <ICalculation>();

            mocks.ReplayAll();

            GeneralResult <TopLevelSubMechanismIllustrationPoint> generalResult = GetGeneralResultWithTwoTopLevelIllustrationPoints();
            var view = new GeneralResultSubMechanismIllustrationPointView(calculation, () => generalResult);

            ShowTestView(view);

            var selectionChangedCount = 0;

            view.SelectionChanged += (sender, args) => selectionChangedCount++;

            DataGridView dataGridView = ControlTestHelper.GetDataGridView(testForm, "DataGridView");

            // When
            dataGridView.CurrentCell = dataGridView.Rows[1].Cells[0];
            EventHelper.RaiseEvent(dataGridView, "CellClick", new DataGridViewCellEventArgs(0, 0));

            // Then
            Assert.AreEqual(1, selectionChangedCount);

            TopLevelSubMechanismIllustrationPoint[] topLevelIllustrationPoints = generalResult.TopLevelIllustrationPoints.ToArray();
            TopLevelSubMechanismIllustrationPoint   topLevelIllustrationPoint  = topLevelIllustrationPoints.ElementAt(1);

            AssertIllustrationPointSelection(topLevelIllustrationPoint,
                                             topLevelIllustrationPoints.Select(ip => ip.ClosingSituation),
                                             view.Selection);
            mocks.VerifyAll();
        }
        public void DeselectAllButton_AllCalculatableItemsSelectedDeselectAllButtonClicked_AllCalculatableItemsNotSelected()
        {
            // Setup
            ShowFullyConfiguredTestCalculatableView();

            DataGridView dataGridView = ControlTestHelper.GetDataGridView(testForm, "DataGridView");
            var          button       = new ButtonTester("DeselectAllButton", testForm);

            DataGridViewRowCollection rows = dataGridView.Rows;

            foreach (DataGridViewRow row in rows)
            {
                row.Cells[calculateColumnIndex].Value = true;
            }

            // Precondition
            Assert.IsTrue((bool)rows[0].Cells[calculateColumnIndex].Value);
            Assert.IsTrue((bool)rows[1].Cells[calculateColumnIndex].Value);

            // Call
            button.Click();

            // Assert
            Assert.IsFalse((bool)rows[0].Cells[calculateColumnIndex].Value);
            Assert.IsFalse((bool)rows[1].Cells[calculateColumnIndex].Value);
        }
Exemple #3
0
        public void OnLoad_DataGridViewCorrectlyInitialized()
        {
            // Setup & Call
            ShowControl();

            // Assert
            DataGridView dataGridView = ControlTestHelper.GetDataGridView(testForm, "DataGridView");

            Assert.AreEqual(4, dataGridView.ColumnCount);
            DataGridViewColumn windDirectionColumn = dataGridView.Columns[windDirectionColumnIndex];

            Assert.AreEqual("Windrichting", windDirectionColumn.HeaderText);
            Assert.IsTrue(windDirectionColumn.ReadOnly);

            DataGridViewColumn closingSituationColumn = dataGridView.Columns[closingScenarioColumnIndex];

            Assert.AreEqual("Keringsituatie", closingSituationColumn.HeaderText);
            Assert.IsTrue(closingSituationColumn.ReadOnly);
            Assert.IsFalse(closingSituationColumn.Visible);

            DataGridViewColumn calculatedProbabilityColumn = dataGridView.Columns[calculatedProbabilityColumnIndex];

            Assert.AreEqual("Berekende kans\r\n[-]", calculatedProbabilityColumn.HeaderText);
            Assert.IsTrue(calculatedProbabilityColumn.ReadOnly);

            DataGridViewColumn calculatedReliabilityColumn = dataGridView.Columns[calculatedReliabilityColumnIndex];

            Assert.AreEqual("Betrouwbaarheidsindex\r\nberekende kans\r\n[-]", calculatedReliabilityColumn.HeaderText);
            Assert.IsTrue(calculatedReliabilityColumn.ReadOnly);
        }
Exemple #4
0
        public void Constructor_DataGridViewCorrectlyInitialized()
        {
            // Setup & Call
            ShowTestHydraulicBoundaryCalculationsView();

            // Assert
            DataGridView dataGridView = ControlTestHelper.GetDataGridView(testForm, "dataGridView");

            Assert.AreEqual(5, dataGridView.ColumnCount);

            var calculateColumn = (DataGridViewCheckBoxColumn)dataGridView.Columns[calculateColumnIndex];

            Assert.AreEqual("Berekenen", calculateColumn.HeaderText);

            var includeIllustrationPointsColumn = (DataGridViewCheckBoxColumn)dataGridView.Columns[includeIllustrationPointsColumnIndex];

            Assert.AreEqual("Illustratiepunten inlezen", includeIllustrationPointsColumn.HeaderText);

            var locationNameColumn = (DataGridViewTextBoxColumn)dataGridView.Columns[locationNameColumnIndex];

            Assert.AreEqual("Naam", locationNameColumn.HeaderText);

            var locationIdColumn = (DataGridViewTextBoxColumn)dataGridView.Columns[locationIdColumnIndex];

            Assert.AreEqual("ID", locationIdColumn.HeaderText);

            var locationColumn = (DataGridViewTextBoxColumn)dataGridView.Columns[locationColumnIndex];

            Assert.AreEqual("Coördinaten [m]", locationColumn.HeaderText);

            var button = (Button)testForm.Controls.Find("CalculateForSelectedButton", true).First();

            Assert.IsFalse(button.Enabled);
        }
        public void GivenFullyConfiguredView_WhenRowsSelected_ThenCalculateForSelectedButtonEnabledAndNoErrorMessageProvided()
        {
            // Given
            TestCalculationsView view         = ShowFullyConfiguredTestCalculatableView();
            DataGridView         dataGridView = ControlTestHelper.GetDataGridView(testForm, "DataGridView");

            // When
            dataGridView.Rows[0].Cells[calculateColumnIndex].Value = true;

            // Then
            var button = (Button)view.Controls.Find("CalculateForSelectedButton", true)[0];

            Assert.IsTrue(button.Enabled);
            var errorProvider = TypeUtils.GetField <ErrorProvider>(view, "CalculateForSelectedButtonErrorProvider");

            Assert.AreEqual("", errorProvider.GetError(button));
        }
Exemple #6
0
        public void Data_SetNewValueWithSameClosingSituations_DataGridViewCorrectlyInitialized()
        {
            // Setup
            var data = new[]
            {
                new IllustrationPointControlItem(new TestTopLevelIllustrationPoint(),
                                                 "SSE",
                                                 "Regular",
                                                 Enumerable.Empty <Stochast>(),
                                                 new RoundedDouble(5, 0.9)),
                new IllustrationPointControlItem(new TestTopLevelIllustrationPoint(),
                                                 "SSE",
                                                 "Regular",
                                                 Enumerable.Empty <Stochast>(),
                                                 new RoundedDouble(5, 0.7))
            };
            IllustrationPointsTableControl control = ShowControl();

            // Call
            control.Data = data;

            // Assert
            DataGridView dataGridView = ControlTestHelper.GetDataGridView(testForm, "DataGridView");

            DataGridViewRowCollection rows = dataGridView.Rows;

            Assert.AreEqual(2, rows.Count);

            DataGridViewCellCollection cells = rows[0].Cells;

            Assert.AreEqual(4, cells.Count);
            Assert.AreEqual("SSE", cells[windDirectionColumnIndex].FormattedValue);
            Assert.AreEqual("Regular", cells[closingScenarioColumnIndex].FormattedValue);
            Assert.AreEqual("1/5", cells[calculatedProbabilityColumnIndex].FormattedValue);
            Assert.AreEqual("0,90000", cells[calculatedReliabilityColumnIndex].FormattedValue);

            cells = rows[1].Cells;
            Assert.AreEqual(4, cells.Count);
            Assert.AreEqual("SSE", cells[windDirectionColumnIndex].FormattedValue);
            Assert.AreEqual("Regular", cells[closingScenarioColumnIndex].FormattedValue);
            Assert.AreEqual("1/4", cells[calculatedProbabilityColumnIndex].FormattedValue);
            Assert.AreEqual("0,70000", cells[calculatedReliabilityColumnIndex].FormattedValue);

            Assert.IsFalse(dataGridView.Columns[closingScenarioColumnIndex].Visible);
        }
        public void GivenFullyConfiguredView_WhenSelectingCellInRow_ThenSelectionChangedFired()
        {
            // Given
            TestCalculationsView view = ShowFullyConfiguredTestCalculatableView();

            var selectionChangedCount = 0;

            view.SelectionChanged += (sender, args) => selectionChangedCount++;

            DataGridView dataGridView = ControlTestHelper.GetDataGridView(testForm, "DataGridView");

            // When
            dataGridView.CurrentCell = dataGridView.Rows[1].Cells[calculateColumnIndex];
            EventHelper.RaiseEvent(dataGridView, "CellClick", new DataGridViewCellEventArgs(0, 0));

            // Then
            Assert.AreEqual(1, selectionChangedCount);
        }
Exemple #8
0
        public void CalculateForSelectedButton_OneSelectedButCalculationGuiServiceNotSet_DoesNotThrowException()
        {
            // Setup
            ShowFullyConfiguredTestHydraulicBoundaryCalculationsView();

            DataGridView dataGridView      = ControlTestHelper.GetDataGridView(testForm, "dataGridView");
            DataGridViewRowCollection rows = dataGridView.Rows;

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

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

            // Call
            TestDelegate test = () => button.Click();

            // Assert
            Assert.DoesNotThrow(test);
        }
Exemple #9
0
        public void CreateInstance_WithContext_SetsExpectedDataGridViewData()
        {
            // Setup
            var random = new Random();

            var calculationsForTargetProbability = new HydraulicBoundaryLocationCalculationsForTargetProbability(0.1)
            {
                HydraulicBoundaryLocationCalculations =
                {
                    new HydraulicBoundaryLocationCalculation(new TestHydraulicBoundaryLocation())
                    {
                        Output = new TestHydraulicBoundaryLocationCalculationOutput(random.NextDouble())
                    },
                    new HydraulicBoundaryLocationCalculation(new TestHydraulicBoundaryLocation())
                    {
                        Output = new TestHydraulicBoundaryLocationCalculationOutput(random.NextDouble())
                    }
                }
            };

            var context = new WaterLevelCalculationsForUserDefinedTargetProbabilityContext(calculationsForTargetProbability, new AssessmentSectionStub());

            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(calculationsForTargetProbability.HydraulicBoundaryLocationCalculations[0].Output.Result.ToString(), rows[0].Cells[waterLevelColumnIndex].FormattedValue);
                    Assert.AreEqual(calculationsForTargetProbability.HydraulicBoundaryLocationCalculations[1].Output.Result.ToString(), rows[1].Cells[waterLevelColumnIndex].FormattedValue);
                }
            }
        }
        public void OnLoad_DataGridViewCorrectlyInitialized()
        {
            // Setup & Call
            TestCalculationsView view = ShowTestCalculatableView();

            // Assert
            DataGridView dataGridView = ControlTestHelper.GetDataGridView(testForm, "DataGridView");

            Assert.AreEqual(1, dataGridView.ColumnCount);

            var          calculateColumn             = (DataGridViewCheckBoxColumn)dataGridView.Columns[calculateColumnIndex];
            const string expectedCalculateHeaderText = "Berekenen";

            Assert.AreEqual(expectedCalculateHeaderText, calculateColumn.HeaderText);

            var button = (Button)view.Controls.Find("CalculateForSelectedButton", true)[0];

            Assert.IsFalse(button.Enabled);
        }
Exemple #11
0
        public void GivenFullyConfiguredControl_WhenSelectingCellInRow_ThenSelectionChangedFired()
        {
            // Given
            IllustrationPointsTableControl control = ShowControl();

            control.Data = GetControlItems();

            var selectionChangedCount = 0;

            control.SelectionChanged += (sender, args) => selectionChangedCount++;

            DataGridView dataGridView = ControlTestHelper.GetDataGridView(testForm, "DataGridView");

            // When
            dataGridView.CurrentCell = dataGridView.Rows[1].Cells[calculatedProbabilityColumnIndex];
            EventHelper.RaiseEvent(dataGridView, "CellClick", new DataGridViewCellEventArgs(0, 0));

            // Then
            Assert.AreEqual(1, selectionChangedCount);
        }
Exemple #12
0
        public void Data_SetNewValueWithDifferentClosingSituations_DataGridViewCorrectlyInitialized()
        {
            // Setup
            IEnumerable <IllustrationPointControlItem> data    = GetControlItems();
            IllustrationPointsTableControl             control = ShowControl();

            // Call
            control.Data = data;

            // Assert
            DataGridView dataGridView = ControlTestHelper.GetDataGridView(testForm, "DataGridView");

            DataGridViewRowCollection rows = dataGridView.Rows;

            Assert.AreEqual(3, rows.Count);

            DataGridViewCellCollection cells = rows[0].Cells;

            Assert.AreEqual(4, cells.Count);
            Assert.AreEqual("SSE", cells[windDirectionColumnIndex].FormattedValue);
            Assert.AreEqual("Regular", cells[closingScenarioColumnIndex].FormattedValue);
            Assert.AreEqual("1/5", cells[calculatedProbabilityColumnIndex].FormattedValue);
            Assert.AreEqual("0,90000", cells[calculatedReliabilityColumnIndex].FormattedValue);

            cells = rows[1].Cells;
            Assert.AreEqual(4, cells.Count);
            Assert.AreEqual("SSE", cells[windDirectionColumnIndex].FormattedValue);
            Assert.AreEqual("Open", cells[closingScenarioColumnIndex].FormattedValue);
            Assert.AreEqual("1/4", cells[calculatedProbabilityColumnIndex].FormattedValue);
            Assert.AreEqual("0,70000", cells[calculatedReliabilityColumnIndex].FormattedValue);

            cells = rows[2].Cells;
            Assert.AreEqual(4, cells.Count);
            Assert.AreEqual("NE", cells[windDirectionColumnIndex].FormattedValue);
            Assert.AreEqual("Open", cells[closingScenarioColumnIndex].FormattedValue);
            Assert.AreEqual("1/5", cells[calculatedProbabilityColumnIndex].FormattedValue);
            Assert.AreEqual("0,80000", cells[calculatedReliabilityColumnIndex].FormattedValue);

            Assert.IsTrue(dataGridView.Columns[closingScenarioColumnIndex].Visible);
        }
        public void CalculateForSelectedButton_OneSelected_CallsCalculateHandleCalculateSelectedObjects()
        {
            // Setup
            TestCalculationsView view = ShowFullyConfiguredTestCalculatableView();

            DataGridView dataGridView = ControlTestHelper.GetDataGridView(testForm, "DataGridView");

            DataGridViewRowCollection rows = dataGridView.Rows;

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

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

            // Call
            buttonTester.Click();

            // Assert
            Assert.AreEqual(1, view.ObjectsToCalculate.Count());
            TestCalculatableObject expectedObject = ((IEnumerable <TestCalculatableObject>)view.Data).First();

            Assert.AreEqual(expectedObject, view.ObjectsToCalculate.First());
        }
Exemple #14
0
        public void Data_SetToNull_DataGridViewCleared()
        {
            // Setup
            IEnumerable <IllustrationPointControlItem> data    = GetControlItems();
            IllustrationPointsTableControl             control = ShowControl();

            control.Data = data;

            DataGridView dataGridView      = ControlTestHelper.GetDataGridView(testForm, "DataGridView");
            DataGridViewRowCollection rows = dataGridView.Rows;

            // Precondition
            Assert.AreEqual(3, rows.Count);

            // Call
            control.Data = null;

            // Assert
            Assert.AreEqual(0, rows.Count);

            Assert.IsFalse(dataGridView.Columns[closingScenarioColumnIndex].Visible);
        }
        public void GetAssessmentSectionFromFile_ShapeWithInvalidNorm_ThrowsCriticalFileValidationException()
        {
            // Setup
            var mockRepository = new MockRepository();
            var parentDialog   = mockRepository.Stub <IWin32Window>();

            mockRepository.ReplayAll();

            var assessmentSectionFromFileHandler = new AssessmentSectionFromFileHandler(parentDialog);

            string pathValidFolder = Path.Combine(testDataPath, "InvalidNorm");

            SetShapeFileDirectory(assessmentSectionFromFileHandler, pathValidFolder);

            DialogBoxHandler = (name, wnd) =>
            {
                var selectionDialog = (ReferenceLineMetaSelectionDialog) new FormTester(name).TheObject;

                DataGridView dataGridView = ControlTestHelper.GetDataGridView(selectionDialog, "dataGridView");
                dataGridView.Rows[0].Selected = true;

                new ButtonTester("Ok", selectionDialog).Click();
            };

            // Call
            void Call() => assessmentSectionFromFileHandler.GetAssessmentSectionFromFile();

            // Assert
            const string expectedMessage = "Het traject kan niet aangemaakt worden met een omgevingswaarde van 1/9.999.999 en een signaleringsparameter van 1/8.888.888. " +
                                           "De waarde van de omgevingswaarde en signaleringsparameter moet in het bereik [0,000001, 0,1] liggen en " +
                                           "de omgevingswaarde moet gelijk zijn aan of groter zijn dan de signaleringsparameter.";
            var exception = Assert.Throws <CriticalFileValidationException>(Call);

            Assert.AreEqual(expectedMessage, exception.Message);
            Assert.IsInstanceOf <ArgumentOutOfRangeException>(exception.InnerException);
            mockRepository.VerifyAll();
        }
Exemple #16
0
        public void HydraulicBoundaryCalculationsView_AssessmentSectionWithData_DataGridViewCorrectlyInitialized()
        {
            // Setup & Call
            ShowFullyConfiguredTestHydraulicBoundaryCalculationsView();

            // Assert
            DataGridView dataGridView      = ControlTestHelper.GetDataGridView(testForm, "dataGridView");
            DataGridViewRowCollection rows = dataGridView.Rows;

            Assert.AreEqual(3, rows.Count);

            DataGridViewCellCollection cells = rows[0].Cells;

            Assert.AreEqual(5, cells.Count);
            Assert.AreEqual(false, cells[calculateColumnIndex].FormattedValue);
            Assert.AreEqual(false, cells[includeIllustrationPointsColumnIndex].FormattedValue);
            Assert.AreEqual("1", cells[locationNameColumnIndex].FormattedValue);
            Assert.AreEqual("1", cells[locationIdColumnIndex].FormattedValue);
            Assert.AreEqual(new Point2D(1, 1).ToString(), cells[locationColumnIndex].FormattedValue);

            cells = rows[1].Cells;
            Assert.AreEqual(5, cells.Count);
            Assert.AreEqual(false, cells[calculateColumnIndex].FormattedValue);
            Assert.AreEqual(false, cells[includeIllustrationPointsColumnIndex].FormattedValue);
            Assert.AreEqual("2", cells[locationNameColumnIndex].FormattedValue);
            Assert.AreEqual("2", cells[locationIdColumnIndex].FormattedValue);
            Assert.AreEqual(new Point2D(2, 2).ToString(), cells[locationColumnIndex].FormattedValue);

            cells = rows[2].Cells;
            Assert.AreEqual(5, cells.Count);
            Assert.AreEqual(false, cells[calculateColumnIndex].FormattedValue);
            Assert.AreEqual(true, cells[includeIllustrationPointsColumnIndex].FormattedValue);
            Assert.AreEqual("3", cells[locationNameColumnIndex].FormattedValue);
            Assert.AreEqual("3", cells[locationIdColumnIndex].FormattedValue);
            Assert.AreEqual(new Point2D(3, 3).ToString(), cells[locationColumnIndex].FormattedValue);
        }
Exemple #17
0
 private DataGridView GetCalculationsDataGridView()
 {
     return(ControlTestHelper.GetDataGridView(testForm, "DataGridView"));
 }
Exemple #18
0
        public void CreateInstance_WithContext_SetsExpectedCalculationData()
        {
            // Setup
            var hydraulicBoundaryLocationCalculation = new HydraulicBoundaryLocationCalculation(new TestHydraulicBoundaryLocation());
            var calculationsForTargetProbability     = new HydraulicBoundaryLocationCalculationsForTargetProbability(0.01)
            {
                HydraulicBoundaryLocationCalculations =
                {
                    hydraulicBoundaryLocationCalculation
                }
            };

            var assessmentSection = new AssessmentSectionStub();

            assessmentSection.WaterLevelCalculationsForUserDefinedTargetProbabilities.Add(calculationsForTargetProbability);

            var context = new WaterLevelCalculationsForUserDefinedTargetProbabilityContext(calculationsForTargetProbability, assessmentSection);

            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(calculationsForTargetProbability.TargetProbability, actualNormValue);
                    Assert.AreSame(hydraulicBoundaryLocationCalculation, performedCalculations.Single());
                }
            }

            mockRepository.VerifyAll();
        }