Skip to content

Add test cases for PropertyGrid.ClearTabs - #14611

Closed
SimonZhao888 wants to merge 1 commit into
dotnet:mainfrom
SimonZhao888:Issue_12055_ClearTabs
Closed

SimonZhao888 wants to merge 1 commit into
dotnet:mainfrom
SimonZhao888:Issue_12055_ClearTabs

Conversation

@SimonZhao888

@SimonZhao888 SimonZhao888 commented Jun 4, 2026 •

Copy link
Copy Markdown
Member

Related #12055

Proposed changes

  • Add tests for PropertyGrid.ClearTabs
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.ClearTabs / PropertyGrid.PropertyTabCollection.Clear(PropertyTabScope) to improve coverage for the scenarios called out in #12055.

Changes:

  • Added tests validating Clear(PropertyTabScope) throws for invalid scopes (Static, Global).
  • Added tests verifying Clear behavior for Document vs Component scopes (removal/no-op and preservation of other scopes).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +2464 to +2478
[WinFormsFact]
public void PropertyGrid_ClearTabs_DirectInternalCall_RemovesDocumentScopedTabs()
{
// Exercises the internal ClearTabs(PropertyTabScope) method directly via TestAccessor
// to provide explicit coverage of the targeted internal entry point.
using PropertyGrid grid = new();
int initialTabCount = grid.PropertyTabs.Count;

grid.PropertyTabs.AddTabType(typeof(TestPropertyTab), PropertyTabScope.Document);
Assert.Equal(initialTabCount + 1, grid.PropertyTabs.Count);

grid.TestAccessor.Dynamic.ClearTabs(PropertyTabScope.Document);

Assert.Equal(initialTabCount, grid.PropertyTabs.Count);
}
using PropertyGrid grid = new();
int initialTabCount = grid.PropertyTabs.Count;

grid.PropertyTabs.AddTabType(typeof(TestPropertyTab), PropertyTabScope.Document);

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.

This test is functionally a duplicate of PropertyGrid_ClearTabs_DocumentScope_RemovesDocumentScopedTabs above. PropertyTabCollection.Clear(PropertyTabScope) is a single-line delegation to _ownerPropertyGrid.ClearTabs(tabScope) with no additional logic (except a null-owner guard that doesn't apply when the collection comes from a live PropertyGrid). Both tests therefore exercise the exact same code path and assert the exact same outcome.

Additionally, the basic positive-case scenario (clear removes tabs of the given scope) is already covered by Clear_RemovesTabsOfGivenScope in PropertyGrid.PropertyTabCollectionTests.cs (using Component scope).

Consider removing this test, or if the intent is to guard against future divergence between the public and internal entry points, add a comment explaining that rationale.

{
using PropertyGrid grid = new();
int initialTabCount = grid.PropertyTabs.Count;

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.

Nice test — it correctly verifies that Component scope (3) doesn't remove Document-scoped (2) tabs because RemoveTabs only removes tabs with scope >= the classification.

However, there's no complementary test that adds a Component-scoped tab and then clears with Document scope to verify it IS removed (since Component(3) >= Document(2)). That positive case would strengthen the coverage of the >= semantics in the other direction. (The existing Clear_RemovesTabsOfGivenScope in PropertyTabCollectionTests.cs tests Component-clears-Component but not Document-clears-Component.)

@github-actions github-actions Bot locked and limited conversation to collaborators Jul 11, 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