Skip to content

Commit

Permalink
feat(test): added tests for wol class
Browse files Browse the repository at this point in the history
  • Loading branch information
sikelio committed Aug 2, 2024
1 parent 93bd911 commit bdd5749
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 1 deletion.
57 changes: 57 additions & 0 deletions System.Test/WakeOnLanTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
using FrApp42.System.Net;

namespace System.Test
{
[TestClass]
public class WakeOnLanTest
{
private readonly string _macAddressColon = "FF:FF:FF:FF:FF:FF";
private readonly string _macAddressDash = "FF-FF-FF-FF-FF-FF";
private readonly string _expectedFormattedMacAddress = "FFFFFFFFFFFF";

[TestMethod]
public void BuildMagicPacketWithColon()
{
BuildMagicPacketTest(_macAddressColon);
}

[TestMethod]
public void BuildMagicPacketWithDash()
{
BuildMagicPacketTest(_macAddressDash);
}

[TestMethod]
public void MacFormatterWithColon()
{
string actualFormattedMac = WakeOnLan.MacFormatter().Replace(_macAddressColon, "");

Assert.AreEqual(_expectedFormattedMacAddress, actualFormattedMac, "The MAC address was not formatted correctly.");
}

[TestMethod]
public void MacFormatterWithDash()
{
string actualFormattedMac = WakeOnLan.MacFormatter().Replace(_macAddressDash, "");

Assert.AreEqual(_expectedFormattedMacAddress, actualFormattedMac, "The MAC address was not formatted correctly.");
}

private void BuildMagicPacketTest(string macAddress)
{
byte[] expectedMagicPacket = new byte[102];

for (int i = 0; i < 6; i++)
expectedMagicPacket[i] = 0xFF;

byte[] macBytes = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };

for (int i = 0; i < 16; i++)
Array.Copy(macBytes, 0, expectedMagicPacket, 6 + i * 6, 6);

byte[] actualMagicPacket = WakeOnLan.BuildMagicPacket(macAddress);

CollectionAssert.AreEqual(expectedMagicPacket, actualMagicPacket, "The magic packet is not built correctly.");
}
}
}
2 changes: 1 addition & 1 deletion System/Net/WakeOnLan.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,6 @@ public static async Task SendWakeOnLan(IPAddress localIpAddress, IPAddress multi
/// </summary>
/// <returns>A Regex object for formatting MAC addresses.</returns>
[GeneratedRegex("[: -]")]
private static partial Regex MacFormatter();
public static partial Regex MacFormatter();
}
}

0 comments on commit bdd5749

Please sign in to comment.