public void Selection_ValidRowSelected_SameAsTableControlSelection() { // Setup using (var form = new Form()) using (var control = new IllustrationPointsControl()) { form.Controls.Add(control); form.Show(); control.Data = GetIllustrationPointControlItems().ToArray(); IllustrationPointsTableControl tableControl = ControlTestHelper.GetControls <IllustrationPointsTableControl>(form, "IllustrationPointsTableControl").Single(); DataGridViewControl dataGridView = ControlTestHelper.GetDataGridViewControl(form, "illustrationPointsDataGridViewControl"); var initialControlSelection = control.Selection as IllustrationPointControlItem; // Precondition Assert.IsNotNull(initialControlSelection); // Call dataGridView.SetCurrentCell(dataGridView.Rows[1].Cells[0]); // Assert var expectedSelection = tableControl.Selection as IllustrationPointControlItem; var controlSelection = (IllustrationPointControlItem)control.Selection; Assert.IsNotNull(expectedSelection); Assert.AreSame(expectedSelection, controlSelection); Assert.AreNotSame(initialControlSelection, controlSelection); } }
public void Selection_WithIllustrationPoints_ReturnsIllustrationPointControlItem() { // Setup IllustrationPointsTableControl control = ShowControl(); control.Data = GetControlItems(); DataGridViewControl dataGridView = ControlTestHelper.GetDataGridViewControl(testForm, "illustrationPointsDataGridViewControl"); // Call var selection = control.Selection as IllustrationPointControlItem; // Assert Assert.NotNull(selection); var dataBoundItem = dataGridView.Rows[0].DataBoundItem as IllustrationPointRow; Assert.NotNull(dataBoundItem); Assert.AreSame(dataBoundItem.IllustrationPointControlItem, selection); }
public void GivenFullyConfiguredControl_WhenSelectingCellInSecondRow_ThenSelectionChangedFired() { // Given using (var form = new Form()) using (var control = new IllustrationPointsControl()) { form.Controls.Add(control); form.Show(); control.Data = GetIllustrationPointControlItems().ToArray(); var selectionChangedCount = 0; control.SelectionChanged += (sender, args) => selectionChangedCount++; DataGridViewControl dataGridView = ControlTestHelper.GetDataGridViewControl(form, "illustrationPointsDataGridViewControl"); // When dataGridView.SetCurrentCell(dataGridView.Rows[1].Cells[0]); // Then Assert.AreEqual(1, selectionChangedCount); } }
public void GivenControlWithIllustrationPoints_WhenSelectingSecondRow_ThenSelectionReturnsIllustrationPointControlItem() { // Given IllustrationPointsTableControl control = ShowControl(); control.Data = GetControlItems(); DataGridViewControl dataGridView = ControlTestHelper.GetDataGridViewControl(testForm, "illustrationPointsDataGridViewControl"); // When DataGridViewRow selectedRow = dataGridView.Rows[1]; dataGridView.SetCurrentCell(selectedRow.Cells[0]); // Then var selection = control.Selection as IllustrationPointControlItem; var dataBoundItem = selectedRow.DataBoundItem as IllustrationPointRow; Assert.NotNull(selection); Assert.NotNull(dataBoundItem); Assert.AreSame(dataBoundItem.IllustrationPointControlItem, selection); }
private DataGridViewControl GetCalculationsDataGridViewControl() { return(ControlTestHelper.GetDataGridViewControl(testForm, "DataGridViewControl")); }