public void AnyAction_NotAuthentacated_Exception()
        {
            var target = new SalesforceClient();

            ExceptionAssert.IsThrowing(new InvalidOperationException("Please, execute Authenticate method before call any REST API operation."), () =>
            {
                target.Create("TESTE", "TESTE");
            });

            ExceptionAssert.IsThrowing(new InvalidOperationException("Please, execute Authenticate method before call any REST API operation."), () =>
            {
                target.Delete("TESTE", "TESTE");
            });

            ExceptionAssert.IsThrowing(new InvalidOperationException("Please, execute Authenticate method before call any REST API operation."), () =>
            {
                target.FindById <Exception>("TESTE", "TESTE");
            });

            ExceptionAssert.IsThrowing(new InvalidOperationException("Please, execute Authenticate method before call any REST API operation."), () =>
            {
                target.Query <Exception>("TESTE");
            });

            ExceptionAssert.IsThrowing(new InvalidOperationException("Please, execute Authenticate method before call any REST API operation."), () =>
            {
                target.Update("TESTE", "TESTE", "TESTE");
            });
        }
        public void Delete_NullOrEmptyId_Exception()
        {
            var target = new SalesforceClient();

            ExceptionAssert.IsThrowing(new ArgumentException("Argument 'recordId' can't be empty.", "recordId"), () =>
            {
                target.Delete("TESTE", "");
            });
        }
        public void Delete_NullOrEmptyObjectName_Exception()
        {
            var target = new SalesforceClient();

            ExceptionAssert.IsThrowing(new ArgumentException("Argument 'objectName' can't be empty.", "objectName"), () =>
            {
                target.Delete("", "TESTE");
            });
        }
        public async Task CreateUpdateDeleteShouldExecuteWithoutException()
        {
            var account = new Account()
            {
                Name = "Test Account " + guid.ToString()
            };

            var id = await client.Create(account);

            Assert.IsNotNull(id);

            account.Name = account.Name + "NEW";

            var successfull = await client.Update(id, account);

            Assert.AreEqual(true, successfull);

            successfull = await client.Delete("Account", id);

            Assert.AreEqual(true, successfull);
        }
示例#5
0
        public void SalesforceClientAddAndDelete()
        {
            // Arrange
            var service = new SalesforceClient(ConsumerKey, ConsumerSecret, RefreshToken);
            var ticks = DateTime.UtcNow.Ticks;
            var contact = new
                          {
                              LastName = "TestContact",
                              FirstName = ticks,
                              Email = "testcontact+" + ticks + "@gmail.com"
                          };

            // Act
            var id = service.Add<Contact>(contact);

            // Assert
            Assert.NotNull(id);

            // Act
            service.Delete<Contact>(id);

            // Assert
        }
示例#6
0
        public void SalesforceClientDeleteValidatesNull()
        {
            // Arrange
            var service = new SalesforceClient(ConsumerKey, ConsumerSecret, RefreshToken);

            // Act
            // Assert
            Assert.Throws<ArgumentNullException>(() => service.Delete<Account>(null));
        }
示例#7
0
        public void SalesforceClientDeleteFails()
        {
            // Arrange
            var service = new SalesforceClient(ConsumerKey, ConsumerSecret, RefreshToken);

            // Act
            // Assert
            var exception = Assert.Throws<SalesforceException>(() => service.Delete<Contact>("BadId"));
            Assert.AreEqual(HttpStatusCode.NotFound, exception.StatusCode);
        }
        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
            }
        }
        static void Main(string[] args)
        {
            // See the SalesforceSetupWalkthrough.doc for information on how to configure your SalesForce account

            // from your setup >> create >> apps >> connected apps settings in SalesForce
            const string sfdcConsumerKey = "3MVG9JZ_r.QzrS7gHCcJexYMP2UL45ZgzaagHsVXfYSjWwlhU7n2uaxzfsuBNvwjofV70lM9QtA_xYLTxXjgf";
            const string sfdcConsumerSecret = "2968907211720668629";

            // your user credentials in salesforce
            const string sfdcUserName = "******";
            const string sfdcPassword = "******";

            // your security token form salesforce.  Name >> My Settings >> Personal >>  Reset My Security Token
            const string sfdcToken = "w7UGcyJnOaWX8U7XRCEbIfLYw";

            var client = new SalesforceClient();
            var authFlow = new UsernamePasswordAuthenticationFlow(sfdcConsumerKey, sfdcConsumerSecret, sfdcUserName, sfdcPassword + sfdcToken);

            // all actions should be in a try-catch - i'll just do the authentication one for an example
            try
            {
                client.Authenticate(authFlow);
            }
            catch (SalesforceException ex)
            {
                Console.WriteLine("Authentication failed: {0} : {1}", ex.Error, ex.Message);
            }

            // create a record using a class instance
            SFCaseUpdate myCase = new SFCaseUpdate();
            myCase.Subject = "This is the subject of my salesforce case";
            myCase.Description = "This is the description of my salesforce case";
            myCase.Rank__c = 5;
            client.Create("Case", myCase);

            // create a record using an anonymous class and returns the ID
            string resultID = client.Create("Case", new { Subject = "This is the subject of another salesforce case", Description = "This is the description of that other salesforce case", Rank__c = 5 });

            // query records
            var records = client.Query<SFCase>("SELECT id, CaseNumber, Subject, Description, Rank__c FROM Case");
            foreach (var r in records)
            {
                Console.WriteLine("Query Records {0}: {1} {2}", r.id, r.CaseNumber, r.Subject);
            }

            // find the record we just added by the ID we captured above in resultID
            var record = client.FindById<SFCase>("Case", resultID);
            Console.WriteLine("\n\nRead this record {0} {1} {2} {3} {4}\n\n", record.id, record.CaseNumber, record.Subject, record.Description, record.Rank__c);

            // update that record and set the custom field rank to 1 using an anonymous class.
            client.Update("Case", resultID, new { Rank__c = 1 });

            // update that record and set the custom field rank to 9001 using a class instance, note that i have to fill in every property from the record or it will push back nulls
            SFCaseUpdate myupdate = new SFCaseUpdate();
            myupdate.Rank__c = 9001;
            myupdate.Description = record.Description;
            myupdate.Subject = record.Subject;
            client.Update("Case", resultID, myupdate);

            // re-read it to see if it updated correctly, rank should = 9001
            var record2 = client.FindById<SFCase>("Case", resultID);
            Console.WriteLine("Read this record again {0} {1} {2} {3} {4}\n\n", record2.id, record2.CaseNumber, record2.Subject, record2.Description, record2.Rank__c);

            // now delete the record I added
            client.Delete("Case", resultID);

            Console.WriteLine("Hit Enter to Exit");
            Console.ReadKey();
        }
