public void SalesforceClientUpdateEntireObject() { // Arrange var service = new SalesforceClient(ConsumerKey, ConsumerSecret, RefreshToken); var contact = new Contact {Id = ContactId, Description = Guid.NewGuid().ToString()}; // Act service.Update<Contact>(contact); // Assert var updatedContact = service.Get<Contact>(ContactId); Assert.AreEqual(contact.Description, updatedContact.Description); }
public void SalesforceClientUpdateExistingObject() { // Arrange var service = new SalesforceClient(ConsumerKey, ConsumerSecret, RefreshToken); Contact contact = service.Get<Contact>(ContactId); var updateContact = new {Description = Guid.NewGuid().ToString()}; // Act service.Update<Contact>(updateContact, contact.Id); // Assert contact = service.Get<Contact>(ContactId); Assert.AreEqual(updateContact.Description, contact.Description); }
public void SalesforceClientUpdateAsyncExistingObject() { // Arrange var service = new SalesforceClient(ConsumerKey, ConsumerSecret, RefreshToken); Contact contact = service.Get<Contact>(ContactId); var updateContact = new {Description = Guid.NewGuid().ToString()}; // Act var response = service.UpdateAsync<Contact>(updateContact, contact.Id).Result; // Assert Assert.AreEqual(HttpStatusCode.NoContent, response.StatusCode); }
public void SalesforceClientGetValidatesNull() { // Arrange var service = new SalesforceClient(ConsumerKey, ConsumerSecret, RefreshToken); // Act // Assert Assert.Throws<ArgumentNullException>(() => service.Get<Account>(null)); }
public void SalesforceClientGetNonExistingObject() { // Arrange var service = new SalesforceClient(ConsumerKey, ConsumerSecret, RefreshToken); // Act // Assert var exception = Assert.Throws<SalesforceException>(() => service.Get<Contact>("003iiiiiiiiiiiii")); Assert.AreEqual(HttpStatusCode.NotFound, exception.StatusCode); }
public void SalesforceClientGetExistingObject() { // Arrange var service = new SalesforceClient(ConsumerKey, ConsumerSecret, RefreshToken); // Act Contact contact = service.Get<Contact>(ContactId); // Assert Assert.NotNull(contact); Assert.AreEqual(ContactId, contact.Id); }
public void ReadmeTest() { // Instantiate the client using a RefreshToken var service = new SalesforceClient(ConsumerKey, ConsumerSecret, RefreshToken); //----------------------------------------------------------------------------- // Queries //----------------------------------------------------------------------------- // Execute a SOQL query IList<Contact> contacts = service.Query<Contact>("SELECT id, name from Contact"); // Iterate through the records returned. foreach (Contact account in contacts) { Console.WriteLine(account.Name); } //----------------------------------------------------------------------------- // CRUD Operations //----------------------------------------------------------------------------- // Add a new record using annonymous object var id = service.Add<Contact>(new { FirstName = "John", LastName = "Smith" }); // Add a new record using POCO object id = service.Add<Contact>(new Contact { FirstName = "John", LastName = "Smith" }); // Read a record Contact contact = service.Get<Contact>(id); // Update a record using POCO object (null values are not serialized) contact.Email = "*****@*****.**"; service.Update<Contact>(contact); // Update a record using annonymous object service.Update<Contact>(new { Email = "*****@*****.**" }, id); // Delete a record service.Delete<Contact>(id); //----------------------------------------------------------------------------- // Error Handling //----------------------------------------------------------------------------- try { service.Add<Contact>(new { Name = "Read-only property" }); } catch (SalesforceException e) { Console.WriteLine("ErrorCode={0}; StatusCode={1}; Message={2}", e.ErrorCode, e.StatusCode, e.Message); // Output: // ErrorCode=INVALID_FIELD_FOR_INSERT_UPDATE; // StatusCode=BadRequest; // Message=Unable to create/update fields: Name. Please check the security settings of this field // and verify that it is read/write for your profile or permission set. // TODO: handle the exception } }