Skip to content

Commit

Permalink
Add test coverage for BaseContextMenuStrip (#11723)
Browse files Browse the repository at this point in the history
* Add test coverage for BaseContextMenuStrip

* change variable declaration
  • Loading branch information
Liv-Goh authored Jul 26, 2024
1 parent 8f7d041 commit 00af9d7
Showing 1 changed file with 35 additions and 0 deletions.
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);
}
}
}

0 comments on commit 00af9d7

Please sign in to comment.