public static void CreateTestDatabase(string testName) { if (testName2DbName.ContainsKey(testName)) { return; } // get the temporary file name and delete the temporary file string tempFile = Path.GetTempFileName(); File.Delete(tempFile); // get the database name and add to cache string dbName = Path.Combine(tempFolder, Path.GetFileNameWithoutExtension(tempFile) + ".db"); testName2DbName[testName] = dbName; // check whether our temp folder exists if (!Directory.Exists(tempFolder)) { Directory.CreateDirectory(tempFolder); } FluentMigrationsRunner.UpSqlite(GetSqliteConnectionString(dbName)); }
public static void CreateTestDatabase(string testName) { if (testName2DbName.ContainsKey(testName)) { return; } // get the temporary file name and delete the temporary file string tempFile = Path.GetTempFileName(); File.Delete(tempFile); // get the database name and add to cache string dbName = Path.GetFileNameWithoutExtension(tempFile); testName2DbName[testName] = dbName; // check whether our temp folder exists if (!Directory.Exists(tempFolder)) { Directory.CreateDirectory(tempFolder); } // create the database using (SqlConnection conn = new SqlConnection(GetMsSqlConnectionString())) { conn.Open(); string sql = $"CREATE DATABASE [{dbName}]"; //sql += $" ON PRIMARY (NAME={dbName}, FILENAME = '{tempFolder}\\{dbName}.mdf')"; //sql += $" LOG ON (NAME={dbName}_log, FILENAME = '{tempFolder}\\{dbName}_log.ldf')"; SqlCommand command = new SqlCommand(sql, conn); command.ExecuteNonQuery(); } // create the database schema FluentMigrationsRunner.UpSqlServer(GetMsSqlConnectionString(dbName)); }
public static void CreateTestDatabase(string testName) { // check whether database has already been created if (testName2DbName.ContainsKey(testName)) { return; } // get the temporary file name and delete the temporary file string tempFile = Path.GetTempFileName(); File.Delete(tempFile); // get the database name and add to cache string dbName = Path.GetFileNameWithoutExtension(tempFile); testName2DbName[testName] = dbName; // check whether our temp folder exists if (!Directory.Exists(tempFolder)) { Directory.CreateDirectory(tempFolder); } // create the database using (MySqlConnection conn = new MySqlConnection(GetMySqlConnectionString())) { conn.Open(); string sql = $"CREATE DATABASE {dbName}"; MySqlCommand command = new MySqlCommand(sql, conn); command.ExecuteNonQuery(); conn.Close(); } FluentMigrationsRunner.UpMySql(GetMySqlConnectionString(dbName)); }