public void JoinAndLeavePrivateRoomTest() { var sgClientMock = new Mock <IEmailSender>(); var controller = new TextChatController(/*sgClientMock.Object*/); controller.JoinChat(AliceUserId, AliceTextChatUser); controller.JoinChat(BobUserId, BobTextChatUser); controller.JoinRoom(AliceUserId, EnglishRoomId); controller.JoinRoom(BobUserId, EnglishRoomId); Assert.AreEqual <int>(2, controller.GetState().Rooms[EnglishRoomId].Count, "Chat Room should contain 2 users."); //User join to private room RoomId privateRoomId = $"{AliceUserId}-{BobUserId}"; controller.JoinRoom(AliceUserId, privateRoomId); Assert.AreEqual <int>(1, controller.GetState().Rooms [privateRoomId].Count, "Private chat Room must contain 1 user."); //Single user leave private room controller.LeaveRoom(AliceUserId, privateRoomId); Assert.AreEqual <int>(1, controller.GetState().Rooms.Count, "Chat Model must contain 1 room (English)."); Assert.IsFalse(controller.GetState().Rooms.Keys.Contains(privateRoomId), $"Private room {privateRoomId} must not exist."); //Add new private room and 2 users joined to room controller.JoinRoom(AliceUserId, privateRoomId); Assert.AreEqual <int>(1, controller.GetState().Rooms [privateRoomId].Count, "Private chat Room must contain 1 user."); controller.JoinRoom(BobUserId, privateRoomId); Assert.AreEqual <int>(2, controller.GetState().Rooms [privateRoomId].Count, "Private chat Room must contain 2 users."); //First user leave private room controller.LeaveRoom(AliceUserId, privateRoomId); Assert.AreEqual <int>(2, controller.GetState().Rooms.Count, "Chat Model must contain 2 rooms."); Assert.IsTrue(controller.GetState().Rooms.Keys.Contains(privateRoomId), $"Private room {privateRoomId} must exist."); Assert.AreEqual <int>(1, controller.GetState().Rooms[privateRoomId].Count, "Private chat Room must contain 1 user."); //Second user leave private room controller.LeaveRoom(BobUserId, privateRoomId); Assert.AreEqual <int>(1, controller.GetState().Rooms.Count, "Chat Model must contain 1 room (English)."); Assert.IsFalse(controller.GetState().Rooms.Keys.Contains(privateRoomId), $"Private room {privateRoomId} must not exist."); //User created, joined private room and leave chat controller.JoinRoom(AliceUserId, privateRoomId); controller.LeaveChat(AliceUserId); Assert.AreEqual <int>(1, controller.GetState().Rooms.Count, "Chat Model must contain 1 room (English)."); Assert.IsFalse(controller.GetState().Rooms.Keys.Contains(privateRoomId), $"Private room {privateRoomId} must not exist."); }
public void LeaveRoomTest() { var sgClientMock = new Mock <IEmailSender>(); var controller = new TextChatController(/*sgClientMock.Object*/); controller.JoinChat(AliceUserId, AliceTextChatUser); controller.JoinChat(BobUserId, BobTextChatUser); controller.JoinChat(CarolUserId, CarolTextChatUser); controller.JoinRoom(AliceUserId, EnglishRoomId); controller.JoinRoom(BobUserId, EnglishRoomId); controller.JoinRoom(CarolUserId, EnglishRoomId); Assert.AreEqual <int>(3, controller.GetState().Rooms[EnglishRoomId].Count, "Chat Room should contain 3 users."); controller.LeaveRoom(AliceUserId, EnglishRoomId); Assert.AreEqual <int>(2, controller.GetState().Rooms[EnglishRoomId].Count, "Chat Room should contain 2 users."); controller.LeaveRoom(BobUserId, EnglishRoomId); controller.LeaveRoom(CarolUserId, EnglishRoomId); Assert.IsFalse(controller.GetState().Rooms.ContainsKey(EnglishRoomId), "Chat Room must not exist."); }