Esempio n. 1
0
 public bool Equals(ContactMethod comparand)
 {
     return(Equals((object)comparand));
 }
Esempio n. 2
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;
        }
Esempio n. 3
0
 public bool Equals(ContactMethod comparand)
 {
     return Equals((object)comparand);
 }