示例#10
0
        static void Main(string[] args)
        {
            // See the SalesforceSetupWalkthrough.doc for information on how to configure your SalesForce account

            // from your setup >> create >> apps >> connected apps settings in SalesForce
            const string sfdcConsumerKey    = "3MVG9JZ_r.QzrS7gHCcJexYMP2UL45ZgzaagHsVXfYSjWwlhU7n2uaxzfsuBNvwjofV70lM9QtA_xYLTxXjgf";
            const string sfdcConsumerSecret = "2968907211720668629";

            // your user credentials in salesforce
            const string sfdcUserName = "******";
            const string sfdcPassword = "******";

            // your security token form salesforce.  Name >> My Settings >> Personal >>  Reset My Security Token
            const string sfdcToken = "w7UGcyJnOaWX8U7XRCEbIfLYw";

            var client   = new SalesforceClient();
            var authFlow = new UsernamePasswordAuthenticationFlow(sfdcConsumerKey, sfdcConsumerSecret, sfdcUserName, sfdcPassword + sfdcToken);

            // all actions should be in a try-catch - i'll just do the authentication one for an example
            try
            {
                client.Authenticate(authFlow);
            }
            catch (SalesforceException ex)
            {
                Console.WriteLine("Authentication failed: {0} : {1}", ex.Error, ex.Message);
            }

            // create a record using a class instance
            SFCaseUpdate myCase = new SFCaseUpdate();

            myCase.Subject     = "This is the subject of my salesforce case";
            myCase.Description = "This is the description of my salesforce case";
            myCase.Rank__c     = 5;
            client.Create("Case", myCase);

            // create a record using an anonymous class and returns the ID
            string resultID = client.Create("Case", new { Subject = "This is the subject of another salesforce case", Description = "This is the description of that other salesforce case", Rank__c = 5 });

            // query records
            var records = client.Query <SFCase>("SELECT id, CaseNumber, Subject, Description, Rank__c FROM Case");

            foreach (var r in records)
            {
                Console.WriteLine("Query Records {0}: {1} {2}", r.id, r.CaseNumber, r.Subject);
            }

            // find the record we just added by the ID we captured above in resultID
            var record = client.FindById <SFCase>("Case", resultID);

            Console.WriteLine("\n\nRead this record {0} {1} {2} {3} {4}\n\n", record.id, record.CaseNumber, record.Subject, record.Description, record.Rank__c);

            // update that record and set the custom field rank to 1 using an anonymous class.
            client.Update("Case", resultID, new { Rank__c = 1 });

            // update that record and set the custom field rank to 9001 using a class instance, note that i have to fill in every property from the record or it will push back nulls
            SFCaseUpdate myupdate = new SFCaseUpdate();

            myupdate.Rank__c     = 9001;
            myupdate.Description = record.Description;
            myupdate.Subject     = record.Subject;
            client.Update("Case", resultID, myupdate);

            // re-read it to see if it updated correctly, rank should = 9001
            var record2 = client.FindById <SFCase>("Case", resultID);

            Console.WriteLine("Read this record again {0} {1} {2} {3} {4}\n\n", record2.id, record2.CaseNumber, record2.Subject, record2.Description, record2.Rank__c);

            // now delete the record I added
            client.Delete("Case", resultID);


            Console.WriteLine("Hit Enter to Exit");
            Console.ReadKey();
        }