public void ClientDisconnectsServer_ServerOnClientDisconnectCalled() { //Arrange //Create a second client ObjectTransport clientObjectTransport2 = TestObjectTransportFactory.CreateNewObjectTransport(Client2); clientObjectTransport2.Start("127.0.0.1", Server.LocalPort); //Wait for the connection to have been made Utilities.WaitFor(() => serverObjectTransport.GetConnectedClients().Count() == 2); //Act //disconnect the server from the client Client1ObjectTransport.DisconnectClient(); Utilities.WaitFor(() => ServerOnDisconnectClients.Count == 1); //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(ServerOnDisconnectClients.First().Port, Client1.LocalPort); }
public void ServerWith2Clients_ServerDisconnects1Client_1ClientDisconnected() { //Arrange ObjectTransport clientObjectTransport2 = TestObjectTransportFactory.CreateNewObjectTransport(Client2); clientObjectTransport2.Start("127.0.0.1", Server.LocalPort); //Wait for the connection to have been made Utilities.WaitFor(() => serverObjectTransport.GetConnectedClients().Count() == 2); var FirstClient = serverObjectTransport.GetConnectedClients().First(); //Act serverObjectTransport.DisconnectClient(FirstClient); Utilities.WaitFor(() => ServerOnDisconnectClients.Count() == 1); //Assert Client LastClient = serverObjectTransport.GetConnectedClients().First(); Assert.AreEqual(1, serverObjectTransport.GetConnectedClients().Count()); Assert.AreNotEqual(FirstClient.Port, LastClient.Port); }
public void Server_ServerDisconnects2Client_AllClientsDisconnected() { //Arrange //Create a second client ObjectTransport clientObjectTransport2 = TestObjectTransportFactory.CreateNewObjectTransport(Client2); clientObjectTransport2.Start("127.0.0.1", Server.LocalPort); //Wait for the connection to have been made Utilities.WaitFor(() => serverObjectTransport.GetConnectedClients().Count() == 2); //Act var allClients = serverObjectTransport.GetConnectedClients().ToArray(); serverObjectTransport.DisconnectClient(allClients); Utilities.WaitFor(() => ServerOnDisconnectClients.Count == 2); //Assert Assert.AreEqual(0, serverObjectTransport.GetConnectedClients().Count()); Assert.AreEqual(2, ServerOnDisconnectClients.Count()); }