/// <summary> /// 提供数据源连接字符串,初始化一个 <see cref="Aoite.Data.MsSqlTestManager"/> 类的新实例。 /// </summary> /// <param name="connectionString">数据源连接字符串。</param> /// <param name="server">服务器地址。</param> public MsSqlTestManager(string connectionString, string server) { if (string.IsNullOrWhiteSpace(connectionString)) { throw new ArgumentNullException(nameof(connectionString)); } if (string.IsNullOrWhiteSpace(server)) { throw new ArgumentNullException(nameof(server)); } var provider = new SqlEngineProvider(connectionString); m_masterEngine = new DbEngine(provider); var dbDire = GA.FullPath("_databases"); GA.IO.CreateDirectory(dbDire); this.DatabaseName = Guid.NewGuid().ToString(); this.DbOwnerUser = Guid.NewGuid().ToString(); var sql = @"CREATE DATABASE [{0}] ON PRIMARY ( NAME = N'{0}', FILENAME = N'{1}\{0}.mdf' , SIZE = 5120KB , FILEGROWTH = 1024KB ) LOG ON ( NAME = N'{0}_log', FILENAME = N'{1}\{0}_log.ldf' , SIZE = 2048KB , FILEGROWTH = 10%)"; using (var context = m_masterEngine.Context) { context.Open(); context .Execute(sql.Fmt(this.DatabaseName, dbDire)) .ToNonQuery(); this.CreateUser(this.DatabaseName, this.DbOwnerUser, context); } this.Engine = new DbEngine(new SqlEngineProvider(server, this.DatabaseName, this.DbOwnerUser, "123456")); }
/// <summary> /// 提供数据源连接字符串,初始化一个 <see cref="Aoite.Data.MsSqlTestManager"/> 类的新实例。 /// </summary> /// <param name="connectionString">数据源连接字符串。</param> /// <param name="server">服务器地址。</param> public MsSqlTestManager(string connectionString, string server) { if(string.IsNullOrWhiteSpace(connectionString)) throw new ArgumentNullException(nameof(connectionString)); if(string.IsNullOrWhiteSpace(server)) throw new ArgumentNullException(nameof(server)); var provider = new SqlEngineProvider(connectionString); m_masterEngine = new DbEngine(provider); var dbDire = GA.FullPath("_databases"); GA.IO.CreateDirectory(dbDire); this.DatabaseName = Guid.NewGuid().ToString(); this.DbOwnerUser = Guid.NewGuid().ToString(); var sql = @"CREATE DATABASE [{0}] ON PRIMARY ( NAME = N'{0}', FILENAME = N'{1}\{0}.mdf' , SIZE = 5120KB , FILEGROWTH = 1024KB ) LOG ON ( NAME = N'{0}_log', FILENAME = N'{1}\{0}_log.ldf' , SIZE = 2048KB , FILEGROWTH = 10%)"; using(var context = m_masterEngine.Context) { context.Open(); context .Execute(sql.Fmt(this.DatabaseName, dbDire)) .ToNonQuery(); this.CreateUser(this.DatabaseName, this.DbOwnerUser, context); } this.Engine = new DbEngine(new SqlEngineProvider(server, this.DatabaseName, this.DbOwnerUser, "123456")); }