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 TestCheckFailed()
        {
            Console.WriteLine("Test to fail checking open ports.");
            bool      wait       = true;
            PortCheck port_check = new PortCheck();

            port_check.url        = "http://bogus.url";
            port_check.Completed += delegate(PortCheck port_check_completed)
            {
                Console.WriteLine("");
                Console.WriteLine("Check Completed.");
                Assert.Fail("Failed at failing ;-(");
            };
            port_check.UnableToFetch += delegate(PortCheck port_check_unable)
            {
                Console.WriteLine("");
                Console.WriteLine("Failed to fetch check page.");
                wait = false;
            };

            port_check.CheckPorts();
            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 PortCheck 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 TestCheckFailed()
        {
            Console.WriteLine("Test to fail checking open ports.");
            bool wait = true;
            PortCheck port_check = new PortCheck();
            port_check.url = "http://bogus.url";
            port_check.Completed += delegate(PortCheck port_check_completed)
            {
                Console.WriteLine("");
                Console.WriteLine("Check Completed.");
                Assert.Fail("Failed at failing ;-(");
            };
            port_check.UnableToFetch += delegate(PortCheck port_check_unable)
            {
                Console.WriteLine("");
                Console.WriteLine("Failed to fetch check page.");
                wait = false;

            };

            port_check.CheckPorts();
            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 PortCheck Test successful.");
        }