public async void RunJobAndPoll_NullBatchList_ArgumentNullException()
        {
            var client = new ForceClient("test", "test", "v32");
            await client.RunJobAndPollAsync<List<ISObjectList<SObject>>>("Account", BulkConstants.OperationType.Insert, null);

            // expects exception
        }
        public async void RunJobAndPoll_NullObjectName_ArgumentNullException()
        {
            var client = new ForceClient("test", "test", "v32");
            await client.RunJobAndPollAsync(null, BulkConstants.OperationType.Insert, new List<ISObjectList<SObject>>());

            // expects exception
        }
        public async void RunJobAndPoll_NullObjectName_ArgumentNullException()
        {
            var client = new ForceClient("test", "test", "v32");
            await client.RunJobAndPollAsync(null, BulkConstants.OperationType.Insert, new List <ISObjectList <SObject> >());

            // expects exception
        }
        public async void RunJobAndPoll_NullBatchList_ArgumentNullException()
        {
            var client = new ForceClient("test", "test", "v32");
            await client.RunJobAndPollAsync <List <ISObjectList <SObject> > >("Account", BulkConstants.OperationType.Insert, null);

            // expects exception
        }
示例#5
0
        public async Task RunJobAndPoll_NullExternalIdOnUpsert_ArgumentNullException()
        {
            var client = new ForceClient("test", "test", "v32");
            await client.RunJobAndPollAsync("Account", null, BulkConstants.OperationType.Upsert, new List <ISObjectList <SObject> >());

            // expects exception
        }
        public async void RunJobAndPoll_GoodData_CompleteRunThroughSucceeds()
        {
            var expectedResponses = new List<HttpResponseMessage>
            {
                // create job
                new HttpResponseMessage(HttpStatusCode.OK)
                {
                    Content = new XmlContent(new JobInfoResult
                    {
                        ApiVersion = 32.0f,
                        ConcurrencyMode = "Parallel",
                        ContentType = "XML",
                        CreatedById = "test",
                        CreatedDate = DateTime.Now,
                        Id = "test",
                        NumberBatchesCompleted = 0,
                        NumberBatchesFailed = 0,
                        NumberBatchesInProgress = 0,
                        NumberBatchesQueued = 1,
                        SystemModstamp = DateTime.Now,
                        State = "Open"
                    })
                },
                // create batch
                new HttpResponseMessage(HttpStatusCode.OK)
                {
                    Content = new XmlContent(new BatchInfoResult
                    {
                        CreatedDate = DateTime.Now,
                        Id = "test",
                        JobId = "test",
                        NumberRecordsProcessed = 0,
                        State = "Queued",
                        SystemModstamp = DateTime.Now
                    })
                },
                // close job
                new HttpResponseMessage(HttpStatusCode.OK)
                {
                    Content = new XmlContent(new JobInfoResult
                    {
                        ApiVersion = 32.0f,
                        ConcurrencyMode = "Parallel",
                        ContentType = "XML",
                        CreatedById = "test",
                        CreatedDate = DateTime.Now,
                        Id = "test",
                        NumberBatchesCompleted = 0,
                        NumberBatchesFailed = 0,
                        NumberBatchesInProgress = 0,
                        NumberBatchesQueued = 1,
                        SystemModstamp = DateTime.Now,
                        State = "Closed"
                    })
                },
                // poll batch
                new HttpResponseMessage(HttpStatusCode.OK)
                {
                    Content = new XmlContent(new BatchInfoResult
                    {
                        CreatedDate = DateTime.Now,
                        Id = "test",
                        JobId = "test",
                        NumberRecordsProcessed = 1,
                        State = "Completed",
                        SystemModstamp = DateTime.Now
                    })
                },
                // get batch result
                new HttpResponseMessage(HttpStatusCode.OK)
                {
                    Content = new XmlContent(new BatchResultList
                    {
                        Items = new SObjectList<BatchResult>
                        {
                            new BatchResult
                            {
                                Id = "000000000000000000",
                                Created = true,
                                Success = true
                            }
                        }
                    })
                }
            };

            var inputList = new List<SObjectList<SObject>>
            {
                new SObjectList<SObject>
                {
                    new SObject
                    {
                        {"Name", "TestAccount1"}
                    }
                }
            };

            var testingActions = new List<Action<HttpRequestMessage>>
            {
                // create job
                r => Assert.AreEqual(r.Content.ReadAsStringAsync().Result, MimicSerialization(new JobInfo
                {
                    ContentType = "XML",
                    Object = "Account",
                    Operation = BulkConstants.OperationType.Insert.Value()
                })),
                // create batch
                r => Assert.AreEqual(r.Content.ReadAsStringAsync().Result, MimicSerialization(inputList[0])),
                // close job
                r => Assert.AreEqual(r.Content.ReadAsStringAsync().Result, MimicSerialization(new JobInfoState
                {
                    State = "Closed"
                })),
                // poll batch
                r => { /* NO PAYLOAD */ },
                // get batch result
                r => { /* NO PAYLOAD */ }
            };

            var httpClient = new HttpClient(new BulkFakeHttpRequestHandler(expectedResponses, testingActions));
            var client = new ForceClient("http://localhost:1899", "accessToken", "v29", new HttpClient(), httpClient);

            using (client)
            {
                await client.RunJobAndPollAsync("Account", BulkConstants.OperationType.Insert, inputList);
            }
        }
        public async void RunJobAndPoll_GoodData_CompleteRunThroughSucceeds()
        {
            var expectedResponses = new List <HttpResponseMessage>
            {
                // create job
                new HttpResponseMessage(HttpStatusCode.OK)
                {
                    Content = new XmlContent(new JobInfoResult
                    {
                        ApiVersion      = 32.0f,
                        ConcurrencyMode = "Parallel",
                        ContentType     = "XML",
                        CreatedById     = "test",
                        CreatedDate     = DateTime.Now,
                        Id = "test",
                        NumberBatchesCompleted  = 0,
                        NumberBatchesFailed     = 0,
                        NumberBatchesInProgress = 0,
                        NumberBatchesQueued     = 1,
                        SystemModstamp          = DateTime.Now,
                        State = "Open"
                    })
                },
                // create batch
                new HttpResponseMessage(HttpStatusCode.OK)
                {
                    Content = new XmlContent(new BatchInfoResult
                    {
                        CreatedDate            = DateTime.Now,
                        Id                     = "test",
                        JobId                  = "test",
                        NumberRecordsProcessed = 0,
                        State                  = "Queued",
                        SystemModstamp         = DateTime.Now
                    })
                },
                // close job
                new HttpResponseMessage(HttpStatusCode.OK)
                {
                    Content = new XmlContent(new JobInfoResult
                    {
                        ApiVersion      = 32.0f,
                        ConcurrencyMode = "Parallel",
                        ContentType     = "XML",
                        CreatedById     = "test",
                        CreatedDate     = DateTime.Now,
                        Id = "test",
                        NumberBatchesCompleted  = 0,
                        NumberBatchesFailed     = 0,
                        NumberBatchesInProgress = 0,
                        NumberBatchesQueued     = 1,
                        SystemModstamp          = DateTime.Now,
                        State = "Closed"
                    })
                },
                // poll batch
                new HttpResponseMessage(HttpStatusCode.OK)
                {
                    Content = new XmlContent(new BatchInfoResult
                    {
                        CreatedDate            = DateTime.Now,
                        Id                     = "test",
                        JobId                  = "test",
                        NumberRecordsProcessed = 1,
                        State                  = "Completed",
                        SystemModstamp         = DateTime.Now
                    })
                },
                // get batch result
                new HttpResponseMessage(HttpStatusCode.OK)
                {
                    Content = new XmlContent(new BatchResultList
                    {
                        Items = new SObjectList <BatchResult>
                        {
                            new BatchResult
                            {
                                Id      = "000000000000000000",
                                Created = true,
                                Success = true
                            }
                        }
                    })
                }
            };

            var inputList = new List <SObjectList <SObject> >
            {
                new SObjectList <SObject>
                {
                    new SObject
                    {
                        { "Name", "TestAccount1" }
                    }
                }
            };

            var testingActions = new List <Action <HttpRequestMessage> >
            {
                // create job
                r => Assert.AreEqual(r.Content.ReadAsStringAsync().Result, MimicSerialization(new JobInfo
                {
                    ContentType = "XML",
                    Object      = "Account",
                    Operation   = BulkConstants.OperationType.Insert.Value()
                })),
                // create batch
                r => Assert.AreEqual(r.Content.ReadAsStringAsync().Result, MimicSerialization(inputList[0])),
                // close job
                r => Assert.AreEqual(r.Content.ReadAsStringAsync().Result, MimicSerialization(new JobInfoState
                {
                    State = "Closed"
                })),
                // poll batch
                r => { /* NO PAYLOAD */ },
                // get batch result
                r => { /* NO PAYLOAD */ }
            };

            var httpClient = new HttpClient(new BulkFakeHttpRequestHandler(expectedResponses, testingActions));
            var client     = new ForceClient("http://localhost:1899", "accessToken", "v29", new HttpClient(), httpClient);

            using (client)
            {
                await client.RunJobAndPollAsync("Account", BulkConstants.OperationType.Insert, inputList);
            }
        }
        public async Task FullRunThrough()
        {
            // Make a strongly typed Account list
            var stAccountsBatch = new SObjectList <Account>
            {
                new Account {
                    Name = "TestStAccount1"
                },
                new Account {
                    Name = "TestStAccount2"
                },
                new Account {
                    Name = "TestStAccount3"
                }
            };

            // insert the accounts
            var results1 = await _client.RunJobAndPollAsync("Account", BulkConstants.OperationType.Insert,
                                                            new List <SObjectList <Account> > {
                stAccountsBatch
            });

            // (one SObjectList<T> per batch, the example above uses one batch)

            Assert.IsTrue(results1 != null, "[results1] empty result object");
            Assert.AreEqual(results1.Count, 1, "[results1] wrong number of results");
            Assert.AreEqual(results1[0].Items.Count, 3, "[results1] wrong number of result records");
            Assert.IsTrue(results1[0].Items[0].Created);
            Assert.IsTrue(results1[0].Items[0].Success);
            Assert.IsTrue(results1[0].Items[1].Created);
            Assert.IsTrue(results1[0].Items[1].Success);
            Assert.IsTrue(results1[0].Items[2].Created);
            Assert.IsTrue(results1[0].Items[2].Success);


            // Make a dynamic typed Account list
            var dtAccountsBatch = new SObjectList <SObject>
            {
                new SObject {
                    { "Name", "TestDtAccount1" }
                },
                new SObject {
                    { "Name", "TestDtAccount2" }
                },
                new SObject {
                    { "Name", "TestDtAccount3" }
                }
            };

            // insert the accounts
            var results2 = await _client.RunJobAndPollAsync("Account", BulkConstants.OperationType.Insert,
                                                            new List <SObjectList <SObject> > {
                dtAccountsBatch
            });

            Assert.IsTrue(results2 != null, "[results2] empty result object");
            Assert.AreEqual(results2.Count, 1, "[results2] wrong number of results");
            Assert.AreEqual(results2[0].Items.Count, 3, "[results2] wrong number of result records");
            Assert.IsTrue(results2[0].Items[0].Created);
            Assert.IsTrue(results2[0].Items[0].Success);
            Assert.IsTrue(results2[0].Items[1].Created);
            Assert.IsTrue(results2[0].Items[1].Success);
            Assert.IsTrue(results2[0].Items[2].Created);
            Assert.IsTrue(results2[0].Items[2].Success);

            // get the id of the first account created in the first batch
            var id = results2[0].Items[0].Id;

            dtAccountsBatch = new SObjectList <SObject>
            {
                new SObject
                {
                    { "Id", id },
                    { "Name", "TestDtAccount1Renamed" }
                }
            };

            // update the first accounts name (dont really need bulk for this, just an example)
            var results3 = await _client.RunJobAndPollAsync("Account", BulkConstants.OperationType.Update,
                                                            new List <SObjectList <SObject> > {
                dtAccountsBatch
            });

            Assert.IsTrue(results3 != null);
            Assert.AreEqual(results3.Count, 1);
            Assert.AreEqual(results3[0].Items.Count, 1);
            Assert.AreEqual(results3[0].Items[0].Id, id);
            Assert.IsFalse(results3[0].Items[0].Created);
            Assert.IsTrue(results3[0].Items[0].Success);

            // create an Id list for the original strongly typed accounts created
            var idBatch = new SObjectList <SObject>();

            idBatch.AddRange(results1[0].Items.Select(result => new SObject {
                { "Id", result.Id }
            }));

            // delete all the strongly typed accounts
            var results4 = await _client.RunJobAndPollAsync("Account", BulkConstants.OperationType.Delete,
                                                            new List <SObjectList <SObject> > {
                idBatch
            });



            Assert.IsTrue(results4 != null, "[results4] empty result object");
            Assert.AreEqual(results4.Count, 1, "[results4] wrong number of results");
            Assert.AreEqual(results4[0].Items.Count, 3, "[results4] wrong number of result records");
            Assert.IsFalse(results4[0].Items[0].Created);
            Assert.IsTrue(results4[0].Items[0].Success);
        }
        private static async Task RunSample()
        {
            var auth = new AuthenticationClient();

            // Authenticate with Salesforce
            Console.WriteLine("Authenticating with Salesforce");
            var url = IsSandboxUser.Equals("true", StringComparison.CurrentCultureIgnoreCase)
                ? "https://test.salesforce.com/services/oauth2/token"
                : "https://login.salesforce.com/services/oauth2/token";

            await auth.UsernamePasswordAsync(ConsumerKey, ConsumerSecret, Username, Password, url);
            Console.WriteLine("Connected to Salesforce");

            // Get a bulk client
            var client = new ForceClient(auth.InstanceUrl, auth.AccessToken, auth.ApiVersion);

            // Make a strongly typed Account list
            var stAccountsBatch = new SObjectList<Account>
            {
                new Account {Name = "TestStAccount1"},
                new Account {Name = "TestStAccount2"},
                new Account {Name = "TestStAccount3"}
            };

            // insert the accounts
            var results1 = await client.RunJobAndPollAsync("Account", BulkConstants.OperationType.Insert,
                    new List<SObjectList<Account>>{stAccountsBatch});
            // (one SObjectList<T> per batch, the example above uses one batch)

            Console.WriteLine("Strongly typed accounts created");

            // Make a dynamic typed Account list
            var dtAccountsBatch = new SObjectList<SObject>
            {
                new SObject{{"Name", "TestDtAccount1"}},
                new SObject{{"Name", "TestDtAccount2"}},
                new SObject{{"Name", "TestDtAccount3"}}
            };

            // insert the accounts
            var results2 = await client.RunJobAndPollAsync("Account", BulkConstants.OperationType.Insert,
                    new List<SObjectList<SObject>>{dtAccountsBatch});

            Console.WriteLine("Dynamically typed accounts created");

            // get the id of the first account created in the first batch
            var id = results2[0][0].Id;
            dtAccountsBatch = new SObjectList<SObject>
            {
                new SObject
                {
                    {"Id", id},
                    {"Name", "TestDtAccount1Renamed"}
                }
            };

             // update the first accounts name (dont really need bulk for this, just an example)
            var results3 = await client.RunJobAndPollAsync("Account", BulkConstants.OperationType.Update,
                    new List<SObjectList<SObject>>{dtAccountsBatch});

            Console.WriteLine("Account with ID {0} updated", id);

            // create an Id list for the original strongly typed accounts created
            var idBatch = new SObjectList<SObject>();
            idBatch.AddRange(results1[0].Select(result => new SObject {{"Id", result.Id}}));

            // delete all the strongly typed accounts
            var results4 = await client.RunJobAndPollAsync("Account", BulkConstants.OperationType.Delete,
                    new List<SObjectList<SObject>>{idBatch});

            Console.WriteLine("Accounts deleted");
        }
        private static async Task RunSample()
        {
            var auth = new AuthenticationClient();

            // Authenticate with Salesforce
            Console.WriteLine("Authenticating with Salesforce");
            var url = IsSandboxUser.Equals("true", StringComparison.CurrentCultureIgnoreCase)
                ? "https://test.salesforce.com/services/oauth2/token"
                : "https://login.salesforce.com/services/oauth2/token";

            await auth.UsernamePasswordAsync(ConsumerKey, ConsumerSecret, Username, Password, url);

            Console.WriteLine("Connected to Salesforce");

            // Get a bulk client
            var client = new ForceClient(auth.InstanceUrl, auth.AccessToken, auth.ApiVersion);

            // Make a strongly typed Account list
            var stAccountsBatch = new SObjectList <Account>
            {
                new Account {
                    Name = "TestStAccount1"
                },
                new Account {
                    Name = "TestStAccount2"
                },
                new Account {
                    Name = "TestStAccount3"
                }
            };

            // insert the accounts
            var results1 = await client.RunJobAndPollAsync("Account", BulkConstants.OperationType.Insert,
                                                           new List <SObjectList <Account> > {
                stAccountsBatch
            });

            // (one SObjectList<T> per batch, the example above uses one batch)

            Console.WriteLine("Strongly typed accounts created");

            // Make a dynamic typed Account list
            var dtAccountsBatch = new SObjectList <SObject>
            {
                new SObject {
                    { "Name", "TestDtAccount1" }
                },
                new SObject {
                    { "Name", "TestDtAccount2" }
                },
                new SObject {
                    { "Name", "TestDtAccount3" }
                }
            };

            // insert the accounts
            var results2 = await client.RunJobAndPollAsync("Account", BulkConstants.OperationType.Insert,
                                                           new List <SObjectList <SObject> > {
                dtAccountsBatch
            });

            Console.WriteLine("Dynamically typed accounts created");

            // get the id of the first account created in the first batch
            var id = results2[0][0].Id;

            dtAccountsBatch = new SObjectList <SObject>
            {
                new SObject
                {
                    { "Id", id },
                    { "Name", "TestDtAccount1Renamed" }
                }
            };

            // update the first accounts name (dont really need bulk for this, just an example)
            var results3 = await client.RunJobAndPollAsync("Account", BulkConstants.OperationType.Update,
                                                           new List <SObjectList <SObject> > {
                dtAccountsBatch
            });

            Console.WriteLine("Account with ID {0} updated", id);

            // create an Id list for the original strongly typed accounts created
            var idBatch = new SObjectList <SObject>();

            idBatch.AddRange(results1[0].Select(result => new SObject {
                { "Id", result.Id }
            }));

            // delete all the strongly typed accounts
            var results4 = await client.RunJobAndPollAsync("Account", BulkConstants.OperationType.Delete,
                                                           new List <SObjectList <SObject> > {
                idBatch
            });

            Console.WriteLine("Accounts deleted");
        }