Ejemplo n.º 1
0
        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);
            }
        }
Ejemplo n.º 2
0
 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();
     }
 }
Ejemplo n.º 3
0
        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();
                }
            }
        }
Ejemplo n.º 4
0
        public void QueryContactTypesEndToEnd()
        {
            var unitOfWorkPhoneBookData = new PhoneBookUnitOfWork();

            var contactTypes = new List<ContactType> {
                new ContactType() { Name = "Work" },
                new ContactType() { Name = "Cell phone" },
                new ContactType() { Name = "Home" }
            };

            var results = unitOfWorkPhoneBookData.ContactTypesRepository.GetEntities().OrderBy(e => e.Id).ToList();

            Assert.AreEqual(3, results.Count);
            Assert.AreEqual("Work", results[0].Name);
            Assert.AreEqual("Cell phone", results[1].Name);
            Assert.AreEqual("Home", results[2].Name);

            unitOfWorkPhoneBookData.Dispose();
        }
Ejemplo n.º 5
0
        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();
            }
        }