-
Notifications
You must be signed in to change notification settings - Fork 998
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add unit test for UserControlDocumentDesigner (#12710)
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
Showing
1 changed file
with
79 additions
and
0 deletions.
There are no files selected for viewing
79 changes: 79 additions & 0 deletions
79
...ms.Design/tests/UnitTests/System/Windows/Forms/Design/UserControlDocumentDesignerTests.cs
This file contains 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 |
---|---|---|
@@ -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(); | ||
} | ||
} |