Пример #1
0
        public async Task <GameLobby> AddGameLobby(int userId, List <GameSettingDto>?gameSettings = null)
        {
            var existingLobby = await GetLobbyByOwnerId(userId);

            if (existingLobby != null)
            {
                throw new UserAlreadyHaveALobbyException();
            }

            string gameCode = null;

            while (true)
            {
                gameCode = GenerateGameLobbyCode();
                var gameLobby = await GetGameLobbyById(gameCode);

                if (gameLobby == null)
                {
                    break;
                }
            }

            GameLobby lobby = new GameLobby
            {
                Code         = gameCode,
                LobbyOwnerId = userId,
                GameSettings = Map(gameSettings ?? new List <GameSettingDto>(), gameCode)
            };

            await _gameLobbyRepository.AddGameLobby(lobby);

            return(lobby);
        }
        public async Task AddGameLobbyToDb_Success()
        {
            //Arrange
            var gameLobby = TestData.GameLobbies.FlorisLobby !;

            //Act
            await _gameLobbyRepository.AddGameLobby(gameLobby);

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

            //Assert
            Assert.IsNotNull(lobby);
        }