public async Task TestSyncUpWithLocallyDeletedRecordsWithoutOverwrite() { TrySyncDown(SyncState.MergeModeOptions.LeaveIfChanged); string[] allIds = _idToNames.Keys.ToArray(); string[] idsLocallyDeleted = { allIds[0], allIds[1], allIds[2] }; DeleteAccountsLocally(idsLocallyDeleted); var idToNamesRemotelyDeleted = new Dictionary <string, string>(); foreach (string id in idsLocallyDeleted) { idToNamesRemotelyDeleted[id] = _idToNames[id] + "_updated"; } await UpdateAccountsOnServer(idToNamesRemotelyDeleted); TrySyncUp(3, SyncState.MergeModeOptions.LeaveIfChanged); String idsClause = "('" + String.Join("', '", idsLocallyDeleted) + "')"; QuerySpec smartStoreQuery = QuerySpec.BuildSmartQuerySpec( "SELECT {accounts:_soup}, {accounts:Name} FROM {accounts} WHERE {accounts:Id} IN " + idsClause, idsLocallyDeleted.Count()); JArray accountsFromDb = _smartStore.Query(smartStoreQuery, 0); Assert.IsTrue(accountsFromDb.Count == 3, "3 accounts should have been returned by smartstore"); // check server String soql = "SELECT Id, Name FROM Account WHERE Id IN " + idsClause; RestRequest request = RestRequest.GetRequestForQuery(ApiVersionStrings.VersionNumber, soql); var response = await _restClient.SendAsync(request); var records = response.AsJObject.ExtractValue <JArray>(RecordsStr); Assert.AreEqual(records.Count, 3, "3 accounts should have been returned from server"); }
public void TestSmartQueryDoingCount() { JArray result = Store.Query(QuerySpec.BuildSmartQuerySpec("select count(*) from {employees}", 1), 0); JArray compare = JArray.Parse("[[7]]"); Assert.AreEqual(compare.ToString(), result.ToString()); }
public void TestSmartQueryDoingSum() { JArray result = Store.Query(QuerySpec.BuildSmartQuerySpec("select sum({departments:budget}) from {departments}", 1), 0); JArray compare = JArray.Parse("[[3000000]]"); Assert.AreEqual(compare.ToString(), result.ToString()); }
public void TestSmartQueryReturningOneRowWithOneInteger() { JArray result = Store.Query( QuerySpec.BuildSmartQuerySpec( "select {employees:salary} from {employees} where {employees:lastName} = 'Haas'", 1), 0); JArray compare = JArray.Parse("[[200000]]"); Assert.AreEqual(compare.ToString(), result.ToString()); }
public void TestSmartQueryReturningTwoRowsWithOneIntegerEach() { JArray result = Store.Query( QuerySpec.BuildSmartQuerySpec( "select {employees:salary} from {employees} where {employees:managerId} = '00010' order by {employees:firstName}", 2), 0); JArray compare = JArray.Parse("[[120000],[100000]]"); Assert.AreEqual(compare.ToString(), result.ToString()); }
public void TestSmartQueryReturningOneRowWithTwoIntegers() { JArray result = Store.Query( QuerySpec.BuildSmartQuerySpec( "select mgr.{employees:salary}, e.{employees:salary} from {employees} as mgr, {employees} as e where e.{employees:lastName} = 'Thompson' and mgr.{employees:employeeId} = e.{employees:managerId}", 1), 0); JArray compare = JArray.Parse("[[200000,120000]]"); Assert.AreEqual(compare.ToString(), result.ToString()); }
public void TestUpsertManyEntries() { Debug.WriteLine("SmartStoreLoadTest", "In testUpsertManyEntries"); for (int k = 1; k < MAX_NUMBER_ENTRIES; k *= 2) { UpsertManyEntriesWithManyFields(k); } JArray result = Store.Query( QuerySpec.BuildSmartQuerySpec( "select {test_soup:key} from {" + TEST_SOUP + "} WHERE {test_soup:key} = 'k_100'", 1), 0); JArray compare = JArray.Parse("[[\"k_100\"]]"); Assert.AreEqual(compare.ToString(), result.ToString()); }
public void TestSmartQueryWithPaging() { QuerySpec query = QuerySpec.BuildSmartQuerySpec( "select {employees:firstName} from {employees} order by {employees:firstName}", 1); Assert.AreEqual(7, Store.CountQuery(query), "Expected 7 employees"); String[] expectedResults = { "Christine", "Eileen", "Eva", "Irving", "John", "Michael", "Sally" }; for (int i = 0; i < 7; i++) { JArray result = Store.Query(query, i); Assert.AreEqual(JArray.Parse("[[\"" + expectedResults[i] + "\"]]").ToString(), result.ToString(), "Wrong result at page " + i); } }
public async Task TestSyncUpWithLocallyUpdatedRecordsWithoutOverwrite() { TrySyncDown(SyncState.MergeModeOptions.LeaveIfChanged); Dictionary <string, string> idToNamesLocallyUpdated = MakeSomeLocalChanges(); var idToNamesRemotelyUpdated = new Dictionary <string, string>(); foreach (string id in idToNamesLocallyUpdated.Keys) { idToNamesRemotelyUpdated[id] = idToNamesLocallyUpdated[id] + "_updated_again"; } await UpdateAccountsOnServer(idToNamesRemotelyUpdated); // sync up TrySyncUp(3, SyncState.MergeModeOptions.LeaveIfChanged); String idsClause = "('" + String.Join("', '", idToNamesRemotelyUpdated.Keys) + "')"; QuerySpec smartStoreQuery = QuerySpec.BuildSmartQuerySpec( "SELECT {accounts:_soup} FROM {accounts} WHERE {accounts:Id} IN " + idsClause, idToNamesRemotelyUpdated.Keys.Count); JArray accountsFromDb = _smartStore.Query(smartStoreQuery, 0); foreach (JToken token in accountsFromDb) { var row = token.ToObject <JArray>(); var soupElt = row[0].ToObject <JObject>(); Assert.IsTrue(soupElt.ExtractValue <bool>(SyncManager.Local), "Wrong local flag"); Assert.IsTrue(soupElt.ExtractValue <bool>(SyncManager.LocallyUpdated), "Wrong local flag"); } // check server String soql = "SELECT Id, Name FROM Account WHERE Id IN " + idsClause; RestRequest request = RestRequest.GetRequestForQuery(ApiVersionStrings.VersionNumber, soql); var idToNamesFromServer = new JObject(); var response = await _restClient.SendAsync(request); var records = response.AsJObject.ExtractValue <JArray>(RecordsStr); foreach (JToken token in records) { var row = token.ToObject <JObject>(); idToNamesFromServer[row.ExtractValue <string>(Constants.Id)] = row.ExtractValue <string>(Constants.Name); } Assert.IsTrue(JToken.DeepEquals(JObject.FromObject(idToNamesRemotelyUpdated), idToNamesFromServer)); }
private void CheckDb(Dictionary <string, string> expectedIdToNames) { string idsClause = "('" + String.Join("', '", expectedIdToNames.Keys) + "')"; QuerySpec smartStoreQuery = QuerySpec.BuildSmartQuerySpec( "SELECT {accounts:Id}, {accounts:Name} FROM {accounts} WHERE {accounts:Id} IN " + idsClause, CountTestAccounts); JArray accountsFromDb = _smartStore.Query(smartStoreQuery, 0); var idToNamesFromDb = new JObject(); foreach (JToken t in accountsFromDb) { var row = t.ToObject <JArray>(); idToNamesFromDb[row[0].ToObject <string>()] = row[1].ToObject <string>(); } Assert.IsTrue(JToken.DeepEquals(JObject.FromObject(expectedIdToNames), idToNamesFromDb)); }
public void TestSmartQueryWithSpecialFields() { var christineJson = Store.Query(QuerySpec.BuildExactQuerySpec(EMPLOYEES_SOUP, "employeeId", "00010", 1), 0)[0] as JObject; Assert.AreEqual("Christine", christineJson.GetValue(FIRST_NAME), "Wrong elt"); JArray result = Store.Query( QuerySpec.BuildSmartQuerySpec( "select {employees:_soup}, {employees:_soupEntryId}, {employees:_soupLastModifiedDate}, {employees:salary} from {employees} where {employees:lastName} = 'Haas'", 1), 0); Assert.AreEqual(1, result.Count, "Expected one row"); Assert.AreEqual(christineJson.ToString(), result[0][0].ToString(), "Wrong soup"); Assert.AreEqual(christineJson.GetValue(SoupEntryId), result[0][1], "Wrong soupEntryId"); Assert.AreEqual(christineJson.GetValue(SoupLastModifiedDate), result[0][2], "Wrong soupLastModifiedDate"); }
public void TestSmartQueryReturningSoupStringAndInteger() { JArray query = Store.Query(QuerySpec.BuildExactQuerySpec(EMPLOYEES_SOUP, "employeeId", "00010", 1), 0); var christineJson = query[0] as JObject; Assert.AreEqual("Christine", christineJson.GetValue(FIRST_NAME).ToString(), "Wrong elt"); JArray result = Store.Query( QuerySpec.BuildSmartQuerySpec( "select {employees:_soup}, {employees:firstName}, {employees:salary} from {employees} where {employees:lastName} = 'Haas'", 1), 0); Assert.AreEqual(1, result.Count(), "Expected one row"); Assert.AreEqual(christineJson.ToString(), result[0][0].ToString(), "Wrong soup"); Assert.AreEqual("Christine", result[0][1].ToString(), "Wrong first name"); Assert.AreEqual(200000, (int)(result[0][2]), "Wrong salary"); }
public async Task TestSyncUpWithLocallyUpdatedRecords() { // first sync down TrySyncDown(SyncState.MergeModeOptions.Overwrite); // make local changes Dictionary <string, string> idToNamesLocallyUpdated = MakeSomeLocalChanges(); // sync up TrySyncUp(3); // check that the db doesn't show entries as locally modified anymore Dictionary <string, string> .KeyCollection ids = idToNamesLocallyUpdated.Keys; string idsClause = "('" + String.Join("', '", ids) + "')"; QuerySpec smartStoreQuery = QuerySpec.BuildSmartQuerySpec( "SELECT {accounts:_soup} FROM {accounts} WHERE {accounts:Id} IN " + idsClause, ids.Count); JArray accountsFromDb = _smartStore.Query(smartStoreQuery, 0); foreach (JArray row in accountsFromDb.Select(row => row.ToObject <JArray>())) { var soupElt = row[0].ToObject <JObject>(); Assert.AreEqual(false, soupElt.ExtractValue <bool>(SyncManager.Local), "Wrong local flag"); Assert.AreEqual(false, soupElt.ExtractValue <bool>(SyncManager.LocallyUpdated), "Wrong local flag"); } string soql = "SELECT Id, Name FROM Account WHERE Id IN " + idsClause; var request = RestRequest.GetRequestForQuery(ApiVersionStrings.VersionNumber, soql); var response = await _restClient.SendAsync(request); var records = response.AsJObject.ExtractValue <JArray>(RecordsStr); var idToNamesFromServer = new JObject(); foreach (JToken rowToken in records) { var row = rowToken.ToObject <JObject>(); idToNamesFromServer[row.ExtractValue <string>(Constants.Id)] = row.ExtractValue <string>(Constants.Name); } Assert.IsTrue(JToken.DeepEquals(JObject.FromObject(idToNamesLocallyUpdated), idToNamesFromServer)); }