﻿using System.Net.Sockets;
using System.Threading.Tasks;
using RapidCore.Network;
using Xunit;

namespace RapidCore.UnitTests.Network
{
    public class HostnameToIpResolverTest
    {
        [Fact]
        public async Task HostnameToIpResolver_can_resolveAsync()
        {
            var resolver = new HostnameToIpResolver();
            var ip = await resolver.ResolveToIpv4Async("localhost");

            Assert.Equal("127.0.0.1", ip);
        }

        [Fact]
        public async Task HostnameToIpResolve_can_fail()
        {
            var resolver = new HostnameToIpResolver();
            await Assert.ThrowsAsync<SocketException>(async () => await resolver.ResolveToIpv4Async("this-host-is-invalid"));
        }
    }
}

﻿using System.Net.Sockets;
using System.Threading.Tasks;
using RapidCore.Network;
using Xunit;

namespace RapidCore.UnitTests.Network
{
    public class HostnameToIpResolverTest
    {
        [Fact]
        public async Task HostnameToIpResolver_can_resolveAsync()
        {
            var resolver = new HostnameToIpResolver();
            var ip = await resolver.ResolveToIpv4Async("localhost");

            Assert.Equal("127.0.0.1", ip);
        }

        [Fact]
        public async Task HostnameToIpResolve_can_fail()
        {
            var resolver = new HostnameToIpResolver();
            var exception =
                await Record.ExceptionAsync(async () => await resolver.ResolveToIpv4Async("this-host-is-invalid"));
            Assert.NotNull(exception);
            
            Assert.IsAssignableFrom<SocketException>(exception);
        }
    }
}

Fix test assertion for hostname to ip resolver
Fix test assertion for hostname to ip resolver

Rather than testing that the caught exception is _of_ type SocketException
we test that it is assignable to this type - the exception thrown on niX
variants inherit from the SocketException but are not that actual type.

Stupid...
