Esempio n. 1
0
        public async Task TestUpdate()
        {
            // Create
            IdName newAccountIdName = await CreateAccount();

            // Update
            string updatedAccountName = generateAccountName();
            var    fields             = new Dictionary <string, object> {
                { "name", updatedAccountName }
            };

            RestResponse updateResponse =
                await
                _restClient.SendAsync(RestRequest.GetRequestForUpdate(TestCredentials.API_VERSION, "account",
                                                                      newAccountIdName.Id, fields));

            Assert.IsTrue(updateResponse.Success, "Update failed");

            // Retrieve - expect updated name
            RestResponse response =
                await
                _restClient.SendAsync(RestRequest.GetRequestForRetrieve(TestCredentials.API_VERSION, "account",
                                                                        newAccountIdName.Id, new[] { "name" }));

            Assert.AreEqual(updatedAccountName, response.AsJObject["Name"], "Wrong row returned");
        }
Esempio n. 2
0
        public async Task TestSearchWithUnAuthenticatedClient()
        {
            IdName newAccountIdName = await CreateAccount();

            RestResponse response =
                await
                _unauthenticatedRestClient.SendAsync(RestRequest.GetRequestForSearch(TestCredentials.API_VERSION,
                                                                                     "find {" + newAccountIdName.Name + "}"));

            Assert.AreEqual(response.StatusCode.ToString().ToLower(), HttpStatusCode.Unauthorized.ToString().ToLower());
        }
Esempio n. 3
0
        public async Task TestQueryWithUnAuthenticatedClient()
        {
            IdName newAccountIdName = await CreateAccount();

            RestResponse response =
                await
                _unauthenticatedRestClient.SendAsync(RestRequest.GetRequestForQuery(TestCredentials.API_VERSION,
                                                                                    "select name from account where id = '" + newAccountIdName.Id + "'"));

            Assert.AreEqual(response.StatusCode.ToString().ToLower(), HttpStatusCode.Unauthorized.ToString().ToLower());
        }
        public void TestQuery()
        {
            IdName       newAccountIdName = CreateAccount();
            RestResponse response         = _restClient.SendSync(RestRequest.GetRequestForQuery(TestCredentials.API_VERSION, "select name from account where id = '" + newAccountIdName.Id + "'"));

            CheckResponse(response, HttpStatusCode.OK, false);
            JObject jsonResponse = response.AsJObject;

            CheckKeys(jsonResponse, "done", "totalSize", "records");
            Assert.AreEqual(1, jsonResponse["totalSize"], "Expected one row");
            Assert.AreEqual(newAccountIdName.Name, jsonResponse["records"][0]["Name"], "Wrong row returned");
        }
        public void TestRetrieve()
        {
            string[]     fields           = new string[] { "name", "ownerId" };
            IdName       newAccountIdName = CreateAccount();
            RestResponse response         = _restClient.SendSync(RestRequest.GetRequestForRetrieve(TestCredentials.API_VERSION, "account", newAccountIdName.Id, fields));

            CheckResponse(response, HttpStatusCode.OK, false);
            JObject jsonResponse = response.AsJObject;

            CheckKeys(jsonResponse, "attributes", "Name", "OwnerId", "Id");
            Assert.AreEqual(newAccountIdName.Name, jsonResponse["Name"], "Wrong row returned");
        }
