示例#1
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;
        }
示例#2
0
 public bool Equals(Person comparand)
 {
     return Equals((object)comparand);
 }
示例#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 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!");
            }
        }
示例#5
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);
            }
        }