diff --git a/tests/monotouch-test/System.Net.Http/NetworkResources.cs b/tests/monotouch-test/System.Net.Http/NetworkResources.cs index 99fe7fc5c24f..6fa21fe58507 100644 --- a/tests/monotouch-test/System.Net.Http/NetworkResources.cs +++ b/tests/monotouch-test/System.Net.Http/NetworkResources.cs @@ -6,6 +6,7 @@ namespace MonoTests.System.Net.Http { [Preserve (AllMembers = true)] public static class NetworkResources { + public const string AppleHost = "apple.com"; public static string MicrosoftUrl => AssertNetworkConnection ("https://www.microsoft.com"); public static Uri MicrosoftUri => new Uri (MicrosoftUrl); public static string MicrosoftHttpUrl => AssertNetworkConnection ("http://www.microsoft.com"); diff --git a/tests/monotouch-test/SystemConfiguration/NetworkReachabilityTest.cs b/tests/monotouch-test/SystemConfiguration/NetworkReachabilityTest.cs index e4da98fe4040..5a1a4d692281 100644 --- a/tests/monotouch-test/SystemConfiguration/NetworkReachabilityTest.cs +++ b/tests/monotouch-test/SystemConfiguration/NetworkReachabilityTest.cs @@ -14,6 +14,7 @@ using System.Net; using System.Threading; using System.Threading.Tasks; +using MonoTests.System.Net.Http; namespace MonoTouchFixtures.SystemConfiguration { @@ -78,7 +79,14 @@ public void CtorIPAddress () [Test] public void CtorIPAddressPair () { - var address = Dns.GetHostAddresses ("apple.com") [0]; + IPAddress address; + try { + address = Dns.GetHostAddresses (NetworkResources.AppleHost) [0]; + } catch (Exception e) { + TestRuntime.IgnoreInCIIfBadNetwork (e); + throw; + } + using (var nr = new NetworkReachability (IPAddress.Loopback, address)) { NetworkReachabilityFlags flags; @@ -90,8 +98,9 @@ public void CtorIPAddressPair () NetworkReachabilityFlags flags; Assert.IsTrue (nr.TryGetFlags (out flags), "#2"); - flags &= ~NetworkReachabilityFlags.TransientConnection; // Remove the TransientConnection flag if it's set - Assert.That (flags, Is.EqualTo (NetworkReachabilityFlags.Reachable), "#2 Reachable"); + // Different OS versions report different flags, so just + // check that Reachable is set and no unexpected flags appear. + CheckRemoteFlags (flags, "2"); } using (var nr = new NetworkReachability (IPAddress.Loopback, null)) { @@ -114,6 +123,17 @@ void CheckLoopbackFlags (NetworkReachabilityFlags flags, string number, bool has Assert.AreEqual (noFlags, otherFlags, $"#{number} No other flags: {flags.ToString ()}"); } + void CheckRemoteFlags (NetworkReachabilityFlags flags, string number) + { + var noFlags = (NetworkReachabilityFlags) 0; + var otherFlags = (flags & ~(NetworkReachabilityFlags.Reachable | NetworkReachabilityFlags.TransientConnection | NetworkReachabilityFlags.ConnectionRequired)); + + // Different versions of OSes report different flags, so just + // verify Reachable is set and no unexpected flags appear. + Assert.That (flags & NetworkReachabilityFlags.Reachable, Is.Not.EqualTo (noFlags), $"#{number} Reachable: {flags.ToString ()}"); + Assert.AreEqual (noFlags, otherFlags, $"#{number} No other flags: {flags.ToString ()}"); + } + [Test] public void Ctor_Invalid () {