Exemple #1
0
        public void TestAccount()
        {
            Random ran       = new Random();
            int    name      = ran.Next(2000000);
            Guid   accountId = Guid.Empty;

            CRMClient crmClient = new CRMClient(AuthenticationHelper.AuthToken(), ConfigurationManager.AppSettings["ida:CrmResourceURL"]);
            var       task      = crmClient.ReadData("Account", "Name", "microsoft", "AccountId");

            task.Wait();
            string result = task.Result;

            if (result.IndexOf("guid") != -1)
            {
                accountId = new Guid(result.Substring(result.IndexOf("guid") + 5, 36));
                Assert.AreNotEqual(Guid.Empty, accountId);
            }
            accountId = Guid.NewGuid();
            string jsonData = "{\"AccountId\":\"" + accountId.ToString() + "\",\"Name\":\"" + name.ToString() + "\"}";

            task = crmClient.CreateData(jsonData, "Account");
            task.Wait();
            result = task.Result;
            task   = crmClient.ReadData("Account", "Name", name.ToString(), "AccountId");
            task.Wait();
            result = task.Result;
            Assert.AreNotEqual(-1, result.IndexOf("guid"));
            Guid guid = new Guid(result.Substring(result.IndexOf("guid") + 5, 36));

            Assert.IsNotNull(guid);
            Assert.AreEqual(accountId, guid);
        }
Exemple #2
0
        public void TestAuth()
        {
            var token      = AuthenticationHelper.AuthToken();
            var httpClient = new HttpClient();

            httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
            string             url = "https://dynplatformdev.crm.dynamics.com/XRMServices/2011/OrganizationData.svc/";
            HttpRequestMessage req = new HttpRequestMessage(HttpMethod.Get, url);
            var response           = httpClient.SendAsync(req);

            response.Wait();
            Assert.IsTrue(response.Result.IsSuccessStatusCode);
            var content = response.Result.Content.ReadAsStringAsync();

            content.Wait();
            Debug.Write(content.Result);
            Assert.IsFalse(content.Result.Contains("Sign in to Dynamics CRM Online"));
        }
Exemple #3
0
        private string GetCrmMetadata()
        {
            string    modelString = string.Empty;
            CRMClient crmClient;

            if (ConfigurationManager.AppSettings["CRMVersion"] == "online")
            {
                crmClient = new CRMClient(AuthenticationHelper.AuthToken(), ConfigurationManager.AppSettings["ida:CrmResourceURL"]);
            }
            else
            {
                crmClient = new CRMClient(AuthenticationHelper.GetHandler(), ConfigurationManager.AppSettings["ida:CrmResourceURL"]);
            }

            //need to spin up a new thread to get the metadata
            Thread thread = new Thread(new ThreadStart(() => modelString = crmClient.GetMetaData().Result));

            thread.Start();
            thread.Join(95000 * 4);

            return(modelString);
        }