public async Task GetsTeamById() { using (var context = new ApplicationDbContext(_options)) { context.Teams.AddRange( new Team { Id = 1 }, new Team { Id = 2 }); context.SaveChanges(); } using (var context = new ApplicationDbContext(_options)) { var teamsRepository = new TeamsRepository(context); var team = await teamsRepository.GetById(1); var team2 = await teamsRepository.GetById(2); Assert.NotNull(team); Assert.NotNull(team2); Assert.Equal(1, team.Id); Assert.Equal(2, team2.Id); } }
internal Team GetById(int id) { var found = _repo.GetById(id); if (found == null) { throw new Exception("Invalid id"); } return(found); }
public ActionResult <Team> Get(int id) { Team found = _tr.GetById(id); if (found == null) { return(BadRequest()); } return(Ok(found)); }