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);
         }
     }
 }
 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);
         }
     }
 }
        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);
                }
            }
        }
        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);
        }