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

            if (found == null)
            {
                throw new Exception("Invalid id");
            }
            return(found);
        }
Beispiel #3
0
        public ActionResult <Player> Get(int id)
        {
            Player found = _pr.GetById(id);

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