public static IPEndPoint GetEndPoint(string server)
 {
     const int maxSplits = 2;
     var address = server.Split(':');
     if (address.Count() != maxSplits)
     {
         throw new ArgumentException("server");
     }
     IPAddress ipAddress;
     if (!IPAddress.TryParse(address[0], out ipAddress))
     {
         var uri = new Uri(String.Format("http://{0}", address[0]));
         ipAddress = uri.GetIpAddress(ClientConfiguration.UseInterNetworkV6Addresses);
         if (ipAddress == null)
         {
             throw new ArgumentException("ipAddress");
         }
     }
     int port;
     if (!int.TryParse(address[1], out port))
     {
         throw new ArgumentException("port");
     }
     return new IPEndPoint(ipAddress, port);
 }
        public void GetIpAddress_DnsEntry_NoDeadlock()
        {
            // Using an asynchronous view query within an MVC Web API action causes
            // a deadlock if you wait for the result synchronously.

            var context = new Mock<SynchronizationContext>
            {
                CallBase = true
            };

            SynchronizationContext.SetSynchronizationContext(context.Object);
            try
            {
                var uri = new Uri("http://localhost/");

                uri.GetIpAddress(false);

                // If view queries are incorrectly awaiting on the current SynchronizationContext
                // We will see calls to Post or Send on the mock

                context.Verify(m => m.Post(It.IsAny<SendOrPostCallback>(), It.IsAny<object>()), Times.Never);
                context.Verify(m => m.Send(It.IsAny<SendOrPostCallback>(), It.IsAny<object>()), Times.Never);
            }
            finally
            {
                SynchronizationContext.SetSynchronizationContext(null);
            }
        }
        public void GetIpAddress_DnsEntry_ReturnsIp()
        {
            // Arrange

            var uri = new Uri("http://localhost/");

            // Act

            var result = uri.GetIpAddress(false);

            // Assert

            Assert.AreEqual(new IPAddress(new byte[] {127, 0, 0, 1}), result);
        }
 public static IPEndPoint GetEndPoint(NodeExt nodeExt, BucketConfiguration bucketConfig, IBucketConfig serverConfig)
 {
     var address = nodeExt.Hostname.Split(':').First();
     IPAddress ipAddress;
     if (!IPAddress.TryParse(address, out ipAddress))
     {
         var uri = new Uri(String.Format("http://{0}", address));
         ipAddress = uri.GetIpAddress(ClientConfiguration.UseInterNetworkV6Addresses);
         if (ipAddress == null)
         {
             throw new ArgumentException("ipAddress");
         }
     }
     var port = bucketConfig.UseSsl ? nodeExt.Services.KvSSL : nodeExt.Services.KV;
     return new IPEndPoint(ipAddress, port);
 }
 public static IPEndPoint GetEndPoint(INodeAdapter adapter, BucketConfiguration clientConfig, IBucketConfig server)
 {
     var address = adapter.Hostname.Split(':').First();
     IPAddress ipAddress;
     if (!IPAddress.TryParse(address, out ipAddress))
     {
         var uri = new Uri(String.Format("http://{0}", address));
         ipAddress = uri.GetIpAddress(ClientConfiguration.UseInterNetworkV6Addresses);
         if (ipAddress == null)
         {
             throw new ArgumentException("ipAddress");
         }
     }
     var port = clientConfig.UseSsl ? adapter.KeyValueSsl : adapter.KeyValue;
     return new IPEndPoint(ipAddress, port);
 }
 public static IPEndPoint GetEndPoint(Node node, BucketConfiguration clientConfig, IBucketConfig serverConfig)
 {
     var address = node.Hostname.Split(':').First();
     IPAddress ipAddress;
     if (!IPAddress.TryParse(address, out ipAddress))
     {
         var uri = new Uri(String.Format("http://{0}", address));
         ipAddress = uri.GetIpAddress();
         if (ipAddress == null)
         {
             throw new ArgumentException("ipAddress");
         }
     }
     var port = clientConfig.UseSsl ? node.Ports.SslDirect : node.Ports.Direct;
     return new IPEndPoint(ipAddress, port);
 }
 public void When_GetIpAddress_Called_With_IpAddress_Returns_HostIP()
 {
     var uri = new Uri("http://127.0.0.1:8091/pools");
     var ipAddress = uri.GetIpAddress();
     Assert.AreEqual("127.0.0.1", ipAddress.ToString());
 }
 public void When_Hostname_Is_IPAddress_Return_It()
 {
     var uri = new Uri("http://192.168.56.102:8091/pools");
     var ipAddress = uri.GetIpAddress();
     Assert.AreEqual("192.168.56.102", ipAddress.ToString());
 }
 public void When_GetIPAddress_Called_With_LocalHost_Returns_LoopBackIP()
 {
     var uri = new Uri("http://localhost:8091/pools");
     var ipAddress = uri.GetIpAddress();
     Assert.AreEqual("127.0.0.1", ipAddress.ToString());
 }
 public void When_GetIpAddress_Called_With_IpAddress_Returns_HostIP()
 {
     var uri = new Uri("http://127.0.0.1:8091/pools");
     var ipAddress = uri.GetIpAddress(ClientConfiguration.UseInterNetworkV6Addresses);
     Assert.AreEqual("127.0.0.1", ipAddress.ToString());
 }
 public void When_Hostname_Is_IPAddress_Return_It()
 {
     var uri = new Uri("http://192.168.56.102:8091/pools");
     var ipAddress = uri.GetIpAddress(ClientConfiguration.UseInterNetworkV6Addresses);
     Assert.AreEqual("192.168.56.102", ipAddress.ToString());
 }