Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4637,6 +4637,59 @@ public void PropertyGrid_OnComponentRemoved_NullSelectedObjects_DoesNotThrow()
Assert.Empty(propertyGrid.SelectedObjects);
}

[WinFormsTheory]
[InlineData(PropertyTabScope.Static)]
[InlineData(PropertyTabScope.Global)]
public void PropertyGrid_RefreshTabs_ScopeBelowDocument_ThrowsArgumentException(PropertyTabScope tabScope)
{
using PropertyGrid propertyGrid = new();

Assert.Throws<ArgumentException>(() => propertyGrid.RefreshTabs(tabScope));
}

[WinFormsFact]
public void PropertyGrid_RefreshTabs_ComponentScope_AddsCommonComponentTabs()
{
using PropertyGrid propertyGrid = new();
using TestComponent component = new();
propertyGrid.SelectedObjects = [component];

propertyGrid.RefreshTabs(PropertyTabScope.Component);

// TestComponent declares a Component-scoped DocumentScopePropertyTab.
bool found = false;
foreach (PropertyTab tab in propertyGrid.PropertyTabs)
{
if (tab is DocumentScopePropertyTab)
{
found = true;
break;
}
}

Assert.True(found);
}

[WinFormsFact]
public void PropertyGrid_RefreshTabs_DocumentScope_EnumeratesContainerComponents()
{
using PropertyGrid propertyGrid = CreatePropertyGridWithActiveDesigner(
out Mock<IDesignerHost> mockDesignerHost,
out _);

using TestComponent component = new();
ComponentCollection components = new(new IComponent[] { component });

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.

Collection initialization can be simplified

Mock<IContainer> mockContainer = new();
mockContainer.Setup(c => c.Components).Returns(components);
mockDesignerHost.Setup(h => h.Container).Returns(mockContainer.Object);

// Walks the container components; the collection type has no document-scoped
// PropertyTabAttribute, so only the default tab remains.
propertyGrid.RefreshTabs(PropertyTabScope.Document);

Assert.Single(propertyGrid.PropertyTabs);
}

[PropertyTab(typeof(DocumentScopePropertyTab), PropertyTabScope.Component)]
private class TestComponent : Component, IDisposable
{
Expand Down
Loading