Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test coverage for PropertyGrid #11587

Merged
merged 3 commits into from
Jul 2, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 var propertyGridToolStrip = new PropertyGridToolStrip(propertyGrid);
MelonWang1 marked this conversation as resolved.
Show resolved Hide resolved
propertyGridToolStrip.AccessibleName = toolStripAccessibleName;
var accessibleObject = new PropertyGridToolStrip.PropertyGridToolStripAccessibleObject(propertyGridToolStrip, propertyGrid);

MelonWang1 marked this conversation as resolved.
Show resolved Hide resolved
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,62 @@ 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;
};

var tab1 = new TestPropertyTab();
var tab2 = new TestPropertyTab();
MelonWang1 marked this conversation as resolved.
Show resolved Hide resolved
propertyGrid.PropertyTabs.AddTabType(tab2.GetType());
propertyGrid.PropertyTabs.AddTabType(tab1.GetType());
MelonWang1 marked this conversation as resolved.
Show resolved Hide resolved

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;
};

var gridItemMock = new Mock<GridItem>();
MelonWang1 marked this conversation as resolved.
Show resolved Hide resolved
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);
MelonWang1 marked this conversation as resolved.
Show resolved Hide resolved
}

private class SubToolStripRenderer : ToolStripRenderer
{
}
Expand Down