-
Notifications
You must be signed in to change notification settings - Fork 985
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test coverage for BaseContextMenuStrip (#11723)
* Add test coverage for BaseContextMenuStrip * change variable declaration
- Loading branch information
Showing
1 changed file
with
35 additions
and
0 deletions.
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
...ows.Forms.Design/tests/UnitTests/System/Windows/Forms/Design/BaseContextMenuStripTests.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,35 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System.Drawing; | ||
using Moq; | ||
|
||
namespace System.Windows.Forms.Design.Tests; | ||
|
||
public sealed class BaseContextMenuStripTests | ||
{ | ||
[Fact] | ||
public void RefreshItems_SetsFontFromIUIService() | ||
{ | ||
Mock<IServiceProvider> serviceProviderMock = new(); | ||
Mock<IUIService> uiServiceMock = new(); | ||
Font expectedFont = new Font("Arial", 12.0f); | ||
uiServiceMock.Setup(uis => uis.Styles["DialogFont"]).Returns(expectedFont); | ||
serviceProviderMock.Setup(sp => sp.GetService(typeof(IUIService))).Returns(uiServiceMock.Object); | ||
|
||
using BaseContextMenuStrip contextMenuStrip = new(serviceProviderMock.Object); | ||
contextMenuStrip.Font = new Font("Times New Roman", 10.0f, FontStyle.Italic); | ||
for (int i = 0; i < 3; i++) | ||
{ | ||
contextMenuStrip.Items.Add(new ToolStripMenuItem()); | ||
} | ||
|
||
contextMenuStrip.RefreshItems(); | ||
|
||
contextMenuStrip.Font.Should().Be(expectedFont); | ||
foreach (var item in contextMenuStrip.Items.OfType<ToolStripMenuItem>()) | ||
{ | ||
item.Font.Should().Be(expectedFont); | ||
} | ||
} | ||
} |