Exemplo n.º 1
0
        public async Task DeleteAdTests()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: "Delete_Ad")
                          .Options;

            var ad = new Ad {
                Id = 1
            };
            int countAfterAdd;
            int countAfterDelete;

            using (var db = new ApplicationDbContext(options))
            {
                db.Ads.Add(ad);
                db.SaveChanges();
                countAfterAdd = db.Ads.Count();

                AdService service = new AdService(db);
                await service.DeleteAd(ad.Id);

                countAfterDelete = db.Ads.Count();
            }

            Assert.NotEqual(countAfterAdd, countAfterDelete);
        }
Exemplo n.º 2
0
        public ActionResult DeleteConfirmed(int id)
        {
            Ad ad = adService.getbyId(id);

            adService.DeleteAd(id);
            return(RedirectToAction("Index"));
        }
Exemplo n.º 3
0
        public async Task <ActionResult <Ad> > DeleteAd(string id)
        {
            var ad = await adService.DeleteAd(id);

            if (ad == null)
            {
                return(NotFound());
            }

            return(ad);
        }