public void DefaultConstructor_DefaultValues()
        {
            // Call
            using (var view = new TestCalculationsView())
            {
                // Assert
                Assert.IsInstanceOf <UserControl>(view);
                Assert.IsInstanceOf <ISelectionProvider>(view);
                Assert.IsInstanceOf <IView>(view);
                Assert.IsNull(view.Data);

                Assert.AreEqual(1, view.Controls.Count);

                var splitContainer = view.Controls[0] as SplitContainer;
                Assert.IsNotNull(splitContainer);
                Control.ControlCollection verticalSplitContainerPanel1Controls = splitContainer.Panel1.Controls;
                Assert.AreEqual(new Size(535, 0), splitContainer.Panel1.AutoScrollMinSize);
                Assert.AreEqual(2, verticalSplitContainerPanel1Controls.Count);
                Assert.IsInstanceOf <DataGridViewControl>(verticalSplitContainerPanel1Controls[0]);
                Assert.IsInstanceOf <GroupBox>(verticalSplitContainerPanel1Controls[1]);

                Control.ControlCollection verticalSplitContainerPanel2Controls = splitContainer.Panel2.Controls;
                Assert.AreEqual(1, verticalSplitContainerPanel2Controls.Count);
                Assert.IsInstanceOf <IllustrationPointsControl>(verticalSplitContainerPanel2Controls[0]);
            }
        }
예제 #2
0
        public void CalculationsView_EditingNameViaDataGridView_ObserversCorrectlyNotified()
        {
            // Setup
            var mocks = new MockRepository();
            var calculationObserver = mocks.StrictMock <IObserver>();

            calculationObserver.Expect(o => o.UpdateObserver());
            var assessmentSection = mocks.Stub <IAssessmentSection>();

            mocks.ReplayAll();

            TestCalculationsView calculationsView = ShowFullyConfiguredCalculationsView(assessmentSection);

            var data        = (CalculationGroup)calculationsView.Data;
            var calculation = (TestCalculation)data.Children.First();

            calculation.Attach(calculationObserver);

            var dataGridView = (DataGridView) new ControlTester("dataGridView").TheObject;

            // Call
            dataGridView.Rows[0].Cells[nameColumnIndex].Value = "New name";

            // Assert
            mocks.VerifyAll();
        }
예제 #3
0
        private TestCalculationsView ShowCalculationsView(CalculationGroup calculationGroup, TestCalculatableFailureMechanism failureMechanism, IAssessmentSection assessmentSection)
        {
            var calculationsView = new TestCalculationsView(calculationGroup, failureMechanism, assessmentSection);

            testForm.Controls.Add(calculationsView);
            testForm.Show();

            return(calculationsView);
        }
 public void Selection_WithoutCalculations_ReturnsNull()
 {
     // Call
     using (var view = new TestCalculationsView())
     {
         // Assert
         Assert.IsNull(view.Selection);
     }
 }
        private TestCalculationsView ShowTestCalculatableView()
        {
            var view = new TestCalculationsView();

            testForm.Controls.Add(view);
            testForm.Show();

            return(view);
        }
        public void Constructor_CalculateAllButtonCorrectlyInitialized()
        {
            // Setup & Call
            TestCalculationsView view = ShowTestCalculatableView();

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

            Assert.IsFalse(button.Enabled);
        }
        private TestCalculationsView ShowFullyConfiguredTestCalculatableView()
        {
            TestCalculationsView view = ShowTestCalculatableView();

            view.Data = new[]
            {
                new TestCalculatableObject
                {
                    GeneralResult = new GeneralResult <TopLevelSubMechanismIllustrationPoint>(
                        WindDirectionTestFactory.CreateTestWindDirection(),
                        Enumerable.Empty <Stochast>(),
                        new[]
                    {
                        new TopLevelSubMechanismIllustrationPoint(
                            WindDirectionTestFactory.CreateTestWindDirection(), "Regular",
                            new SubMechanismIllustrationPoint("Point 1", 0.9,
                                                              Enumerable.Empty <SubMechanismIllustrationPointStochast>(),
                                                              Enumerable.Empty <IllustrationPointResult>())),
                        new TopLevelSubMechanismIllustrationPoint(
                            WindDirectionTestFactory.CreateTestWindDirection(), "Open",
                            new SubMechanismIllustrationPoint("Point 2", 0.7,
                                                              Enumerable.Empty <SubMechanismIllustrationPointStochast>(),
                                                              Enumerable.Empty <IllustrationPointResult>()))
                    })
                },
                new TestCalculatableObject
                {
                    GeneralResult = new GeneralResult <TopLevelSubMechanismIllustrationPoint>(
                        WindDirectionTestFactory.CreateTestWindDirection(),
                        Enumerable.Empty <Stochast>(),
                        new[]
                    {
                        new TopLevelSubMechanismIllustrationPoint(
                            WindDirectionTestFactory.CreateTestWindDirection(), "Regular",
                            new SubMechanismIllustrationPoint("Point 1", 0.9,
                                                              Enumerable.Empty <SubMechanismIllustrationPointStochast>(),
                                                              Enumerable.Empty <IllustrationPointResult>())),
                        new TopLevelSubMechanismIllustrationPoint(
                            WindDirectionTestFactory.CreateTestWindDirection(), "Open",
                            new SubMechanismIllustrationPoint("Point 2", 0.7,
                                                              Enumerable.Empty <SubMechanismIllustrationPointStochast>(),
                                                              Enumerable.Empty <IllustrationPointResult>())),
                        new TopLevelSubMechanismIllustrationPoint(
                            WindDirectionTestFactory.CreateTestWindDirection(), "Closed",
                            new SubMechanismIllustrationPoint("Point 3", 0.8,
                                                              Enumerable.Empty <SubMechanismIllustrationPointStochast>(),
                                                              Enumerable.Empty <IllustrationPointResult>()))
                    })
                }
            };
            return(view);
        }
        public void GivenFullyConfiguredView_WhenNoRowsSelected_ThenCalculateForSelectedButtonDisabledAndErrorMessageProvided()
        {
            // Given & When
            TestCalculationsView view = ShowFullyConfiguredTestCalculatableView();

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

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

            Assert.AreEqual("Er zijn geen berekeningen geselecteerd.", errorProvider.GetError(button));
        }
