Skip to content

Commit

Permalink
Managed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gfoidl committed Apr 7, 2020
1 parent cf13c70 commit 4614267
Showing 1 changed file with 62 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.IO;
using System.Net.Sockets;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using Xunit;
using Xunit.Abstractions;

Expand Down Expand Up @@ -48,6 +49,33 @@ public void TryGetAddrInfo_LocalHost(bool justAddresses)
}
Assert.NotNull(aliases);
Assert.NotNull(addresses);
Assert.True(addresses.Length > 0);
}

[Theory]
[InlineData(false)]
[InlineData(true)]
public async Task GetAddrInfoAsync_LocalHost(bool justAddresses)
{
if (!NameResolutionPal.SupportsGetAddrInfoAsync)
{
return;
}

if (justAddresses)
{
IPAddress[] addresses = await ((Task<IPAddress[]>)NameResolutionPal.GetAddrInfoAsync("localhost", justAddresses)).ConfigureAwait(false);

Assert.NotNull(addresses);
Assert.True(addresses.Length > 0);
}
else
{
IPHostEntry hostEntry = await ((Task<IPHostEntry>)NameResolutionPal.GetAddrInfoAsync("localhost", justAddresses)).ConfigureAwait(false);

Assert.NotNull(hostEntry);
Assert.True(hostEntry.AddressList.Length > 0);
}
}

[Theory]
Expand Down Expand Up @@ -160,6 +188,40 @@ public void TryGetAddrInfo_ExternalHost(bool justAddresses)
Assert.Equal(SocketError.Success, error);
Assert.NotNull(aliases);
Assert.NotNull(addresses);
Assert.True(addresses.Length > 0);
}

[Theory]
[InlineData(false)]
[InlineData(true)]
public async Task GetAddrInfoAsync_ExternalHost(bool justAddresses)
{
if (!NameResolutionPal.SupportsGetAddrInfoAsync)
{
return;
}

const string hostName = "microsoft.com";

if (!NameResolutionPal.SupportsGetAddrInfoAsync)
{
return;
}

if (justAddresses)
{
IPAddress[] addresses = await ((Task<IPAddress[]>)NameResolutionPal.GetAddrInfoAsync(hostName, justAddresses)).ConfigureAwait(false);

Assert.NotNull(addresses);
Assert.True(addresses.Length > 0);
}
else
{
IPHostEntry hostEntry = await ((Task<IPHostEntry>)NameResolutionPal.GetAddrInfoAsync(hostName, justAddresses)).ConfigureAwait(false);

Assert.NotNull(hostEntry);
Assert.True(hostEntry.AddressList.Length > 0);
}
}

[Theory]
Expand Down

0 comments on commit 4614267

Please sign in to comment.