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 ForceClient(string instanceUrl, string accessToken, string apiVersion, HttpClient httpClientForJson, HttpClient httpClientForXml)
        {
            if (string.IsNullOrEmpty(instanceUrl))
            {
                throw new ArgumentNullException("instanceUrl");
            }
            if (string.IsNullOrEmpty(accessToken))
            {
                throw new ArgumentNullException("accessToken");
            }
            if (string.IsNullOrEmpty(apiVersion))
            {
                throw new ArgumentNullException("apiVersion");
            }
            if (httpClientForJson == null)
            {
                throw new ArgumentNullException("httpClientForJson");
            }
            if (httpClientForXml == null)
            {
                throw new ArgumentNullException("httpClientForXml");
            }

            _jsonHttpClient = new JsonHttpClient(instanceUrl, apiVersion, accessToken, httpClientForJson);
            _xmlHttpClient  = new XmlHttpClient(instanceUrl, apiVersion, accessToken, httpClientForXml);

            SelectListResolver = new DataMemberSelectListResolver();
        }
Beispiel #4
0
        public DnfClient(string?instanceUrl, string?accessToken, string?refreshToken, Action <string>?logger = null)
        {
            Logger             = logger;
            SelectListResolver = new DataMemberSelectListResolver();
            HttpClient jsonClient;
            HttpClient xmlClient;

            if (UseCompression)
            {
                var httpHandler = new HttpClientHandler
                {
                    AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate
                };
                jsonClient = new HttpClient(httpHandler)
                {
                    Timeout = TimeSpan.FromSeconds(60 * 30)
                };
                //jsonClient.DefaultRequestHeaders.ConnectionClose = true;
                jsonClient.DefaultRequestHeaders.AcceptEncoding.Add(new StringWithQualityHeaderValue("gzip"));
                xmlClient = new HttpClient(httpHandler)
                {
                    Timeout = TimeSpan.FromSeconds(60 * 30)
                };
            }
            else
            {
                jsonClient = new HttpClient {
                    Timeout = TimeSpan.FromSeconds(60 * 30)
                };
                xmlClient = new HttpClient {
                    Timeout = TimeSpan.FromSeconds(60 * 30)
                };
            }

            //xmlClient.DefaultRequestHeaders.ConnectionClose = true;
            xmlClient.DefaultRequestHeaders.AcceptEncoding.Add(new StringWithQualityHeaderValue("gzip"));
            InstanceUrl  = instanceUrl;
            AccessToken  = accessToken;
            RefreshToken = refreshToken;
            ApiVersion   = DefaultApiVersion;

            JsonHttp = new JsonHttpClient(InstanceUrl, ApiVersion, AccessToken, jsonClient);
            XmlHttp  = new XmlHttpClient(InstanceUrl, ApiVersion, AccessToken, xmlClient);

            Chatter   = new ChatterClient(JsonHttp);
            Composite = new CompositeClient(JsonHttp, ApiVersion, Logger);
            Tooling   = new ToolingClient(JsonHttp);
            Bulk      = new BulkClient(XmlHttp, JsonHttp);
            Layout    = new LayoutClient(XmlHttp, JsonHttp);
        }
 public void CheckInterfaces()
 {
     using (IAuthenticationClient aa = new AuthenticationClient())
     {
         Assert.IsNotNull(aa);
     }
     using (IJsonHttpClient aa = new JsonHttpClient("instanceUrl", "apiVersion", "accessToken", new HttpClient()))
     {
         Assert.IsNotNull(aa);
     }
     using (IXmlHttpClient aa = new XmlHttpClient("instanceUrl", "apiVersion", "accessToken", new HttpClient()))
     {
         Assert.IsNotNull(aa);
     }
 }
        public async Task Requests_CheckHttpRequestMessage_HttpGetXml()
        {
            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");
            }, new object()));

            using (var httpClient = new XmlHttpClient("http://localhost:1899", "v32", "accessToken", client))
            {
                await httpClient.HttpGetAsync <object>("brad");
            }
        }
        public async void Requests_CheckHttpRequestMessage_HttpGetXml()
        {
            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");
            }, new object()));

            using (var httpClient = new XmlHttpClient("http://localhost:1899", "v32", "accessToken", client))
            {
                await httpClient.HttpGetAsync<object>("brad");
            }
        }
        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);
            }
        }
Beispiel #9
0
 public LayoutClient(XmlHttpClient xmlHttpClient, JsonHttpClient jsonHttpClient)
 {
     XmlHttpClient  = xmlHttpClient;
     JsonHttpClient = jsonHttpClient;
 }
Beispiel #10
0
 public BulkClient(XmlHttpClient xmlHttpClient, JsonHttpClient jsonHttpClient)
 {
     XmlHttpClient  = xmlHttpClient;
     JsonHttpClient = jsonHttpClient;
 }