public ActionResult <String> DeletePoll(int Id) { try { return(_ps.DeletePoll(Id)); } catch (Exception e) { return(BadRequest(e.Message)); } }
public void DeletePollShouldDeletePollFromDatabase() { var options = new DbContextOptionsBuilder <ApplicationDbContext>().UseInMemoryDatabase("Database_For_Tests").Options; var dbContext = new ApplicationDbContext(options); var service = new PollsService(dbContext); dbContext.Polls.Add(new Poll()); dbContext.Polls.Add(new Poll()); dbContext.Polls.Add(new Poll()); dbContext.SaveChanges(); var poll = dbContext.Polls.First(); service.DeletePoll(poll); Assert.Equal(2, dbContext.Polls.Count()); }