public void TestContactListItemsCRUD() { Contact c1 = new Contact { FirstName = "name1", HomePhone = "12345678901" }; Contact c2 = new Contact { FirstName = "name2", HomePhone = "12345678902" }; CreateContactListRequest<Contact> request = new CreateContactListRequest<Contact> { Contacts = new List<Contact> { c1, c2 }, Name = "listFromContacts" }; ResourceId id = Client.ContactListsApi.Create(request); AddContactListContactsRequest<string> addItemsRequest = new AddContactListContactsRequest<string> { ContactListId = id.Id, Contacts = new List<string> { "12345543211" } }; Client.ContactListsApi.AddListItems(addItemsRequest); GetByIdRequest getItemsRequest = new GetByIdRequest { Id = id.Id }; Page<Contact> contactListItems = Client.ContactListsApi.GetListItems(getItemsRequest); IList<Contact> items = contactListItems.Items; Assert.AreEqual(3, items.Count); Client.ContactListsApi.RemoveListItem(id.Id, (long)items[0].Id); contactListItems = Client.ContactListsApi.GetListItems(getItemsRequest); items = contactListItems.Items; Assert.AreEqual(2, items.Count); Client.ContactListsApi.RemoveListItems(id.Id, new List<long> { (long)items[0].Id, (long)items[1].Id }); contactListItems = Client.ContactListsApi.GetListItems(getItemsRequest); Assert.True(contactListItems.Items.Count == 0); Assert.AreEqual(0, contactListItems.TotalCount); Client.ContactListsApi.Delete(id.Id); }
public void ContactsCRUD() { var contact1 = new Contact { HomePhone = "12345678901", FirstName = "firstName", LastName = "lastName", Properties = new Dictionary<string, string> { { "age", "30" }, { "customFieldN", "customValue" } } }; var contact2 = new Contact { HomePhone = "12345678902" }; var contacts = Client.ContactsApi.Create(new List<Contact> { contact1, contact2 }); Console.WriteLine(String.Join(",", contacts)); Assert.AreEqual(2, contacts.Count); var savedContact1 = Client.ContactsApi.Get((long)contacts[0].Id); Console.WriteLine(savedContact1); Assert.AreEqual("12345678901", savedContact1.HomePhone); Assert.AreEqual("firstName", savedContact1.FirstName); Assert.AreEqual("lastName", savedContact1.LastName); contact2.Id = contacts[1].Id; contact2.FirstName = "contact2"; contact2.Zipcode = "12345"; contact2.Properties = new Dictionary<string, string> { { "key1", "value1" }, { "key2", "value2" } }; Client.ContactsApi.Update(contact2); var savedContact2 = Client.ContactsApi.Get((long)contact2.Id, "homePhone,zipcode,properties"); Console.WriteLine(savedContact2); Assert.IsNull(savedContact2.FirstName); Assert.AreEqual("12345678902", savedContact2.HomePhone); Assert.AreEqual("12345", savedContact2.Zipcode); Assert.AreEqual(contact2.Properties, savedContact2.Properties); Client.ContactsApi.Delete((long)contacts[0].Id); var contact = Client.ContactsApi.Get((long)contacts[0].Id, "id,deleted"); Assert.IsTrue((bool)contact.Deleted); Assert.IsNotNull(contact.Id); Assert.IsNull(contact.FirstName); Assert.IsNull(contact.HomePhone); }
public void Create() { string responseJson = GetJsonPayload("/contacts/contactsApi/response/createContactList.json"); var restRequest = MockRestResponse(responseJson); Contact c1 = new Contact { HomePhone = "123456" }; Contact c2 = new Contact { HomePhone = "123457" }; CreateContactListRequest<Contact> requestContact = new CreateContactListRequest<Contact> { Name = "listFromContacts", Contacts = new List<Contact> { c1, c2 } }; ResourceId res = Client.ContactListsApi.Create(requestContact); Assert.That(Serializer.Serialize(res), Is.EqualTo(responseJson)); Assert.AreEqual(Method.POST, restRequest.Value.Method); }
public void Create() { var requestJson = GetJsonPayload("/contacts/contactsApi/request/createContact.json"); var responseJson = GetJsonPayload("/contacts/contactsApi/response/createContact.json"); var restRequest = MockRestResponse(responseJson); var contact = new Contact { FirstName = "Test", LastName = "Contact", HomePhone = "12135551124" }; var contact2 = new Contact { FirstName = "Test2", LastName = "Contact2", HomePhone = "12135551125" }; var ids = Client.ContactsApi.Create(new List<Contact>{ contact, contact2 }); Assert.AreEqual(Method.POST, restRequest.Value.Method); Assert.That(Serializer.Serialize(new ListHolder<ResourceId>(ids)), Is.EqualTo(responseJson)); var requestBodyParam = restRequest.Value.Parameters.FirstOrDefault(p => p.Type == ParameterType.RequestBody); Assert.That(requestBodyParam.Value, Is.EqualTo(requestJson)); }
public void TestDynamicPropertiesSerializationContactPojos() { Contact c1 = new Contact { FirstName = "name1" }; Contact c2 = new Contact { FirstName = "name1" }; CreateContactListRequest<Contact> requestContact = new CreateContactListRequest<Contact>(); requestContact.Name = "listFromContacts"; requestContact.Contacts = new List<Contact> { c1, c2 }; String serialized = Serializer.Serialize(requestContact); Assert.That(serialized, Is.StringContaining("\"contacts\":")); Assert.That(serialized, Is.StringContaining("\"listFromContacts\"")); }
public void TestAddContactsToContactListById() { string expectedJson = GetJsonPayload("/contacts/contactsApi/response/addContactsToContactList.json"); var restRequest = MockRestResponse(expectedJson); Contact c1 = new Contact { HomePhone = "123456" }; Contact c2 = new Contact { HomePhone = "123457" }; AddContactListContactsRequest<Contact> request = new AddContactListContactsRequest<Contact> { ContactNumbersField = "homePhone", ContactListId = TEST_LONG, Contacts = new List<Contact> { c1, c2 } }; Client.ContactListsApi.AddListItems(request); var requestBodyParam = restRequest.Value.Parameters.FirstOrDefault(p => p.Type == ParameterType.RequestBody); Assert.AreEqual(requestBodyParam.Value, expectedJson); Assert.AreEqual(Method.POST, restRequest.Value.Method); Assert.That(restRequest.Value.Resource, Is.StringContaining("/" + TEST_LONG)); }
public void Update() { var requestJson = GetJsonPayload("/contacts/contactsApi/request/updateContact.json"); var restRequest = MockRestResponse(); var contact = new Contact { Id = 11, FirstName = "Test", LastName = "Contact", WorkPhone = "12135551124" }; Client.ContactsApi.Update(contact); Assert.AreEqual(Method.PUT, restRequest.Value.Method); var requestBodyParam = restRequest.Value.Parameters.FirstOrDefault(p => p.Type == ParameterType.RequestBody); Assert.AreEqual(requestBodyParam.Value, requestJson); Assert.That(restRequest.Value.Resource, Is.StringEnding("/11")); }