public void AddContactEndToEnd() { using (var unitOfWorkPhoneBookData = new PhoneBookUnitOfWork()) { var newContact = new Contact() { FirstName = "Dan", LastName = "Gavrila", Number = "+40752278789" }; var contactTypeId = unitOfWorkPhoneBookData.ContactTypesRepository.GetEntities() .Where(c => c.Name == "Home") .Select(c => c.Id) .DefaultIfEmpty(0).FirstOrDefault(); if (contactTypeId > 0) newContact.ContactTypeId = contactTypeId; var addedContact = unitOfWorkPhoneBookData.ContactsRepository.Insert(newContact); unitOfWorkPhoneBookData.Save(); Assert.AreEqual(newContact, addedContact); } }
public void AddContactTypesEndToEnd() { using (var unitOfWorkPhoneBookData = new PhoneBookUnitOfWork()) { unitOfWorkPhoneBookData.ContactTypesRepository.Insert(new ContactType() { Name = "Work" }); unitOfWorkPhoneBookData.ContactTypesRepository.Insert(new ContactType() { Name = "Cell phone" }); unitOfWorkPhoneBookData.ContactTypesRepository.Insert(new ContactType() { Name = "Home" }); unitOfWorkPhoneBookData.Save(); } }
public void DeleteContactTypesEndToEnd() { using (var unitOfWorkPhoneBookData = new PhoneBookUnitOfWork()) { var contactTypes = unitOfWorkPhoneBookData.ContactTypesRepository.GetEntities().ToList(); if (contactTypes != null && contactTypes.Count > 0) { foreach (var ct in contactTypes) { unitOfWorkPhoneBookData.ContactTypesRepository.Delete(ct.Id); } unitOfWorkPhoneBookData.Save(); } } }
public void UpdateContactEndToEnd() { using (var unitOfWorkPhoneBookData = new PhoneBookUnitOfWork()) { var toBeModifiedContact = unitOfWorkPhoneBookData.ContactsRepository.GetEntities().Where(c => c.Id == 1).FirstOrDefault(); if (toBeModifiedContact != null) { toBeModifiedContact.FirstName = "Nad"; unitOfWorkPhoneBookData.ContactsRepository.Update(toBeModifiedContact); } else throw new AssertFailedException("Contact with Id 1 was not found in DB."); unitOfWorkPhoneBookData.Save(); var contact = unitOfWorkPhoneBookData.ContactsRepository.GetEntities().Where(c => c.Id == 1 && c.FirstName == "Nad").FirstOrDefault(); if (contact != null) Assert.AreEqual(toBeModifiedContact.FirstName, contact.FirstName); else throw new AssertFailedException(); } }