-
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 tests for LinkUtilities (#12647)
related #10453 Proposed changes Add unit tests for LinkUtilities to test its GetIELinkBehavior and EnsureLinkFonts methods.
- Loading branch information
1 parent
52ad3f5
commit e1a1553
Showing
1 changed file
with
66 additions
and
0 deletions.
There are no files selected for viewing
66 changes: 66 additions & 0 deletions
66
src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/LinkUtilitiesTests.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,66 @@ | ||
// 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.Drawing; | ||
using Microsoft.Win32; | ||
|
||
namespace System.Windows.Forms.Tests; | ||
|
||
public class LinkUtilitiesTests | ||
{ | ||
[WinFormsFact] | ||
public void LinkUtilities_GetIELinkBehavior_ReturnsExpected() | ||
{ | ||
// Read the registry value | ||
RegistryKey? key = Registry.CurrentUser.OpenSubKey(LinkUtilities.IEMainRegPath); | ||
string? registryValue = key?.GetValue("Anchor Underline") as string; | ||
|
||
// Determine the expected behavior based on the registry value | ||
LinkBehavior expectedBehavior = registryValue switch | ||
{ | ||
"no" => LinkBehavior.NeverUnderline, | ||
"hover" => LinkBehavior.HoverUnderline, | ||
"always" => LinkBehavior.AlwaysUnderline, | ||
_ => LinkBehavior.AlwaysUnderline | ||
}; | ||
|
||
LinkUtilities.GetIELinkBehavior().Should().Be(expectedBehavior); | ||
} | ||
|
||
[WinFormsTheory] | ||
[InlineData(LinkBehavior.AlwaysUnderline)] | ||
[InlineData(LinkBehavior.HoverUnderline)] | ||
[InlineData(LinkBehavior.NeverUnderline)] | ||
[InlineData(LinkBehavior.SystemDefault)] | ||
public void LinkUtilities_EnsureLinkFonts_CreatesExpectedFonts(LinkBehavior behavior) | ||
{ | ||
using Font baseFont = new("Arial", 12); | ||
Font? linkFont = null; | ||
Font? hoverLinkFont = null; | ||
|
||
Action act = () => LinkUtilities.EnsureLinkFonts(baseFont, behavior, ref linkFont, ref hoverLinkFont); | ||
|
||
act.Should().NotThrow(); | ||
linkFont.Should().BeOfType<Font>(); | ||
hoverLinkFont.Should().BeOfType<Font>(); | ||
} | ||
|
||
[WinFormsTheory] | ||
[InlineData(LinkBehavior.AlwaysUnderline)] | ||
[InlineData(LinkBehavior.HoverUnderline)] | ||
[InlineData(LinkBehavior.NeverUnderline)] | ||
public void LinkUtilities_EnsureLinkFonts_CreatesExpectedFonts_WithActive(LinkBehavior behavior) | ||
{ | ||
using Font baseFont = new("Arial", 12); | ||
Font? linkFont = null; | ||
Font? hoverLinkFont = null; | ||
|
||
Action act = () => LinkUtilities.EnsureLinkFonts(baseFont, behavior, ref linkFont, ref hoverLinkFont, isActive: true); | ||
|
||
act.Should().NotThrow(); | ||
linkFont.Should().BeOfType<Font>(); | ||
hoverLinkFont.Should().BeOfType<Font>(); | ||
} | ||
} |