public async Task DeleteAsyncFunctioningCorrectly() { //Must add a Contact directly to Contacts collection for use when checking DeleteAsync var deleteEntity = new Contact { FirstName = "Mike", LastName = "Magee", Email = "*****@*****.**", PhoneNumber = "555-478-9856", ContactStatus = ApplicationCore.Enums.ContactStatusEnum.ActiveEnum }; _dbContext.Contacts.Add(deleteEntity); _dbContext.SaveChanges(); Assert.True(await _contactRepository.DeleteAsync(deleteEntity.Id)); var entityDeleted = await _dbContext.Contacts.FindAsync(deleteEntity.Id); Assert.NotNull(entityDeleted); Assert.Equal(deleteEntity, entityDeleted); //Check entity has been marked IsDeleted Assert.True(entityDeleted.IsDeleted); }
public async Task DeleteContactShouldRemoveContactPermanently() { using ContactRepository repo = new ContactRepository(_infrastructure); Contact contact = new Contact() { Email = "*****@*****.**", FirstName = "test1", LastName = "test2 ", MainAddress = new Address() { City = "Another City", CountryCode = "CH", PostalCode = "6233A", Street = "Testh Strasse", Number = "B3" } }; contact = await repo.InsertAsync(contact); int contactId = contact.ContactId; await repo.DeleteAsync(contactId); contact = await repo.GetAsync(contactId); Assert.IsNull(contact); }
public async Task <bool> DeleteContactAsync(Guid userId, int contactId) { // Testing to make sure contact submitted matches user. If not will throw ArgumentException. Contact contact = await GetContactAsync(userId, contactId); _logger.Information($"Deleting contact {contact.FullName} ({contact.ContactId})..."); int deleted = await _contactRepo.DeleteAsync(contactId); _logger.Information($"Contacts deleted: {deleted}"); return(deleted == 1); }
public async Task <bool> Delete(string id) { DeleteResult result; try { result = await _contactRepository.DeleteAsync(x => x.Id == id); } catch (Exception) { return(false); } if (!result.IsAcknowledged) { return(false); } return(result.DeletedCount == 1); }