public void GetAnExistingContactReturnEntity()
        {
            var entity = ContactEntityObjectMother.Random();

            entity.AddEmailAddress(EmailValueObjectObjectMother.Random());
            entity.AddEmailAddress(EmailValueObjectObjectMother.Random());
            entity.AddEmailAddress(EmailValueObjectObjectMother.Random());
            entity.AddPhoneNumber(PhoneValueObjectObjectMother.Random());
            entity.AddPhoneNumber(PhoneValueObjectObjectMother.Random());
            _repo.Add(entity);
            _context.SaveChanges();

            var fromRepo = _repo.GetById(entity.Id);

            Assert.IsNotNull(fromRepo);
            Assert.AreEqual(entity.Id, fromRepo.Id);
            Assert.AreEqual(entity.Name, fromRepo.Name);
            Assert.AreEqual(entity.EmailAddresses.Count, fromRepo.EmailAddresses.Count);
            Assert.AreEqual(entity.PhoneNumbers.Count, fromRepo.PhoneNumbers.Count);

            foreach (var email in entity.EmailAddresses)
            {
                Assert.IsTrue(fromRepo.EmailAddresses.Contains(email));
            }

            foreach (var phone in entity.PhoneNumbers)
            {
                Assert.IsTrue(fromRepo.PhoneNumbers.Contains(phone));
            }
        }
Esempio n. 2
0
        public void ObjectsWithSameValuesAreEquals()
        {
            var random = PhoneValueObjectObjectMother.Random();

            var vo1 = new PhoneValueObject(random.PhoneType, random.PhoneNumber);
            var vo2 = new PhoneValueObject(random.PhoneType, random.PhoneNumber);

            Assert.NotNull(vo1);
            Assert.NotNull(vo2);
            Assert.AreEqual(vo1, vo2);
        }
Esempio n. 3
0
        public void ContactAddPhoneNumbersAddNonExistingOrNull()
        {
            var contact = ContactEntityObjectMother.Random();
            var phone1  = PhoneValueObjectObjectMother.Random();

            contact.AddPhoneNumber(phone1);
            contact.AddEmailAddress(null);
            contact.AddPhoneNumber(phone1);

            Assert.AreEqual(1, contact.PhoneNumbers.Count);
            Assert.IsTrue(contact.PhoneNumbers.Contains(phone1));
        }
Esempio n. 4
0
        public void ContactAddPhoneNumbersAddsPhoneNumbers()
        {
            var contact = ContactEntityObjectMother.Random();
            var phone1  = PhoneValueObjectObjectMother.Random();
            var phone2  = PhoneValueObjectObjectMother.Random();

            contact.AddPhoneNumber(phone1);
            contact.AddPhoneNumber(phone2);

            Assert.AreEqual(2, contact.PhoneNumbers.Count);
            Assert.IsTrue(contact.PhoneNumbers.Contains(phone1));
            Assert.IsTrue(contact.PhoneNumbers.Contains(phone2));
        }
Esempio n. 5
0
        public void ContactRemoveAllPhoneNumbersRemoveAllPhoneNumbers()
        {
            var contact = ContactEntityObjectMother.Random();
            var phone1  = PhoneValueObjectObjectMother.Random();
            var phone2  = PhoneValueObjectObjectMother.Random();

            contact.AddPhoneNumber(phone1);
            contact.AddPhoneNumber(phone2);

            contact.RemoveAllPhoneNumbers();

            Assert.AreEqual(0, contact.PhoneNumbers.Count);
        }
Esempio n. 6
0
        public void ContactRemovePhoneNumberDoesNotThrowError()
        {
            var contact = ContactEntityObjectMother.Random();
            var phone1  = PhoneValueObjectObjectMother.Random();
            var phone2  = PhoneValueObjectObjectMother.Random();

            contact.AddPhoneNumber(phone1);

            contact.RemovePhoneNumber(phone2);

            Assert.AreEqual(1, contact.PhoneNumbers.Count);
            Assert.IsTrue(contact.PhoneNumbers.Contains(phone1));
        }
        public void AddContactAddTheEntity()
        {
            var entity = ContactEntityObjectMother.Random();

            entity.AddEmailAddress(EmailValueObjectObjectMother.Random());
            entity.AddEmailAddress(EmailValueObjectObjectMother.Random());
            entity.AddEmailAddress(EmailValueObjectObjectMother.Random());
            entity.AddPhoneNumber(PhoneValueObjectObjectMother.Random());
            entity.AddPhoneNumber(PhoneValueObjectObjectMother.Random());

            _repo.Add(entity);

            _context.SaveChanges();
            VerifySaved(entity);
        }
        public void DeleteRemoveTheContact()
        {
            var entity = ContactEntityObjectMother.Random();

            entity.AddEmailAddress(EmailValueObjectObjectMother.Random());
            entity.AddEmailAddress(EmailValueObjectObjectMother.Random());
            entity.AddEmailAddress(EmailValueObjectObjectMother.Random());
            entity.AddPhoneNumber(PhoneValueObjectObjectMother.Random());
            entity.AddPhoneNumber(PhoneValueObjectObjectMother.Random());
            _repo.Add(entity);
            _context.SaveChanges();

            _repo.Delete(entity.Id);

            _context.SaveChanges();
            Assert.IsFalse(_context.Contacts.Any(x => x.Id == entity.Id.Value));
            Assert.IsFalse(_context.ContactEmails.Any(x => x.ContactId == entity.Id.Value));
            Assert.IsFalse(_context.ContactPhones.Any(x => x.ContactId == entity.Id.Value));
        }
Esempio n. 9
0
        public void ContactAddPhonesListAddAllValidAndNoRepeated()
        {
            var contact = ContactEntityObjectMother.Random();
            var phone1  = PhoneValueObjectObjectMother.Random();
            var phone2  = PhoneValueObjectObjectMother.Random();

            contact.AddPhoneNumbers(new List <Tuple <PhoneType, string> >
            {
                new Tuple <PhoneType, string>(phone1.PhoneType, phone1.PhoneNumber),
                new Tuple <PhoneType, string>(phone2.PhoneType, phone2.PhoneNumber),
                null,
                new Tuple <PhoneType, string>(phone1.PhoneType, phone1.PhoneNumber),
                new Tuple <PhoneType, string>(phone2.PhoneType, phone2.PhoneNumber)
            });


            Assert.AreEqual(2, contact.PhoneNumbers.Count);
            Assert.IsTrue(contact.PhoneNumbers.Contains(phone1));
            Assert.IsTrue(contact.PhoneNumbers.Contains(phone2));
        }