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));
            }
        }
        public void ValidEmailGeneratesValidObject()
        {
            var random = EmailValueObjectObjectMother.Random();

            var vo = new EmailValueObject(random.Value);

            Assert.NotNull(vo);
            Assert.AreEqual(random.Value, vo.Value);
        }
        public void ObjectsWithSameValueAreEquals()
        {
            var random = EmailValueObjectObjectMother.Random();

            var vo1 = new EmailValueObject(random.Value);
            var vo2 = new EmailValueObject(random.Value);

            Assert.NotNull(vo1);
            Assert.NotNull(vo2);
            Assert.AreEqual(vo1, vo2);
        }
示例#4
0
        public void ContactAddEmailAddressesAddNonExistingOrNull()
        {
            var contact = ContactEntityObjectMother.Random();
            var email1  = EmailValueObjectObjectMother.Random();

            contact.AddEmailAddress(email1);
            contact.AddEmailAddress(null);
            contact.AddEmailAddress(email1);

            Assert.AreEqual(1, contact.EmailAddresses.Count);
            Assert.IsTrue(contact.EmailAddresses.Contains(email1));
        }
示例#5
0
        public void ContactRemoveEmailAddressesDoesNotThrowError()
        {
            var contact = ContactEntityObjectMother.Random();
            var email1  = EmailValueObjectObjectMother.Random();
            var email2  = EmailValueObjectObjectMother.Random();

            contact.AddEmailAddress(email1);

            contact.RemoveEmailAddress(email2);

            Assert.AreEqual(1, contact.EmailAddresses.Count);
            Assert.IsTrue(contact.EmailAddresses.Contains(email1));
        }
示例#6
0
        public void ContactAddEmailAddressesAddsMailAddresses()
        {
            var contact = ContactEntityObjectMother.Random();
            var email1  = EmailValueObjectObjectMother.Random();
            var email2  = EmailValueObjectObjectMother.Random();

            contact.AddEmailAddress(email1);
            contact.AddEmailAddress(email2);

            Assert.AreEqual(2, contact.EmailAddresses.Count);
            Assert.IsTrue(contact.EmailAddresses.Contains(email1));
            Assert.IsTrue(contact.EmailAddresses.Contains(email2));
        }
示例#7
0
        public void ContactRemoveAllAddressRemoveAllAddresses()
        {
            var contact = ContactEntityObjectMother.Random();
            var email1  = EmailValueObjectObjectMother.Random();
            var email2  = EmailValueObjectObjectMother.Random();

            contact.AddEmailAddress(email1);
            contact.AddEmailAddress(email2);

            contact.RemoveAllEmailAddress();

            Assert.AreEqual(0, contact.EmailAddresses.Count);
        }
示例#8
0
        public void ContactAddEmailsListAddAllValidAndNoRepeated()
        {
            var contact = ContactEntityObjectMother.Random();
            var email1  = EmailValueObjectObjectMother.Random();
            var email2  = EmailValueObjectObjectMother.Random();

            contact.AddEmailAddresses(new List <string> {
                email1.Value, email2.Value, null, email1.Value, email2.Value
            });

            Assert.AreEqual(2, contact.EmailAddresses.Count);
            Assert.IsTrue(contact.EmailAddresses.Contains(email1));
            Assert.IsTrue(contact.EmailAddresses.Contains(email2));
        }
        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));
        }