コード例 #1
0
        public void ShowPersonWithExternalId()
        {
            using (var session = new NationBuilderSession(TestNationSlug, TestNationAccessToken))
            {
                // Test remote ID escaping:
                string testId = "h!6&access_token=null";

                // Create a test person object:
                var testPerson = new Person()
                {
                    first_name  = "Tes",
                    last_name   = "Per",
                    email       = "*****@*****.**",
                    external_id = testId,
                };
                var newPersonResponse = session.PushPerson(testPerson);

                Assert.AreEqual(newPersonResponse.person.external_id, testId);
                Assert.IsTrue(newPersonResponse.person.id.HasValue);

                var showPersonResponse = session.ShowPersonWithExternalId(testId);

                Assert.AreEqual(showPersonResponse.person.id, newPersonResponse.person.id);
                Assert.AreEqual(showPersonResponse.person.external_id, testId);

                // Remove the test person object:
                session.DestroyPerson(newPersonResponse.person.id.Value);
            }
        }
コード例 #2
0
        public void ShowPerson()
        {
            using (var session = new NationBuilderSession(TestNationSlug, TestNationAccessToken))
            {
                var personMeResponse = session.PersonMe();
                var personMe = personMeResponse.person;

                Assert.IsTrue(personMe.id.HasValue);

                var shownPersonResponse = session.ShowPerson(personMe.id.Value);
                var shownPerson = shownPersonResponse.person;

                Assert.AreEqual(personMe, shownPerson);

                // Make sure equality testing is, possibly, functioning:
                shownPerson.first_name += "suff";
                Assert.AreNotEqual(shownPerson, personMe);

                shownPerson.first_name = personMe.first_name;
                Assert.AreEqual(shownPerson, personMe);

                shownPerson.author_id += "suff";
                Assert.AreNotEqual(shownPerson, personMe);
            }
        }
コード例 #3
0
        public void PushNewPerson()
        {
            using (var session = new NationBuilderSession(TestNationSlug, TestNationAccessToken))
            {
                // Create a test person object:
                var testPerson = new Person()
                {
                    first_name = "Testy",
                    last_name  = "Pushy",
                    email      = "*****@*****.**",
                };
                var newPersonResponse = session.PushPerson(testPerson);

                Assert.IsTrue(newPersonResponse.person.id.HasValue);

                // Ensure we are pushing a new person, rather than updating an existing one:
                session.DestroyPerson(newPersonResponse.person.id.Value);

                newPersonResponse = session.PushPerson(testPerson);
                Assert.IsTrue(newPersonResponse.person.id.HasValue);
                Assert.AreEqual(newPersonResponse.Http.StatusCode, HttpStatusCode.Created);

                var showPersonResponse = session.ShowPerson(newPersonResponse.person.id.Value);

                Assert.AreEqual(showPersonResponse.person.id, newPersonResponse.person.id);

                // Remove the test person object:
                session.DestroyPerson(newPersonResponse.person.id.Value);
            }
        }
コード例 #4
0
        public void GetListsPeopleResults()
        {
            using (var session = new NationBuilderSession(TestNationSlug, TestNationAccessToken))
            {
                int listCount        = 0;
                int totalPersonCount = 0;

                // Test parsing all people in all lists in the nation:
                foreach (var list in session.GetListsResults())
                {
                    Assert.IsTrue(list.id.HasValue);
                    Assert.IsTrue(list.count.HasValue);
                    ++listCount;

                    int personCount = 0;

                    foreach (var person in session.GetPeopleInListResults(list.id.Value))
                    {
                        Assert.IsTrue(person.id.HasValue);
                        ++personCount;
                    }
                    Assert.AreEqual(list.count.Value, personCount);
                    totalPersonCount += personCount;
                }

                if (listCount < 1)
                {
                    Assert.Inconclusive("Zero lists found in the configured nation.");
                }
                if (totalPersonCount < 1)
                {
                    Assert.Inconclusive("Zero total number of people found in all of the nation's lists.");
                }
            }
        }
コード例 #5
0
ファイル: Contacts.cs プロジェクト: pavpen/NationBuilderAPI
        public void GetContactsToPersonResults()
        {
            using (var session = new NationBuilderSession(TestNationSlug, TestNationAccessToken))
            {
                int contactsCount = 0;
                int peopleCount = 0;

                // Test parsing all contacts in the nation:
                foreach (var person in session.GetPeopleResults())
                {
                    foreach (var contact in session.GetContactsToPersonResults(person.id.Value))
                    {
                        ++contactsCount;
                    }
                    ++peopleCount;
                }

                if (contactsCount < 1)
                {
                    Assert.Inconclusive("Zero contacts found in the configured test nation.");
                }

                System.Diagnostics.Trace.WriteLine("Retrieved ard parsed " + contactsCount + (1 == contactsCount ? " contact" : " contacts") +
                    " for " + peopleCount + (1 == peopleCount ? " person" : " people") + ".");
            }
        }
