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

            contact2.TaxId++;

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

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

            // 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);
        }
Beispiel #2
0
        public void TestContact_Equals_WhenParmNotContact_ShouldReturnFalse()
        {
            // Arrange
            var contact = ContactFactory.Get <CompanyContact>();
            var obj     = new object();

            // Act
            var condition = contact.Equals(obj);

            // Assert
            Assert.IsFalse(condition);
        }
Beispiel #3
0
        public void TestContact_Equals_WhenAllPropertiesEqual_ShouldReturnTrue()
        {
            // Arrange
            var contact1 = ContactFactory.Get <CompanyContact>();
            var contact2 = ContactFactory.Get <CompanyContact>();

            // Act
            var condition = contact1.Equals(contact2);

            // Assert
            Assert.IsTrue(condition);
        }
        public void TestContactRepository_AddContact_WhenDuplicateTaxId_ShouldThrowException()
        {
            // Arrange
            var contact1 = ContactFactory.Get <CompanyContact>(ContactDataType.Minimum);
            var contact2 = ContactFactory.Get <CompanyContact>(ContactDataType.Minimum);

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

            // Assert
        }
        public void TestContactRepository_AddContact_WhenNameIsEmpty_ShouldThrowArgumentException()
        {
            // Arrange
            var contact = ContactFactory.Get <CompanyContact>();

            contact.Name = string.Empty;

            // Act
            var condition = repository.Add(contact);

            // Assert
            Assert.IsFalse(condition);
        }
        public void TestContactRepository_AddContact_WhenTaxIdIsZero_ShouldThrowArgumentException()
        {
            // Arrange
            var contact = ContactFactory.Get <CompanyContact>();

            contact.TaxId = 0;

            // Act
            var condition = repository.Add(contact);

            // Assert
            Assert.IsFalse(condition);
        }
Beispiel #7
0
        public void TestValidation_Validate_WhenRequiredPropertyIsNull_ShouldThrowArgumentException()
        {
            // Arrange
            var contact = ContactFactory.Get <CompanyContact>();

            contact.Name = null;

            var validation = new Validation();

            // Act
            validation.Validate(contact);

            // Assert
        }
Beispiel #8
0
        public void TestContact_Equals_WhenDateCreatedNotEqual_ShouldReturnFalse()
        {
            // Arrange
            var contact1 = ContactFactory.Get <CompanyContact>();

            Thread.Sleep(500);
            var contact2 = ContactFactory.Get <CompanyContact>();

            // Act
            var condition = contact1.Equals(contact2);

            // Assert
            Assert.IsFalse(condition);
        }
        public void TestContactRepository_AddContact_WhenFriend_ShouldBeSuccessful()
        {
            // Arrange
            var contact = ContactFactory.Get <FriendContact>();

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

            // Assert
            Assert.IsNotNull(contacts);
            Assert.AreEqual(1, contacts.Count);
            Assert.IsTrue(contact.Equals(contacts[0]));
        }
        public void TestContactRepository_UpdateContact_WhenNotPresent_ShouldReturnFalse()
        {
            // Arrange
            var contact1 = ContactFactory.Get <CompanyContact>(ContactDataType.Minimum);

            repository.Add(contact1);
            int badTaxId = contact1.TaxId + 1;

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

            // Assert
            Assert.IsFalse(condition);
        }
        public void TestContactRepository_UpdateContact_WhenNull_ShouldReturnFalse()
        {
            // Arrange
            var contact1 = ContactFactory.Get <CompanyContact>(ContactDataType.Minimum);

            repository.Add(contact1);

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

            // Assert
            Assert.IsFalse(condition);
            Assert.IsTrue(contact1.Equals(repository.Get(contact1.TaxId)));
        }
Beispiel #12
0
        public void TestContact_Equals_WhenTaxIdNotEqual_ShouldReturnFalse()
        {
            // Arrange
            var contact1 = ContactFactory.Get <CompanyContact>();
            var contact2 = ContactFactory.Get <CompanyContact>();

            contact2.TaxId++;

            // Act
            var condition = contact1.Equals(contact2);

            // Assert
            Assert.IsFalse(condition);
        }
        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
        }
        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 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_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_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_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]);
        }