public async Task GetGameById_WithGenre() { // Arrange var testGenre = new GenreModel() { GenreId = _fixture.Create <int>(), GenreName = _fixture.Create <string>() }; var testGame = new GameModel() { GameId = _fixture.Create <int>(), GameName = _fixture.Create <string>() }; var testGameGenre = new GameGenreModel() { GameGenreId = _fixture.Create <int>(), GameId = testGame.GameId, GenreId = testGenre.GenreId }; var publisherDbSet = CreateDbSetMock(new List <PublisherModel>() { }); // Empty as we're not testing this var genreDbSet = CreateDbSetMock(new List <GenreModel> { testGenre }); // Same var gameGenreDbSet = CreateDbSetMock(new List <GameGenreModel> { testGameGenre }); // Same _videoGameContextMock.Setup(x => x.Games.FindAsync(It.IsAny <int>())).ReturnsAsync(testGame); _videoGameContextMock.Setup(x => x.Publishers).Returns(publisherDbSet.Object); _videoGameContextMock.Setup(x => x.Genres).Returns(genreDbSet.Object); _videoGameContextMock.Setup(x => x.GamesGenres).Returns(gameGenreDbSet.Object); // Act var gameResult = await _gameRepo.GetGameById(testGame.GameId); // Assert Assert.AreEqual(testGame.GameId, gameResult.Value.GameId); Assert.AreEqual(testGame.GameName, gameResult.Value.GameName); Assert.AreEqual(testGame.Genres.Count, 1); Assert.AreEqual(testGame.Genres.First(), testGenre.GenreName); }
public async Task AddGenreToGameByDescription(int gameId, string genreDescription) { if (gameId != 0 && !string.IsNullOrEmpty(genreDescription)) { var genreId = await AddGenre(genreDescription); var gameGenre = new GameGenreModel { GameId = gameId, GenreId = genreId }; var genreGameDB = await _tagDbAccess.GetGameGenre(gameGenre); if (genreGameDB == null) { _tagDbAccess.AddGenreToGame(gameGenre); } } else { throw new Exception("String cannot be null or empty"); } }
public async void AddGenreToGame(GameGenreModel gameAddGenreModel) { string query = $@"INSERT INTO GameGenre (GameId, GenreId) VALUES(@GameId, @GenreId)"; await SaveDataAsync(query, gameAddGenreModel); }
public async Task <GameGenreModel> GetGameGenre(GameGenreModel gameGenre) { string query = @"SELECT * FROM GameGenre WHERE GameId=@GameId AND GenreId=@GenreId"; return(await GetSingleDataAsync <GameGenreModel>(query, gameGenre)); }