コード例 #6
0
        public void ShowPerson()
        {
            using (var session = new NationBuilderSession(TestNationSlug, TestNationAccessToken))
            {
                var personMeResponse = session.PersonMe();
                var personMe         = personMeResponse.person;

                Assert.IsTrue(personMe.id.HasValue);

                var shownPersonResponse = session.ShowPerson(personMe.id.Value);
                var shownPerson         = shownPersonResponse.person;

                Assert.AreEqual(personMe, shownPerson);

                // Make sure equality testing is, possibly, functioning:
                shownPerson.first_name += "suff";
                Assert.AreNotEqual(shownPerson, personMe);

                shownPerson.first_name = personMe.first_name;
                Assert.AreEqual(shownPerson, personMe);

                shownPerson.author_id += "suff";
                Assert.AreNotEqual(shownPerson, personMe);
            }
        }
コード例 #7
0
ファイル: Lists.cs プロジェクト: pavpen/NationBuilderAPI
        public void GetListsPeopleResults()
        {
            using (var session = new NationBuilderSession(TestNationSlug, TestNationAccessToken))
            {
                int listCount = 0;
                int totalPersonCount = 0;

                // Test parsing all people in all lists in the nation:
                foreach (var list in session.GetListsResults())
                {
                    Assert.IsTrue(list.id.HasValue);
                    Assert.IsTrue(list.count.HasValue);
                    ++listCount;

                    int personCount = 0;

                    foreach (var person in session.GetPeopleInListResults(list.id.Value))
                    {
                        Assert.IsTrue(person.id.HasValue);
                        ++personCount;
                    }
                    Assert.AreEqual(list.count.Value, personCount);
                    totalPersonCount += personCount;
                }

                if (listCount < 1)
                {
                    Assert.Inconclusive("Zero lists found in the configured nation.");
                }
                if (totalPersonCount < 1)
                {
                    Assert.Inconclusive("Zero total number of people found in all of the nation's lists.");
                }
            }
        }
コード例 #8
0
        public void GetContactsToPersonResults()
        {
            using (var session = new NationBuilderSession(TestNationSlug, TestNationAccessToken))
            {
                int contactsCount = 0;
                int peopleCount   = 0;

                // Test parsing all contacts in the nation:
                foreach (var person in session.GetPeopleResults())
                {
                    foreach (var contact in session.GetContactsToPersonResults(person.id.Value))
                    {
                        ++contactsCount;
                    }
                    ++peopleCount;
                }

                if (contactsCount < 1)
                {
                    Assert.Inconclusive("Zero contacts found in the configured test nation.");
                }

                System.Diagnostics.Trace.WriteLine("Retrieved ard parsed " + contactsCount + (1 == contactsCount ? " contact" : " contacts") +
                                                   " for " + peopleCount + (1 == peopleCount ? " person" : " people") + ".");
            }
        }
コード例 #9
0
 public void GetPeopleResults()
 {
     using (var session = new NationBuilderSession(TestNationSlug, TestNationAccessToken))
     {
         // Test parsing all people in the nation:
         foreach (var person in session.GetPeopleResults())
         {
             Assert.IsTrue(person.id.HasValue);
         }
     }
 }
コード例 #10
0
 public void GetPeopleResults()
 {
     using (var session = new NationBuilderSession(TestNationSlug, TestNationAccessToken))
     {
         // Test parsing all people in the nation:
         foreach (var person in session.GetPeopleResults())
         {
             Assert.IsTrue(person.id.HasValue);
         }
     }
 }
コード例 #11
0
        public void PersonMe()
        {
            using (var session = new NationBuilderSession(TestNationSlug, TestNationAccessToken))
            {
                var personResponse = session.PersonMe();
                var person         = personResponse.person;

                Assert.IsTrue(person.id.HasValue);
                Assert.AreNotEqual(person.created_at, DateTimeOffset.MinValue);
                Assert.AreNotEqual(person.created_at, DateTimeOffset.MaxValue);
                Assert.AreNotEqual(person.updated_at, DateTimeOffset.MinValue);
                Assert.AreNotEqual(person.updated_at, DateTimeOffset.MaxValue);
            }
        }
コード例 #12
0
        public void PersonMe()
        {
            using (var session = new NationBuilderSession(TestNationSlug, TestNationAccessToken))
            {
                var personResponse = session.PersonMe();
                var person = personResponse.person;

                Assert.IsTrue(person.id.HasValue);
                Assert.AreNotEqual(person.created_at, DateTimeOffset.MinValue);
                Assert.AreNotEqual(person.created_at, DateTimeOffset.MaxValue);
                Assert.AreNotEqual(person.updated_at, DateTimeOffset.MinValue);
                Assert.AreNotEqual(person.updated_at, DateTimeOffset.MaxValue);
            }
        }
コード例 #13
0
        public void ShowPerson_WithNonExistentId()
        {
            using (var session = new NationBuilderSession(TestNationSlug, TestNationAccessToken))
            {
                long testId;
                var  testPerson = new Person()
                {
                    first_name = "Tes",
                    last_name  = "Per",
                    email      = "*****@*****.**",
                };

                try
                {
                    var personResponse = session.MatchPerson(testPerson.email, testPerson.first_name, testPerson.last_name);

                    testId = personResponse.person.id.Value;
                }
                catch (NationBuilderRemoteException exc)
                {
                    if ("no_matches" == exc.ExceptionCode || "multiple_matches" == exc.ExceptionCode)
                    {
                        // Allocate a new person ID:
                        var newPersonResponse = session.CreatePerson(testPerson);

                        testId = newPersonResponse.person.id.Value;
                    }
                    else
                    {
                        throw exc;
                    }
                }

                // Make sure there's no person with that ID:
                session.DestroyPerson(testId);

                try
                {
                    var nonExistentPersonResponse = session.ShowPerson(testId);
                }
                catch (NationBuilderRemoteException exc)
                {
                    Assert.AreEqual("not_found", exc.ExceptionCode);
                    Assert.AreEqual(HttpStatusCode.NotFound, exc.HttpStatusCode);
                    return;
                }

                Assert.Fail("ShowPerson() did not thrown an exception with the expected parameters!");
            }
        }
コード例 #14
0
 public void GetPeopleTagResults_GetPeopleWithTagResults()
 {
     using (var session = new NationBuilderSession(TestNationSlug, TestNationAccessToken))
     {
         foreach (var tag in session.GetPeopleTagsResults())
         {
             Assert.IsNotNull(tag.name);
             foreach (var person in session.GetPeopleWithTagResults(tag.name))
             {
                 Assert.IsTrue(person.id.HasValue);
             }
         }
     }
 }
コード例 #15
0
 public void GetPeopleTagResults_GetPeopleWithTagResults()
 {
     using (var session = new NationBuilderSession(TestNationSlug, TestNationAccessToken))
     {
         foreach (var tag in session.GetPeopleTagsResults())
         {
             Assert.IsNotNull(tag.name);
             foreach (var person in session.GetPeopleWithTagResults(tag.name))
             {
                 Assert.IsTrue(person.id.HasValue);
             }
         }
     }
 }
コード例 #16
0
        private bool DoesContactTypeExist(NationBuilderSession session, ContactType value)
        {
            foreach (var contactType in session.GetContactTypeResults())
            {
                if (value.Equals(contactType))
                {
                    Assert.AreEqual(value.id, contactType.id);
                    Assert.AreEqual(value.name, contactType.name);

                    return(true);
                }
            }

            return(false);
        }
コード例 #17
0
 private void TestConnectionButton_Click(object sender, RoutedEventArgs e)
 {
     using (var session = new NationBuilderSession(Settings.TestNationSlug, Settings.TestNationAccessToken))
     {
         try
         {
             session.PersonMe();
             OutputSuccess("Successfully connected to the Nation Builder service with slug \"" + Settings.TestNationSlug + "\".");
         }
         catch (Exception exc)
         {
             OutputError("Error connecting to the Nation Builder service.", exc);
         }
     }
 }
コード例 #18
0
        public void CreateUpdateDestroyList()
        {
            using (var session = new NationBuilderSession(TestNationSlug, TestNationAccessToken))
            {
                var personSelf = session.PersonMe().person;
                var testList   = new List {
                    name = "teslist", slug = "utest_lugs", author_id = personSelf.id.Value
                };
                List newList = session.CreateList(testList, true).list_resource;

                Assert.IsTrue(newList.id.HasValue);
                Assert.IsTrue(newList.count.HasValue);
                Assert.AreEqual(newList.count.Value, 0);
                Assert.AreEqual(testList.name, newList.name);
                Assert.AreEqual(testList.slug, newList.slug);

                newList.name += " +1";

                var updatedList = session.UpdateList(newList.id.Value, newList).list_resource;

                Assert.IsTrue(updatedList.id.HasValue);
                Assert.AreEqual(updatedList.id.Value, newList.id.Value);
                Assert.IsTrue(updatedList.count.HasValue);
                Assert.AreEqual(updatedList.count.Value, newList.count.Value);
                Assert.AreEqual(newList.name, updatedList.name);

                session.AddPeopleToList(newList.id.Value, new List <long> {
                    personSelf.id.Value
                });

                session.DeletePeopleFromList(newList.id.Value, new List <long> {
                    personSelf.id.Value
                });

                session.DestroyList(newList.id.Value);

                // Make sure the list was deleted:
                foreach (var list in session.GetListsResults())
                {
                    Assert.IsTrue(list.id.HasValue);
                    if (newList.id.Value == list.id.Value)
                    {
                        Assert.Fail("DestroyList operation did not delete the list from the nation!");
                    }
                }
            }
        }
コード例 #19
0
ファイル: Contacts.cs プロジェクト: pavpen/NationBuilderAPI
        public void GetContactTypeResults()
        {
            using (var session = new NationBuilderSession(TestNationSlug, TestNationAccessToken))
            {
                int typeCount = 0;

                // Test parsing all contact types:s
                foreach (var contactType in session.GetContactTypeResults())
                {
                    Assert.IsTrue(contactType.id.HasValue);
                    ++typeCount;
                }

                if (typeCount < 1)
                {
                    Assert.Inconclusive("Zero contact types found in the configured test nation.");
                }
            }
        }
コード例 #20
0
        public void GetContactTypeResults()
        {
            using (var session = new NationBuilderSession(TestNationSlug, TestNationAccessToken))
            {
                int typeCount = 0;

                // Test parsing all contact types:s
                foreach (var contactType in session.GetContactTypeResults())
                {
                    Assert.IsTrue(contactType.id.HasValue);
                    ++typeCount;
                }

                if (typeCount < 1)
                {
                    Assert.Inconclusive("Zero contact types found in the configured test nation.");
                }
            }
        }
コード例 #21
0
        // This is rather slow.  Enable when needed.
        //[TestMethod]
        public void ParseAllPeople()
        {
            using (var session = new NationBuilderSession(TestNationSlug, TestNationAccessToken))
            {
                bool parsedCouldVote = false;

                foreach (var person in session.GetPeopleResults())
                {
                    var personResponse = session.ShowPerson(person.id.Value);

                    Assert.IsTrue(personResponse.person.id.HasValue);
                    if (personResponse.person.could_vote_status.HasValue)
                    {
                        parsedCouldVote = true;
                    }
                }

                System.Diagnostics.Trace.WriteLine("ParsedCouldVote: " + parsedCouldVote);
            }
        }
コード例 #22
0
        public void GetListsResults()
        {
            using (var session = new NationBuilderSession(TestNationSlug, TestNationAccessToken))
            {
                int listCount = 0;

                // Test parsing all lists in the nation:
                foreach (var list in session.GetListsResults())
                {
                    Assert.IsTrue(list.id.HasValue);
                    Assert.IsTrue(list.count.HasValue);
                    ++listCount;
                }

                if (listCount < 1)
                {
                    Assert.Inconclusive("Zero lists found in the configured test nation.");
                }
            }
        }
コード例 #23
0
ファイル: Lists.cs プロジェクト: pavpen/NationBuilderAPI
        public void GetListsResults()
        {
            using (var session = new NationBuilderSession(TestNationSlug, TestNationAccessToken))
            {
                int listCount = 0;

                // Test parsing all lists in the nation:
                foreach (var list in session.GetListsResults())
                {
                    Assert.IsTrue(list.id.HasValue);
                    Assert.IsTrue(list.count.HasValue);
                    ++listCount;
                }

                if (listCount < 1)
                {
                    Assert.Inconclusive("Zero lists found in the configured test nation.");
                }
            }
        }
コード例 #24
0
        // This is rather slow.  Enable when needed.
        //[TestMethod]
        public void ParseAllPeople()
        {
            using (var session = new NationBuilderSession(TestNationSlug, TestNationAccessToken))
            {
                bool parsedCouldVote = false;

                foreach (var person in session.GetPeopleResults())
                {
                    var personResponse = session.ShowPerson(person.id.Value);

                    Assert.IsTrue(personResponse.person.id.HasValue);
                    if (personResponse.person.could_vote_status.HasValue)
                    {
                        parsedCouldVote = true;
                    }
                }

                System.Diagnostics.Trace.WriteLine("ParsedCouldVote: " + parsedCouldVote);
            }
        }
コード例 #25
0
ファイル: Lists.cs プロジェクト: pavpen/NationBuilderAPI
        public void CreateUpdateDestroyList()
        {
            using (var session = new NationBuilderSession(TestNationSlug, TestNationAccessToken))
            {
                var personSelf = session.PersonMe().person;
                var testList = new List { name = "teslist", slug = "utest_lugs", author_id = personSelf.id.Value };
                List newList = session.CreateList(testList, true).list_resource;

                Assert.IsTrue(newList.id.HasValue);
                Assert.IsTrue(newList.count.HasValue);
                Assert.AreEqual(newList.count.Value, 0);
                Assert.AreEqual(testList.name, newList.name);
                Assert.AreEqual(testList.slug, newList.slug);

                newList.name += " +1";
                
                var updatedList = session.UpdateList(newList.id.Value, newList).list_resource;

                Assert.IsTrue(updatedList.id.HasValue);
                Assert.AreEqual(updatedList.id.Value, newList.id.Value);
                Assert.IsTrue(updatedList.count.HasValue);
                Assert.AreEqual(updatedList.count.Value, newList.count.Value);
                Assert.AreEqual(newList.name, updatedList.name);

                session.AddPeopleToList(newList.id.Value, new List<long> { personSelf.id.Value });

                session.DeletePeopleFromList(newList.id.Value, new List<long> { personSelf.id.Value });

                session.DestroyList(newList.id.Value);

                // Make sure the list was deleted:
                foreach (var list in session.GetListsResults())
                {
                    Assert.IsTrue(list.id.HasValue);
                    if (newList.id.Value == list.id.Value)
                    {
                        Assert.Fail("DestroyList operation did not delete the list from the nation!");
                    }
                }
            }
        }
コード例 #26
0
        public void ShowPersonWithExternalId_WithNonExistentId()
        {
            using (var session = new NationBuilderSession(TestNationSlug, TestNationAccessToken))
            {
                // Test remote ID escaping:
                string testId = "h!6&access_token=null";

                try
                {
                    var nonExistentPersonResponse = session.ShowPersonWithExternalId(testId);
                }
                catch (NationBuilderRemoteException exc)
                {
                    Assert.AreEqual("not_found", exc.ExceptionCode);
                    Assert.AreEqual(HttpStatusCode.NotFound, exc.HttpStatusCode);
                    return;
                }

                Assert.Fail("ShowPersonWithExternalId() did not throw an exception with the expected parameters!");
            }
        }
コード例 #27
0
        public void CreateUpdateDestroyContactType()
        {
            using (var session = new NationBuilderSession(TestNationSlug, TestNationAccessToken))
            {
                // Create a temporary test contact type:
                var aTestContactType = new ContactType()
                {
                    name = "Test Contact Type Drive 2015",
                };
                var newContactTypeResponse = session.CreateContactType(aTestContactType);

                Assert.IsTrue(newContactTypeResponse.contact_type.id.HasValue);
                Assert.AreEqual(newContactTypeResponse.contact_type.name, aTestContactType.name);

                var testContactType = newContactTypeResponse.contact_type;

                Assert.IsTrue(DoesContactTypeExist(session, testContactType));

                // Update the contact type:
                testContactType.name += "+1";
                var contactTypeResponse = session.UpdateContactType(testContactType.id.Value, testContactType);

                Assert.AreEqual(testContactType.id, contactTypeResponse.contact_type.id);
                Assert.AreEqual(testContactType.name, contactTypeResponse.contact_type.name);

                Assert.IsTrue(DoesContactTypeExist(session, testContactType));

                // Destroy the contact type:
                session.DestroyContactType(testContactType.id.Value);
                // It seems that destruction is asynchronous, and doesn't occur imeediately:
                for (int c = 0; c < 5; ++c)
                {
                    session.PersonMe();
                }
                Assert.IsFalse(DoesContactTypeExist(session, testContactType));
            }
        }
コード例 #28
0
ファイル: Contacts.cs プロジェクト: pavpen/NationBuilderAPI
        public void CreateUpdateDestroyContactType()
        {
            using (var session = new NationBuilderSession(TestNationSlug, TestNationAccessToken))
            {
                // Create a temporary test contact type:
                var aTestContactType = new ContactType()
                {
                    name = "Test Contact Type Drive 2015",
                };
                var newContactTypeResponse = session.CreateContactType(aTestContactType);

                Assert.IsTrue(newContactTypeResponse.contact_type.id.HasValue);
                Assert.AreEqual(newContactTypeResponse.contact_type.name, aTestContactType.name);

                var testContactType = newContactTypeResponse.contact_type;
                
                Assert.IsTrue(DoesContactTypeExist(session, testContactType));

                // Update the contact type:
                testContactType.name += "+1";
                var contactTypeResponse = session.UpdateContactType(testContactType.id.Value, testContactType);

                Assert.AreEqual(testContactType.id, contactTypeResponse.contact_type.id);
                Assert.AreEqual(testContactType.name, contactTypeResponse.contact_type.name);

                Assert.IsTrue(DoesContactTypeExist(session, testContactType));

                // Destroy the contact type:
                session.DestroyContactType(testContactType.id.Value);
                // It seems that destruction is asynchronous, and doesn't occur imeediately:
                for (int c = 0; c < 5; ++c)
                {
                    session.PersonMe();
                }
                Assert.IsFalse(DoesContactTypeExist(session, testContactType));
            }
        }
コード例 #29
0
        public void CreateContactToPerson()
        {
            using (var session = new NationBuilderSession(TestNationSlug, TestNationAccessToken))
            {
                var testSender = session.PersonMe().person;

                Person        testPerson;
                ContactType   testContactType;
                ContactMethod testContactMethod;
                ContactStatus testContactStatus;

                CreateTestContactObjects(session, out testPerson, out testContactType, out testContactMethod, out testContactStatus);

                // Create a test contact to a person:
                var testContact = new Contact()
                {
                    type_id   = testContactType.id.Value,
                    method    = testContactMethod.api_name,
                    sender_id = testSender.id.Value,
                    status    = testContactStatus.api_name,
                    note      = "Tasted well",
                };
                var contactResponse = CreateTestContact(session, testPerson.id.Value, testContact);

                // Test destroying the contact type:
                session.DestroyContactType(testContactType.id.Value);

                //foreach (var contact in session.GetContactsToPersonResults(testPerson.id.Value))
                //{
                //    Assert.AreNotEqual(contact.type_id, testContactType.id.Value);
                //}

                // Destroy temporary objects:
                session.DestroyPerson(testPerson.id.Value);
            }
        }
コード例 #30
0
        private ContactResponse CreateTestContact(NationBuilderSession session, long contactedPersonId, Contact contact)
        {
            var contactResponse = session.CreateContactToPerson(contactedPersonId, contact);

            Assert.AreEqual(contactResponse.contact.type_id, contact.type_id);
            Assert.AreEqual(contactResponse.contact.method, contact.method);
            Assert.AreEqual(contactResponse.contact.sender_id, contact.sender_id);
            Assert.AreEqual(contactResponse.contact.status, contact.status);
            Assert.AreEqual(contactResponse.contact.note, contact.note);

            bool foundContact = false;

            foreach (var personContact in session.GetContactsToPersonResults(contactedPersonId))
            {
                if (contactResponse.contact.Equals(personContact))
                {
                    foundContact = true;
                    break;
                }
            }
            Assert.IsTrue(foundContact);

            return(contactResponse);
        }
コード例 #31
0
ファイル: Contacts.cs プロジェクト: pavpen/NationBuilderAPI
        private ContactResponse CreateTestContact(NationBuilderSession session, long contactedPersonId, Contact contact)
        {
            var contactResponse = session.CreateContactToPerson(contactedPersonId, contact);

            Assert.AreEqual(contactResponse.contact.type_id, contact.type_id);
            Assert.AreEqual(contactResponse.contact.method, contact.method);
            Assert.AreEqual(contactResponse.contact.sender_id, contact.sender_id);
            Assert.AreEqual(contactResponse.contact.status, contact.status);
            Assert.AreEqual(contactResponse.contact.note, contact.note);

            bool foundContact = false;

            foreach (var personContact in session.GetContactsToPersonResults(contactedPersonId))
            {
                if (contactResponse.contact.Equals(personContact))
                {
                    foundContact = true;
                    break;
                }
            }
            Assert.IsTrue(foundContact);

            return contactResponse;
        }
コード例 #32
0
ファイル: Contacts.cs プロジェクト: pavpen/NationBuilderAPI
        private void CreateTestContactObjects(NationBuilderSession session, out Person testPerson, out ContactType testContactType, out ContactMethod testContactMethod,
            out ContactStatus testContactStatus)
        {
            // Create a temporary test person object:
            var aTestPerson = new Person()
            {
                first_name = "Tes",
                last_name = "Per",
                email = "*****@*****.**",
            };
            var newPersonResponse = session.PushPerson(aTestPerson);

            Assert.IsTrue(newPersonResponse.person.id.HasValue);
            Assert.AreEqual(newPersonResponse.person.first_name, aTestPerson.first_name);
            Assert.AreEqual(newPersonResponse.person.last_name, aTestPerson.last_name);
            Assert.AreEqual(newPersonResponse.person.email, aTestPerson.email);

            testPerson = newPersonResponse.person;

            // Create a temporary test contact type:
            var aTestContactType = new ContactType()
            {
                name = "Test Contact Type Drive 2015",
            };
            try
            {
                var newContactTypeResponse = session.CreateContactType(aTestContactType);

                Assert.IsTrue(newContactTypeResponse.contact_type.id.HasValue);
                Assert.AreEqual(newContactTypeResponse.contact_type.name, aTestContactType.name);

                testContactType = newContactTypeResponse.contact_type;
            }
            catch (NationBuilderRemoteException exc)
            {
                if (HttpStatusCode.BadRequest == exc.HttpStatusCode && "Validation Failed." == exc.Message)
                {
                    // A contact type with that name probably already exists, attempt to find it:
                    testContactType = null;

                    foreach (var contactType in session.GetContactTypeResults())
                    {
                        if (contactType.name == aTestContactType.name)
                        {
                            testContactType = contactType;
                            break;
                        }
                    }

                    Assert.IsNotNull(testContactType);
                }
                else
                {
                    throw exc;
                }
            }

            // Find a test contact method:
            ContactMethod aTestContactMethod = null;

            foreach (var contactMethod in session.GetContactMethodResults())
            {
                aTestContactMethod = contactMethod;
                break;
            }
            if (null == aTestContactMethod)
            {
                throw new InvalidOperationException("No available contact methods found for testing.");
            }

            testContactMethod = aTestContactMethod;

            // Find a test contact status:
            ContactStatus aTestContactStatus = null;

            foreach (var contactStatus in session.GetContactStatusesResults())
            {
                aTestContactStatus = contactStatus;
                break;
            }
            if (null == aTestContactStatus)
            {
                throw new InvalidOperationException("No available contact statuses found for testing.");
            }

            testContactStatus = aTestContactStatus;
        }
コード例 #33
0
        public void ShowPersonWithExternalId()
        {
            using (var session = new NationBuilderSession(TestNationSlug, TestNationAccessToken))
            {
                // Test remote ID escaping:
                string testId = "h!6&access_token=null";

                // Create a test person object:
                var testPerson = new Person()
                {
                    first_name = "Tes",
                    last_name = "Per",
                    email = "*****@*****.**",
                    external_id = testId,
                };
                var newPersonResponse = session.PushPerson(testPerson);

                Assert.AreEqual(newPersonResponse.person.external_id, testId);
                Assert.IsTrue(newPersonResponse.person.id.HasValue);

                var showPersonResponse = session.ShowPersonWithExternalId(testId);

                Assert.AreEqual(showPersonResponse.person.id, newPersonResponse.person.id);
                Assert.AreEqual(showPersonResponse.person.external_id, testId);

                // Remove the test person object:
                session.DestroyPerson(newPersonResponse.person.id.Value);
            }
        }
コード例 #34
0
ファイル: Contacts.cs プロジェクト: pavpen/NationBuilderAPI
        private bool DoesContactTypeExist(NationBuilderSession session, ContactType value)
        {
            foreach (var contactType in session.GetContactTypeResults())
            {
                if (value.Equals(contactType))
                {
                    Assert.AreEqual(value.id, contactType.id);
                    Assert.AreEqual(value.name, contactType.name);

                    return true;
                }
            }

            return false;
        }
コード例 #35
0
ファイル: Contacts.cs プロジェクト: pavpen/NationBuilderAPI
        public void CreateContactToPerson()
        {
            using (var session = new NationBuilderSession(TestNationSlug, TestNationAccessToken))
            {
                var testSender = session.PersonMe().person;
                
                Person testPerson;
                ContactType testContactType;
                ContactMethod testContactMethod;
                ContactStatus testContactStatus;

                CreateTestContactObjects(session, out testPerson, out testContactType, out testContactMethod, out testContactStatus);

                // Create a test contact to a person:
                var testContact = new Contact()
                {
                    type_id = testContactType.id.Value,
                    method = testContactMethod.api_name,
                    sender_id = testSender.id.Value,
                    status = testContactStatus.api_name,
                    note = "Tasted well",
                };
                var contactResponse = CreateTestContact(session, testPerson.id.Value, testContact);

                // Test destroying the contact type:
                session.DestroyContactType(testContactType.id.Value);

                //foreach (var contact in session.GetContactsToPersonResults(testPerson.id.Value))
                //{
                //    Assert.AreNotEqual(contact.type_id, testContactType.id.Value);
                //}

                // Destroy temporary objects:
                session.DestroyPerson(testPerson.id.Value);
            }
        }
コード例 #36
0
        public void ShowPersonWithExternalId_WithNonExistentId()
        {
            using (var session = new NationBuilderSession(TestNationSlug, TestNationAccessToken))
            {
                // Test remote ID escaping:
                string testId = "h!6&access_token=null";

                try
                {
                    var nonExistentPersonResponse = session.ShowPersonWithExternalId(testId);
                }
                catch (NationBuilderRemoteException exc)
                {
                    Assert.AreEqual("not_found", exc.ExceptionCode);
                    Assert.AreEqual(HttpStatusCode.NotFound, exc.HttpStatusCode);
                    return;
                }

                Assert.Fail("ShowPersonWithExternalId() did not throw an exception with the expected parameters!");
            }
        }
コード例 #37
0
        public void ShowPerson_WithNonExistentId()
        {
            using (var session = new NationBuilderSession(TestNationSlug, TestNationAccessToken))
            {
                long testId;
                var testPerson = new Person()
                {
                    first_name = "Tes",
                    last_name = "Per",
                    email = "*****@*****.**",
                };

                try
                {
                    var personResponse = session.MatchPerson(testPerson.email, testPerson.first_name, testPerson.last_name);

                    testId = personResponse.person.id.Value;
                }
                catch (NationBuilderRemoteException exc)
                {
                    if ("no_matches" == exc.ExceptionCode || "multiple_matches"==exc.ExceptionCode)
                    {
                        // Allocate a new person ID:
                        var newPersonResponse = session.CreatePerson(testPerson);

                        testId = newPersonResponse.person.id.Value;
                    }
                    else
                    {
                        throw exc;
                    }
                }

                // Make sure there's no person with that ID:
                session.DestroyPerson(testId);

                try
                {
                    var nonExistentPersonResponse = session.ShowPerson(testId);
                }
                catch (NationBuilderRemoteException exc)
                {
                    Assert.AreEqual("not_found", exc.ExceptionCode);
                    Assert.AreEqual(HttpStatusCode.NotFound, exc.HttpStatusCode);
                    return;
                }

                Assert.Fail("ShowPerson() did not thrown an exception with the expected parameters!");
            }
        }
コード例 #38
0
        private void CreateTestContactObjects(NationBuilderSession session, out Person testPerson, out ContactType testContactType, out ContactMethod testContactMethod,
                                              out ContactStatus testContactStatus)
        {
            // Create a temporary test person object:
            var aTestPerson = new Person()
            {
                first_name = "Tes",
                last_name  = "Per",
                email      = "*****@*****.**",
            };
            var newPersonResponse = session.PushPerson(aTestPerson);

            Assert.IsTrue(newPersonResponse.person.id.HasValue);
            Assert.AreEqual(newPersonResponse.person.first_name, aTestPerson.first_name);
            Assert.AreEqual(newPersonResponse.person.last_name, aTestPerson.last_name);
            Assert.AreEqual(newPersonResponse.person.email, aTestPerson.email);

            testPerson = newPersonResponse.person;

            // Create a temporary test contact type:
            var aTestContactType = new ContactType()
            {
                name = "Test Contact Type Drive 2015",
            };

            try
            {
                var newContactTypeResponse = session.CreateContactType(aTestContactType);

                Assert.IsTrue(newContactTypeResponse.contact_type.id.HasValue);
                Assert.AreEqual(newContactTypeResponse.contact_type.name, aTestContactType.name);

                testContactType = newContactTypeResponse.contact_type;
            }
            catch (NationBuilderRemoteException exc)
            {
                if (HttpStatusCode.BadRequest == exc.HttpStatusCode && "Validation Failed." == exc.Message)
                {
                    // A contact type with that name probably already exists, attempt to find it:
                    testContactType = null;

                    foreach (var contactType in session.GetContactTypeResults())
                    {
                        if (contactType.name == aTestContactType.name)
                        {
                            testContactType = contactType;
                            break;
                        }
                    }

                    Assert.IsNotNull(testContactType);
                }
                else
                {
                    throw exc;
                }
            }

            // Find a test contact method:
            ContactMethod aTestContactMethod = null;

            foreach (var contactMethod in session.GetContactMethodResults())
            {
                aTestContactMethod = contactMethod;
                break;
            }
            if (null == aTestContactMethod)
            {
                throw new InvalidOperationException("No available contact methods found for testing.");
            }

            testContactMethod = aTestContactMethod;

            // Find a test contact status:
            ContactStatus aTestContactStatus = null;

            foreach (var contactStatus in session.GetContactStatusesResults())
            {
                aTestContactStatus = contactStatus;
                break;
            }
            if (null == aTestContactStatus)
            {
                throw new InvalidOperationException("No available contact statuses found for testing.");
            }

            testContactStatus = aTestContactStatus;
        }
コード例 #39
0
        public void PushNewPerson()
        {
            using (var session = new NationBuilderSession(TestNationSlug, TestNationAccessToken))
            {
                // Create a test person object:
                var testPerson = new Person()
                {
                    first_name = "Testy",
                    last_name = "Pushy",
                    email = "*****@*****.**",
                };
                var newPersonResponse = session.PushPerson(testPerson);

                Assert.IsTrue(newPersonResponse.person.id.HasValue);

                // Ensure we are pushing a new person, rather than updating an existing one:
                session.DestroyPerson(newPersonResponse.person.id.Value);

                newPersonResponse = session.PushPerson(testPerson);
                Assert.IsTrue(newPersonResponse.person.id.HasValue);
                Assert.AreEqual(newPersonResponse.Http.StatusCode, HttpStatusCode.Created);

                var showPersonResponse = session.ShowPerson(newPersonResponse.person.id.Value);

                Assert.AreEqual(showPersonResponse.person.id, newPersonResponse.person.id);

                // Remove the test person object:
                session.DestroyPerson(newPersonResponse.person.id.Value);
            }
        }
コード例 #40
0
 private void TestConnectionButton_Click(object sender, RoutedEventArgs e)
 {
     using (var session = new NationBuilderSession(Settings.TestNationSlug, Settings.TestNationAccessToken))
     {
         try
         {
             session.PersonMe();
             OutputSuccess("Successfully connected to the Nation Builder service with slug \"" + Settings.TestNationSlug + "\".");
         }
         catch (Exception exc)
         {
             OutputError("Error connecting to the Nation Builder service.", exc);
         }
     }
 }