public async Task Requests_CheckHttpRequestMessageAndResponseDeserialization_HttpPostXml()
        {
            var testObject = new SerializerTest {
                TestField = "testMessage"
            };
            var client = new HttpClient(new BulkServiceClientRouteHandler(r =>
            {
                // the v should be removed...
                Assert.AreEqual(r.RequestUri.ToString(), "http://localhost:1899/services/data/32/brad");

                Assert.IsNotNull(r.Headers.UserAgent);
                Assert.AreEqual(r.Headers.UserAgent.ToString(), UserAgent + "/v32");

                Assert.IsNotNull(r.Headers.GetValues("X-SFDC-Session"));
                Assert.IsTrue(r.Headers.GetValues("X-SFDC-Session").Count() == 1);
                Assert.AreEqual(r.Headers.GetValues("X-SFDC-Session").First(), "accessToken");

                // check the object is serialized as expected
                var serializedPayload = MimicSerialization(testObject);
                var stringContent     = r.Content.ReadAsStringAsync().Result;
                Assert.AreEqual(serializedPayload, stringContent);
            }, testObject)); // pass in the object to be returned (Same object roundtripped here for simplicity)

            using (var httpClient = new XmlHttpClient("http://localhost:1899", "v32", "accessToken", client))
            {
                var result = await httpClient.HttpPostAsync <SerializerTest>(testObject, "brad");

                Assert.AreEqual(testObject.TestField, result.TestField);
            }
        }
        public async void Requests_CheckHttpRequestMessageAndResponseDeserialization_HttpPostXml()
        {
            var testObject = new SerializerTest {TestField = "testMessage"};
            var client = new HttpClient(new BulkServiceClientRouteHandler(r =>
            {
                // the v should be removed...
                Assert.AreEqual(r.RequestUri.ToString(), "http://localhost:1899/services/data/32/brad");

                Assert.IsNotNull(r.Headers.UserAgent);
                Assert.AreEqual(r.Headers.UserAgent.ToString(), UserAgent + "/v32");

                Assert.IsNotNull(r.Headers.GetValues("X-SFDC-Session"));
                Assert.IsTrue(r.Headers.GetValues("X-SFDC-Session").Count() == 1);
                Assert.AreEqual(r.Headers.GetValues("X-SFDC-Session").First(), "accessToken");

                // check the object is serialized as expected
                var serializedPayload = MimicSerialization(testObject);
                var stringContent = r.Content.ReadAsStringAsync().Result;
                Assert.AreEqual(serializedPayload, stringContent);

            }, testObject)); // pass in the object to be returned (Same object roundtripped here for simplicity)

            using (var httpClient = new XmlHttpClient("http://localhost:1899", "v32", "accessToken", client))
            {
                var result = await httpClient.HttpPostAsync<SerializerTest>(testObject, "brad");
                Assert.AreEqual(testObject.TestField, result.TestField);
            }
        }
        public async Task <JobInfoResult> CreateJobAsync(string objectName, BulkConstants.OperationType operationType)
        {
            if (string.IsNullOrEmpty(objectName))
            {
                throw new ArgumentNullException("objectName");
            }

            var jobInfo = new JobInfo
            {
                ContentType = "XML",
                Object      = objectName,
                Operation   = operationType.Value()
            };

            return(await _xmlHttpClient.HttpPostAsync <JobInfoResult>(jobInfo, "/services/async/{0}/job"));
        }
Beispiel #4
0
        public async Task <JobInfoResult> CreateJobAsync(string objectName, BulkConstants.OperationType operationType)
        {
            if (string.IsNullOrEmpty(objectName))
            {
                throw new ArgumentNullException(nameof(objectName));
            }

            var jobInfo = new JobInfo
            {
                ContentType = "XML",
                Object      = objectName,
                Operation   = operationType.Value()
            };

            const string resourceName = "/services/async/{0}/job";

            return(await XmlHttpClient.HttpPostAsync <JobInfoResult>(jobInfo, resourceName)
                   .ConfigureAwait(false) ?? new JobInfoResult());
        }
        public async Task BadTokenHandlingWithXml()
        {
            var badToken          = "badtoken";
            var serviceHttpClient = new XmlHttpClient(_auth.InstanceUrl, _auth.ApiVersion, badToken, new HttpClient());

            var jobInfo = new JobInfo
            {
                ContentType = "XML",
                Object      = "BadObject",
                Operation   = "BadOperation"
            };

            try
            {
                await serviceHttpClient.HttpPostAsync <JobInfoResult>(jobInfo, "/services/async/{0}/job");
            }
            catch (ForceException ex)
            {
                Assert.IsNotNull(ex);
                Assert.IsNotNull(ex.Message);
                Assert.That(ex.Message, Is.EqualTo("Invalid session id"));
                Assert.IsNotNull(ex.Error);
            }
        }