public void SqliteInitializationTest() { string dbPath = Path.Combine(PCLStorage.FileSystem.Current.LocalStorage.Path, DB_FILE_NAME); using (SQLiteLocalStorage storage = new SQLiteLocalStorage()) { } using (SQLiteConnection connection = new SQLiteConnection(dbPath)) { var query = "SELECT name FROM sqlite_master WHERE type='table'"; var tableName = new List<string>(); using (var sqliteStatement = connection.Prepare(query)) { while(sqliteStatement.Step() == SQLiteResult.ROW) { tableName.Add(sqliteStatement.GetText(0)); } } Assert.IsTrue(tableName.Count == 2); Assert.IsTrue(tableName.Contains("datasets")); Assert.IsTrue(tableName.Contains("records")); } }
public void SqliteInitializationTest() { using (SQLiteLocalStorage storage = new SQLiteLocalStorage()) { } using (SQLiteConnection connection = new SQLiteConnection(string.Format("Data Source={0};Version=3;", DB_FILE_PATH))) { connection.Open(); var cmd = connection.CreateCommand(); cmd.CommandText = "SELECT name FROM sqlite_master WHERE type='table'"; var reader = cmd.ExecuteReader(); var tableName = new List<string>(); while (reader.Read()) { tableName.Add(reader.GetString(0)); } Assert.IsTrue(tableName.Count == 3); Assert.IsTrue(tableName.Contains("datasets")); Assert.IsTrue(tableName.Contains("records")); Assert.IsTrue(tableName.Contains("kvstore")); connection.Close(); } }
public override void ClearIdentityCache() { base.ClearIdentityCache(); using (var kvStore = new SQLiteLocalStorage()) { kvStore.DeleteCachedIdentity(GetNamespacedKey(IDENTITY_ID_CACHE_KEY)); } }
public override void CacheIdentityId(string identityId) { base.CacheIdentityId(identityId); using (var kvStore = new SQLiteLocalStorage()) { kvStore.CacheIdentity(GetNamespacedKey(IDENTITY_ID_CACHE_KEY), identityId); } }
public override string GetCachedIdentityId() { string identityId = null; using (var kvStore = new SQLiteLocalStorage()) { identityId = kvStore.GetIdentity(GetNamespacedKey(IDENTITY_ID_CACHE_KEY)); } return identityId; }
public CognitoSyncManager(CognitoAWSCredentials cognitoCredentials, AmazonCognitoSyncConfig config) { if (cognitoCredentials == null) { throw new ArgumentNullException("cognitoCredentials"); } if (string.IsNullOrEmpty(cognitoCredentials.IdentityPoolId)) { throw new ArgumentNullException("cognitoCredentials.IdentityPoolId"); } this.cognitoCredentials = cognitoCredentials; Local = new SQLiteLocalStorage(System.IO.Path.Combine(Application.persistentDataPath, DATABASE_NAME)); remote = new CognitoSyncStorage(cognitoCredentials, config); cognitoCredentials.IdentityChangedEvent += this.IdentityChanged; _logger = Logger.GetLogger(this.GetType()); }
public void SQliteDatasetsTests() { string dbPath = Path.Combine(PCLStorage.FileSystem.Current.LocalStorage.Path, DB_FILE_NAME); string randomId = "old"; string randomDataset = Guid.NewGuid().ToString(); using (SQLiteLocalStorage storage = new SQLiteLocalStorage()) { storage.WipeData(); storage.CreateDataset(randomId, randomDataset); storage.PutValue(randomId, randomDataset, "Voldemort", "He who must not be named"); using (SQLiteConnection connection = new SQLiteConnection(dbPath)) { string query = "select count(*) from datasets where dataset_name = @dataset_name and identity_id = @identity_id "; using (var sqliteStatement = connection.Prepare(query)) { BindData(sqliteStatement, randomDataset, randomId); if(sqliteStatement.Step()==SQLiteResult.ROW) { var count = sqliteStatement.GetInteger(0); Assert.IsTrue(count == 1); } else { Assert.Fail(); } } query = "select count(*) from records where dataset_name = @dataset_name and identity_id = @identity_id "; using( var sqliteStatement = connection.Prepare(query)) { BindData(sqliteStatement, randomDataset, randomId); if (sqliteStatement.Step() == SQLiteResult.ROW) { var count = sqliteStatement.GetInteger(0); Assert.IsTrue(count == 1); } else { Assert.Fail(); } } } var datasets = storage.GetDatasetMetadata(randomId); Assert.IsTrue(datasets.Count == 1); var Id = "new"; storage.ChangeIdentityId(randomId, Id); randomId = Id; using (SQLiteConnection connection = new SQLiteConnection(dbPath)) { var query = "select count(*) from datasets where dataset_name = @dataset_name and identity_id = @identity_id "; using (var sqliteStatement = connection.Prepare(query)) { BindData(sqliteStatement, randomDataset, randomId); if (sqliteStatement.Step() == SQLiteResult.ROW) { var count = sqliteStatement.GetInteger(0); Assert.IsTrue(count == 1); } else { Assert.Fail(); } } query = "select count(*) from records where dataset_name = @dataset_name and identity_id = @identity_id "; using (var sqliteStatement = connection.Prepare(query)) { BindData(sqliteStatement, randomDataset, randomId); if (sqliteStatement.Step() == SQLiteResult.ROW) { var count = sqliteStatement.GetInteger(0); Assert.IsTrue(count == 1); } else { Assert.Fail(); } } } storage.DeleteDataset(randomId, randomDataset); using (SQLiteConnection connection = new SQLiteConnection(dbPath)) { var query = "select last_sync_count from datasets where dataset_name = @dataset_name and identity_id = @identity_id"; using (var sqliteStatement = connection.Prepare(query)) { BindData(sqliteStatement, randomDataset, randomId); if (sqliteStatement.Step() == SQLiteResult.ROW) { var count = sqliteStatement.GetInteger(0); Assert.IsTrue(count == -1); } else { Assert.Fail(); } } } Assert.IsNotNull(storage.GetDatasetMetadata(randomId)[0]); } }
public void SQliteDatasetsTests() { string randomId = "old"; string randomDataset = Guid.NewGuid().ToString(); using (SQLiteLocalStorage storage = new SQLiteLocalStorage()) { storage.WipeData(); storage.CreateDataset(randomId, randomDataset); storage.PutValue(randomId, randomDataset, "Voldemort", "He who must not be named"); using (SQLiteConnection connection = new SQLiteConnection(string.Format("Data Source={0};Version=3;", DB_FILE_PATH))) { connection.Open(); using (var cmd = connection.CreateCommand()) { cmd.CommandText = "select count(*) from datasets where dataset_name = @dataset_name and identity_id = @identity_id "; cmd.Parameters.Add(new SQLiteParameter("@dataset_name", randomDataset)); cmd.Parameters.Add(new SQLiteParameter("@identity_id", randomId)); using (var reader = cmd.ExecuteReader()) { if (reader.Read()) { var count = reader.GetInt32(0); Assert.IsTrue(count == 1); } else { Assert.Fail(); } } } using (var cmd = connection.CreateCommand()) { cmd.CommandText = "select count(*) from records where dataset_name = @dataset_name and identity_id = @identity_id "; cmd.Parameters.Add(new SQLiteParameter("@dataset_name", randomDataset)); cmd.Parameters.Add(new SQLiteParameter("@identity_id", randomId)); using (var reader = cmd.ExecuteReader()) { if (reader.Read()) { var count = reader.GetInt32(0); Assert.IsTrue(count == 1); } else { Assert.Fail(); } } } connection.Close(); } var datasets = storage.GetDatasetMetadata(randomId); Assert.IsTrue(datasets.Count == 1); var Id = "new"; storage.ChangeIdentityId(randomId, Id); randomId = Id; using (SQLiteConnection connection = new SQLiteConnection(string.Format("Data Source={0};Version=3;", DB_FILE_PATH))) { connection.Open(); using (var cmd = connection.CreateCommand()) { cmd.CommandText = "select count(*) from datasets where dataset_name = @dataset_name and identity_id = @identity_id "; cmd.Parameters.Add(new SQLiteParameter("@dataset_name", randomDataset)); cmd.Parameters.Add(new SQLiteParameter("@identity_id", randomId)); using (var reader = cmd.ExecuteReader()) { if (reader.Read()) { var count = reader.GetInt32(0); Assert.IsTrue(count == 1); } else { Assert.Fail(); } } } using (var cmd = connection.CreateCommand()) { cmd.CommandText = "select count(*) from records where dataset_name = @dataset_name and identity_id = @identity_id "; cmd.Parameters.Add(new SQLiteParameter("@dataset_name", randomDataset)); cmd.Parameters.Add(new SQLiteParameter("@identity_id", randomId)); using (var reader = cmd.ExecuteReader()) { if (reader.Read()) { var count = reader.GetInt32(0); Assert.IsTrue(count == 1); } else { Assert.Fail(); } } } connection.Close(); } storage.DeleteDataset(randomId, randomDataset); using (SQLiteConnection connection = new SQLiteConnection(string.Format("Data Source={0};Version=3;", DB_FILE_PATH))) { connection.Open(); using (var cmd = connection.CreateCommand()) { cmd.CommandText = "select last_sync_count from datasets where dataset_name = @dataset_name and identity_id = @identity_id"; cmd.Parameters.Add(new SQLiteParameter("@dataset_name", randomDataset)); cmd.Parameters.Add(new SQLiteParameter("@identity_id", randomId)); using (var reader = cmd.ExecuteReader()) { if (reader.Read()) { var count = reader.GetInt32(0); Assert.IsTrue(count == -1); } else { Assert.Fail(); } } } connection.Close(); } Assert.IsNotNull(storage.GetDatasetMetadata(randomId)[0]); } }