DeleteDataset() public méthode

Deletes a dataset. All the records associated with dataset are cleared and dataset is marked as deleted for future sync.
public DeleteDataset ( string identityId, string datasetName ) : void
identityId string Identity identifier.
datasetName string Dataset name.
Résultat void
        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]);

            }
        }
Exemple #2
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]);

            }
        }