public async Task GetsPlayerById() { using (var context = new ApplicationDbContext(_options)) { context.Players.AddRange( new Player { Id = 1 }, new Player { Id = 2 }); context.SaveChanges(); } using (var context = new ApplicationDbContext(_options)) { var playersRepository = new PlayersRepository(context); var player = await playersRepository.GetById(1); var player2 = await playersRepository.GetById(2); Assert.NotNull(player); Assert.NotNull(player2); Assert.Equal(1, player.Id); Assert.Equal(2, player2.Id); } }
internal Player GetById(int id) { var found = _repo.GetById(id); if (found == null) { throw new Exception("Invalid id"); } return(found); }
public ActionResult <Player> Get(int id) { Player found = _pr.GetById(id); if (found == null) { return(BadRequest()); } return(Ok(found)); }