Add tests for PropertyGrid.OnComponentRemoved#14561
Open
LeafShi1 wants to merge 3 commits into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Adds unit test coverage for PropertyGrid’s OnComponentRemoved design-time event handler, improving coverage for removal scenarios related to issue #12055.
Changes:
- Adds new unit tests exercising
OnComponentRemovedbehavior for null components, single/multi-selection updates, batch mode behavior, and no-op removal. - Introduces test-only helper component and property tab types to ensure the handler’s code path executes.
Comments suppressed due to low confidence (3)
src/test/unit/System.Windows.Forms/System/Windows/Forms/PropertyGridTests.cs:4593
- This test reaches into the private
_selectedObjectsfield viaTestAccessor.Dynamic. The behavior under test is observable via the publicSelectedObjectsproperty (which clones the internal array), and using it makes the test less brittle to internal refactors.
// In batch mode, the component should be removed from internal list
dynamic testAccessor = propertyGrid.TestAccessor.Dynamic;
object[] selectedObjects = testAccessor._selectedObjects;
Assert.Single(selectedObjects);
src/test/unit/System.Windows.Forms/System/Windows/Forms/PropertyGridTests.cs:4648
TestComponentis alreadyIDisposableviaComponent, so explicitly implementingIDisposableis redundant. Also,DocumentScopePropertyTabis registered withPropertyTabScope.Component, which makes the name/TabName misleading; rename it to match the actual scope to avoid confusion in future test maintenance.
[PropertyTab(typeof(DocumentScopePropertyTab), PropertyTabScope.Component)]
private class TestComponent : Component, IDisposable
{
public string TestProperty { get; set; } = "Test";
}
private class DocumentScopePropertyTab : PropertyTab
{
private Bitmap _bitmap;
public override string TabName => "Document Tab";
public override Bitmap Bitmap => _bitmap ??= new(1, 1);
src/test/unit/System.Windows.Forms/System/Windows/Forms/PropertyGridTests.cs:4630
TestComponentimplementsIDisposable(viaComponent) and should be disposed in this test as well to be consistent with the other test cases in this region.
TestComponent component = new();
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…nWithoutRaisingSelectedObjectsChanged
Member
ricardobossan
left a comment
There was a problem hiding this comment.
Other than small comments, all LGTM!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Related #12055
Proposed changes
Microsoft Reviewers: Open in CodeFlow