public async Task AllGameSettingsAdded()
        {
            //Arrange
            var gameLobby = TestData.GameLobbies.FlorisLobby !;

            //Act
            GameLobby lobby = await _gameLobbyRepository.GetGameLobbyByLobbyCode(gameLobby.Code);

            IEnumerable <GameSetting> gameSetting = await _gameLobbyRepository.GetGameSettingsByGameCode(gameLobby.Code);

            List <GameSetting> gameSettingList = gameSetting.ToList();

            //Assert
            Assert.AreEqual(2, gameSettingList.Count());
        }
예제 #2
0
        public async Task AddToLobby(int userId, string gameCode)
        {
            try
            {
                await _addingUserToLobbySemaphore.WaitAsync();

                var users = await _userRepository.GetUsersByGameCode(gameCode);

                int numberOfUsers = users.Count();
                var gameSettings  = await _gameLobbyRepository.GetGameSettingsByGameCode(gameCode);

                int maxPlayers = Convert.ToInt32(gameSettings.First(s => s.SettingType == "MaxPlayers").Value);

                if (numberOfUsers >= maxPlayers)
                {
                    throw new LobbyIsFullException("Too many players");
                }
                await _userRepository.AddUserToLobby(userId, gameCode);
            }
            finally
            {
                _addingUserToLobbySemaphore.Release();
            }
        }
예제 #3
0
        public async Task <List <GameSetting> > GetGameSettingsByGameId(string gameCode)
        {
            IEnumerable <GameSetting> gameSettingList = await _gameLobbyRepository.GetGameSettingsByGameCode(gameCode);

            return(gameSettingList.ToList());
        }