public async Task TestGameDetaillsByAnotherPassingGameId() { try { var result = await _gamesController.GetGameDetails(8); Assert.IsNotNull(result); Assert.IsInstanceOfType(((ObjectResult)result).Value, typeof(GamesDetailsDTOOut)); GamesDetailsDTOOut gamesDetailsDTOOut = (GamesDetailsDTOOut)((ObjectResult)result).Value; Assert.IsFalse(gamesDetailsDTOOut.gameDetailsView.Count == 0); Assert.AreEqual(gamesDetailsDTOOut.gameDetailsView.Count, 1); Assert.AreEqual(gamesDetailsDTOOut.gameDetailsView.ToList()[0].DeviceName, "Mobile"); } catch (Exception ex) { Assert.Fail(); } }
public async Task TestGameDetaillsByPassingNullParam() { try { var result = await _gamesController.GetGameDetails(null); Assert.IsNotNull(result); Assert.IsInstanceOfType(((ObjectResult)result).Value, typeof(GamesDetailsDTOOut)); GamesDetailsDTOOut gamesDetailsDTOOut = (GamesDetailsDTOOut)((ObjectResult)result).Value; Assert.IsFalse(gamesDetailsDTOOut.gameDetailsView.Count == 0); Assert.AreEqual(gamesDetailsDTOOut.gameDetailsView.Count, 15); Assert.AreEqual(gamesDetailsDTOOut.gameDetailsView.ToList()[1].GameCollections.Count, 2); } catch (Exception ex) { Assert.Fail(); } }
/// <summary> /// Used for fetching Game information based on gameId or fecth all by passing NUll from Databse. /// </summary> /// <param name="gameId"></param> /// <returns></returns> public static async Task <GamesDetailsDTOOut> GetGameDetails(int?gameId) { GamesDetailsDTOOut gamesDetailsDTOOut = new GamesDetailsDTOOut(); try { using (POCDB_testContext pOCDB_testContext = new POCDB_testContext()) { var gameIdParam = new SqlParameter("@gameId", SqlDbType.Int); gameIdParam.Value = (object)gameId ?? DBNull.Value; gamesDetailsDTOOut.gameDetailsView = await pOCDB_testContext.GetGamesDetaillsSP .FromSql("Exec dbo.[GetGamesDetaills] @gameId=@gameId", gameIdParam) .GroupBy(g => g.GameId) .Select(x => new GameDetailsView { Name = x.Select(g => g.Name).FirstOrDefault(), GameId = x.Key, Thumbnail = x.Select(g => g.Thumbnail).FirstOrDefault(), CategoryName = x.Select(g => g.CategoryName).FirstOrDefault(), DeviceName = x.Select(g => g.DeviceName).FirstOrDefault(), GameCollections = x.Select(gc => new Gamecollection { CollectionId = gc.GameCollectionId, Name = gc.GameCollectionName }).ToList() }).ToListAsync(); return(gamesDetailsDTOOut); } } catch (Exception ex) { return(null); } }