Inheritance: IDatabase
Ejemplo 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);
        }
Ejemplo 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]")));
        }
Ejemplo 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")));
        }
Ejemplo 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));
        }
Ejemplo 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);
        }
Ejemplo 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")));
        }
Ejemplo 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")));
        }
Ejemplo 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")));
        }
Ejemplo 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);
        }