Exemple #1
0
        public void Ev3TCPServer_UnitTest_5()
        {
            // Server Ip Address and server initialization
            // IPAddress ipTest = new IPAddress(new byte[4] { 192, 168, 1, 170 });
            Ev3TCPServer server   = new Ev3TCPServer(withIPAddress: localAddress);
            IPEndPoint   remoteEP = new IPEndPoint(localAddress, 11000);

            // Starts the server and checks
            server.Start();
            Thread.Sleep(100);
            Assert.AreEqual(server.IsRunning, true);

            // Connects to the server and check
            Socket client = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

            client.Connect(remoteEP);
            Assert.AreEqual(client.Connected, true);

            // Disconnects from the server and check
            client.Disconnect(false);
            Assert.AreEqual(client.Connected, false);

            // Stops the server and checks
            server.Stop();
            Thread.Sleep(100);
            Assert.AreEqual(server.IsRunning, false);
        }
Exemple #2
0
        public void Ev3TCPServer_UnitTest_1()
        {
            Ev3TCPServer server = new Ev3TCPServer();

            Assert.IsNotNull(server);
            Assert.AreEqual(server.IsRunning, false);
        }
Exemple #3
0
        public void Ev3TCPServer_UnitTest_1_2()
        {
            IPAddress ipAddress = new IPAddress(new byte[4] {
                192, 168, 35, 10
            });

            Ev3TCPServer server = new Ev3TCPServer(withIPAddress: ipAddress);

            Assert.IsNotNull(server);
            Assert.AreEqual(ipAddress, server.IPAddress);
        }
Exemple #4
0
        public void Ev3TCPServer_UnitTest_13()
        {
            // Server Ip Address and server initialization
            Ev3TCPServer server   = new Ev3TCPServer(withIPAddress: localAddress);
            IPEndPoint   remoteEP = new IPEndPoint(localAddress, 11000);

            bool propertyChangedEventFired = false;

            server.PropertyChanged += (object sender, System.ComponentModel.PropertyChangedEventArgs e) =>
            {
                propertyChangedEventFired = true;
            };

            // Starts the server and checks
            server.Start();
            Thread.Sleep(100);
            Assert.AreEqual(server.IsRunning, true);

            // Connects to the server and check
            Socket client = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

            client.Connect(remoteEP);
            Assert.AreEqual(client.Connected, true);

            // Create a message to send
            RobotMessage sentMessage = new RobotMessage();

            sentMessage.Sender = Sender.FromClient;
            string encodedMessage = RobotMessage.Serialize(theMessage: sentMessage);
            // Send the message
            int bytesSent = client.Send(Encoding.ASCII.GetBytes(encodedMessage));

            Assert.AreNotEqual(0, bytesSent);

            // Checks message received
            Thread.Sleep(100);
            Assert.IsNotNull(server.LastMessage);
            Assert.AreNotEqual(string.Empty, server.LastMessage);
            Assert.AreEqual(sentMessage.Sender, RobotMessage.DeSerialize(server.LastMessage, typeof(RobotMessage)).Sender);

            // Checks event fired
            Assert.AreEqual(true, propertyChangedEventFired);

            // Disconnects from the server and check
            client.Disconnect(false);
            Assert.AreEqual(client.Connected, false);

            // Stops the server and checks
            server.Stop();
            Thread.Sleep(100);
            Assert.AreEqual(server.IsRunning, false);
        }
Exemple #5
0
        public void Ev3TCPServer_UnitTest_3()
        {
            Ev3TCPServer server = new Ev3TCPServer();

            // Starts the server and checks
            IPAddress ipTest = new IPAddress(new byte[4] {
                192, 168, 0, 10
            });

            server.IPAddress = ipTest;

            Assert.AreEqual(ipTest, server.IPAddress);
        }
            protected override void ProcessLastReceivedMessage()
            {
                base.ProcessLastReceivedMessage();
                okIHaveReceivedAMessage = true;

                // Sends a message back
                SpecialMessage message = new SpecialMessage();

                message.Sender    = Sender.FromRobot;
                message.testField = 150;

                string encodedMessage = RobotMessage.Serialize(theMessage: message);

                // Send the message
                Ev3TCPServer.Send(encodedMessage);
            }
Exemple #7
0
        public void Ev3TCPServer_UnitTest_4()
        {
            // Server Ip Address and server initialization
            //IPAddress ipTest = new IPAddress(new byte[4] { 192, 168, 1, 170 });
            Ev3TCPServer server = new Ev3TCPServer(withIPAddress: localAddress);

            // Starts the server and checks
            server.Start();

            Thread.Sleep(100);
            Assert.AreEqual(server.IsRunning, true);

            // Stops the server and checks
            server.Stop();

            Thread.Sleep(100);
            Assert.AreEqual(server.IsRunning, false);
        }
Exemple #8
0
        public void Ev3TCPServer_UnitTest_12()
        {
            // Server Ip Address and server initialization
            // IPAddress ipTest = new IPAddress(new byte[4] { 192, 168, 1, 170 });
            Ev3TCPServer server   = new Ev3TCPServer(withIPAddress: localAddress);
            IPEndPoint   remoteEP = new IPEndPoint(localAddress, 11000);

            // Starts the server and checks
            server.Start();
            Thread.Sleep(100);
            Assert.AreEqual(server.IsRunning, true);

            // Connects to the server and check
            Socket client = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

            client.Connect(remoteEP);
            Assert.AreEqual(client.Connected, true);

            // Create a message to send
            RobotMessage sentMessage = new RobotMessage();

            sentMessage.Sender = Sender.FromClient;
            string encodedMessage = RobotMessage.Serialize(theMessage: sentMessage);
            // Send the message
            int bytesSent = client.Send(Encoding.ASCII.GetBytes(encodedMessage));

            Assert.AreNotEqual(0, bytesSent);

            // Checks message received
            Thread.Sleep(100);
            Assert.IsNotNull(server.LastMessage);
            Assert.AreNotEqual(string.Empty, server.LastMessage);
            Assert.AreEqual(sentMessage.Sender, RobotMessage.DeSerialize(server.LastMessage, typeof(RobotMessage)).Sender);

            // Disconnects from the server and check
            client.Disconnect(false);
            Assert.AreEqual(client.Connected, false);

            // Stops the server and checks
            server.Stop();
            Thread.Sleep(100);
            Assert.AreEqual(server.IsRunning, false);
        }
Exemple #9
0
 public RobotWithTCPServer()
 {
     Server = new Ev3TCPServer();
 }