예제 #1
0
        public void UDPClient_ServerDisconnects_ClientDisconnectCallbackCalled()
        {
            //Arrange
            Client client           = null;
            Client clientDisconnect = null;

            udpServer.Start("127.0.0.1", 0);
            ObjectTransport serverObjectTransport = TestObjectTransportFactory.CreateNewObjectTransport(udpServer);

            udpClient.Start("127.0.0.1", udpServer.LocalPort);
            ObjectTransport clientObjectTransport = TestObjectTransportFactory.CreateNewObjectTransport(udpClient);

            clientObjectTransport.OnClientDisconnect(c => clientDisconnect = c);
            client = clientObjectTransport.GetConnectedClients().First();

            Utilities.WaitFor(ref client);
            Utilities.WaitFor(() => serverObjectTransport.GetConnectedClients().Count() == 1);
            //Act

            serverObjectTransport.Stop();

            Utilities.WaitFor(ref clientDisconnect);

            //Assert
            Assert.AreEqual(client.IPAddress, "127.0.0.1");
            Assert.AreEqual(clientDisconnect.IPAddress, "127.0.0.1");
            Assert.AreEqual(clientDisconnect, client);
            Utilities.WaitFor(() => clientObjectTransport.GetConnectedClients().Count() == 0);
            Utilities.WaitFor(() => serverObjectTransport.GetConnectedClients().Count() == 0);
        }
예제 #2
0
        public void UDPServer_WhenClientConnects_CallbackFunctionCalled()
        {
            bool connected = false;

            udpServer.Start("127.0.0.1", 0);
            udpServer.OnClientConnect(c => connected = true);

            udpClient.Start("127.0.0.1", udpServer.LocalPort);

            Utilities.WaitFor(ref connected);
            Assert.IsTrue(connected);
        }
예제 #3
0
        public void UDPServerWith2Clients_Disconnect2Client_AllClientsDisconnected()
        {
            //Arrange
            List <Client> disconnectedClients = new List <Client>();

            udpServer.Start("127.0.0.1", 0);
            ObjectTransport serverObjectTransport = TestObjectTransportFactory.CreateNewObjectTransport(udpServer);

            serverObjectTransport.OnClientDisconnect(c => disconnectedClients.Add(c));

            udpClient.Start("127.0.0.1", udpServer.LocalPort);
            ObjectTransport clientObjectTransport = TestObjectTransportFactory.CreateNewObjectTransport(udpClient);

            udpClient2.Start("127.0.0.1", udpServer.LocalPort);
            ObjectTransport clientObjectTransport2 = TestObjectTransportFactory.CreateNewObjectTransport(udpClient2);

            Utilities.WaitFor(() => serverObjectTransport.GetConnectedClients().Count() == 2);

            //Act

            var allClients = serverObjectTransport.GetConnectedClients().ToArray();

            serverObjectTransport.DisconnectClient(allClients);

            Utilities.WaitFor(() => disconnectedClients.Count == 2);

            //Assert
            Assert.AreEqual(0, serverObjectTransport.GetConnectedClients().Count());
            Assert.AreEqual(2, disconnectedClients.Count());
        }
예제 #4
0
        public void UDPServerWith2Clients_Disconnect1Client_1ClientDisconnected()
        {
            //Arrange
            Client disconnectedClient = null;

            udpServer.Start("127.0.0.1", 0);
            ObjectTransport serverObjectTransport = TestObjectTransportFactory.CreateNewObjectTransport(udpServer);

            serverObjectTransport.OnClientDisconnect(c => disconnectedClient = c);

            udpClient.Start("127.0.0.1", udpServer.LocalPort);
            ObjectTransport clientObjectTransport = TestObjectTransportFactory.CreateNewObjectTransport(udpClient);

            udpClient2 = new UDPClientChannel();
            udpClient2.Start("127.0.0.1", udpServer.LocalPort);
            ObjectTransport clientObjectTransport2 = TestObjectTransportFactory.CreateNewObjectTransport(udpClient2);

            Utilities.WaitFor(() => serverObjectTransport.GetConnectedClients().Count() == 2);

            //Act

            var FirstClient = serverObjectTransport.GetConnectedClients().First();

            serverObjectTransport.DisconnectClient(FirstClient);

            Utilities.WaitFor(ref disconnectedClient);

            //Assert
            Client LastClient = serverObjectTransport.GetConnectedClients().First();

            Assert.AreEqual(1, serverObjectTransport.GetConnectedClients().Count());
            Assert.AreNotEqual(FirstClient.Port, LastClient.Port);
        }
예제 #5
0
        public static Tuple <ObjectTransport, ObjectTransport> GetConnectObjectTransports()
        {
            server = new UDPServerChannel();
            server.Start("127.0.0.1", 0);

            ObjectTransport serverObjectTransport = TestObjectTransportFactory.CreateNewObjectTransport(server);

            udpclient = new UDPClientChannel();
            udpclient.Start("127.0.0.1", server.LocalPort);
            ObjectTransport client = TestObjectTransportFactory.CreateNewObjectTransport(udpclient);

            Tuple <ObjectTransport, ObjectTransport> result = new Tuple <ObjectTransport, ObjectTransport>(serverObjectTransport, client);

            return(result);
        }
예제 #6
0
        public void UDPClient_ClientDisconnectsServer_ServerOnClientDisconnectCalled()
        {
            //Arrange
            Client disconnectedClient = null;
            Client connectedServer    = null;

            udpServer.Start("127.0.0.1", 0);
            ObjectTransport serverObjectTransport = TestObjectTransportFactory.CreateNewObjectTransport(udpServer);

            serverObjectTransport.OnClientDisconnect(c => disconnectedClient = c);

            udpClient.Start("127.0.0.1", udpServer.LocalPort);
            ObjectTransport clientObjectTransport = TestObjectTransportFactory.CreateNewObjectTransport(udpClient);

            clientObjectTransport.OnClientConnect(c => connectedServer = c);

            udpClient2 = new UDPClientChannel();
            udpClient2.Start("127.0.0.1", udpServer.LocalPort);
            ObjectTransport clientObjectTransport2 = TestObjectTransportFactory.CreateNewObjectTransport(udpClient2);

            Utilities.WaitFor(() => serverObjectTransport.GetConnectedClients().Count() == 2);

            //Act

            //disconnect the server from the client
            clientObjectTransport.DisconnectClient();

            Utilities.WaitFor(ref disconnectedClient);

            //Assert
            //Ensure that the client record was disconnect from the server
            Assert.AreEqual(1, serverObjectTransport.GetConnectedClients().Count());

            //Esnure that the client who disconnected from the server was the one that we called disconect
            Assert.AreEqual(disconnectedClient.Port, udpClient.LocalPort);
        }