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