public DbAccessLayer GetWrapper(DbAccessType type, string testName) { if (ConfigurationManager.AppSettings["RDBMS.MySql.StartManagedServer"] == "True") { if (!MySqlConnectorInstance.Instance.HasStarted) { MySqlConnectorInstance.Instance.CreateDatabaseFiles().Wait(); MySqlConnectorInstance.Instance.RunMySql(); } } var dbname = string.Format("YAORM_TestDb_{0}", testName); if (_expectWrapper != null) { _expectWrapper.Database.CloseAllConnection(); } //Darn MySql with only 64 chars? if (dbname.Length > 64) { dbname = dbname.Substring(dbname.Length - 64); } var redesginDatabase = string.Format( "DROP DATABASE IF EXISTS {0};", dbname); _expectWrapper = new DbAccessLayer(DbAccessType, ConnectionString, new DbConfig(true)); _expectWrapper.ExecuteGenericCommand(_expectWrapper.Database.CreateCommand(redesginDatabase)); _expectWrapper.ExecuteGenericCommand( _expectWrapper.Database.CreateCommand(string.Format("CREATE DATABASE {0};", dbname))); _expectWrapper = new DbAccessLayer(DbAccessType, string.Format(ConnectionString + "Database={0};", dbname)); foreach (var databaseMeta in MetaManager.DatabaseMetas) { _expectWrapper.ExecuteGenericCommand(_expectWrapper.Database.CreateCommand(databaseMeta.Value.CreationCommand(DbAccessType))); } //_expectWrapper.ExecuteGenericCommand(_expectWrapper.Database.CreateCommand("CREATE PROC TestProcA " + // "AS BEGIN " + // "SELECT * FROM Users " + // "END")); //_expectWrapper.ExecuteGenericCommand(_expectWrapper.Database.CreateCommand("CREATE PROC TestProcB @bigThen INT " + // "AS BEGIN " + // "SELECT * FROM Users us WHERE @bigThen > us.User_ID " + // "END ")); return(_expectWrapper); }
public DbAccessLayer GetWrapper(DbAccessType type, string testName) { _dbname = string.Format("YAORM_2_TestDb_Test_MsSQL_{0}", testName); if (_expectWrapper != null) { _expectWrapper.Database.CloseAllConnection(); } var dbConfig = new DbConfig(true); dbConfig.EnableInstanceThreadSafety = true; _expectWrapper = new DbAccessLayer(DbAccessType, ConnectionString, dbConfig); var redesginDatabase = string.Format( "IF EXISTS (select * from sys.databases where name=\'{0}\') DROP DATABASE {0}", _dbname); _expectWrapper.ExecuteGenericCommand(_expectWrapper.Database.CreateCommand(redesginDatabase)); _expectWrapper.ExecuteGenericCommand( _expectWrapper.Database.CreateCommand(string.Format("CREATE DATABASE {0}", _dbname))); _expectWrapper = new DbAccessLayer(DbAccessType, string.Format(ConnectionString + "Initial Catalog={0};", _dbname), dbConfig); foreach (var databaseMeta in MetaManager.DatabaseMetas) { _expectWrapper.ExecuteGenericCommand(_expectWrapper.Database.CreateCommand(databaseMeta.Value.CreationCommand(DbAccessType))); } _expectWrapper.ExecuteGenericCommand(_expectWrapper.Database.CreateCommand("CREATE PROC TestProcA " + "AS BEGIN " + "SELECT * FROM Users " + "END")); _expectWrapper.ExecuteGenericCommand( _expectWrapper.Database.CreateCommand("CREATE PROC TestProcB @bigThen INT " + "AS BEGIN " + "SELECT * FROM Users us WHERE @bigThen > us.User_ID " + "END ")); return(_expectWrapper); }
public void Clear() { if (_expectWrapper != null) { _expectWrapper.Database.CloseAllConnection(); var redesginDatabase = string.Format( "IF EXISTS (select * from sys.databases where name=\'{0}\') ALTER DATABASE [{0}] SET SINGLE_USER WITH ROLLBACK IMMEDIATE", _dbname); var masterWrapper = new DbAccessLayer(DbAccessType, string.Format(ConnectionString + "Initial Catalog=master;"), new DbConfig(true)); masterWrapper.ExecuteGenericCommand(masterWrapper.Database.CreateCommand(redesginDatabase)); redesginDatabase = string.Format( "IF EXISTS (select * from sys.databases where name=\'{0}\') DROP DATABASE {0}", _dbname); masterWrapper.ExecuteGenericCommand(masterWrapper.Database.CreateCommand(redesginDatabase)); _expectWrapper = null; } }
public static void ClearDb(DbAccessLayer mgr) { mgr.Config.Dispose(); DbConfig.Clear(); if (mgr.DbAccessType.HasFlag(DbAccessType.MsSql)) { mgr.ExecuteGenericCommand(string.Format("DELETE FROM {0} ", UsersMeta.TableName), null); mgr.ExecuteGenericCommand(string.Format("DELETE FROM {0} ", ImageMeta.TableName), null); mgr.ExecuteGenericCommand(string.Format("DELETE FROM {0} ", BookMeta.TableName), null); //mgr.ExecuteGenericCommand(string.Format("TRUNCATE TABLE {0} ", ImageMeta.TableName), null); //mgr.ExecuteGenericCommand(string.Format("TRUNCATE TABLE {0} ", UsersMeta.TableName), null); //mgr.ExecuteGenericCommand(string.Format("TRUNCATE TABLE {0} ", BookMeta.TableName), null); } else if (mgr.DbAccessType.HasFlag(DbAccessType.SqLite)) { mgr.ExecuteGenericCommand(string.Format("DELETE FROM {0} ", UsersMeta.TableName), null); mgr.ExecuteGenericCommand("VACUUM", null); mgr.ExecuteGenericCommand(string.Format("DELETE FROM {0} ", BookMeta.TableName), null); mgr.ExecuteGenericCommand("VACUUM", null); mgr.ExecuteGenericCommand(string.Format("DELETE FROM {0} ", ImageMeta.TableName), null); mgr.ExecuteGenericCommand("VACUUM", null); } }
public DbAccessLayer GetWrapper(DbAccessType type, string testName) { if (_expectWrapper != null) { _expectWrapper.Database.CloseAllConnection(); } SqLiteInteroptWrapper.EnsureSqLiteInteropt(); //string dbname = "testDB"; //var sqlLiteFileName = dbname + ".sqlite"; var sqLiteConnection = Environment.ExpandEnvironmentVariables(ConfigurationManager .ConnectionStrings["RDBMS.SqLite.DefaultConnection"].ConnectionString); var connectionRegex = new Regex("Data Source=(.*);").Match(sqLiteConnection); _dbFilePath = Path.Combine(connectionRegex.Groups[1].Value, string.Format("YAORM_SqLite_{0}.db", testName)); var connection = sqLiteConnection.Replace(connectionRegex.Groups[1].Value, _dbFilePath); if (File.Exists(_dbFilePath)) { GC.Collect(); GC.WaitForPendingFinalizers(); GC.Collect(); File.Delete(_dbFilePath); } File.Create(_dbFilePath).Dispose(); //var file = MemoryMappedFile.CreateNew(dbname, 10000, MemoryMappedFileAccess.ReadWrite); //tempPath = Path.GetTempFileName() + dbname + "sqLite"; _expectWrapper = new DbAccessLayer(new DataAccess.SqLite.SqLiteStrategy(connection), new DbConfig(true)); foreach (var databaseMeta in MetaManager.DatabaseMetas) { _expectWrapper.ExecuteGenericCommand(_expectWrapper.Database.CreateCommand(databaseMeta.Value.CreationCommand(DbAccessType))); } return(_expectWrapper); }