public void DataGridViewCellAccessibleObject_Select_HasSelectionFlagsWithoutValidDataGridView_DoesNothing() { var mockCell = new Mock <DataGridViewCell>(MockBehavior.Strict); mockCell .SetupSet(s => s.State = DataGridViewElementStates.Visible) .Verifiable(); mockCell .Protected() .Setup("Dispose", ItExpr.IsAny <bool>()); var mockObj = mockCell.Object; var accessibleObject = new DataGridViewCellAccessibleObject(mockObj); accessibleObject.Select(AccessibleSelection.None); // NB: asserts are implicit - check that nothing was called on the mock that we didn't anticipate using DataGridView dataGridView = new DataGridView(); mockCell .Protected() .Setup("OnDataGridViewChanged"); mockObj.DataGridView = dataGridView; accessibleObject.Select(AccessibleSelection.None); // NB: asserts are implicit - check that nothing was called on the mock that we didn't anticipate }
public void DataGridViewCellAccessibleObject_Select_HasFocusFlagsWithoutDataGridView_ThrowsInvalidOperationException(AccessibleSelection flags) { using var owner = new SubDataGridViewCell(); var accessibleObject = new DataGridViewCellAccessibleObject(owner); accessibleObject.Select(flags); }
public void DataGridViewCellAccessibleObject_Select_NothingToDo_Nop(AccessibleSelection flags) { using var owner = new SubDataGridViewCell(); var accessibleObject = new DataGridViewCellAccessibleObject(owner); accessibleObject.Select(flags); }
public void DataGridViewCellAccessibleObject_Select_HasSelectionFlagsWithoutDataGridView_ThrowsInvalidOperationException(AccessibleSelection flags) { var owner = new SubDataGridViewCell(); var accessibleObject = new DataGridViewCellAccessibleObject(owner); Assert.Throws <InvalidOperationException>(() => accessibleObject.Select(flags)); }
public void DataGridViewCellAccessibleObject_Select_AddSelection() { using var dataGridView = new DataGridView(); dataGridView.CreateControl(); Assert.True(dataGridView.IsHandleCreated); var mockCell = new Mock <DataGridViewCell>(MockBehavior.Strict); mockCell .SetupSet(s => s.State = DataGridViewElementStates.Visible) .Verifiable(); mockCell .SetupSet(s => s.Selected = true) .Verifiable(); mockCell .Protected() .Setup("Dispose", ItExpr.IsAny <bool>()); mockCell .Protected() .Setup("OnDataGridViewChanged"); mockCell.Object.DataGridView = dataGridView; var accessibleObject = new DataGridViewCellAccessibleObject(mockCell.Object); // verify that we check for a flag, not direct comparison. 128 is an arbitrary large flag. accessibleObject.Select((AccessibleSelection)128 | AccessibleSelection.AddSelection); // NB: asserts are implicit - check that nothing was called on the mock that we didn't anticipate }
public void DataGridViewCellAccessibleObject_Select_TakeSelection() { using var dataGridView = new DataGridView(); dataGridView.CreateControl(); Assert.True(dataGridView.IsHandleCreated); var mockCell = new Mock <DataGridViewCell>(MockBehavior.Strict); mockCell .SetupSet(s => s.State = DataGridViewElementStates.Visible) .Verifiable(); mockCell .SetupSet(s => s.Selected = true) .Verifiable(); mockCell .Protected() .Setup("Dispose", ItExpr.IsAny <bool>()); mockCell .Protected() .Setup("OnDataGridViewChanged"); var mockObj = mockCell.Object; mockObj.DataGridView = dataGridView; var accessibleObject = new DataGridViewCellAccessibleObject(mockObj); // verify that we check for a flag, not direct comparison. 128 is an arbitrary large flag. accessibleObject.Select((AccessibleSelection)128 | AccessibleSelection.TakeSelection); // NB: some asserts are implicit - check that nothing was called on the mock that we didn't anticipate // Can't test whether CurrentCell was set unless we add the whole layer of Rows, Columns, etc. // Assert.Equal(mockObj, dataGridView.CurrentCell); }
public void DataGridViewCellAccessibleObject_Select_RemoveSelection() { using var dataGridView = new DataGridView(); dataGridView.CreateControl(); Assert.True(dataGridView.IsHandleCreated); var mockCell = new Mock <DataGridViewCell>(MockBehavior.Strict); mockCell .SetupSet(s => s.State = DataGridViewElementStates.Visible) .Verifiable(); mockCell .SetupSet(s => s.Selected = It.IsAny <bool>()) .Verifiable(); mockCell .Protected() .Setup("Dispose", ItExpr.IsAny <bool>()); mockCell .Protected() .Setup("OnDataGridViewChanged"); mockCell.Object.DataGridView = dataGridView; var accessibleObject = new DataGridViewCellAccessibleObject(mockCell.Object); // set selection, RemoveSelection is ignored accessibleObject.Select(AccessibleSelection.AddSelection | AccessibleSelection.RemoveSelection); // set selection, RemoveSelection is ignored accessibleObject.Select(AccessibleSelection.TakeSelection | AccessibleSelection.RemoveSelection); // now remove the selection accessibleObject.Select(AccessibleSelection.RemoveSelection); // NB: asserts are implicit - check that nothing was called on the mock that we didn't anticipate mockCell.VerifySet(s => s.Selected = true, Times.Exactly(2)); mockCell.VerifySet(s => s.Selected = false, Times.Once()); }