Skip to content

Add tests for PropertyGrid.OnComponentRemoved#14561

Open
LeafShi1 wants to merge 3 commits into
dotnet:mainfrom
LeafShi1:Add_code_coverage_for_PropertyGrid
Open

Add tests for PropertyGrid.OnComponentRemoved#14561
LeafShi1 wants to merge 3 commits into
dotnet:mainfrom
LeafShi1:Add_code_coverage_for_PropertyGrid

Conversation

@LeafShi1
Copy link
Copy Markdown
Member

@LeafShi1 LeafShi1 commented May 26, 2026

Related #12055

Proposed changes

  • Add tests for `PropertyGrid.OnComponentRemoved
Microsoft Reviewers: Open in CodeFlow

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 OnComponentRemoved behavior 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 _selectedObjects field via TestAccessor.Dynamic. The behavior under test is observable via the public SelectedObjects property (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

  • TestComponent is already IDisposable via Component, so explicitly implementing IDisposable is redundant. Also, DocumentScopePropertyTab is registered with PropertyTabScope.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

  • TestComponent implements IDisposable (via Component) 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.

Comment thread src/test/unit/System.Windows.Forms/System/Windows/Forms/PropertyGridTests.cs Outdated
Copy link
Copy Markdown
Member

@ricardobossan ricardobossan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other than small comments, all LGTM!

Comment thread src/test/unit/System.Windows.Forms/System/Windows/Forms/PropertyGridTests.cs Outdated
@LeafShi1 LeafShi1 requested a review from ricardobossan May 28, 2026 06:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants