public async Task SuccessfulJoin()
        {
            await JoinMm(1);

            var stats = _mmApplication.GetStats();

            await _client1.WaitFor <JoinInfoEvent>(e => true);

            await _client1.Send <LeaveMatchMakingResponse>(new LeaveMatchMakingRequest());

            stats = _mmApplication.GetStats();
            Assert.AreEqual(0, stats.TotalPlayers);
        }
        public void IntegrationTest()
        {
            var isSuccess = false;

            //create 12 clients and connect them to mm
            for (var i = 0; i < CLIENTS_NUMBER_1; i++)
            {
                var client = new TestClientPeer(_clientLogger, taskSchedulerFactory, serializer);
                client.Connect(CLIENT_CONNECTS_TO_IP, SERVER_PORT_MM);
                _clients.Add(client);
                EmptyTask.Wait(WAIT_TIMEOUT);
            }

            //send auth
            _clients.ForEach(c => c.Send <AuthorizationResponse>(new AuthorizationRequest()).Wait());

            //send join matchmaking (with level = 1)
            _clients.ForEach(c => c.Send <EnterMatchMakingResponse>(new EnterMatchMakingRequest(new Dictionary <byte, object> {
                { FakePropertyCodes.PlayerProperties.Level, 1 }
            })).Wait());
            _clients.ForEach(c => c.WaitFor <JoinInfoEvent>(e => e.JoinInfo != null && e.JoinInfo.Status == JoinStatus.RoomIsReady));

            var mmStats = _mmApplication.GetStats();

            Assert.AreEqual(1, mmStats.RegisteredServers.Count);

            //sending leave mathmaking request
            _clients.ForEach(c => c.Send <LeaveMatchMakingResponse>(new LeaveMatchMakingRequest()).Wait());
            _clients.ForEach(c => c.Disconnect());

            mmStats = _mmApplication.GetStats();
            Assert.AreEqual(0, mmStats.TotalPlayers);
            Assert.AreEqual(1, mmStats.RegisteredServers.Count);

            //connect to server
            _clients.ForEach(c => c.Connect(c.GetJoinInfo().ServerIpAddress.ToString(), c.GetJoinInfo().ServerPort));
            var roomId = _clients.First().GetJoinInfo().RoomId;

            EmptyTask.Wait(MM_TICK * 2);
            var stats = _gameApplication.GetStats();

            Assert.AreEqual(CLIENTS_NUMBER_1, stats.PeerCount);
            Assert.AreEqual(1, stats.RoomCount);
            var roomsPeerCount = stats.RoomsPeerCount.First();

            //players did not join room yet
            Assert.AreEqual(roomId, roomsPeerCount.Key);
            Assert.AreEqual(0, roomsPeerCount.Value);

            //authing
            _clients.ForEach(c =>
            {
                var sessionId = Guid.NewGuid();
                c.SessionId   = sessionId;
                c.Send <AuthorizationResponse>(new AuthorizationRequest()
                {
                    SessionId = sessionId
                });
            });
            EmptyTask.Wait(WAIT_TIMEOUT);

            //joining room
            _clients.ForEach(c => c.Send <JoinRoomResponse>(new JoinRoomRequest(roomId, new Dictionary <byte, object>())));
            EmptyTask.Wait(WAIT_TIMEOUT);
            stats          = _gameApplication.GetStats();
            roomsPeerCount = stats.RoomsPeerCount.First();

            //players joined room
            Assert.AreEqual(roomId, roomsPeerCount.Key);
            Assert.AreEqual(CLIENTS_NUMBER_1, roomsPeerCount.Value);

            //activity
            //each client sends 1000 events to others
            _clients.ForEach(c =>
            {
                for (int i = 0; i < EVENTS_SENT; i++)
                {
                    c.SendEvent(new TestRoomEvent(true, 122, 4.668f, new List <int>()));
                }
            });

            EmptyTask.Wait(WAIT_TIMEOUT * 100);

            isSuccess = true;
            _clients.ForEach(c =>
            {
                if (c.CountOf <TestRoomEvent>() != (CLIENTS_NUMBER_1 - 1) * EVENTS_SENT)
                {
                    _clientLogger.Error($"test events {c.CountOf<TestRoomEvent>()}/{(CLIENTS_NUMBER_1 - 1) * EVENTS_SENT}");
                    isSuccess = false;
                }
            });
            Assert.IsTrue(isSuccess);

            //disconnect from server
            _clients.ForEach(c => c.Disconnect());
            EmptyTask.Wait(WAIT_TIMEOUT);
            stats = _gameApplication.GetStats();
            Assert.AreEqual(0, stats.PeerCount);
        }