Esempio n. 1
0
        public void Registrar_TestEndPointReflection()
        {
            RegistrarClient registrar = new RegistrarClient("LocalHttpBinding_IRegistrar");
            // RegistrarClient registrar = new RegistrarClient("ProdHttpBinding_IRegistrar");

            string reflectorEndPointString = registrar.EndPointReflector();

            Assert.IsNotNull(reflectorEndPointString);
            Common.EndPoint reflectorEndPoint = new Common.EndPoint(reflectorEndPointString);

            UdpClient testClient = new UdpClient(0, AddressFamily.InterNetwork);

            byte[] sendBuffer = ASCIIEncoding.ASCII.GetBytes("hello");
            testClient.Send(sendBuffer, sendBuffer.Length, reflectorEndPoint.GetIPEndPoint());

            testClient.Client.ReceiveTimeout = 1000;
            IPEndPoint sendingEP = new IPEndPoint(IPAddress.Any, 0);

            byte[] receiveBuffer = testClient.Receive(ref sendingEP);

            Assert.IsNotNull(receiveBuffer);
            string reflectedEP = ASCIIEncoding.ASCII.GetString(receiveBuffer);

            Assert.IsNotNull(reflectedEP);
            Assert.IsTrue(reflectedEP.Length > 8);
            string[] tmp = reflectedEP.Split(':');
            Assert.IsTrue(tmp.Length == 2);
        }
        public void Registrar_TestEndPointReflection()
        {
            RegistrarClient registrar = new RegistrarClient("LocalHttpBinding_IRegistrar");
            // RegistrarClient registrar = new RegistrarClient("ProdHttpBinding_IRegistrar");

            string reflectorEndPointString = registrar.EndPointReflector();
            Assert.IsNotNull(reflectorEndPointString);
            Common.EndPoint reflectorEndPoint = new Common.EndPoint(reflectorEndPointString);

            UdpClient testClient = new UdpClient(0, AddressFamily.InterNetwork);
            byte[] sendBuffer = ASCIIEncoding.ASCII.GetBytes("hello");
            testClient.Send(sendBuffer, sendBuffer.Length, reflectorEndPoint.GetIPEndPoint());

            testClient.Client.ReceiveTimeout = 1000;
            IPEndPoint sendingEP = new IPEndPoint(IPAddress.Any, 0);
            byte[] receiveBuffer = testClient.Receive(ref sendingEP);

            Assert.IsNotNull(receiveBuffer);
            string reflectedEP = ASCIIEncoding.ASCII.GetString(receiveBuffer);
            Assert.IsNotNull(reflectedEP);
            Assert.IsTrue(reflectedEP.Length > 8);
            string[] tmp = reflectedEP.Split(':');
            Assert.IsTrue(tmp.Length == 2);
        }
