public void ClearDb() { using (var context = new PogGamesContext(options)) { // clear the db context.Character.RemoveRange(context.Character); context.SaveChanges(); }; }
public async Task TestGetSuccessfully() { using (var context = new PogGamesContext(options)) { CharactersController charactersController = new CharactersController(context); ActionResult <IEnumerable <Character> > result = await charactersController.GetCharacter(); Assert.IsNotNull(result); } }
public void SetupDb() { using (var context = new PogGamesContext(options)) { //populate the db context.Character.Add(characters[0]); context.Character.Add(characters[1]); context.SaveChanges(); } }
public async Task TestPutCharacterNoContentStatusCode() { using (var context = new PogGamesContext(options)) { string newCharacter = "mccree"; Character character1 = context.Character.Where(x => x.CharName == characters[0].CharName).Single(); character1.CharName = newCharacter; CharactersController charactersController = new CharactersController(context); IActionResult result = await charactersController.PutCharacter(character1.ApiCharId, character1) as IActionResult; Assert.IsNotNull(result); Assert.IsInstanceOfType(result, typeof(NoContentResult)); } }
public async Task <ActionResult <Game> > PostGame([FromBody] NameDTO data) { Game game; String gameName; try { // Constructing the game object from our helper function gameName = data.gameName; game = GiantBombHelper.GetGameFromName(gameName); } catch { return(BadRequest("Invalid Game Name")); } //add the game object to database _context.Game.Add(game); await _context.SaveChangesAsync(); //Get the ID from the game (same ID from the API) string id = game.GameId; // This is needed because context are NOT thread safe, therefore we create another context for the following task. // We will be using this to insert characters into the database on a separate thread // So that it doesn't block the API. PogGamesContext tempContext = new PogGamesContext(); CharactersController characterController = new CharactersController(tempContext); // This will be executed in the background. Task addCharacters = Task.Run(async() => { // Get the list of characters from the GiantBombHelper List <Character> characters = new List <Character>(); characters = GiantBombHelper.GetCharacterFromGameId(id); foreach (Character chara in characters) { chara.GameId = id; Console.WriteLine(chara); // Add this Character to the database await characterController.PostCharacter(chara); } }); //return success code and game object return(CreatedAtAction("GetGame", new { id = game.GameId }, game)); }
public async Task TestDeleteSuccessfully() { using (var context = new PogGamesContext()) { CharactersController charactersController = new CharactersController(context); ActionResult <IEnumerable <Character> > result1 = await charactersController.GetCharacter(); ActionResult <Character> delete = await charactersController.DeleteCharacter("01"); ActionResult <IEnumerable <Character> > result2 = await charactersController.GetCharacter(); // Make sure that the characters list changed after delete Assert.AreNotEqual(result1, result2); } }
public async Task TestPostSuccessfully() { using (var context = new PogGamesContext(options)) { CharactersController charactersController = new CharactersController(context); Character chara = new Character() { ApiCharId = "03", CharName = "Mccree", GameId = "02" }; ActionResult <IEnumerable <Character> > result1 = await charactersController.GetCharacter(); ActionResult <Character> post = await charactersController.PostCharacter(chara); ActionResult <IEnumerable <Character> > result2 = await charactersController.GetCharacter(); //Asser that the lists are no longer equal Assert.AreNotEqual(result1, result2); } }
public CharactersController(PogGamesContext context) { _context = context; }
public GamesController(PogGamesContext context, IMapper mapper) { _context = context; _mapper = mapper; this.gameRepository = new GameRepository(new PogGamesContext()); }
public GameRepository(PogGamesContext context) { this.context = context; }