public void EnsureDatabaseFileExistsKeepsData()
 {
     string connectionString = "Data Source={0};New=False;UTF8Encoding=True;Version=3";
     string path = Path.GetTempFileName();
     File.Delete(path);
     string fullConnectionString = string.Format(connectionString, path);
     IDataBaseSetupImpl dataBaseSetup = new ProjectsRepository.DataBaseSetup(cfg);
     dataBaseSetup.EnsureDatabaseFileExists(path);
     using (SQLiteConnection sc = new SQLiteConnection(fullConnectionString))
     {
         sc.Open();
         IDbCommand command = sc.CreateCommand();
         command.CommandText = "INSERT INTO Queries (project_id, name,text) VALUES (100,'Test Queries','from Tests As Success')";
         command.ExecuteNonQuery();
     }
     //Call it again to see it destroy data.
     dataBaseSetup.EnsureDatabaseFileExists(path);
     using (SQLiteConnection sc = new SQLiteConnection(fullConnectionString))
     {
         sc.Open();
         IDbCommand command = sc.CreateCommand();
         command.CommandText = "SELECT name,text FROM Queries WHERE project_id = 100";
         IDataReader reader = command.ExecuteReader();
         Assert.IsTrue(reader.Read(), "Data was no preserved when calling EnsureDatabaseFileExists twice");
         Assert.AreEqual("Test Queries", reader.GetValue(0), "Bad data when calling ensure db twice");
         Assert.AreEqual("from Tests As Success", reader.GetValue(1), "Bad data when calling ensure db twice");
     }
     File.Delete(path);
 }
 public void EnsureDatabaseFileExistsCreatesFile()
 {
     string path = Path.GetTempFileName();
     string connectionString = "Data Source={0};New=False;UTF8Encoding=True;Version=3";
     string fullConnectionString = string.Format(connectionString, path);
     File.Delete(path); //We need this because GetTempFileName() also create a file.
     //This force creating the file
     IDataBaseSetupImpl dataBaseSetup = new ProjectsRepository.DataBaseSetup(cfg);
     dataBaseSetup.EnsureDatabaseFileExists(path);
     Assert.IsTrue(File.Exists(path), "EnsureDB File Exists didn't create the file");
     EnsureDatabaseSchemaIsValid(fullConnectionString);
     File.Delete(path);
 }