Skip to content

Add unit tests for ParentControlDesigner #13173

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

Merged
Changes from 1 commit
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 @@ -23,7 +23,10 @@ public ParentControlDesignerTests()
public void Dispose()
{
_designer.Dispose();
_control.Dispose();
if (_control is not null && _control.Site is not null)
{
_control.Dispose();
}
}

[Fact]
Expand Down Expand Up @@ -67,36 +70,32 @@ public void GetGlyphs_SelectionTypeSelected_AddsContainerSelectorGlyph()
Mock<IServiceProvider> mockServiceProvider = new();
Mock<ISite> mockSite = new();
Mock<IDesignerHost> mockDesignerHost = new();
using Control control = new()
{
Site = mockSite.Object
};
Mock<IComponentChangeService> mockChangeService = new();
_control.Site = mockSite.Object;
mockSite.Setup(s => s.GetService(typeof(IDesignerHost))).Returns(mockDesignerHost.Object);
mockSite.Setup(s => s.GetService(typeof(IComponentChangeService))).Returns(mockChangeService.Object);

Mock<DesignerFrame> mockDesignerFrame = new(mockSite.Object) { CallBase = true };
BehaviorService behaviorService = new(mockServiceProvider.Object, mockDesignerFrame.Object);
mockServiceProvider.Setup(sp => sp.GetService(typeof(BehaviorService))).Returns(() => behaviorService);
mockSite.Setup(s => s.GetService(typeof(BehaviorService))).Returns(behaviorService);

ParentControlDesigner designer = new();
designer.Initialize(control);
designer.TestAccessor().Dynamic._behaviorService = behaviorService;
_designer.TestAccessor().Dynamic._behaviorService = behaviorService;
_designer.TestAccessor().Dynamic._host = mockDesignerHost.Object;
_designer.TestAccessor().Dynamic._changeService = mockChangeService.Object;

GlyphSelectionType selectionType = GlyphSelectionType.Selected;

GlyphCollection glyphs = designer.GetGlyphs(selectionType);
GlyphCollection glyphs = _designer.GetGlyphs(selectionType);

glyphs.Should().NotBeNull();
glyphs.Should().BeOfType<GlyphCollection>();
glyphs.OfType<ContainerSelectorGlyph>().Count().Should().Be(1);
}

[Fact]
public void InitializeNewComponent_WithNullDefaultValues_DoesNotThrow()
{
ParentControlDesigner designer = new();
using Control control = new();
designer.Initialize(control);

designer.Invoking(d => d.InitializeNewComponent(null)).Should().NotThrow();
_designer.Invoking(d => d.InitializeNewComponent(null)).Should().NotThrow();
}

[Fact]
Expand All @@ -108,19 +107,21 @@ public void InitializeNewComponent_ShouldReparentControls_WhenAllowControlLassoI
Mock<IServiceProvider> mockServiceProvider = new();
Mock<ISite> mockSite = new();
Mock<ISelectionService> mockSelectionService = new();
Mock<IComponentChangeService> mockChangeService = new();

using TestControl testComponent = new();
using TestControl parentComponent = new();
ParentControlDesigner parentControlDesigner = new();

mockSite.Setup(s => s.GetService(typeof(IDesignerHost))).Returns(mockDesignerHost.Object);
mockSite.Setup(s => s.GetService(typeof(ISelectionService))).Returns(mockSelectionService.Object);
mockSite.Setup(s => s.GetService(typeof(IComponentChangeService))).Returns(mockChangeService.Object);
testComponent.Site = mockSite.Object;
parentComponent.Site = mockSite.Object;

mockDesignerHost.Setup(h => h.GetDesigner(mockParentComponent.Object)).Returns(parentControlDesigner);
mockDesignerHost.Setup(h => h.GetDesigner(mockParentComponent.Object)).Returns(_designer);

parentControlDesigner.Initialize(testComponent);
_designer.Initialize(testComponent);
_designer.TestAccessor().Dynamic._changeService = mockChangeService.Object;

Dictionary<string, object> defaultValues = new()
{
Expand All @@ -132,7 +133,7 @@ public void InitializeNewComponent_ShouldReparentControls_WhenAllowControlLassoI
DisableDragDrop(testComponent);
DisableDragDrop(parentComponent);

parentControlDesigner.InitializeNewComponent(defaultValues);
_designer.InitializeNewComponent(defaultValues);

mockDesignerHost.Verify(h => h.GetDesigner(mockParentComponent.Object), Times.AtMost(2));
}
Expand Down