Example #1
0
 public void create_database()
 {
     var sqlserver = new SqlServerCommander(CreateDatabaseConnection);
     database = sqlserver.Create();
     using (IDbConnection connection = CreateConnection())
     {
         connection.Open();
         using (IDbCommand cmd = connection.CreateCommand())
         {
             cmd.CommandText = string.Format("select count(*) from sys.databases where name='{0}'", database);
             object result = cmd.ExecuteScalar();
             Assert.AreEqual(1, result);
         }
     }
 }
Example #2
0
 public void current_version_returns_missing_control_table_when_there_is_a_database_but_no_history_table()
 {
     database = "db_" + Guid.NewGuid().ToString("N");
     var sqlserver = new SqlServerCommander(CreateConnection, null, database);
     using (IDbConnection connection = CreateConnection())
     {
         connection.Open();
         using (IDbCommand cmd = connection.CreateCommand())
         {
             cmd.CommandText = string.Format("create database {0}", database);
             object result = cmd.ExecuteNonQuery();
         }
     }
     DatabaseVersion version = sqlserver.CurrentVersion();
     Assert.AreEqual(DatabaseVersionType.MissingMigrationHistoryTable, version.Type);
 }
Example #3
0
 public void database_created_has_migration_history_table()
 {
     var sqlserver = new SqlServerCommander(CreateDatabaseConnection);
     database = sqlserver.Create();
     using (IDbConnection connection = CreateConnection())
     {
         connection.Open();
         using (IDbCommand cmd = connection.CreateCommand())
         {
             cmd.CommandText =
                 string.Format(
                     "select count(*) from {0}.sys.tables t inner join  {0}.sys.schemas s on s.schema_id=t.schema_id where t.name='history' and s.name='migrations'",
                     database);
             object result = cmd.ExecuteScalar();
             Assert.AreEqual(1, result);
         }
     }
 }
Example #4
0
        public void execute_migration()
        {
            var sqlserver = new SqlServerCommander(CreateDatabaseConnection);
            database = sqlserver.Create();
            sqlserver.ExecuteMigration(new Migration
            {
                Number = "20150101",
                Sql = "create table test (id int primary key clustered)"
            });

            using (IDbConnection connection = CreateConnection())
            {
                connection.Open();
                using (IDbCommand cmd = connection.CreateCommand())
                {
                    cmd.CommandText = string.Format("select count(*) from {0}.sys.tables where name='test'", database);
                    object result = cmd.ExecuteScalar();
                    Assert.AreEqual(1, result);
                }
            }
        }
Example #5
0
 public void current_version_returns_not_created_when_there_is_no_database()
 {
     var sqlserver = new SqlServerCommander(CreateConnection);
     DatabaseVersion version = sqlserver.CurrentVersion();
     Assert.AreEqual(DatabaseVersionType.NotCreated, version.Type);
 }
Example #6
0
        public void get_correct_version_number()
        {
            var sqlserver = new SqlServerCommander(CreateDatabaseConnection);
            database = sqlserver.Create();
            sqlserver.ExecuteMigration(new Migration
            {
                Number = "20150101",
                Sql = "create table test (id int primary key clustered)"
            });
            sqlserver.ExecuteMigration(new Migration
            {
                Number = "20150102",
                Sql = "create table test2 (id int primary key clustered)"
            });

            DatabaseVersion version = sqlserver.CurrentVersion();
            Assert.AreEqual(DatabaseVersionType.VersionNumber, version.Type);
            Assert.AreEqual("20150102", version.Number);
        }