-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Add test cases for PropertyGrid.AddTab #14574
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
+100
−0
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2387,6 +2387,106 @@ public void PropertyGrid_PropertyTabCollection_AddAndRemoveTabType_Success() | |
| Assert.Single(grid.PropertyTabs); | ||
| } | ||
|
|
||
| [WinFormsFact] | ||
| public void PropertyGrid_AddTab_NewTabType_AddsTabToCollection() | ||
| { | ||
| using PropertyGrid control = new(); | ||
| int initialCount = control.PropertyTabs.Count; | ||
|
|
||
| control.AddTab(typeof(TestPropertyTab), PropertyTabScope.Static); | ||
|
|
||
| // AddTab does not unconditionally append; it picks an insertion index | ||
| // based on tab kind and alphabetical order. Insertion order is verified | ||
| // separately by PropertyGrid_AddTab_OrdersCustomTabsAlphabetically. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This 'PropertyGrid_AddTab_OrdersCustomTabsAlphabetically' no longer exists, so it should not be referenced in this comment. |
||
| Assert.Equal(initialCount + 1, control.PropertyTabs.Count); | ||
| Assert.Contains(control.PropertyTabs.Cast<PropertyTab>(), t => t is TestPropertyTab); | ||
| } | ||
|
|
||
| [WinFormsFact] | ||
| public void PropertyGrid_AddTab_ExistingTabType_DoesNotAddDuplicate() | ||
| { | ||
| using PropertyGrid control = new(); | ||
| control.AddTab(typeof(TestPropertyTab), PropertyTabScope.Static); | ||
| int countAfterFirst = control.PropertyTabs.Count; | ||
|
|
||
| // Adding the same tab type a second time should be a no-op for tab insertion. | ||
| control.AddTab(typeof(TestPropertyTab), PropertyTabScope.Static); | ||
|
|
||
|
SimonZhao888 marked this conversation as resolved.
|
||
| Assert.Equal(countAfterFirst, control.PropertyTabs.Count); | ||
| Assert.Single(control.PropertyTabs.Cast<PropertyTab>(), t => t is TestPropertyTab); | ||
| } | ||
|
|
||
| [WinFormsFact] | ||
| public void PropertyGrid_AddTab_ExistingTabType_RetainsOriginalScopeAndComponents() | ||
| { | ||
| using PropertyGrid control = new(); | ||
| using Button originalComponent = new(); | ||
|
|
||
| // First call: attach a component with PropertyTabScope.Component. | ||
| control.AddTab(typeof(TestPropertyTab), PropertyTabScope.Component, originalComponent, setupToolbar: false); | ||
| int countAfterFirst = control.PropertyTabs.Count; | ||
|
|
||
| // Second call uses a different scope and no component. This must not | ||
| // replace the existing tab or wipe out the previously-attached component, | ||
| // and the originally recorded scope must be preserved. | ||
| control.AddTab(typeof(TestPropertyTab), PropertyTabScope.Static, @object: null, setupToolbar: false); | ||
|
|
||
| Assert.Equal(countAfterFirst, control.PropertyTabs.Count); | ||
|
|
||
| PropertyTab tab = control.PropertyTabs.Cast<PropertyTab>().Single(t => t is TestPropertyTab); | ||
| Assert.NotNull(tab.Components); | ||
| Assert.Single(tab.Components); | ||
| Assert.Same(originalComponent, tab.Components[0]); | ||
|
|
||
| // Verify the original scope is preserved (TabInfo.Scope is read via | ||
| // reflection because TabInfo is a private nested record). | ||
| Collections.IList tabs = control.TestAccessor.Dynamic._tabs; | ||
| object matchingTabInfo = null; | ||
| foreach (object tabInfo in tabs) | ||
| { | ||
| PropertyTab candidate = (PropertyTab)tabInfo.GetType().GetProperty("Tab").GetValue(tabInfo); | ||
| if (candidate is TestPropertyTab) | ||
| { | ||
| matchingTabInfo = tabInfo; | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| Assert.NotNull(matchingTabInfo); | ||
| PropertyTabScope actualScope = (PropertyTabScope)matchingTabInfo.GetType().GetProperty("Scope").GetValue(matchingTabInfo); | ||
| Assert.Equal(PropertyTabScope.Component, actualScope); | ||
| } | ||
|
|
||
| [WinFormsFact] | ||
| public void PropertyGrid_AddTab_WithComponent_AddsComponentToTab() | ||
| { | ||
| using PropertyGrid control = new(); | ||
| using Button component = new(); | ||
|
|
||
| control.AddTab(typeof(TestPropertyTab), PropertyTabScope.Component, component, setupToolbar: false); | ||
|
|
||
| PropertyTab tab = control.PropertyTabs.Cast<PropertyTab>().Single(t => t is TestPropertyTab); | ||
| Assert.NotNull(tab.Components); | ||
| Assert.Single(tab.Components); | ||
| Assert.Same(component, tab.Components[0]); | ||
| } | ||
|
|
||
| [WinFormsFact] | ||
| public void PropertyGrid_AddTab_SameTypeMultipleComponents_AccumulatesComponents() | ||
| { | ||
| using PropertyGrid control = new(); | ||
| using Button first = new(); | ||
| using Button second = new(); | ||
|
|
||
| control.AddTab(typeof(TestPropertyTab), PropertyTabScope.Component, first, setupToolbar: false); | ||
| control.AddTab(typeof(TestPropertyTab), PropertyTabScope.Component, second, setupToolbar: false); | ||
|
|
||
| PropertyTab tab = control.PropertyTabs.Cast<PropertyTab>().Single(t => t is TestPropertyTab); | ||
| Assert.Equal(2, tab.Components.Length); | ||
| Assert.Same(first, tab.Components[0]); | ||
| Assert.Same(second, tab.Components[1]); | ||
| } | ||
|
|
||
| private class TestPropertyTab : PropertyTab | ||
| { | ||
| public override string TabName => "TestTabName"; | ||
|
|
||
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.
Uh oh!
There was an error while loading. Please reload this page.