public async Task GivenTwoAddressesInDatabase_WhenIDelete_ItDeletesTheCorrectAddress() { var address1 = GetNewAddress(); var address2 = GetNewAddress(); using (var context = new DefaultContext(DbContextOptions)) { var addressRepository = new AddressRepository(context); address1 = await addressRepository.CreateAsync(address1); address2 = await addressRepository.CreateAsync(address2); List <AddressDb> allAddresses = await context.Addresses.ToListAsync(); Assert.AreEqual(2, allAddresses.Count); } using (var context = new DefaultContext(DbContextOptions)) { var addressRepository = new AddressRepository(context); await addressRepository.DeleteAsync(address2.Id); List <AddressDb> allAddresses = await context.Addresses.ToListAsync(); Assert.AreEqual(1, allAddresses.Count); Assert.IsNull(await context.Addresses.FindAsync(address2.Id)); } }
public async Task <bool> Delete(string id) { DeleteResult result; try { result = await _addressRepository.DeleteAsync(x => x.Id == id); } catch (Exception) { return(false); } if (!result.IsAcknowledged) { return(false); } return(result.DeletedCount == 1); }