public void TestOpenClose()
        {
            Console.WriteLine("Test to open and close listening sockets.");
            ListeningSockets ls = new ListeningSockets();

            ls.SetupListeningSocket();
            ls.CloseListeningSocket();
            Console.WriteLine("Opening and Closing Sockets Test successful.");

            /*bool wait = true;
             * u.RouterDiscovered += delegate(Router r)
             * {
             *  wait = false;
             * };
             * Console.WriteLine("Waiting for data");
             * DateTime start = DateTime.Now;
             * while (wait)
             * {
             *  if (DateTime.Now - start > new TimeSpan(0, 0, 300))
             *  {
             *      Console.WriteLine("");
             *      Console.WriteLine("Operation took too long");
             *      wait = false;
             *      Assert.Fail("Operation took too long");
             *  }
             *  Console.Write(".");
             *  Thread.Sleep(250);
             * }*/
        }
        public void TestOpenWithoutClosing()
        {
            Console.WriteLine("Test to open and NOT close listening sockets.");
            ListeningSockets ls = new ListeningSockets();

            ls.SetupListeningSocket();
            Console.WriteLine("Opening and NOT Closing Sockets Test successful.");
        }
        public void TestOpenWithoutClosingAndPortsSpecified()
        {
            Console.WriteLine("Test to open and NOT close listening sockets(using specified ports).");
            ListeningSockets ls = new ListeningSockets();

            ls.UdpPort = 5000;
            ls.TcpPort = 5000;
            ls.SetupListeningSocket();
            Console.WriteLine("Opening and NOT Closing Sockets 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 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 TestOpenWithoutClosingAndPortsSpecified()
 {
     Console.WriteLine("Test to open and NOT close listening sockets(using specified ports).");
     ListeningSockets ls = new ListeningSockets();
     ls.UdpPort = 5000;
     ls.TcpPort = 5000;
     ls.SetupListeningSocket();
     Console.WriteLine("Opening and NOT Closing Sockets Test successful.");
 }
 public void TestOpenWithoutClosing()
 {
     Console.WriteLine("Test to open and NOT close listening sockets.");
     ListeningSockets ls = new ListeningSockets();
     ls.SetupListeningSocket();
     Console.WriteLine("Opening and NOT Closing Sockets Test successful.");
 }
        public void TestOpenClose()
        {
            Console.WriteLine("Test to open and close listening sockets.");
            ListeningSockets ls = new ListeningSockets();
            ls.SetupListeningSocket();
            ls.CloseListeningSocket();
            Console.WriteLine("Opening and Closing Sockets Test successful.");

            /*bool wait = true;
            u.RouterDiscovered += delegate(Router r)
            {
                wait = false;
            };
            Console.WriteLine("Waiting for data");
            DateTime start = DateTime.Now;
            while (wait)
            {
                if (DateTime.Now - start > new TimeSpan(0, 0, 300))
                {
                    Console.WriteLine("");
                    Console.WriteLine("Operation took too long");
                    wait = false;
                    Assert.Fail("Operation took too long");
                }
                Console.Write(".");
                Thread.Sleep(250);
            }*/
        }