-
Notifications
You must be signed in to change notification settings - Fork 986
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test for SplitterPanelDesigner.cs (#12269)
* Add test for SplitterPanelDesigner.cs * Add License comment at the strat of file * add using for IDisposable variables * Remove extra space
- Loading branch information
Showing
1 changed file
with
63 additions
and
0 deletions.
There are no files selected for viewing
63 changes: 63 additions & 0 deletions
63
...ws.Forms.Design/tests/UnitTests/System/Windows/Forms/Design/SplitterPanelDesignerTests.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,63 @@ | ||
// 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 Moq; | ||
using System.Collections; | ||
using System.ComponentModel; | ||
using System.ComponentModel.Design; | ||
|
||
namespace System.Windows.Forms.Design.Tests; | ||
public sealed class SplitterPanelDesignerTests | ||
{ | ||
[Fact] | ||
public void Initialize_CanBeParentedTo_ReturnsExpectedResults() | ||
{ | ||
using ToolStripContainerDesigner toolStripContainerDesigner = new(); | ||
using SplitContainerDesigner splitContainerDesigner = new(); | ||
using SplitContainer splitContainer = new(); | ||
using SplitterPanel splitterPanel = new(splitContainer); | ||
using SplitterPanelDesigner splitterPanelDesigner = new(); | ||
|
||
Mock<IDesignerHost> mockDesignerHost = new(); | ||
mockDesignerHost.Setup(dh => dh.GetDesigner(splitterPanel.Parent!)).Returns(splitContainerDesigner); | ||
|
||
Mock<ISite> mockSite = new(); | ||
mockSite.Setup(s => s.GetService(typeof(IDesignerHost))).Returns(mockDesignerHost.Object); | ||
|
||
Mock<IComponentChangeService> mockChangeService = new(); | ||
mockSite.Setup(s => s.GetService(typeof(IComponentChangeService))).Returns(mockChangeService.Object); | ||
mockDesignerHost.Setup(dh => dh.GetService(typeof(IComponentChangeService))).Returns(mockChangeService.Object); | ||
|
||
using ToolStripContainer toolStripContainer = new(); | ||
toolStripContainer.Site = mockSite.Object; | ||
toolStripContainerDesigner.Initialize(toolStripContainer); | ||
|
||
splitContainer.Site = mockSite.Object; | ||
splitContainerDesigner.Initialize(splitContainer); | ||
|
||
splitterPanel.Site = mockSite.Object; | ||
|
||
mockChangeService.VerifyAdd(cs => cs.ComponentChanged += It.IsAny<ComponentChangedEventHandler>(), Times.Never()); | ||
|
||
splitterPanelDesigner.Initialize(splitterPanel); | ||
|
||
mockChangeService.VerifyAdd(cs => cs.ComponentChanged += It.IsAny<ComponentChangedEventHandler>(), Times.Once()); | ||
|
||
splitterPanelDesigner.CanBeParentedTo(splitContainerDesigner).Should().Be(true); | ||
splitterPanelDesigner.CanBeParentedTo(toolStripContainerDesigner).Should().Be(false); | ||
|
||
((SplitterPanel)splitterPanelDesigner.TestAccessor().Dynamic._splitterPanel).Should().Be(splitterPanel); | ||
((IDesignerHost)splitterPanelDesigner.TestAccessor().Dynamic._designerHost).Should().Be(mockDesignerHost.Object); | ||
((SplitContainerDesigner)splitterPanelDesigner.TestAccessor().Dynamic._splitContainerDesigner).Should().Be(splitContainerDesigner); | ||
|
||
IList snapLines = splitterPanelDesigner.SnapLines; | ||
snapLines.Should().NotBeNull(); | ||
snapLines.Should().BeOfType<ArrayList>(); | ||
snapLines.Count.Should().BeGreaterThan(0); | ||
|
||
SelectionRules selectionRules = splitterPanelDesigner.SelectionRules; | ||
selectionRules.Should().Be(SelectionRules.None); | ||
} | ||
} |