public async void Create_Account_Typed()
        {
            var client = await GetForceClient();
            var account = new Account() { Name = "New Account", Description = "New Account Description" };
            var id = await client.Create("Account", account);

            Assert.IsNotNullOrEmpty(id);
        }
        public async Task CreateLotsOfAccounts(ForceClient forceClient)
        {
            var account = new Account { Name = "Test Account", Description = "New Account Description" };

            for (var i = 0; i < 1000; i++)
            {
                account.Name = "Test Account (" + i + ")";
                await forceClient.CreateAsync("Account", account);
            }
        }
        public async void Update_Account_NameChanged()
        {
            var client = await GetForceClient();
            
            var originalName = "New Account";
            var newName = "New Account 2";

            var account = new Account() { Name = originalName, Description = "New Account Description" };
            var id = await client.Create("Account", account);
            account.Name = newName;
            await client.Update("Account", id, account);
            
            var result = await client.QueryById<Account>("Account", id);

            Assert.True(result.Name == newName);
        }
        public async void Update_Account_IsSuccess()
        {
            var client = await GetForceClient();
            
            string originalName = "New Account";
            string newName = "New Account 2";

            var account = new Account() { Name = originalName, Description = "New Account Description" };
            var id = await client.Create("Account", account);

            account.Name = newName;

            var success = await client.Update("Account", id, account);

            Assert.IsTrue(success);
        }
        public async void Upsert_Account_NameChanged()
        {
            const string fieldName = "ExternalId__c";
            await CreateExternalIdField("Account", fieldName);

            const string originalName = "New Account External Upsert";
            const string newName = "New Account External Upsert 2";

            var account = new Account { Name = originalName, Description = "New Account Description" };
            await _client.UpsertExternalAsync("Account", fieldName, "4", account);

            account.Name = newName;
            await _client.UpsertExternalAsync("Account", fieldName, "4", account);

            var accountResult = await _client.QueryAsync<Account>(string.Format("SELECT Name FROM Account WHERE {0} = '4'", fieldName));
            var firstOrDefault = accountResult.Records.FirstOrDefault();

            Assert.True(firstOrDefault != null && firstOrDefault.Name == newName);
        }
        public async void Upsert_Account_Insert_IsSuccess()
        {
            const string objectName = "Account";
            const string fieldName = "ExternalId__c";

            await CreateExternalIdField(objectName, fieldName);

            var account = new Account { Name = "Upserted Account" + DateTime.Now.Ticks, Description = "New Upserted Account Description" + DateTime.Now.Ticks };
            var success = await _client.UpsertExternalAsync(objectName, fieldName, "123" + DateTime.Now.Ticks, account);

            Assert.IsNotNull(success);
            Assert.IsNotNull(success.Id);
            Assert.IsNotNullOrEmpty(success.Id);
        }
        public async void Delete_Account_ValidateIsGone()
        {
            using (var httpClient = new HttpClient())
            {
                var client = await GetForceClient(httpClient);
                var account = new Account() { Name = "New Account", Description = "New Account Description" };
                var id = await client.Create("Account", account);
                await client.Delete("Account", id);

                var result = await client.QueryById<Account>("Account", id);

                Assert.IsNull(result);
            }
        }
        public async Task Delete_Account_ObjectDoesNotExist()
        {
            try
            {
                var account = new Account { Name = "New Account", Description = "New Account Description" };
                var successResponse = await _client.CreateAsync("Account", account);
                var success = await _client.DeleteAsync("BadAccount", successResponse.Id);

                Assert.IsTrue(success);
            }
            catch (ForceException ex)
            {
                Assert.IsNotNull(ex);
                Assert.IsNotNull(ex.Message);
                Assert.IsNotNull(ex.Error);
            }
        }
        public async Task Update_Account_NameChanged()
        {
            const string originalName = "New Account";
            const string newName = "New Account 2";

            var account = new Account { Name = originalName, Description = "New Account Description" };
            var successResponse = await _client.CreateAsync("Account", account);
            account.Name = newName;
            await _client.UpdateAsync("Account", successResponse.Id, account);

            var result = await _client.QueryByIdAsync<Account>("Account", successResponse.Id);

            Assert.True(result.Name == newName);
        }
        public async Task Update_Account_NullValues()
        {
            const string originalName = "New Account";
            const string newName = "New Account 2";

            var newAccount = new Account { Name = originalName, Description = "New Account Description" };
            var success1 = await _client.CreateAsync("Account", newAccount);
            Assert.IsNotNull(success1);

            var id = success1.Id;

            const string query = "SELECT AccountNumber,AccountSource,Active__c,AnnualRevenue,BillingAddress,BillingCity,BillingCountry,BillingGeocodeAccuracy,BillingLatitude,BillingLongitude,BillingPostalCode,BillingState,BillingStreet,CleanStatus,CreatedById,CreatedDate,CustomerPriority__c,DandbCompanyId,Description,DunsNumber,ExternalId__c,External_Id__c,Fax,Id,Industry,IsDeleted,Jigsaw,JigsawCompanyId,LastActivityDate,LastModifiedById,LastModifiedDate,LastReferencedDate,LastViewedDate,MasterRecordId,MyCustomField__c,NaicsCode,NaicsDesc,Name,NumberOfEmployees,NumberofLocations__c,OwnerId,Ownership,ParentId,Phone,PhotoUrl,Rating,ShippingAddress,ShippingCity,ShippingCountry,ShippingGeocodeAccuracy,ShippingLatitude,ShippingLongitude,ShippingPostalCode,ShippingState,ShippingStreet,Sic,SicDesc,Site,SLAExpirationDate__c,SLASerialNumber__c,SLA__c,SystemModstamp,TickerSymbol,Tradestyle,Type,UpsellOpportunity__c,Website,YearStarted FROM Account WHERE Id = '{0}'";

            var account1 = await _client.QueryAsync<Account>(string.Format(query, id));
            var newAccount2 = new Account { Name = newName };

            var success2 = await _client.UpdateAsync("Account", id, newAccount2);
            Assert.IsNotNull(success2);

            var account2 = await _client.QueryAsync<Account>(string.Format(query, id));

            Assert.AreEqual(account1.Records[0].Description, account2.Records[0].Description);
        }
        public async void Delete_Account_IsSuccess()
        {
            var account = new Account { Name = "New Account", Description = "New Account Description" };
            var id = await _client.CreateAsync("Account", account);
            var success = await _client.DeleteAsync("Account", id);

            Assert.IsTrue(success);
        }
 public async void Upsert_Account_BadObject()
 {
     try
     {
         using (var httpClient = new HttpClient())
         {
             var client = await GetForceClient(httpClient);
             var account = new Account { Name = "New Account ExternalID", Description = "New Account Description" };
             await client.UpsertExternalAsync("BadAccount", "ExternalID__c", "2", account);
         }
     }
     catch (ForceException ex)
     {
         Assert.IsNotNull(ex);
         Assert.IsNotNull(ex.Message);
         Assert.IsNotNull(ex.Error);
     }
 }
        public async void Delete_Account_ObjectDoesNotExist()
        {
            try
            {
                using (var httpClient = new HttpClient())
                {
                    var client = await GetForceClient(httpClient);
                    var account = new Account { Name = "New Account", Description = "New Account Description" };
                    var id = await client.CreateAsync("Account", account);
                    var success = await client.DeleteAsync("BadAccount", id);

                    Assert.IsTrue(success);
                }
            }
            catch (ForceException ex)
            {
                Assert.IsNotNull(ex);
                Assert.IsNotNull(ex.Message);
                Assert.IsNotNull(ex.Error);
            }
        }
        public async void Delete_Account_IsSuccess()
        {
            using (var httpClient = new HttpClient())
            {
                var client = await GetForceClient(httpClient);
                var account = new Account { Name = "New Account", Description = "New Account Description" };
                var id = await client.CreateAsync("Account", account);
                var success = await client.DeleteAsync("Account", id);

                Assert.IsTrue(success);
            }
        }
        public async void Update_Account_BadObject()
        {
            try
            {
                using (var httpClient = new HttpClient())
                {
                    var client = await GetForceClient(httpClient);

                    var originalName = "New Account";
                    var newName = "New Account 2";

                    var account = new Account { Name = originalName, Description = "New Account Description" };
                    var id = await client.CreateAsync("Account", account);

                    account.Name = newName;

                    await client.UpdateAsync("BadAccount", id, account);
                }
            }
            catch (ForceException ex)
            {
                Assert.IsNotNull(ex);
                Assert.IsNotNull(ex.Message);
                Assert.IsNotNull(ex.Error);
            }
        }
        public async void Update_Account_IsSuccess()
        {
            using (var httpClient = new HttpClient())
            {
                var client = await GetForceClient(httpClient);

                var originalName = "New Account";
                var newName = "New Account 2";

                var account = new Account { Name = originalName, Description = "New Account Description" };
                var id = await client.CreateAsync("Account", account);

                account.Name = newName;

                var success = await client.UpdateAsync("Account", id, account);

                Assert.IsTrue(success);
            }
        }
        public async Task Create_Account_Typed()
        {
            var account = new Account { Name = "New Account", Description = "New Account Description" };
            var successResponse = await _client.CreateAsync("Account", account);

            Assert.That(successResponse.Id, Is.Not.Null.And.Not.Empty);
        }
        public async Task Update_Account_IsSuccess()
        {
            const string originalName = "New Account";
            const string newName = "New Account 2";

            var account = new Account { Name = originalName, Description = "New Account Description" };
            var successResponse = await _client.CreateAsync("Account", account);

            account.Name = newName;

            var success = await _client.UpdateAsync("Account", successResponse.Id, account);

            Assert.IsNotNull(success);
        }
        public async void Delete_Account_ValidateIsGone()
        {
            var account = new Account { Name = "New Account", Description = "New Account Description" };
            var id = await _client.CreateAsync("Account", account);
            await _client.DeleteAsync("Account", id);

            var result = await _client.QueryByIdAsync<Account>("Account", id);

            Assert.IsNull(result);
        }
        public async Task Update_Account_BadObject()
        {
            try
            {
                const string originalName = "New Account";
                const string newName = "New Account 2";

                var account = new Account { Name = originalName, Description = "New Account Description" };
                var successResponse = await _client.CreateAsync("Account", account);

                account.Name = newName;

                await _client.UpdateAsync("BadAccount", successResponse.Id, account);
            }
            catch (ForceException ex)
            {
                Assert.IsNotNull(ex);
                Assert.IsNotNull(ex.Message);
                Assert.IsNotNull(ex.Error);
            }
        }
        public async void Upsert_Account_Update_IsSuccess()
        {
            const string objectName = "Account";
            const string fieldName = "ExternalId__c";

            await CreateExternalIdField(objectName, fieldName);

            var account = new Account { Name = "Upserted Account", Description = "Upserted Account Description" };
            var success = await _client.UpsertExternalAsync(objectName, fieldName, "123", account);

            Assert.IsNotNull(success);
            Assert.IsEmpty(success.id);
        }
        public async Task Delete_Account_IsSuccess()
        {
            var account = new Account { Name = "New Account", Description = "New Account Description" };
            var successResponse = await _client.CreateAsync("Account", account);
            var success = await _client.DeleteAsync("Account", successResponse.Id);

            Assert.IsTrue(success);
        }
        public async Task Object_GetDeleted_IsNotNull()
        {
            var account = new Account { Name = "New Account to Delete", Description = "New Account Description" };
            var successResponse = await _client.CreateAsync("Account", account);

            await _client.DeleteAsync("Account", successResponse.Id);
            var dateTime = DateTime.Now;

            await Task.Run(() => Thread.Sleep(5000));

            var sdt = dateTime.Subtract(new TimeSpan(0, 0, 2, 0));
            var edt = dateTime.Add(new TimeSpan(0, 0, 2, 0));
            var deleted = await _client.GetDeleted<DeletedRecordRootObject>("Account", sdt, edt);

            Assert.IsNotNull(deleted);
            Assert.IsNotNull(deleted.DeletedRecords);
            Assert.IsTrue(deleted.DeletedRecords.Count > 0);
        }
        public async Task Delete_Account_ValidateIsGone()
        {
            var account = new Account { Name = "New Account", Description = "New Account Description" };
            var successResponse = await _client.CreateAsync("Account", account);
            await _client.DeleteAsync("Account", successResponse.Id);

            var result = await _client.QueryByIdAsync<Account>("Account", successResponse.Id);

            Assert.IsNull(result);
        }
 public async Task Upsert_Account_BadObject()
 {
     try
     {
         var account = new Account { Name = "New Account ExternalID", Description = "New Account Description" };
         await _client.UpsertExternalAsync("BadAccount", "ExternalID__c", "2", account);
     }
     catch (ForceException ex)
     {
         Assert.IsNotNull(ex);
         Assert.IsNotNull(ex.Message);
         Assert.IsNotNull(ex.Error);
     }
 }
        public async Task Object_GetUpdated_IsNotNull()
        {
            const string originalName = "New Account";
            const string newName = "New Account 2";

            var account = new Account { Name = originalName, Description = "New Account Description" };
            var successResponse = await _client.CreateAsync("Account", account);

            account.Name = newName;
            var dateTime = DateTime.Now;

            await _client.UpdateAsync("Account", successResponse.Id, account);

            await Task.Run(() => Thread.Sleep(5000));

            var sdt = dateTime.Subtract(new TimeSpan(0, 0, 2, 0));
            var edt = dateTime.Add(new TimeSpan(0, 0, 2, 0));
            var updated = await _client.GetUpdated<UpdatedRecordRootObject>("Account", sdt, edt);

            Assert.IsNotNull(updated);
            Assert.IsTrue(updated.Ids.Count > 0);
        }
        public async void Create_Account_Typed()
        {
            var account = new Account { Name = "New Account", Description = "New Account Description" };
            var successResponse = await _client.CreateAsync("Account", account);

            Assert.IsNotNullOrEmpty(successResponse.Id);
        }
        public async Task Create_EventWithDate_IsSuccess()
        {
            // This test is to ensure we have proper date serialization and don't get the following error:
            // "Cannot deserialize instance of date from VALUE_STRING value 2015-08-25T11:49:53.0113029-07:00"

            var account = new Account { Name = "New Account", Description = "New Account Description" };
            var accountSuccessResponse = await _client.CreateAsync("Account", account);

            var newEvent = new Event()
            {
                Description = "new Event",
                Subject = "new Event",
                WhatId = accountSuccessResponse.Id,
                ActivityDate = DateTime.Now,
                DurationInMinutes = 10,
                ActivityDateTime = DateTime.Now
            };

            var eventSuccessResponse = await _client.CreateAsync("Event", newEvent);

            Assert.IsTrue(eventSuccessResponse.Success);
        }
        public async void Delete_External_ValidateIsGone()
        {
            const string objectName = "Account";
            const string fieldName = "ExternalId__c";
            var fieldId = "123" + DateTime.Now.Ticks;

            await CreateExternalIdField(objectName, fieldName);

            var account = new Account { Name = "Upserted To Delete", Description = "Upserted Account Description to Delete" };
            var success = await _client.UpsertExternalAsync(objectName, fieldName, fieldId, account);

            var resultExists = await _client.QueryByIdAsync<Account>("Account", success.Id);

            Assert.IsNotNull(resultExists);

            await _client.DeleteExternalAsync("Account", fieldName, fieldId);

            var resultDoesNotExists = await _client.QueryByIdAsync<Account>("Account", success.Id);

            Assert.IsNull(resultDoesNotExists);
        }