Fix AddressRegistrationTests.RegisterAddresses_IPv6ScopeId_Success (#1363).

This commit is contained in:
Cesar Blum Silveira 2017-02-14 10:53:06 -08:00
parent 68cc4fdb24
commit bfe1f06938
3 changed files with 38 additions and 14 deletions

View File

@ -70,6 +70,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
[ConditionalTheory, MemberData(nameof(AddressRegistrationDataIPv6ScopeId))]
[IPv6SupportedCondition]
[IPv6ScopeIdPresentCondition]
public async Task RegisterAddresses_IPv6ScopeId_Success(string addressInput, Func<IServerAddressesFeature, string[]> testUrls)
{
await RegisterAddresses_Success(addressInput, testUrls);

View File

@ -0,0 +1,35 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Linq;
using System.Net.NetworkInformation;
using System.Net.Sockets;
using Microsoft.AspNetCore.Testing.xunit;
namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
{
public class IPv6ScopeIdPresentConditionAttribute : Attribute, ITestCondition
{
private static readonly Lazy<bool> _ipv6ScopeIdPresent = new Lazy<bool>(IPv6ScopeIdAddressPresent);
public bool IsMet => _ipv6ScopeIdPresent.Value;
public string SkipReason => "No IPv6 addresses with scope IDs were found on the host.";
private static bool IPv6ScopeIdAddressPresent()
{
try
{
return NetworkInterface.GetAllNetworkInterfaces()
.Where(iface => iface.OperationalStatus == OperationalStatus.Up)
.SelectMany(iface => iface.GetIPProperties().UnicastAddresses)
.Any(addrInfo => addrInfo.Address.AddressFamily == AddressFamily.InterNetworkV6 && addrInfo.Address.ScopeId != 0);
}
catch (SocketException)
{
return false;
}
}
}
}

View File

@ -13,21 +13,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
{
private static readonly Lazy<bool> _ipv6Supported = new Lazy<bool>(CanBindToIPv6Address);
public bool IsMet
{
get
{
return _ipv6Supported.Value;
}
}
public bool IsMet => _ipv6Supported.Value;
public string SkipReason
{
get
{
return "IPv6 not supported on the host.";
}
}
public string SkipReason => "IPv6 not supported on the host.";
private static bool CanBindToIPv6Address()
{