예제 #1
0
        public void Delete_NoData_ReturnsNull()
        {
            var options = new DbContextOptionsBuilder <GameInfoContext>()
                          .UseInMemoryDatabase(databaseName: "NoRaces_Db_ForDelete")
                          .Options;

            using (var context = new GameInfoContext(options))
            {
                var service = new RacesService(context, null);
                Assert.False(service.Delete(2));
            }
        }
예제 #2
0
        public async Task <ActionResult <string> > Delete(int id)
        {
            try
            {
                Profile userInfo = await HttpContext.GetUserInfoAsync <Profile>();

                return(Ok(_service.Delete(id, userInfo.Id)));
            }
            catch (Exception e)
            {
                return(BadRequest(e.Message));
            }
        }
예제 #3
0
        public void Delete_WithData_DeletesRace()
        {
            var options = new DbContextOptionsBuilder <GameInfoContext>()
                          .UseInMemoryDatabase(databaseName: "Db_WithRace_ForDelete")
                          .Options;

            using (var context = new GameInfoContext(options))
            {
                context.Races.Add(new Race()
                {
                    Name = "ToDelete", Description = "No Desc"
                });
                context.SaveChanges();
            }

            using (var context = new GameInfoContext(options))
            {
                var service = new RacesService(context, null);
                var result  = service.Delete(1);

                Assert.True(result);
                Assert.Equal(0, context.Races.Count());
            }
        }