//Prepares for full run with a specified server public static void Reset(DbServerType serverType) { DeleteLocalLogFiles(); InitAppConfig(); ServerType = serverType; if (ServerType == DbServerType.SQLite) { DeleteSqliteDbFile(); //it will be created on connect, creat-option in conn string } Driver = DataUtility.CreateDriver(ServerType); //Load connection string var connStringName = ServerType.ToString() + "ConnectionString"; // For SQLite we can use either provider var useMsSqlite = AppConfig["UseMsSqliteProvider"] == "true"; if (ServerType == DbServerType.SQLite && useMsSqlite) { var sqliteDriver = (Data.SQLite.SQLiteDbDriver)Driver; sqliteDriver.ConnectionFactory = (s) => new Microsoft.Data.Sqlite.SqliteConnection(s); sqliteDriver.CommandFactory = () => new Microsoft.Data.Sqlite.SqliteCommand(); connStringName += "_MS"; } var connString = AppConfig[connStringName]; Util.Check(!string.IsNullOrEmpty(connString), "Connection string not found for key: {0}.", connStringName); if (connString.Contains("{bin}")) { var asmPath = Assembly.GetExecutingAssembly().Location; var binFolder = Path.GetDirectoryName(asmPath); connString = connString.Replace("{bin}", binFolder); } ConnectionString = connString; DbOptions = Driver.GetDefaultOptions(); //enable batch var useBatch = AppConfig["useBatchMode"] == "true"; if (useBatch && Driver.Supports(DbFeatures.BatchedUpdates)) { DbOptions |= DbOptions.UseBatchMode; } else { DbOptions &= ~DbOptions.UseBatchMode; } //check connection if (!DataUtility.TestConnection(Driver, ConnectionString, out var error)) { Util.Throw("Failed to connect to the database: {0} \r\n Connection string: {1}", error, ConnectionString); } }
//Prepares for full run with a specified server internal static void Reset(TestRunConfig config) { CurrentConfig = config; ServerType = config.ServerType; if (BooksApp != null) { BooksApp.Flush(); } Thread.Sleep(100); //to allow log dump of buffered messages DeleteLogFiles(); //it will happen only once WriteLog("\r\n------------------------ " + config.ToString() + "---------------------------------------------\r\n\r\n"); ServerType = config.ServerType; UseBatchMode = config.UseBatchMode; BooksApp = null; _initFailed = false; //Check connection string Util.Check(!string.IsNullOrEmpty(config.ConnectionString), "Connection string not found for server: {0}.", ServerType); Driver = DataUtility.CreateDriver(ServerType); var dbOptions = Driver.GetDefaultOptions(); if (config.UseBatchMode) { dbOptions |= DbOptions.UseBatchMode; } else { dbOptions &= ~DbOptions.UseBatchMode; } // Custom naming policy. Uncomment below to see how all-lower case policy works for Postgres IDbNamingPolicy customNamingPolicy = null; //if(ServerType == DbServerType.Postgres) //customNamingPolicy = new AllLowCaseNamingPolicy("books", "login"); DbSettings = new DbSettings(Driver, dbOptions, config.ConnectionString, upgradeMode: DbUpgradeMode.Always, namingPolicy: customNamingPolicy); //Test: remap login schema into login2 // Remapping schemas might used in MySql, where schemas are actually databases // if (ServerType == DbServerType.MsSql) // DbSettings.ModelConfig.MapSchema("login", "login2"); }