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 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 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);
        }