-
Notifications
You must be signed in to change notification settings - Fork 998
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 unit test case for DataGridView 7 events #11618
Add unit test case for DataGridView 7 events #11618
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #11618 +/- ##
===================================================
+ Coverage 74.55540% 74.56167% +0.00627%
===================================================
Files 3040 3040
Lines 629493 629605 +112
Branches 46835 46839 +4
===================================================
+ Hits 469321 469444 +123
+ Misses 156818 156800 -18
- Partials 3354 3361 +7
Flags with carried forward coverage won't be shown. Click here to find out more. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe you can simplify your code by something like this:
[WinFormsFact]
public void DataGridView_PaddingChangedEvent_Raised_Success()
{
TestEvent(nameof(DataGridView.PaddingChanged), nameof(DataGridView.Padding), new Padding(10), new Padding(20));
}
[WinFormsFact]
public void DataGridView_TextChangedEvent_Raised_Success()
{
TestEvent(nameof(DataGridView.TextChanged), nameof(DataGridView.Text), "New Text", "Another Text");
}
private void TestEvent(string eventName, string propertyName, object propertyValue, object newPropertyValue)
{
Type type = typeof(DataGridView);
int callCount = 0;
EventHandler handler = (sender, e) =>
{
sender.Should().Be(_dataGridView);
e.Should().Be(EventArgs.Empty);
callCount++;
};
Reflection.EventInfo eventInfo = type.GetEvent(eventName);
eventInfo.AddEventHandler(_dataGridView, handler);
Reflection.PropertyInfo propertyInfo = type.GetProperty(propertyName);
propertyInfo.SetValue(_dataGridView, propertyValue, null);
callCount.Should().Be(1);
eventInfo.RemoveEventHandler(_dataGridView, handler);
propertyInfo.SetValue(_dataGridView, newPropertyValue, null);
callCount.Should().Be(1);
}
Using InlineData can make the code more concise, like this winforms/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/SplitterTests.cs Line 1063 in 10f120d
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
related #10453
Proposed changes
Microsoft Reviewers: Open in CodeFlow