public void GetIpAddressForInvalidHostnameReturnsNull()
        {
            var resolver = new IpAddressResolver();
            var ip = resolver.GetIpAddressForHostname("bogus93937329923.bespokeindustries.com");

            Assert.IsNull(ip);
        }
        public void CanGetPublicIpAddressFromDynDns()
        {
            var resolver = new IpAddressResolver();
            var ip = resolver.GetPublicIpAddressFromDynDns();

            Assert.AreEqual(ExpectedPublicIpAddress, ip);
        }
        public void CanGetIpAddressForHostname()
        {
            var resolver = new IpAddressResolver();
            var ip = resolver.GetIpAddressForHostname("bespokeindustries.com");

            Assert.AreEqual("204.246.37.132", ip);
        }
        /// <summary>
        /// Updates the given hostnames via DNS-O-Matic with the public facing
        /// IP Address for the system that the request is made from.
        /// </summary>
        /// <param name="hostnames">A comma delimited list of hostnames to update.</param>
        /// <returns>True, if all of the hostnames updated correctly, otherwise false.</returns>
        public bool UpdateHostnames(string hostnames)
        {
            var resolver = new IpAddressResolver();

            var ip = resolver.GetPublicIpAddress();

            if (ip == null)
            {
                return(false);
            }

            logger.Info(string.Format("Resolved public IP Address as {0}", ip));

            return(UpdateHostnames(hostnames, ip));
        }
        /// <summary>
        /// Initialize the LastUpdateIpAddresses collection with the current IP Address (in DNS) for each of the given hostnames.
        /// This can be used when the client is run for the first time, when we don't have a record of what the previous IP
        /// Address was that was sent to DNS-O-Matic.  This way we won't have to attempt to update the IP Address, if the current
        /// DNS entry matches the current IP Address.
        /// </summary>
        /// <param name="hostnames">The hostnames to update.</param>
        public void InitializeLastUpdateIpAddresses(string hostnames)
        {
            var resolver      = new IpAddressResolver();
            var hostnamesList = HostnamesToList(hostnames);

            foreach (var hostname in hostnamesList)
            {
                var ipAddress = resolver.GetIpAddressForHostname(hostname);

                if (ipAddress != null)
                {
                    LastUpdateIpAddresses[hostname] = ipAddress;
                }
            }
        }
        /// <summary>
        /// Initialize the LastUpdateIpAddresses collection with the current IP Address (in DNS) for each of the given hostnames.
        /// This can be used when the client is run for the first time, when we don't have a record of what the previous IP
        /// Address was that was sent to DNS-O-Matic.  This way we won't have to attempt to update the IP Address, if the current
        /// DNS entry matches the current IP Address.
        /// </summary>
        /// <param name="hostnames">The hostnames to update.</param>
        public void InitializeLastUpdateIpAddresses(string hostnames)
        {
            var resolver = new IpAddressResolver();
            var hostnamesList = HostnamesToList(hostnames);

            foreach (var hostname in hostnamesList)
            {
                var ipAddress = resolver.GetIpAddressForHostname(hostname);

                if (ipAddress != null)
                {
                    LastUpdateIpAddresses[hostname] = ipAddress;
                }
            }
        }
        /// <summary>
        /// Updates the specified hostnames via DNS-O-Matic with the public facing
        /// IP Address for the system that the request is made from.
        /// </summary>
        /// <param name="hostnames">The hostnames to update.</param>
        /// <returns>
        /// True if all updates were successful, otherwise false.
        /// Check UpdateStatusCodes dictionary for individual hostname status.
        /// </returns>
        public bool UpdateHostnames(List<string> hostnames)
        {
            var resolver = new IpAddressResolver();

            var ip = resolver.GetPublicIpAddress();

            if (ip == null) return false;

            logger.Info(string.Format("Resolved public IP Address as {0}", ip));

            return UpdateHostnames(hostnames, ip);
        }