Skip to content

Commit

Permalink
add unit test for UserControlDocumentDesigner (#12710)
Browse files Browse the repository at this point in the history
Related #10773

Proposed changes
Add unit test UserControlDocumentDesignerTests.cs for public properties and method of the UserControlDocumentDesigner.UserControlDocumentDesigner.
Enable nullability in UserControlDocumentDesignerTests.cs.
  • Loading branch information
chaowendy authored Jan 10, 2025
1 parent 31ab37c commit 847499e
Showing 1 changed file with 79 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

#nullable enable

using System.ComponentModel.Design;
using System.ComponentModel.Design.Serialization;
using System.Drawing.Design;
using System.Windows.Forms.Design.Behavior;
using System.Windows.Forms.Design.Tests.Mocks;
using Moq;

namespace System.Windows.Forms.Design.Tests;

public class UserControlDocumentDesignerTests
{
[WinFormsFact]
public void Constructor_ShouldSetAutoResizeHandlesToTrue()
{
using UserControlDocumentDesigner designer = new();
using UserControl control = new();

Mock<IDesignerHost> designerHost = new();
Mock<IComponentChangeService> componentChangeService = new(MockBehavior.Strict);
designerHost
.Setup(s => s.GetService(typeof(IComponentChangeService)))
.Returns(componentChangeService.Object);
Mock<ISelectionService> selectionService = new(MockBehavior.Strict);
designerHost
.Setup(s => s.GetService(typeof(ISelectionService)))
.Returns(selectionService.Object);
designerHost
.Setup(s => s.GetService(typeof(IDesignerHost)))
.Returns(designerHost.Object);

var mockSite = MockSite.CreateMockSiteWithDesignerHost(designerHost.Object);
mockSite
.Setup(s => s.GetService(typeof(IExtenderProviderService)))
.Returns(null!);
mockSite
.Setup(s => s.GetService(typeof(IUIService)))
.Returns(null!);
mockSite
.Setup(s => s.GetService(typeof(IOverlayService)))
.Returns(null!);
mockSite
.Setup(s => s.GetService(typeof(IMenuCommandService)))
.Returns(null!);
mockSite
.Setup(s => s.GetService(typeof(INameCreationService)))
.Returns(null!);
mockSite
.Setup(s => s.GetService(typeof(IPropertyValueUIService)))
.Returns(null!);
Mock<IEventHandlerService> eventHandlerService = new(MockBehavior.Strict);
mockSite
.Setup(s => s.GetService(typeof(IEventHandlerService)))
.Returns(eventHandlerService.Object);
Mock<IDictionaryService> dictionaryService = new(MockBehavior.Strict);
dictionaryService
.Setup(s => s.GetValue(It.IsAny<object>()))
.Returns(null!);
dictionaryService
.Setup(s => s.SetValue(It.IsAny<object>(), It.IsAny<object>()));
mockSite
.Setup(s => s.GetService(typeof(IDictionaryService)))
.Returns(dictionaryService.Object);
mockSite
.Setup(s => s.GetService(typeof(ComponentCache)))
.Returns(null!);
mockSite
.Setup(s => s.GetService(typeof(BehaviorService)))
.Returns(null!);
control.Site = mockSite.Object;

designer.Initialize(control);
designer.AutoResizeHandles.Should().BeTrue();
}
}

0 comments on commit 847499e

Please sign in to comment.