Capitalize IP acronym

This commit is contained in:
Oliver Booth 2022-04-25 10:21:55 +01:00
parent 99bdbccf85
commit 1f9bbe9319
No known key found for this signature in database
GPG Key ID: 32A00B35503AF634
3 changed files with 46 additions and 36 deletions

View File

@ -0,0 +1,43 @@
using System.Net;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using X10D.Net;
namespace X10D.Tests.Net;
[TestClass]
public class IPAddressTests
{
private IPAddress _ipv4Address = null!;
private IPAddress _ipv6Address = null!;
[TestInitialize]
public void Initialize()
{
_ipv4Address = IPAddress.Parse("127.0.0.1");
_ipv6Address = IPAddress.Parse("::1");
}
[TestMethod]
public void IsIPv4_ShouldBeTrue_GivenIPv4()
{
Assert.IsTrue(_ipv4Address.IsIPv4());
}
[TestMethod]
public void IsIPv4_ShouldBeFalse_GivenIPv6()
{
Assert.IsFalse(_ipv6Address.IsIPv4());
}
[TestMethod]
public void IsIPv6_ShouldBeFalse_GivenIPv4()
{
Assert.IsFalse(_ipv4Address.IsIPv6());
}
[TestMethod]
public void IsIPv6_ShouldBeTrue_GivenIPv6()
{
Assert.IsTrue(_ipv6Address.IsIPv6());
}
}

View File

@ -1,33 +0,0 @@
using System.Net;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using X10D.Net;
namespace X10D.Tests.Net;
[TestClass]
public class IpAddressTests
{
private IPAddress _ipv4Address = null!;
private IPAddress _ipv6Address = null!;
[TestInitialize]
public void Initialize()
{
_ipv4Address = IPAddress.Parse("127.0.0.1");
_ipv6Address = IPAddress.Parse("::1");
}
[TestMethod]
public void IsIPv4()
{
Assert.IsTrue(_ipv4Address.IsIpV4());
Assert.IsFalse(_ipv6Address.IsIpV4());
}
[TestMethod]
public void IsIPv6()
{
Assert.IsTrue(_ipv6Address.IsIpV6());
Assert.IsFalse(_ipv4Address.IsIpV6());
}
}

View File

@ -6,7 +6,7 @@ namespace X10D.Net;
/// <summary> /// <summary>
/// Extension methods for <see cref="IPAddress" />. /// Extension methods for <see cref="IPAddress" />.
/// </summary> /// </summary>
public static class IpAddressExtensions public static class IPAddressExtensions
{ {
/// <summary> /// <summary>
/// Returns a value indicating whether the specified IP address is a valid IPv4 address. /// Returns a value indicating whether the specified IP address is a valid IPv4 address.
@ -15,7 +15,7 @@ public static class IpAddressExtensions
/// <returns> /// <returns>
/// <see langword="true" /> if the specified IP address is a valid IPv4 address; otherwise, <see langword="false" />. /// <see langword="true" /> if the specified IP address is a valid IPv4 address; otherwise, <see langword="false" />.
/// </returns> /// </returns>
public static bool IsIpV4(this IPAddress address) public static bool IsIPv4(this IPAddress address)
{ {
return address.AddressFamily == AddressFamily.InterNetwork; return address.AddressFamily == AddressFamily.InterNetwork;
} }
@ -27,7 +27,7 @@ public static class IpAddressExtensions
/// <returns> /// <returns>
/// <see langword="true" /> if the specified IP address is a valid IPv6 address; otherwise, <see langword="false" />. /// <see langword="true" /> if the specified IP address is a valid IPv6 address; otherwise, <see langword="false" />.
/// </returns> /// </returns>
public static bool IsIpV6(this IPAddress address) public static bool IsIPv6(this IPAddress address)
{ {
return address.AddressFamily == AddressFamily.InterNetworkV6; return address.AddressFamily == AddressFamily.InterNetworkV6;
} }