Esempio n. 3
0
        public void EndPoint_CheckPropertiesAndMethods()
        {
            Common.EndPoint ep1 = new Common.EndPoint(3255420, 3004);
            Assert.AreEqual(3255420, ep1.Address);
            Assert.AreEqual(3004, ep1.Port);

            ep1.Address = 54365439;
            ep1.Port    = 4354;
            Assert.AreEqual(54365439, ep1.Address);
            Assert.AreEqual(4354, ep1.Port);

            ep1.Address = 0;
            ep1.Port    = 0;
            Assert.AreEqual(0, ep1.Address);
            Assert.AreEqual(0, ep1.Port);

            ep1.Address = Int32.MaxValue;
            ep1.Port    = IPEndPoint.MaxPort;
            Assert.AreEqual(Int32.MaxValue, ep1.Address);
            Assert.AreEqual(IPEndPoint.MaxPort, ep1.Port);
            ep1.Port = IPEndPoint.MinPort;
            Assert.AreEqual(IPEndPoint.MinPort, ep1.Port);

            try
            {
                ep1.Port = IPEndPoint.MaxPort + 1;
                Assert.Fail("Excepted exception not thrown for too big of a port number");
            }
            catch (ApplicationException) { }

            try
            {
                ep1.Port = IPEndPoint.MinPort - 1;
                Assert.Fail("Excepted exception not thrown for too small of a port number");
            }
            catch (ApplicationException) { }

            ep1.Address = 54365439;
            ep1.Port    = 4354;
            Common.EndPoint ep2 = new Common.EndPoint(34445, 3255);
            Assert.IsFalse(Common.EndPoint.Match(ep1, ep2));
            Assert.IsFalse(Common.EndPoint.Match(ep1.GetIPEndPoint(), ep2.GetIPEndPoint()));
            ep2.Port = 4354;
            Assert.IsFalse(Common.EndPoint.Match(ep1, ep2));
            Assert.IsFalse(Common.EndPoint.Match(ep1.GetIPEndPoint(), ep2.GetIPEndPoint()));
            ep2.Address = 54365439;
            Assert.IsTrue(Common.EndPoint.Match(ep1, ep2));
            Assert.IsTrue(Common.EndPoint.Match(ep1.GetIPEndPoint(), ep2.GetIPEndPoint()));

            byte[] addressBytes = new byte[4];
            addressBytes[0] = 10;
            addressBytes[1] = 211;
            addressBytes[2] = 55;
            addressBytes[3] = 20;

            Common.EndPoint ep3      = new Common.EndPoint(addressBytes, 2001);
            byte[]          tmpBytes = BitConverter.GetBytes(ep3.Address);
            Assert.AreEqual(10, tmpBytes[0]);
            Assert.AreEqual(211, tmpBytes[1]);
            Assert.AreEqual(55, tmpBytes[2]);
            Assert.AreEqual(20, tmpBytes[3]);
            Assert.AreEqual(2001, ep3.Port);

            IPEndPoint ipEp = ep3.GetIPEndPoint();

            Assert.AreEqual(10, ipEp.Address.GetAddressBytes()[0]);
            Assert.AreEqual(211, ipEp.Address.GetAddressBytes()[1]);
            Assert.AreEqual(55, ipEp.Address.GetAddressBytes()[2]);
            Assert.AreEqual(20, ipEp.Address.GetAddressBytes()[3]);
            Assert.AreEqual(2001, ipEp.Port);
        }
        public void EndPoint_CheckPropertiesAndMethods()
        {
            Common.EndPoint ep1 = new Common.EndPoint(3255420, 3004);
            Assert.AreEqual(3255420, ep1.Address);
            Assert.AreEqual(3004, ep1.Port);

            ep1.Address = 54365439;
            ep1.Port = 4354;
            Assert.AreEqual(54365439, ep1.Address);
            Assert.AreEqual(4354, ep1.Port);

            ep1.Address = 0;
            ep1.Port = 0;
            Assert.AreEqual(0, ep1.Address);
            Assert.AreEqual(0, ep1.Port);

            ep1.Address = Int32.MaxValue;
            ep1.Port = IPEndPoint.MaxPort;
            Assert.AreEqual(Int32.MaxValue, ep1.Address);
            Assert.AreEqual(IPEndPoint.MaxPort, ep1.Port);
            ep1.Port = IPEndPoint.MinPort;
            Assert.AreEqual(IPEndPoint.MinPort, ep1.Port);

            try
            {
                ep1.Port = IPEndPoint.MaxPort + 1;
                Assert.Fail("Excepted exception not thrown for too big of a port number");
            }
            catch (ApplicationException) { }

            try
            {
                ep1.Port = IPEndPoint.MinPort - 1;
                Assert.Fail("Excepted exception not thrown for too small of a port number");
            }
            catch (ApplicationException) { }

            ep1.Address = 54365439;
            ep1.Port = 4354;
            Common.EndPoint ep2 = new Common.EndPoint(34445, 3255);
            Assert.IsFalse(Common.EndPoint.Match(ep1, ep2));
            Assert.IsFalse(Common.EndPoint.Match(ep1.GetIPEndPoint(), ep2.GetIPEndPoint()));
            ep2.Port = 4354;
            Assert.IsFalse(Common.EndPoint.Match(ep1, ep2));
            Assert.IsFalse(Common.EndPoint.Match(ep1.GetIPEndPoint(), ep2.GetIPEndPoint()));
            ep2.Address = 54365439;
            Assert.IsTrue(Common.EndPoint.Match(ep1, ep2));
            Assert.IsTrue(Common.EndPoint.Match(ep1.GetIPEndPoint(), ep2.GetIPEndPoint()));

            byte[] addressBytes = new byte[4];
            addressBytes[0] = 10;
            addressBytes[1] = 211;
            addressBytes[2] = 55;
            addressBytes[3] = 20;

            Common.EndPoint ep3 = new Common.EndPoint(addressBytes, 2001);
            byte[] tmpBytes = BitConverter.GetBytes(ep3.Address);
            Assert.AreEqual(10, tmpBytes[0]);
            Assert.AreEqual(211, tmpBytes[1]);
            Assert.AreEqual(55, tmpBytes[2]);
            Assert.AreEqual(20, tmpBytes[3]);
            Assert.AreEqual(2001, ep3.Port);

            IPEndPoint ipEp = ep3.GetIPEndPoint();
            Assert.AreEqual(10, ipEp.Address.GetAddressBytes()[0]);
            Assert.AreEqual(211, ipEp.Address.GetAddressBytes()[1]);
            Assert.AreEqual(55, ipEp.Address.GetAddressBytes()[2]);
            Assert.AreEqual(20, ipEp.Address.GetAddressBytes()[3]);
            Assert.AreEqual(2001, ipEp.Port);
        }