Beispiel #1
0
        public void Visit_with_rename_index_operation()
        {
            var modelBuilder = new BasicModelBuilder();

            modelBuilder.Entity("T",
                                b =>
            {
                b.Property <int>("Id");
                b.Key("Id");
                b.Index("Id").IndexName("IX").IsUnique();
            });

            var renameIndexOperation = new RenameIndexOperation("T", "IX", "IX2");

            var preProcessor = new SQLiteMigrationOperationPreProcessor();
            var context
                = new SQLiteMigrationOperationPreProcessor.Context(
                      new SQLiteMigrationOperationSqlGeneratorFactory().Create(
                          new DatabaseBuilder().GetDatabase(modelBuilder.Model)));

            preProcessor.Visit(renameIndexOperation, context);

            Assert.Equal(2, context.Statements.Count);

            Assert.Equal(@"DROP INDEX ""IX""", context.Statements[0].Sql);
            Assert.Equal(@"CREATE UNIQUE CLUSTERED INDEX ""IX"" ON ""T"" (""Id"")", context.Statements[1].Sql);
        }
Beispiel #2
0
        public void Visit_with_non_table_operation_handles_pending_operations()
        {
            var modelBuilder = new BasicModelBuilder();

            modelBuilder.Entity("T1",
                                b =>
            {
                b.Property <int>("Id");
                b.Key("Id");
            });

            var createTableOperation
                = new CreateTableOperation(
                      new Table("T2", new[]
            {
                new Column("C", typeof(int))
            }));
            var addForeignKeyOperation
                = new AddForeignKeyOperation("T2", "FK", new[] { "C" }, "T1", new[] { "Id" }, cascadeDelete: true);
            var sqlOperation = new SqlOperation("Sql");

            var preProcessor = new SQLiteMigrationOperationPreProcessor();
            var context
                = new MySQLiteMigrationOperationPreProcessorContext(
                      new SQLiteMigrationOperationSqlGeneratorFactory().Create(
                          new DatabaseBuilder().GetDatabase(modelBuilder.Model)));

            preProcessor.Visit(createTableOperation, context);
            preProcessor.Visit(addForeignKeyOperation, context);

            context.HandlePendingOperationsFlag = false;

            Assert.Equal(0, context.Statements.Count);

            context.HandlePendingOperationsFlag = true;

            preProcessor.Visit(sqlOperation, context);

            context.HandlePendingOperationsFlag = false;

            Assert.Equal(2, context.Statements.Count);
            Assert.Equal(
                @"CREATE TABLE ""T2"" (
    ""C"" INT,
    CONSTRAINT ""FK"" FOREIGN KEY (""C"") REFERENCES ""T1"" (""Id"") ON DELETE CASCADE
)",
                context.Statements[0].Sql);
            Assert.Equal("Sql", context.Statements[1].Sql);
        }