Skip to content

Commit

Permalink
Add test coverage for PropertyGrid (#11587)
Browse files Browse the repository at this point in the history
* Add test coverage for PropertyGrid

* Handle feedback!

* Updated
  • Loading branch information
MelonWang1 authored Jul 2, 2024
1 parent cc501de commit 48da9be
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,22 @@ public void PropertyGridToolStripAccessibleObject_Role_IsToolBar_ByDefault()
Assert.False(propertyGrid.IsHandleCreated);
Assert.False(propertyGridToolStrip.IsHandleCreated);
}

[WinFormsTheory]
[InlineData("Test Name", null, "Test Name")]
[InlineData(null, "Parent Name", "Parent Name")]
public void PropertyGridToolStripAccessibleObject_Name_ReturnsExpected(string toolStripAccessibleName, string parentAccessibleName, string expectedName)
{
using PropertyGrid propertyGrid = new();
propertyGrid.AccessibleName = parentAccessibleName;
using PropertyGridToolStrip propertyGridToolStrip = new(propertyGrid);
propertyGridToolStrip.AccessibleName = toolStripAccessibleName;
PropertyGridToolStrip.PropertyGridToolStripAccessibleObject accessibleObject = new(propertyGridToolStrip, propertyGrid);

string name = accessibleObject.Name;

name.Should().Be(expectedName);
propertyGrid.IsHandleCreated.Should().BeFalse();
propertyGridToolStrip.IsHandleCreated.Should().BeFalse();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4068,6 +4068,60 @@ public class TestObject
public string Property1 { get; set; }
}

[WinFormsFact]
public void PropertyGrid_PropertyTabChangedEventTriggered()
{
using PropertyGrid propertyGrid = new();
int eventCallCount = 0;
PropertyTabChangedEventArgs eventArgs = null;

propertyGrid.PropertyTabChanged += (sender, e) =>
{
eventCallCount++;
eventArgs = e;
};

TestPropertyTab tab1 = new();
TestPropertyTab tab2 = new();

var oldTab = tab2;
var newTab = tab1;
var accessor = propertyGrid.TestAccessor();
accessor.Dynamic.OnPropertyTabChanged(new PropertyTabChangedEventArgs(oldTab, newTab));

eventCallCount.Should().Be(1);
eventArgs.Should().NotBeNull();
eventArgs.OldTab.Should().Be(oldTab);
eventArgs.NewTab.Should().Be(newTab);
}

[WinFormsFact]
public void PropertyGrid_SelectedGridItemChanged_TriggeredCorrectly()
{
using PropertyGrid propertyGrid = new();
int eventCallCount = 0;
SelectedGridItemChangedEventArgs eventArgs = null;
object actualSender = null;

propertyGrid.SelectedGridItemChanged += (sender, e) =>
{
eventCallCount++;
eventArgs = e;
actualSender = sender;
};

Mock<GridItem> gridItemMock = new();
var gridItem = gridItemMock.Object;

var accessor = propertyGrid.TestAccessor();
accessor.Dynamic.OnSelectedGridItemChanged(new SelectedGridItemChangedEventArgs(null, gridItem));

eventCallCount.Should().Be(1);
eventArgs.Should().NotBeNull();
actualSender.Should().Be(propertyGrid);
eventArgs.NewSelection.Should().Be(gridItem);
}

private class SubToolStripRenderer : ToolStripRenderer
{
}
Expand Down

0 comments on commit 48da9be

Please sign in to comment.