public void TestResolve()
 {
     Console.WriteLine("Test to resolve own external ip.");
     bool wait = true;
     ExternalIP ex_ip = new ExternalIP();
     ex_ip.Completed += delegate(ExternalIP ex_ip_completed)
     {
         Console.WriteLine("");
         Console.WriteLine("Fetch Completed (ip found : " + ex_ip_completed.MyIP + ")");
         Assert.IsTrue(!string.IsNullOrEmpty(ex_ip_completed.MyIP), "no ip address fetched");
         wait = false;
     };
     ex_ip.FetchIP();
     Console.WriteLine("Waiting for data");
     DateTime start = DateTime.Now;
     while (wait)
     {
         if (DateTime.Now - start > new TimeSpan(0, 0, 5))
         {
             Console.WriteLine("");
             Console.WriteLine("Operation took too long");
             wait = false;
             Assert.Fail("Operation took too long");
         }
         Console.Write(".");
         Thread.Sleep(250);
     }
     Console.WriteLine("External IP resolve Test successful.");
 }
        public void TestCheckRunningLocalPeers()
        {
            Console.WriteLine("Test to check running open ports.");
            bool             wait = true;
            ListeningSockets ls   = new ListeningSockets();

            ls.TcpPort = 3412;
            ls.UdpPort = 3412;
            ls.UpdateConnectionSettings();

            //Assert.IsTrue(!string.IsNullOrEmpty(port_check_completed.MyIP), "no ip address fetched");
            ExternalIP ex_ip = new ExternalIP();

            ex_ip.Completed += delegate(ExternalIP ex_ip_completed)
            {
                wait = true;
                Console.WriteLine("Fetch Completed (ip found : " + ex_ip_completed.MyIP + ")");
                PortCheck port_check = new PortCheck();
                port_check.MyIP      = ex_ip.MyIP;
                port_check.MyTcpPort = 3412;
                port_check.MyUdpPort = 3412;

                port_check.Completed += delegate(PortCheck port_check_completed)
                {
                    Console.WriteLine("");
                    Console.WriteLine("Check Completed (open ports : " + Enum.GetName(typeof(Ports), port_check_completed.OpenPorts) + ")");
                    if (port_check_completed.OpenPorts == Ports.None || port_check_completed.OpenPorts == Ports.Udp)
                    {
                        Assert.Fail("Test failed: tcp port not open!");
                    }
                    wait = false;
                };
                port_check.CheckPorts();
            };
            ex_ip.FetchIP();
            Console.WriteLine("Waiting for data");
            DateTime ip_start = DateTime.Now;

            while (wait)
            {
                if (DateTime.Now - ip_start > new TimeSpan(0, 0, 35))
                {
                    Console.WriteLine("");
                    Console.WriteLine("Operation took too long");
                    wait = false;
                    Assert.Fail("Operation took too long");
                }
                Console.Write(".");
                Thread.Sleep(250);
            }
            Console.WriteLine("PortCheck running open ports Test successful.");
        }
        public void TestResolveFailServiceOffine()
        {
            Console.WriteLine("Test to fail resolve own external ip.");
            bool wait = true;
            ExternalIP ex_ip = new ExternalIP();
            ex_ip.url = "http://bogus.url";
            ex_ip.Completed += delegate(ExternalIP ex_ip_completed)
            {
                Console.WriteLine("");
                Console.WriteLine("Fetch Completed (ip found : " + ex_ip_completed.MyIP + ")");
                Assert.Fail("Failed at failing ;-(");
            };
            ex_ip.UnableToFetch += delegate(ExternalIP ex_ip_unable)
            {
                Console.WriteLine("");
                Console.WriteLine("Failed to fetch ip page.");
                wait = false;
                
            };

            ex_ip.FetchIP();
            Console.WriteLine("Waiting for data");
            DateTime start = DateTime.Now;
            while (wait)
            {
                if (DateTime.Now - start > new TimeSpan(0, 0, 5))
                {
                    Console.WriteLine("");
                    Console.WriteLine("Operation took too long");
                    wait = false;
                    Assert.Fail("Operation took too long");
                }
                Console.Write(".");
                Thread.Sleep(250);
            }
            Console.WriteLine("Failed External IP resolve Test successful.");
        }
        public void TestCheckRunningLocalPeers()
        {
            Console.WriteLine("Test to check running open ports.");
            bool wait = true;
            ListeningSockets ls = new ListeningSockets();
            ls.TcpPort = 3412;
            ls.UdpPort = 3412;
            ls.UpdateConnectionSettings();

            //Assert.IsTrue(!string.IsNullOrEmpty(port_check_completed.MyIP), "no ip address fetched");
            ExternalIP ex_ip = new ExternalIP();
            ex_ip.Completed += delegate(ExternalIP ex_ip_completed)
            {
                wait = true;
                Console.WriteLine("Fetch Completed (ip found : " + ex_ip_completed.MyIP + ")");
                PortCheck port_check = new PortCheck();
                port_check.MyIP = ex_ip.MyIP;
                port_check.MyTcpPort = 3412;
                port_check.MyUdpPort = 3412;

                port_check.Completed += delegate(PortCheck port_check_completed)
                {
                    Console.WriteLine("");
                    Console.WriteLine("Check Completed (open ports : " + Enum.GetName(typeof(Ports), port_check_completed.OpenPorts) + ")");
                    if(port_check_completed.OpenPorts == Ports.None || port_check_completed.OpenPorts == Ports.Udp)
                        Assert.Fail("Test failed: tcp port not open!");
                    wait = false;
                };
                port_check.CheckPorts();

            };
            ex_ip.FetchIP();
            Console.WriteLine("Waiting for data");
            DateTime ip_start = DateTime.Now;
            while (wait)
            {
                if (DateTime.Now - ip_start > new TimeSpan(0, 0, 35))
                {
                    Console.WriteLine("");
                    Console.WriteLine("Operation took too long");
                    wait = false;
                    Assert.Fail("Operation took too long");
                }
                Console.Write(".");
                Thread.Sleep(250);
            }
            Console.WriteLine("PortCheck running open ports Test successful.");
        }
        public void TestResolveFailServiceOffine()
        {
            Console.WriteLine("Test to fail resolve own external ip.");
            bool wait = true;
            ExternalIP ex_ip = new ExternalIP();
            ex_ip.url = "http://bogus.url";
            ex_ip.Completed += delegate(ExternalIP ex_ip_completed)
            {
                Console.WriteLine("");
                Console.WriteLine("Fetch Completed (ip found : " + ex_ip_completed.MyIP + ")");
                Assert.Fail("Failed at failing ;-(");
            };
            ex_ip.UnableToFetch += delegate(ExternalIP ex_ip_unable)
            {
                Console.WriteLine("");
                Console.WriteLine("Failed to fetch ip page.");
                wait = false;

            };

            ex_ip.FetchIP();
            Console.WriteLine("Waiting for data");
            DateTime start = DateTime.Now;
            while (wait)
            {
                if (DateTime.Now - start > new TimeSpan(0, 0, 5))
                {
                    Console.WriteLine("");
                    Console.WriteLine("Operation took too long");
                    wait = false;
                    Assert.Fail("Operation took too long");
                }
                Console.Write(".");
                Thread.Sleep(250);
            }
            Console.WriteLine("Failed External IP resolve Test successful.");
        }
 public void TestResolve()
 {
     Console.WriteLine("Test to resolve own external ip.");
     bool wait = true;
     ExternalIP ex_ip = new ExternalIP();
     ex_ip.Completed += delegate(ExternalIP ex_ip_completed)
     {
         Console.WriteLine("");
         Console.WriteLine("Fetch Completed (ip found : " + ex_ip_completed.MyIP + ")");
         Assert.IsTrue(!string.IsNullOrEmpty(ex_ip_completed.MyIP), "no ip address fetched");
         wait = false;
     };
     ex_ip.FetchIP();
     Console.WriteLine("Waiting for data");
     DateTime start = DateTime.Now;
     while (wait)
     {
         if (DateTime.Now - start > new TimeSpan(0, 0, 5))
         {
             Console.WriteLine("");
             Console.WriteLine("Operation took too long");
             wait = false;
             Assert.Fail("Operation took too long");
         }
         Console.Write(".");
         Thread.Sleep(250);
     }
     Console.WriteLine("External IP resolve Test successful.");
 }