Ejemplo n.º 1
0
        public void MapScoreTest()
        {
            D_Score sampleScoreD = new D_Score
            {
                ScoreId = 100,
                UserId  = 100,
                GameId  = 100,
                Score   = 5566,
                User    = new D_User
                {
                    Username = "******"
                },
                Game = new D_Game
                {
                    GameName = "Test Game Name."
                }
            };

            L_Score sampleScoreL = new L_Score
            {
                ScoreId  = 100,
                UserId   = 100,
                Username = "******",
                GameId   = 100,
                GameName = "Test Game Name.",
                Score    = 5566
            };

            L_Score resultScoreL = Mapper.MapScore(sampleScoreD);

            Assert.True(compareScoreL(resultScoreL, sampleScoreL));
        }
Ejemplo n.º 2
0
        /// <summary> Fetches one score related to its id.
        /// <param name="scoreId"> int (score id) </param>
        /// <returns> A single score related to input id </returns>
        /// </summary>
        public async Task <L_Score> GetScoreById(int scoreId)
        {
            _logger.LogInformation($"Retrieving score with id: {scoreId}");
            D_Score returnScore = await _dbContext.Scores
                                  .Include(p => p.User)
                                  .Include(p => p.Game)
                                  .FirstOrDefaultAsync(p => p.ScoreId == scoreId);

            return(Mapper.MapScore(returnScore));
        }
Ejemplo n.º 3
0
// ! XXXXXXXXXXXXXXXXXXXXXXXXXXXXX
// ! ---------  SCORE  -----------
// ! XXXXXXXXXXXXXXXXXXXXXXXXXXXXX
        public static L_Score MapScore(D_Score score)
        {
            return(new L_Score
            {
                ScoreId = score.ScoreId,
                UserId = score.UserId,
                Username = score.User.Username,
                GameId = score.GameId,
                GameName = score.Game.GameName,
                Score = score.Score
            });
        }
Ejemplo n.º 4
0
        /// <summary> Changes all score related to a particular existing score.
        /// <param name="inputScore"> object L_Score (name of object) - This is a logic object of type Score. </param>
        /// <returns> void </returns>
        /// </summary>
        public async Task UpdateScore(L_Score inputScore)
        {
            _logger.LogInformation($"Updating score with ID {inputScore.ScoreId}");
            D_Score currentEntity = await _dbContext.Scores
                                    .Include(p => p.User)
                                    .Include(p => p.Game)
                                    .FirstOrDefaultAsync(p => p.ScoreId == inputScore.ScoreId);

            D_Score newEntity = Mapper.UnMapScore(inputScore);

            _dbContext.Entry(currentEntity).CurrentValues.SetValues(newEntity);
            Save();
        }
Ejemplo n.º 5
0
 private bool compareScoreD(D_Score x, D_Score y)
 {
     if (
         x.GameId != y.GameId ||
         x.Score != y.Score ||
         x.ScoreId != y.ScoreId ||
         x.UserId != y.ScoreId
         )
     {
         return(false);
     }
     return(true);
 }
Ejemplo n.º 6
0
        /// <summary> Deletes one score related to a score id.
        /// <param name="scoreId"> int (score id) </param>
        /// <returns> void </returns>
        /// </summary>
        public async Task DeleteScoreById(int scoreId)
        {
            _logger.LogInformation($"Deleting score with ID {scoreId}");
            D_Score entity = await _dbContext.Scores
                             .Include(p => p.User)
                             .Include(p => p.Game)
                             .FirstOrDefaultAsync(p => p.ScoreId == scoreId);

            if (entity == null)
            {
                _logger.LogInformation($"Score ID {scoreId} not found to delete! : Returning.");
                return;
            }
            _dbContext.Remove(entity);
            Save();
        }
Ejemplo n.º 7
0
        /// <summary> Adds a new game data to the database.
        /// <param name="inputScore"> object L_Score (name of object) - This is a logic object of type score. </param>
        /// <returns> void </returns>
        /// </summary>
        public void AddScore(L_Score inputScore)
        {
            if (inputScore.ScoreId != 0)
            {
                _logger.LogWarning($"Score to be added has an ID ({inputScore.ScoreId}) already!");
                throw new ArgumentException("Id already exists when trying to add a new score!", $"{inputScore.ScoreId}");
            }

            _logger.LogInformation("Adding game.");

            D_Score entity = Mapper.UnMapScore(inputScore);

            entity.ScoreId = 0;
            _dbContext.Add(entity);
            Save();
        }
Ejemplo n.º 8
0
        public void UnMapScoreTest()
        {
            L_Score sampleScoreL = new L_Score
            {
                ScoreId  = 100,
                UserId   = 100,
                GameId   = 100,
                Score    = 5566,
                Username = "******",
                GameName = "Test Game Name."
            };

            D_Score sampleScoreD = new D_Score
            {
                ScoreId = 100,
                UserId  = 100,
                GameId  = 100,
                Score   = 5566
            };

            D_Score resultScoreD = Mapper.UnMapScore(sampleScoreL);

            Assert.True(compareScoreD(resultScoreD, sampleScoreD));
        }