示例#1
0
 public string RetrievePlayerPasswordById(Guid playerId)
 {
     using (var context = new GameServerEntities())
     {
         var playerRow = context.Players.Single(x => x.id == playerId);
         if (playerRow.Equals(null))
         {
             throw new EmptyResultsException();
         }
         return(playerRow.password);
     }
 }
示例#2
0
        public void CreatePlayer_DoesNotThrowException()
        {
            var playerId = Guid.NewGuid();
            var username = playerId.ToString();
            var password = "******";
            _controller.CreatePlayer(playerId, username, password);

            using (var context = new GameServerEntities())
            {
                var players = context.Players.Select(x => x.username);
                Assert.Contains(username, players);
            }
        }
示例#3
0
 public List <MatchResult> RetrieveAllMatchesByPlayerId(Guid playerId)
 {
     using (var context = new GameServerEntities())
     {
         var matches    = context.Matches.Where(x => x.Players.Select(y => y.id).Contains(playerId)).ToList();
         var resultList = new List <MatchResult>();
         if (matches.Count() != 0)
         {
             resultList = ModelConverter.FromRow.GetMatchResultsFromMatches(matches);
         }
         return(resultList);
     }
 }
示例#4
0
 public PlayerProfile RetrievePlayerByUsername(string username)
 {
     using (var context = new GameServerEntities())
     {
         var playerRow = context.Players.FirstOrDefault(x => x.username == username);
         if (playerRow == null)
         {
             throw new InvalidUsernameException();
         }
         var profile = ModelConverter.FromRow.GetPlayerProfileFromPlayer(playerRow);
         return(profile);
     }
 }
示例#5
0
        public void CreatePlayer(Guid userId, string username, string password)
        {
            using (var context = new GameServerEntities())
            {
                var player = new Player
                {
                    id       = userId,
                    username = username,
                    password = password,
                };

                context.Players.Add(player);
                context.SaveChanges();
            }
        }
示例#6
0
 public List <GameInformation> RetrieveGameList()
 {
     using (var context = new GameServerEntities())
     {
         var dataList = context.Games.ToList();
         if (dataList.Count == 0)
         {
             throw new EmptyResultsException();
         }
         var infoList = dataList
                        .Select(x => ModelConverter.FromRow.GetGameInformationFromGame(x))
                        .ToList();
         return(infoList);
     }
 }
示例#7
0
 public void StoreMatch(MatchState matchState)
 {
     using (var context = new GameServerEntities())
     {
         var players  = context.Players.Where(x => matchState.players.Contains(x.id)).ToList();
         var matchRow = ModelConverter.ToRow.GetMatchFromMatchState(matchState);
         if (players.Count == 0)
         {
             throw new EmptyResultsException();
         }
         matchRow.Players = players;
         context.Matches.Add(matchRow);
         context.SaveChanges();
     }
 }
示例#8
0
 public bool CheckUsernameExists(string username)
 {
     using (var context = new GameServerEntities())
     {
         var usernames = context.Players.ToList().Select(x => x.username).ToList();
         if (usernames.Count == 0)
         {
             throw new EmptyResultsException();
         }
         if (usernames.Contains(username))
         {
             return(true);
         }
         return(false);
     }
 }
示例#9
0
        public void StoreMatch_DoesNotThrowException()
        {
            var match = new MatchState
            {
                id = Guid.NewGuid(),
                gameStartTime = DateTime.Now,
                gameEndTime = DateTime.Now.AddHours(1),
                gameType = GameType.TicTacToe,
                operationState = GameOperationState.Completed,
                winnerId = _firstPlayer,
                playerTurnId = _firstPlayer,
                players = new List<Guid> { _firstPlayer, _secondPlayer },
                inGameState = new TicTacToeState
                {
                    firstPlayer = _firstPlayer,
                    secondPlayer = _secondPlayer,
                    board = new List<PlayerMark>(),
                }
            };
            _controller.StoreMatch(match);

            using (var context = new GameServerEntities())
            {
                var storedMatches = context.Matches.ToList();
                Assert.Contains(match.id, storedMatches.Select(x => x.id));
            }
        }