예제 #1
0
        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);
            }
        }
예제 #2
0
        internal Team GetById(int id)
        {
            var found = _repo.GetById(id);

            if (found == null)
            {
                throw new Exception("Invalid id");
            }
            return(found);
        }
예제 #3
0
        public ActionResult <Team> Get(int id)
        {
            Team found = _tr.GetById(id);

            if (found == null)
            {
                return(BadRequest());
            }
            return(Ok(found));
        }