Skip to content

Add tests for PropertyGrid.OnComponentRemoved - #14561

Merged
LeafShi1 merged 3 commits into
dotnet:mainfrom
LeafShi1:Add_code_coverage_for_PropertyGrid
May 29, 2026
Merged

LeafShi1 merged 3 commits into
dotnet:mainfrom
LeafShi1:Add_code_coverage_for_PropertyGrid

Conversation

@LeafShi1

@LeafShi1 LeafShi1 commented May 26, 2026 •

Copy link
Copy Markdown
Member

Related #12055

Proposed changes

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

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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.

@ricardobossan ricardobossan left a comment

Copy link
Copy Markdown
Member

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!

@LeafShi1
LeafShi1 requested a review from ricardobossan May 28, 2026 06:17
@LeafShi1
LeafShi1 merged commit 5d30e4c into dotnet:main May 29, 2026
8 checks passed
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 11.0-preview6 milestone May 30, 2026
@github-actions github-actions Bot locked and limited conversation to collaborators Jun 30, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants