Ejemplo n.º 1
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);
            }
        }
Ejemplo n.º 2
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);
            }
        }
Ejemplo n.º 3
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!");
            }
        }
Ejemplo n.º 4
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);
            }
        }
Ejemplo n.º 5
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);
            }
        }
Ejemplo n.º 6
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!");
            }
        }
Ejemplo n.º 7
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);
            }
        }
Ejemplo n.º 8
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);
            }
        }