예제 #9
0
        public void Constructor_ExpectedValues()
        {
            // Call
            TestCalculationsView view = ShowCalculationsView(new CalculationGroup(), new TestCalculatableFailureMechanism(), new AssessmentSectionStub());

            // Assert
            Assert.IsInstanceOf <UserControl>(view);
            Assert.IsInstanceOf <ISelectionProvider>(view);
            Assert.IsInstanceOf <IView>(view);

            var button = (Button) new ControlTester("generateButton").TheObject;

            Assert.AreEqual("Genereer &berekeningen...", button.Text);
        }
        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));
        }
예제 #11
0
        public void Selection_DataGridViewCellSelected_ReturnsTheSelectedRowObject(int selectedRow)
        {
            // Setup
            var mocks             = new MockRepository();
            var assessmentSection = mocks.Stub <IAssessmentSection>();

            mocks.ReplayAll();

            TestCalculationsView calculationsView = ShowFullyConfiguredCalculationsView(assessmentSection);

            // Call
            object selection = calculationsView.Selection;

            // Assert
            Assert.IsInstanceOf <TestCalculationRow>(selection);
            mocks.VerifyAll();
        }
        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);
        }
예제 #13
0
        public void GenerateButton_Always_HasCorrectState(bool state)
        {
            // Setup
            var view = new TestCalculationsView(new CalculationGroup(), new TestCalculatableFailureMechanism(), new AssessmentSectionStub())
            {
                CanGenerateCalculationState = state
            };

            testForm.Controls.Add(view);
            testForm.Show();

            var button = (Button) new ControlTester("generateButton").TheObject;

            // Call
            bool buttonState = button.Enabled;

            // Assert
            Assert.AreEqual(state, buttonState);
        }
        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);
        }
예제 #15
0
        public void GivenCalculationsView_WhenGenerateCalculationsButtonClicked_ThenGenerateCalculationsCalled()
        {
            // Given
            var view = new TestCalculationsView(new CalculationGroup(), new TestCalculatableFailureMechanism(), new AssessmentSectionStub())
            {
                CanGenerateCalculationState = true
            };

            testForm.Controls.Add(view);
            testForm.Show();

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

            // Precondition
            Assert.IsFalse(view.GenerateButtonClicked);

            // When
            button.Click();

            // Then
            Assert.IsTrue(view.GenerateButtonClicked);
        }
        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());
        }
예제 #17
0
        public void CalculationsView_ChangingSubscribedRow_ListenerCorrectlyNotified()
        {
            // Setup
            var mocks             = new MockRepository();
            var assessmentSection = mocks.Stub <IAssessmentSection>();

            mocks.ReplayAll();

            TestCalculationsView calculationsView = ShowFullyConfiguredCalculationsView(assessmentSection);

            var dataGridView = (DataGridView) new ControlTester("dataGridView").TheObject;
            DataGridViewCell dataGridViewCell = dataGridView.Rows[0].Cells[selectableHydraulicBoundaryLocationsColumnIndex];

            dataGridView.CurrentCell = dataGridViewCell;
            dataGridView.BeginEdit(false);

            // Call
            dataGridViewCell.Value = dataGridView.Rows[1].Cells[selectableHydraulicBoundaryLocationsColumnIndex].Value;

            // Assert
            Assert.AreEqual(1, calculationsView.HydraulicBoundaryLocationChangedCounter);
            mocks.VerifyAll();
        }
예제 #18
0
        public void CalculationsView_SelectingCellInRow_SelectionChangedFired()
        {
            // Setup
            var mocks             = new MockRepository();
            var assessmentSection = mocks.Stub <IAssessmentSection>();

            mocks.ReplayAll();

            TestCalculationsView calculationsView = ShowFullyConfiguredCalculationsView(assessmentSection);

            var selectionChangedCount = 0;

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

            var dataGridView = (DataGridView) new ControlTester("dataGridView").TheObject;

            // Call
            dataGridView.CurrentCell = dataGridView.Rows[1].Cells[0];

            // Assert
            Assert.AreEqual(1, selectionChangedCount);
            mocks.VerifyAll();
        }