public void MapGameTest() { D_Game sampleGameD = new D_Game { GameId = 100, GameName = "Test Game Name.", GameDescription = "Test Game Description", Reviews = new List <D_Review> { }, Scores = new List <D_Score> { }, Data = new List <D_GameData> { } }; L_Game sampleGameL = new L_Game { GameId = 100, GameName = "Test Game Name.", GameDescription = "Test Game Description", Reviews = new List <L_Review> { }, Scores = new List <L_Score> { }, Data = new List <L_GameData> { } }; L_Game resultGameL = Mapper.MapGame(sampleGameD); Assert.True(compareGameL(resultGameL, sampleGameL)); }
/// <summary> Fetches one game related to its id. /// <param name="gameId"> int (game id) </param> /// <returns> A single game related to input id </returns> /// </summary> public async Task <L_Game> GetGameById(int gameId) { _logger.LogInformation($"Retrieving game with id: {gameId}"); D_Game returnGame = await _dbContext.Games .Include(p => p.Scores) .Include(p => p.Reviews) .Include(p => p.Data) .FirstOrDefaultAsync(p => p.GameId == gameId); return(Mapper.MapGame(returnGame)); }
// ! XXXXXXXXXXXXXXXXXXXXXXXXXXXXX // ! --------- GAME ------------ // ! XXXXXXXXXXXXXXXXXXXXXXXXXXXXX public static L_Game MapGame(D_Game game) { return(new L_Game { GameId = game.GameId, GameName = game.GameName, GameDescription = game.GameDescription, Reviews = game.Reviews.Select(MapReview).ToList(), Scores = game.Scores.Select(MapScore).ToList(), Data = game.Data.Select(MapGameData).ToList() }); }
private bool compareGameD(D_Game x, D_Game y) { if ( x.GameId != y.GameId || x.GameDescription != y.GameDescription || x.GameName != y.GameName ) { return(false); } return(true); }
/// <summary> Changes all game related to a particular existing game. /// <param name="inputGame"> object L_Game (name of object) - This is a logic object of type game. </param> /// <returns> void </returns> /// </summary> public async Task UpdateGame(L_Game inputGame) { _logger.LogInformation($"Updating game with ID {inputGame.GameId}"); D_Game currentEntity = await _dbContext.Games .Include(p => p.Scores) .Include(p => p.Reviews) .Include(p => p.Data) .FirstOrDefaultAsync(p => p.GameId == inputGame.GameId); D_Game newEntity = Mapper.UnMapGame(inputGame); _dbContext.Entry(currentEntity).CurrentValues.SetValues(newEntity); Save(); }
/// <summary> Adds a new game to the database. /// <param name="inputGame"> object L_Game (name of object) - This is a logic object of type game. </param> /// <returns> void </returns> /// </summary> public void AddGame(L_Game inputGame) { if (inputGame.GameId != 0) { _logger.LogWarning($"Game to be added has an ID ({inputGame.GameId}) already!"); throw new ArgumentException("Id already exists when trying to add a new game!", $"{inputGame.GameId}"); } _logger.LogInformation("Adding game."); D_Game entity = Mapper.UnMapGame(inputGame); entity.GameId = 0; _dbContext.Add(entity); Save(); }
/// <summary> Deletes one game related to a game id. /// <param name="gameId"> int (game id) </param> /// <returns> void </returns> /// </summary> public async Task DeleteGameById(int gameId) { _logger.LogInformation($"Deleting game with ID {gameId}"); D_Game entity = await _dbContext.Games .Include(p => p.Scores) .Include(p => p.Reviews) .Include(p => p.Data) .FirstOrDefaultAsync(p => p.GameId == gameId); if (entity == null) { _logger.LogInformation($"Game ID {gameId} not found to delete! : Returning."); return; } _dbContext.Remove(entity); Save(); }
public void UnMapGameTest() { L_Game sampleGameL = new L_Game { GameId = 100, GameName = "Test Game Name.", GameDescription = "Test Game Description", }; D_Game sampleGameD = new D_Game { GameId = 100, GameName = "Test Game Name.", GameDescription = "Test Game Description", }; D_Game resultGameD = Mapper.UnMapGame(sampleGameL); Assert.True(compareGameD(resultGameD, sampleGameD)); }