public void GetContacts_DoesNotReturnExistingContact_IfSearchTermIsUsed_BecauseUserIsNotRecordOwner()
        {
            var repository = new PhoneBookRepository(_soundexFilter)
            {
                ConnectionString = _connectionString
            };

            repository.SetOwnerGuid(Guid.NewGuid());
            var results = repository.GetContacts("Lenna Paprocki");

            Assert.DoesNotContain(results, contact => contact.FirstName == "Lenna" && contact.LastName == "Paprocki");
        }
        public void AddContact_ReturnsZero_IfContactExists()
        {
            var repository = new PhoneBookRepository(_soundexFilter)
            {
                ConnectionString = _connectionString
            };
            repository.SetOwnerGuid(_guid);

            var newContact = _contact;
            var result = repository.AddContact(newContact);
            var expected = 0;

            Assert.Equal(expected, result);
        }
        public void AddContact_AddsContact_IfContactDoesNotExistsYet()
        {
            var repository = new PhoneBookRepository(_soundexFilter)
            {
                ConnectionString = _connectionString
            };
            repository.SetOwnerGuid(_guid);

            var newContact = new Contact();
            var contactId = repository.AddContact(newContact);
            var expected = newContact;
            var result = repository.GetContact(contactId);

            Assert.True(EqualContacts(expected, result));
        }
        public void GetContacts_ReturnsExactContact_IfProperSearchTermIsUsed()
        {
            var repository = new PhoneBookRepository(_soundexFilter)
            {
                ConnectionString = _connectionString
            };
            repository.SetOwnerGuid(_guid);

            var results = repository.GetContacts("Lena Paprocki");

            Assert.Contains(results, contact => contact.FirstName == "Lenna" && contact.LastName == "Paprocki");
        }
        public void UpdateContact_UpdatesContact_IfItExists()
        {
            var repository = new PhoneBookRepository(_soundexFilter)
            {
                ConnectionString = _connectionString
            };
            repository.SetOwnerGuid(_guid);

            var newContact = new Contact();
            repository.AddContact(newContact);
            var updatedContact = newContact;
            updatedContact.FirstName = "John";
            updatedContact.LastName = "Doe";
            repository.UpdateContact(updatedContact);
            var expected = updatedContact;
            var result = repository.GetContact(updatedContact.Id);

            Assert.True(EqualContacts(expected, result));
        }
        public void UpdateContact_ReturnsFalse_IfContactExists_ButUserIsNotRecordOwner()
        {
            var repository = new PhoneBookRepository(_soundexFilter)
            {
                ConnectionString = _connectionString
            };
            repository.SetOwnerGuid(_guid);

            var newContact = new Contact() { Owner = _guid };
            repository.AddContact(newContact);
            repository.SetOwnerGuid(Guid.NewGuid());
            var result = repository.RemoveContact(newContact);

            Assert.False(result);
        }
        public void UpdateContact_ReturnsFalse_IfContactDoesNotExists()
        {
            var repository = new PhoneBookRepository(_soundexFilter)
            {
                ConnectionString = _connectionString
            };
            repository.SetOwnerGuid(_guid);

            var newContact = new Contact();
            newContact.Id = 9999;
            var result = repository.UpdateContact(newContact);

            Assert.False(result);
        }
        public void IsContactConsistent_ReturnsTrue_IfRepositoryOwnerIsSetAndContactOwnerIsNotSet()
        {
            var repository = new PhoneBookRepository(_soundexFilter)
            {
                ConnectionString = _connectionString
            };
            repository.SetOwnerGuid(_guid);

            var newContact = new Contact();
            var result = repository.IsContactConsistent(newContact);

            Assert.True(result);
        }
        public void RemoveContact_RemovesContact_IfContactExists()
        {
            var repository = new PhoneBookRepository(_soundexFilter)
            {
                ConnectionString = _connectionString
            };
            repository.SetOwnerGuid(_guid);

            var newContact = new Contact();
            var contactId = repository.AddContact(newContact);
            repository.RemoveContact(newContact);
            var result = repository.GetContact(contactId);

            Assert.Null(result);
        }
        public void IsContactConsistent_ReturnsFalse_IfRepositoryOwnerAndContactOwnerAreNotConsistent()
        {
            var repository = new PhoneBookRepository(_soundexFilter)
            {
                ConnectionString = _connectionString
            };
            repository.SetOwnerGuid(_guid);

            var newContact = new Contact() {Owner = Guid.NewGuid()};
            var result = repository.IsContactConsistent(newContact);

            Assert.False(result);
        }
        public void GetContact_ReturnsNull_IfIncorrectIdIsUsed()
        {
            var repository = new PhoneBookRepository(_soundexFilter)
            {
                ConnectionString = _connectionString
            };
            repository.SetOwnerGuid(_guid);

            var result = repository.GetContact(9999);

            Assert.Null(result);
        }
        public void GetContact_ReturnsContact_IfCorrectIdIsUsed()
        {
            var repository = new PhoneBookRepository(_soundexFilter)
            {
                ConnectionString = _connectionString
            };
            repository.SetOwnerGuid(_guid);

            var result = repository.GetContact(_contact.Id);
            var expected = _contact;

            Assert.True(EqualContacts(expected, result));
        }
        public void GetContacts_ReturnsPagedContactList_WithoutParameter()
        {
            var repository = new PhoneBookRepository(_soundexFilter)
            {
                ConnectionString = _connectionString
            };
            repository.SetOwnerGuid(_guid);

            var expected = repository.PageSize;
            var result = repository.GetContacts().Count;

            Assert.Equal(expected, result);
        }
        public void GetContacts_ReturnsPagedContactList_InAlphabeticalOrder()
        {
            var repository = new PhoneBookRepository(_soundexFilter)
            {
                ConnectionString = _connectionString
            };
            repository.SetOwnerGuid(_guid);

            var result = repository.GetContacts();
            var expected = result.OrderBy(contact => contact.LastName).ThenBy(contact => contact.FirstName);

            Assert.Equal(expected,result);
        }