Exemplo n.º 1
0
        public void DropDatabase(Data.Tools.UnitTesting.TestSetup.Configuration.ConnectionContext connection)
        {
            // connect to master database and execute drop database statement for databasename in connectionstring of connection
            connection.ThrowIfNull("databaseDeployment");

            using (var cn = connection.Provider.CreateConnection())
            {
                cn.ConnectionString = connection.GetConnectionStringForDatabaseFromConnectionContext("master");
                cn.Open();

                using (var cm = cn.CreateCommand())
                {
                    cm.CommandText = $"DROP DATABASE [{GetDatabaseNameFromConnectionContext(connection)}]";
                    cm.ExecuteNonQuery();
                }
            }
        }
Exemplo n.º 2
0
        public string GetNewUniqueDatabaseName(Data.Tools.UnitTesting.TestSetup.Configuration.ConnectionContext connection)
        {
            connection.ThrowIfNull("connection");

            using (var cn = connection.Provider.CreateConnection())
            {
                cn.ConnectionString = connection.GetConnectionStringForDatabaseFromConnectionContext("master");
                cn.Open();

                var dbName = $"{GetDatabaseNameFromConnectionContext(connection)}-{DateTime.UtcNow.ToString("o")}";

                while (DoesDatabaseExist(cn, dbName))
                {
                    dbName = $"{GetDatabaseNameFromConnectionContext(connection)}-{DateTime.UtcNow.ToString("o")}";
                }

                return(dbName);
                //return GetConnectionStringForDatabaseNameFromConnectionContext(connection, dbName);
            }
        }