public void TestContactRepository_AddContactCollection_WhenDuplicateTaxId_ShouldThrowException()
        {
            // Arrange
            var contact1 = ContactFactory.Get <CompanyContact>(ContactDataType.Minimum);
            var contact2 = ContactFactory.Get <CompanyContact>(ContactDataType.Minimum);

            var contactList = new List <Contact>
            {
                contact1,
                contact2
            };

            // Act
            bool condition = repository.Add(contactList);

            // Assert
        }
示例#2
0
        public void TestContactMapper_MapToContactDtos_WhenAllContactChildTypes_ShouldAllContactChildDtoTypes()
        {
            // Arrange
            var contact1 = ContactFactory.Get <CompanyContact>(ContactDataType.Company);
            var contact2 = ContactFactory.Get <FriendContact>(ContactDataType.Friend);
            var contact3 = ContactFactory.Get <WorkContact>(ContactDataType.Work);

            // Act
            var dtos = contactMapper.MapToContactDtos(new Contact[] { contact1, contact2, contact3 }).ToList();

            // Assert
            CollectionAssert.AllItemsAreInstancesOfType(dtos, typeof(ContactDto));
            CollectionAssert.AllItemsAreUnique(dtos);
            Assert.AreEqual(3, dtos.Count);
            Assert.IsInstanceOfType(dtos[0], typeof(CompanyContactDto));
            Assert.IsInstanceOfType(dtos[1], typeof(FriendContactDto));
            Assert.IsInstanceOfType(dtos[2], typeof(WorkContactDto));
        }
        public void TestContactRepository_GetContactById_WhenPresent_ShouldBeSuccessful()
        {
            // Arrange
            var contact1 = ContactFactory.Get <CompanyContact>(ContactDataType.Minimum);
            var contact2 = ContactFactory.Get <CompanyContact>(ContactDataType.Minimum);

            contact2.TaxId++;

            repository.Add(contact1);
            repository.Add(contact2);

            // Act
            var contact = repository.Get(contact1.TaxId);

            // Assert
            Assert.IsNotNull(contact);
            Assert.IsTrue(contact1.Equals(contact));
        }
        public void TestContactRepository_GetAllContacts_WhenPopulated_ShouldBeSuccessful()
        {
            // Arrange
            var contact1 = ContactFactory.Get <CompanyContact>(ContactDataType.Minimum);
            var contact2 = ContactFactory.Get <CompanyContact>(ContactDataType.Minimum);

            contact2.TaxId++;

            repository.Add(contact1);
            repository.Add(contact2);

            // Act
            var contacts = repository.Get().ToList();

            // Assert
            Assert.IsNotNull(contacts);
            Assert.AreEqual(2, contacts.Count);
        }
        public void TestContactRepository_UpdateContact_WhenTaxIdChangeDuplicate_ShouldReturnFalse()
        {
            // Arrange
            var contact1 = ContactFactory.Get <CompanyContact>(ContactDataType.Minimum);
            var contact2 = ContactFactory.Get <CompanyContact>(ContactDataType.Minimum);

            contact2.Name += "2";
            contact2.TaxId++;

            repository.Add(contact1);
            repository.Add(contact2);

            // Act
            var contact = repository.Get(contact1.Name);

            // Assert
            Assert.IsNotNull(contact);
            Assert.IsTrue(contact1.Equals(contact));
        }
        public void TestContactRepository_UpdateContact_WhenPresentWithNewTaxId_ShouldReturnTrue()
        {
            // Arrange
            var contact1 = ContactFactory.Get <CompanyContact>(ContactDataType.Minimum);
            var contact2 = ContactFactory.Get <CompanyContact>(ContactDataType.Minimum);

            contact2.Name += "2";
            contact2.TaxId++;

            repository.Add(contact1);

            // Act
            var condition = repository.Update(contact2, contact1.TaxId);

            // Assert
            Assert.IsTrue(condition);
            Assert.IsTrue(contact2.Equals(repository.Get(contact2.TaxId)));
            Assert.AreEqual(1, repository.Get().Count());
        }
        public void TestContactRepository_RemoveContact_WhenNotPresent_ShouldReturnFalse()
        {
            // Arrange
            var contact1 = ContactFactory.Get <CompanyContact>(ContactDataType.Minimum);
            var contact2 = ContactFactory.Get <CompanyContact>(ContactDataType.Minimum);

            contact2.Name += "2";
            contact2.TaxId++;

            repository.Add(contact1);

            // Act
            var condition = repository.Remove(contact2);

            // Assert
            var contacts = repository.Get().ToList();

            Assert.IsFalse(condition);
            Assert.AreEqual(1, contacts.Count);
            Assert.AreEqual(contact1, contacts[0]);
        }
        public void TestContactRepository_AddContact_WhenNotDuplicateTaxId_ShouldBeSuccessful()
        {
            // Arrange
            var contact1 = ContactFactory.Get <CompanyContact>(ContactDataType.Minimum);
            var contact2 = ContactFactory.Get <CompanyContact>(ContactDataType.Minimum);

            contact2.TaxId++;

            // Act
            bool condition = repository.Add(contact1);

            condition &= repository.Add(contact2);

            // Assert
            Assert.IsTrue(condition);

            var contacts = repository.Get().ToList();

            Assert.AreEqual(2, contacts.Count);
            Assert.AreEqual(contact1.TaxId, contacts[0].TaxId);
            Assert.AreEqual(contact2.TaxId, contacts[1].TaxId);
        }