Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions tests/monotouch-test/System.Net.Http/NetworkResources.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
using System.Net;
using System.Threading;
using System.Threading.Tasks;
using MonoTests.System.Net.Http;

namespace MonoTouchFixtures.SystemConfiguration {

Expand Down Expand Up @@ -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;

Expand All @@ -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)) {
Expand All @@ -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 ()
{
Expand Down
Loading