public void SameClientIdEnterToMultipleRoomsLeavesPrevRoomTestMethod() { var server = new EchoRoomServer(TimeSpan.FromMilliseconds(1000)); var networkId1 = new object(); var networkId2 = new object(); var client1 = server.EnterInRoom("client", networkId1, "room1"); var client2 = server.EnterInRoom("client", networkId2, "room2"); Assert.AreEqual(3, server.GetMessagesToSendCount()); }
public void EnterToExpiredRoomTestMethod() { var server = new EchoRoomServer(TimeSpan.FromMilliseconds(50)); var networkId1 = new object(); var networkId2 = new object(); var client1 = server.EnterInRoom("client1", networkId1, "room"); Thread.Sleep(100); var client2 = server.EnterInRoom("client2", networkId2, "room"); Assert.AreEqual(2, server.GetMessagesToSendCount()); }
public void EnterTestMethod() { var server = new EchoRoomServer(TimeSpan.FromMilliseconds(1000)); var networkId = new object(); var client = server.EnterInRoom("client", networkId, "room"); Assert.IsNotNull(client); Assert.AreEqual("client", client.Id); Assert.AreSame(networkId, client.NetworkId); Assert.AreEqual(1, server.GetMessagesToSendCount()); }
public void GetMessageToSendTestMethod() { var server = new EchoRoomServer(TimeSpan.FromMilliseconds(1000)); var networkId = new object(); var client = server.EnterInRoom("client", networkId, "room"); Message message = server.GetMessageToSend(); Assert.IsNotNull(message); Assert.AreEqual(MessageType.System, message.MessageType); Assert.AreEqual("client", message.Client.Id); Assert.AreEqual("client", message.Author.Id); }
public void CleanupExpiredRoomTestMethod() { var server = new EchoRoomServer(TimeSpan.FromMilliseconds(50)); var networkId1 = new object(); var client1 = server.EnterInRoom("client1", networkId1, "room"); server.DropSilentRooms(); Assert.AreEqual(1, server.RoomsCount); Thread.Sleep(100); server.DropSilentRooms(); Assert.AreEqual(0, server.RoomsCount); }
/// <summary> /// Login process for client /// it's done simple - client send two lines: /// login /// room /// all lines after that is messages /// </summary> /// <param name="tcpClient"></param> /// <param name="reader"></param> /// <returns></returns> private static async Task <IClient> Login(TcpClient tcpClient, StreamReader reader) { var clientId = await reader.ReadLineAsync(); if (clientId == null) { return(null); } var roomName = await reader.ReadLineAsync(); if (roomName == null) { return(null); } // TODO: in real world apps some auth suggested return(EchoRoomServer.EnterInRoom(clientId, tcpClient, roomName)); }