Repository navigation
Add test cases for PropertyGrid.ClearTabs - #14611
SimonZhao888 wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
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
Clearbehavior forDocumentvsComponentscopes (removal/no-op and preservation of other scopes).
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| [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); |
There was a problem hiding this comment.
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; | ||
|
|
There was a problem hiding this comment.
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.)
Related #12055
Proposed changes
Microsoft Reviewers: Open in CodeFlow