Esempio n. 6
0
        public async Task TestRetrieveWithUnAuthenticatedClient()
        {
            string[] fields           = { "name", "ownerId" };
            IdName   newAccountIdName = await CreateAccount();

            RestResponse response =
                await
                _unauthenticatedRestClient.SendAsync(RestRequest.GetRequestForRetrieve(TestCredentials.API_VERSION, "account",
                                                                                       newAccountIdName.Id, fields));

            Assert.AreEqual(response.StatusCode.ToString().ToLower(), HttpStatusCode.Unauthorized.ToString().ToLower());
        }
        public void TestSearch()
        {
            IdName       newAccountIdName = CreateAccount();
            RestResponse response         = _restClient.SendSync(RestRequest.GetRequestForSearch(TestCredentials.API_VERSION, "find {" + newAccountIdName.Name + "}"));

            CheckResponse(response, HttpStatusCode.OK, true);
            JArray matchingRows = response.AsJArray;

            Assert.AreEqual(1, matchingRows.Count, "Expected one row");
            JObject matchingRow = (JObject)matchingRows[0];

            CheckKeys(matchingRow, "attributes", "Id");
            Assert.AreEqual(newAccountIdName.Id, matchingRow["Id"], "Wrong row returned");
        }
        public void TestDelete()
        {
            // Create
            IdName newAccountIdName = CreateAccount();

            // Delete
            RestResponse deleteResponse = _restClient.SendSync(RestRequest.GetRequestForDelete(TestCredentials.API_VERSION, "account", newAccountIdName.Id));

            Assert.IsTrue(deleteResponse.Success, "Delete failed");

            // Retrieve - expect 404
            RestResponse response = _restClient.SendSync(RestRequest.GetRequestForRetrieve(TestCredentials.API_VERSION, "account", newAccountIdName.Id, new string[] { "name" }));

            Assert.AreEqual(HttpStatusCode.NotFound, response.StatusCode, "404 was expected");
        }
        public async Task TestQuery()
        {
            IdName newAccountIdName = await CreateAccount();

            var response =
                await
                _restClient.SendAsync(RestRequest.GetRequestForQuery(new TestCredentials().ApiVersion,
                                                                     "select name from account where id = '" + newAccountIdName.Id + "'"));

            CheckResponse(response, HttpStatusCode.OK, false);
            JObject jsonResponse = response.AsJObject;

            CheckKeys(jsonResponse, "done", "totalSize", "records");
            Assert.AreEqual(1, jsonResponse["totalSize"], "Expected one row");
            Assert.AreEqual(newAccountIdName.Name, jsonResponse["records"][0]["Name"], "Wrong row returned");
        }
        public async Task TestRetrieve()
        {
            string[] fields           = { "name", "ownerId" };
            IdName   newAccountIdName = await CreateAccount();

            var response =
                await
                _restClient.SendAsync(RestRequest.GetRequestForRetrieve(new TestCredentials().ApiVersion, "account",
                                                                        newAccountIdName.Id, fields));

            CheckResponse(response, HttpStatusCode.OK, false);
            JObject jsonResponse = response.AsJObject;

            CheckKeys(jsonResponse, "attributes", "Name", "OwnerId", "Id");
            Assert.AreEqual(newAccountIdName.Name, jsonResponse["Name"], "Wrong row returned");
        }
        public async Task TestSearch()
        {
            IdName newAccountIdName = await CreateAccount();

            var response =
                await
                _restClient.SendAsync(RestRequest.GetRequestForSearch(new TestCredentials().ApiVersion,
                                                                      "find {" + newAccountIdName.Name + "}"));

            CheckResponse(response, HttpStatusCode.OK, true);
            JArray matchingRows = response.AsJArray;

            Assert.AreEqual(1, matchingRows.Count, "Expected one row");
            var matchingRow = (JObject)matchingRows[0];

            CheckKeys(matchingRow, "attributes", "Id");
            Assert.AreEqual(newAccountIdName.Id, matchingRow["Id"], "Wrong row returned");
        }
Esempio n. 12
0
        public async Task TestDelete()
        {
            // Create
            IdName newAccountIdName = await CreateAccount();

            // Delete
            RestResponse deleteResponse =
                await
                _restClient.SendAsync(RestRequest.GetRequestForDelete(TestCredentials.API_VERSION, "account",
                                                                      newAccountIdName.Id));

            Assert.IsTrue(deleteResponse.Success, "Delete failed");

            // Retrieve - expect 404
            RestResponse response =
                await
                _restClient.SendAsync(RestRequest.GetRequestForRetrieve(TestCredentials.API_VERSION, "account",
                                                                        newAccountIdName.Id, new[] { "name" }));

            Assert.AreEqual(HttpStatusCode.NotFound.ToString().ToLower(), response.StatusCode.ToString().ToLower(), "404 was expected");
        }