コード例 #1
0
        public async Task deleteFriend(int playerId, int friendId)
        {
            var playerSide = _context.Friends.FirstOrDefault(f => f.PlayerId == playerId && f.FriendId == friendId);
            var friendSide = _context.Friends.FirstOrDefault(f => f.PlayerId == friendId && f.FriendId == playerId);

            if (playerSide != null)
            {
                _context.Friends.Remove(playerSide);
            }
            if (friendSide != null)
            {
                _context.Friends.Remove(friendSide);
            }
            await _context.SaveChangesAsync();
        }
コード例 #2
0
        public async Task UpdatePlayerScore(int gameId, int playerId, int score)
        {
            var player = await _context.GamePlayers.FirstOrDefaultAsync(p => p.PlayerId == playerId);

            player.TotalCorrect = score;
            _context.Update(player);

            await _context.SaveChangesAsync();
        }
コード例 #3
0
 /// <summary>
 /// Save changes async
 /// </summary>
 public async Task saveAsync()
 {
     await _context.SaveChangesAsync();
 }
コード例 #4
0
        public async Task CreatePlayer_PlayerIsValid_Success()
        {
            //arrange
            using var contextfactory        = new TestTriviaGameContextFactory();
            using TriviaRankContext context = contextfactory.CreateContext();

            var insertOwner = new Player
            {
                Username  = "******",
                Password  = "******",
                Birthday  = DateTime.Now,
                Points    = 100,
                FirstName = "Test",
                LastName  = "Player"
            };
            var insertPlayer = new Player
            {
                Username  = "******",
                Password  = "******",
                Birthday  = DateTime.Now,
                Points    = 100,
                FirstName = "TestPlayer",
                LastName  = "Playerlastname"
            };

            await context.AddAsync(insertOwner);

            await context.AddAsync(insertPlayer);

            await context.SaveChangesAsync();

            var insertPlayerModel = new PlayerModel
            {
                Id        = insertPlayer.Id,
                Username  = insertPlayer.Username,
                Password  = insertPlayer.Password,
                Birthday  = insertPlayer.Birthday,
                Points    = insertPlayer.Points,
                FirstName = insertPlayer.FirstName,
                LastName  = insertPlayer.LastName
            };

            var game = new Game
            {
                GameName       = "testgame1",
                GameMode       = true,
                OwnerId        = insertOwner.Id,
                StartDate      = DateTimeOffset.Now,
                EndDate        = DateTimeOffset.Now.AddMinutes(20.0),
                TotalQuestions = 10,
                IsPublic       = true
            };
            await context.AddAsync(game);

            await context.SaveChangesAsync();

            var repo = new GameRepository(context);

            //act

            var insertedId = await repo.AddPlayerToGame(game.Id, insertPlayerModel);

            var gp = await context.GamePlayers.Where(gp => gp.PlayerId == insertPlayer.Id).FirstOrDefaultAsync();

            //assert
            Assert.Equal(insertedId, gp.Id);
        }