diff --git a/X10D.Tests/src/Net/EndPointTests.cs b/X10D.Tests/src/Net/EndPointTests.cs index 8bb38e0..fd3afb0 100644 --- a/X10D.Tests/src/Net/EndPointTests.cs +++ b/X10D.Tests/src/Net/EndPointTests.cs @@ -13,42 +13,42 @@ public class EndPointTests Assert.ThrowsException(() => ((IPEndPoint?)null)!.GetHost()); Assert.ThrowsException(() => ((DnsEndPoint?)null)!.GetHost()); } - + [TestMethod] public void GetPort_Null_ShouldThrow() { Assert.ThrowsException(() => ((IPEndPoint?)null)!.GetPort()); Assert.ThrowsException(() => ((DnsEndPoint?)null)!.GetPort()); } - + [TestMethod] public void DnsEndPoint_GetHost_Localhost() { var endPoint = new DnsEndPoint("localhost", 1234); Assert.AreEqual("localhost", endPoint.GetHost()); } - + [TestMethod] public void DnsEndPoint_GetPort_1234() { var endPoint = new DnsEndPoint("localhost", 1234); Assert.AreEqual(1234, endPoint.GetPort()); } - + [TestMethod] public void IPEndPoint_IPv4_Loopback_GetHost_127_0_0_1() { var endPoint = new IPEndPoint(IPAddress.Loopback, 1234); Assert.AreEqual("127.0.0.1", endPoint.GetHost()); } - + [TestMethod] public void IPEndPoint_IPv6_Loopback_GetHost_ColonColon1() { var endPoint = new IPEndPoint(IPAddress.IPv6Loopback, 1234); Assert.AreEqual("::1", endPoint.GetHost()); } - + [TestMethod] public void IPEndPoint_GetPort_1234() { diff --git a/X10D.Tests/src/Net/IpAddressTests.cs b/X10D.Tests/src/Net/IpAddressTests.cs new file mode 100644 index 0000000..630216f --- /dev/null +++ b/X10D.Tests/src/Net/IpAddressTests.cs @@ -0,0 +1,33 @@ +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()); + } +}