Inheritance: IDatabase
Esempio n. 1
0
        public void ItShouldCallNotCreateSchemaTableMethodIfEnsureSchemaVersionTableAndTableExists()
        {
            var database = new DatabaseStub(1);
            var schema = new Schema(database, new LoggerStub());

            schema.EnsureSchemaVersionTable();

            Assert.That(database.Statements.Any(x => x.Contains(@"CREATE TABLE [dbo].[SchemaInfo]")), Is.False);
        }
Esempio n. 2
0
        public void ItShouldProduceSqlForCreatingSchemaVersionTable()
        {
            var database = new DatabaseStub(0);
            var schema = new Schema(database, new LoggerStub());

            schema.CreateSchemaVersionTable();

            Assert.That(database.Statements.Any(x => x.Contains(@"CREATE TABLE [dbo].[SchemaInfo]")));
        }
Esempio n. 3
0
        public void ItShouldCreateSqlForUpdatingSchemaToSpecificVersionWhenRequested()
        {
            var database = new DatabaseStub(1);
            var schema = new Schema(database, new LoggerStub());

            schema.UpdateSchemaVersionTo(10);

            Assert.That(database.Statements.Any(x => x.Contains(@"INSERT INTO [dbo].[SchemaInfo]")));
            Assert.That(database.Statements.Any(x => x.Contains(@"10")));
        }
Esempio n. 4
0
        public void ItShouldCreateSqlForFetchingSchemaVersionWhenRequested()
        {
            var database = new DatabaseStub(1);
            var schema = new Schema(database, new LoggerStub());

            var result = schema.GetLatestSchemaVersion();

            Assert.That(database.Statements.Any(x => x.Contains(@"SELECT Max([Version])")));
            Assert.That(result, Is.EqualTo(1));
        }
Esempio n. 5
0
        public void ItShouldNotApplyMigrationsSinceLastVersionWhenVersionBiggerThanMigration()
        {
            var database = new DatabaseStub(3);
            var logger = new LoggerStub();
            var schema = new Schema(database, logger);
            var migrator = new Migrator(schema, typeof(FirstMigration).Assembly, logger);

            migrator.MigrateToLatest();

            Assert.That(database.Statements.Any(x => x.Contains("FirstMigration")), Is.False);
        }
Esempio n. 6
0
        public void ItShouldInformIfNoMigrationsFoundInAssembly()
        {
            var database = new DatabaseStub();
            var logger = new LoggerStub();
            var schema = new Schema(database, logger);
            var migrator = new Migrator(schema, typeof (Schema).Assembly, logger);

            migrator.MigrateToLatest();

            Assert.That(logger.Logs.Any(x=>x.Contains(@"No Migrations Found")));
        }
Esempio n. 7
0
        public void ItShouldFindFirstMigrationInAssembly()
        {
            var database = new DatabaseStub();
            var logger = new LoggerStub();
            var schema = new Schema(database, logger);
            var migrator = new Migrator(schema, typeof(FirstMigration).Assembly, logger);

            migrator.MigrateToLatest();

            Assert.That(logger.Logs.Any(x => x.Contains(@"Found 1 Migrations")));
        }
Esempio n. 8
0
        public void ItShouldApplyMigrationsSinceLastVersionAndUpdateSchemaTable()
        {
            var database = new DatabaseStub();
            var logger = new LoggerStub();
            var schema = new Schema(database, logger);
            var migrator = new Migrator(schema, typeof(FirstMigration).Assembly, logger);

            migrator.MigrateToLatest();

            Assert.That(database.Statements.Any(x => x.Contains("FirstMigration")));
        }
Esempio n. 9
0
        public void ItShouldNotUpdateSchemaVersionTo1IfMigrationNotApplicable()
        {
            var database = new DatabaseStub(3);
            var logger = new LoggerStub();
            var schema = new Schema(database, logger);
            var migrator = new Migrator(schema, typeof(FirstMigration).Assembly, logger);

            migrator.MigrateToLatest();

            Assert.That(database.Statements.Any(x => x.Contains(@"INSERT INTO [dbo].[SchemaInfo]
               ([Version])
             VALUES
               (1)")), Is.False);
        }