public async Task GivenTwoAddressesInDatabase_WhenIDelete_ItDeletesTheCorrectAddress() { var venue1 = GetNewVenue(); var venue2 = GetNewVenue(); using (var context = new DefaultContext(DbContextOptions)) { var venueRepository = new VenueRepository(context); venue1 = await venueRepository.CreateAsync(venue1); venue2 = await venueRepository.CreateAsync(venue2); List <VenueDb> allVenues = await context.Venues.ToListAsync(); Assert.AreEqual(2, allVenues.Count); } using (var context = new DefaultContext(DbContextOptions)) { var venueRepository = new VenueRepository(context); await venueRepository.DeleteAsync(venue2.Id); List <VenueDb> allVenues = await context.Venues.ToListAsync(); Assert.AreEqual(1, allVenues.Count); Assert.IsNull(await context.Venues.FindAsync(venue2.Id)); } }
public async void DeleteAsync_RemovesFromContext() { var venue = VenueGenerator.Create(); using (var context = new booking_facilitiesContext(contextOptions)) { context.Database.EnsureCreated(); context.Venue.Add(venue); context.SaveChanges(); Assert.Equal(1, await context.Venue.CountAsync()); var repository = new VenueRepository(context); await repository.DeleteAsync(venue); Assert.Equal(0, await context.Venue.CountAsync()); } }