Пример #1
0
        public void Constructor_DataGridViewCorrectlyInitialized()
        {
            // Setup & Call
            using (var dialog = new TestFullyConfiguredSelectionDialogBase(testForm))
            {
                dialog.Show();

                // Assert
                CollectionAssert.IsEmpty(dialog.SelectedItems);

                var          dataGridViewControl = (DataGridViewControl) new ControlTester("DataGridViewControl", dialog).TheObject;
                DataGridView dataGridView        = dataGridViewControl.Controls.OfType <DataGridView>().First();
                Assert.AreEqual(2, dataGridView.ColumnCount);

                var          locationCalculateColumn             = (DataGridViewCheckBoxColumn)dataGridView.Columns[selectItemColumnIndex];
                const string expectedLocationCalculateHeaderText = "Gebruik";
                Assert.AreEqual(expectedLocationCalculateHeaderText, locationCalculateColumn.HeaderText);
                Assert.AreEqual("Selected", locationCalculateColumn.DataPropertyName);
                Assert.IsFalse(locationCalculateColumn.ReadOnly);

                var nameColumn = (DataGridViewTextBoxColumn)dataGridView.Columns[nameColumnIndex];
                Assert.IsEmpty(nameColumn.HeaderText);
                Assert.AreEqual("Name", nameColumn.DataPropertyName);
                Assert.AreEqual(DataGridViewAutoSizeColumnMode.Fill, nameColumn.AutoSizeMode);
                Assert.IsTrue(nameColumn.ReadOnly);

                var buttonTester = new ButtonTester("DoForSelectedButton", dialog);
                var button       = (Button)buttonTester.TheObject;
                Assert.IsFalse(button.Enabled);
            }
        }
Пример #2
0
        public void DeselectAllButton_AllItemsSelectedDeselectAllButtonClicked_AllItemsNotSelected()
        {
            // Setup
            var items = new[]
            {
                new object(),
                new object()
            };

            using (var dialog = new TestFullyConfiguredSelectionDialogBase(testForm))
            {
                dialog.SetDataSource(items);
                dialog.Show();

                var dataGridView = (DataGridViewControl) new ControlTester("DataGridViewControl", dialog).TheObject;
                DataGridViewRowCollection rows = dataGridView.Rows;
                var button = new ButtonTester("DeselectAllButton", dialog);

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

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

                // Call
                button.Click();

                // Assert
                Assert.IsFalse((bool)rows[0].Cells[selectItemColumnIndex].Value);
                Assert.IsFalse((bool)rows[1].Cells[selectItemColumnIndex].Value);
            }
        }
Пример #3
0
        public void GivenDialogWithSelectedItems_WhenDoForSelectedButtonClicked_ThenReturnsSelectedCollection()
        {
            // Given
            var selectedItem = new object();

            object[] items =
            {
                selectedItem,
                new object()
            };

            using (var dialog = new TestFullyConfiguredSelectionDialogBase(testForm))
            {
                dialog.SetDataSource(items);
                dialog.Show();

                var selectionView = (DataGridViewControl) new ControlTester("DataGridViewControl", dialog).TheObject;
                selectionView.Rows[0].Cells[0].Value = true;

                // When
                var generateButton = new ButtonTester("DoForSelectedButton", dialog);
                generateButton.Click();

                // Then
                IEnumerable <object> result = dialog.SelectedItems;

                CollectionAssert.AreEqual(new[]
                {
                    selectedItem
                }, result);
            }
        }
Пример #4
0
        public void GivenDialogWithSelectedItems_WhenCancelButtonClicked_ThenReturnsEmptyCollection()
        {
            // Given
            var selectedItem = new object();

            object[] items =
            {
                selectedItem,
                new object()
            };

            using (var dialog = new TestFullyConfiguredSelectionDialogBase(testForm))
            {
                dialog.SetDataSource(items);
                dialog.Show();

                var selectionView = (DataGridViewControl) new ControlTester("DataGridViewControl", dialog).TheObject;
                selectionView.Rows[0].Cells[0].Value = true;

                // When
                var cancelButton = new ButtonTester("CustomCancelButton", dialog);
                cancelButton.Click();

                // Then
                CollectionAssert.IsEmpty(dialog.SelectedItems);
            }
        }
Пример #5
0
        public void DoForSelectedButton_NoneSelected_DoForSelectedButtonDisabled()
        {
            // Setup
            var items = new[]
            {
                new object(),
                new object()
            };

            using (var dialog = new TestFullyConfiguredSelectionDialogBase(testForm))
            {
                dialog.SetDataSource(items);
                dialog.Show();

                var buttonTester = new ButtonTester("DoForSelectedButton", dialog);

                // Call
                var button = (Button)buttonTester.TheObject;

                // Assert
                Assert.IsFalse(button.Enabled);
                CollectionAssert.IsEmpty(dialog.SelectedItems);
            }
        }
Пример #6
0
        public void GivenDialogWithSelectedItems_WhenCloseWithoutConfirmation_ThenReturnsEmptyCollection()
        {
            // Given
            var items = new[]
            {
                new object(),
                new object()
            };

            using (var dialog = new TestFullyConfiguredSelectionDialogBase(testForm))
            {
                dialog.SetDataSource(items);
                dialog.Show();

                var selectionView = (DataGridViewControl) new ControlTester("DataGridViewControl", dialog).TheObject;
                selectionView.Rows[0].Cells[0].Value = true;

                // When
                dialog.Close();

                // Then
                CollectionAssert.IsEmpty(dialog.SelectedItems);
            }
        }