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); } }
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); } }
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); } }
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."); } } }
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") + "."); } }
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); } } }
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); } }
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!"); } }
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); } } } }
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); }
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); } } }
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!"); } } } }
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."); } } }
// 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); } }
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."); } } }
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!"); } } } }
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!"); } }
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)); } }
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); } }
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); }
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; }
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; }
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; }
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!"); } }