public async Task RemoveVenueFromDb() { var options = new DbContextOptionsBuilder <BoboTuDbContext>() .UseInMemoryDatabase($"BoboTuDatabaseForTesting{Guid.NewGuid()}") .Options; var venueData = System.IO.File.ReadAllText(@"VenueDataSeed/venueDataSeed.json"); var venues = JsonConvert.DeserializeObject <List <Venue> >(venueData); int venueCount = 0; using (var context = new BoboTuDbContext(options)) { context.Venues.AddRange(venues); context.SaveChanges(); venueCount = context.Venues.Count(); } using (var context = new BoboTuDbContext(options)) { var venueRepo = new VenueRepository(context); var venue = (await venueRepo.GetAllVenuesAsync(new List <int>().ToArray(), new List <int>().ToArray())).First(); venueRepo.DeleteVenue(venue); await venueRepo.SaveChanges(); } using (var context = new BoboTuDbContext(options)) { var venueRepo = new VenueRepository(context); Assert.Equal(venueCount - 1, context.Venues.Count()); } }
public async Task RemoveVenue_Null_ThrowsArgumentException() { var options = new DbContextOptionsBuilder <BoboTuDbContext>() .UseInMemoryDatabase($"BoboTuDatabaseForTesting{Guid.NewGuid()}") .Options; var venueData = System.IO.File.ReadAllText(@"VenueDataSeed/venueDataSeed.json"); var venues = JsonConvert.DeserializeObject <List <Venue> >(venueData); int venueCount = 0; using (var context = new BoboTuDbContext(options)) { context.Venues.AddRange(venues); context.SaveChanges(); venueCount = context.Venues.Count(); } using (var context = new BoboTuDbContext(options)) { var venueRepo = new VenueRepository(context); await Assert.ThrowsAsync <ArgumentException>( // Act async() => { venueRepo.DeleteVenue(null); await venueRepo.SaveChanges(); } ); } }
public virtual IActionResult DeleteVenue([FromBody] Venue venue) { var result = _venueRepository.DeleteVenue((int)venue.VenueID); if (result) { return(Ok()); } return(NotFound()); }