public void Dispatches_visitor()
        {
            var addForeignKeyOperation = new AddForeignKeyOperation(
                "dbo.MyTable", "MyFK", new[] { "Foo", "Bar" },
                "dbo.MyTable2", new[] { "Foo2", "Bar2" },
                cascadeDelete: true);
            var mockVisitor = new Mock<MigrationOperationSqlGenerator>(new RelationalTypeMapper());
            var builder = new Mock<IndentedStringBuilder>();
            addForeignKeyOperation.GenerateSql(mockVisitor.Object, builder.Object);

            mockVisitor.Verify(g => g.Generate(addForeignKeyOperation, builder.Object), Times.Once());
        }
        public void Create_and_initialize_operation()
        {
            var addForeignKeyOperation = new AddForeignKeyOperation(
                "dbo.MyTable", "MyFK", new[] { "Foo", "Bar" },
                "dbo.MyTable2", new[] { "Foo2", "Bar2" },
                cascadeDelete: true);

            Assert.Equal("MyFK", addForeignKeyOperation.ForeignKeyName);
            Assert.Equal("dbo.MyTable", addForeignKeyOperation.TableName);
            Assert.Equal("dbo.MyTable2", addForeignKeyOperation.ReferencedTableName);
            Assert.Equal(new[] { "Foo", "Bar" }, addForeignKeyOperation.ColumnNames);
            Assert.Equal(new[] { "Foo2", "Bar2" }, addForeignKeyOperation.ReferencedColumnNames);
            Assert.True(addForeignKeyOperation.CascadeDelete);
            Assert.False(addForeignKeyOperation.IsDestructiveChange);
        }
        public void FilterOperations_preserves_add_foreign_key_when_no_create_table()
        {
            var addForeignKey = new AddForeignKeyOperation(
                "Pony",
                "BFFK",
                new[] { "FriendId" },
                "Pony",
                new[] { "Id" },
                false);
            var operations = new MigrationOperation[] { addForeignKey };
            var generator = CreateGenerator();

            var result = generator.FilterOperations(operations);

            Assert.Equal(new[] { addForeignKey }, result);
        }
        public void FilterOperations_preserves_add_foreign_key_when_create_table_but_no_fk()
        {
            var createTable = new CreateTableOperation(
                new Table(
                    "Pony",
                    new[] { new Column("Id", typeof(long)), new Column("FriendId", typeof(long)) }));
            var addForeignKey = new AddForeignKeyOperation(
                "Pony",
                "BFFK",
                new[] { "FriendId" },
                "Pony",
                new[] { "Id" },
                false);
            var operations = new MigrationOperation[] { createTable, addForeignKey };
            var generator = CreateGenerator();

            var result = generator.FilterOperations(operations);

            Assert.Equal(new MigrationOperation[] { createTable, addForeignKey }, result);
        }
        public void FilterOperations_removes_add_foreign_key_when_corresponding_create_table()
        {
            var friendId = new Column("FriendId", typeof(long));
            var id = new Column("Id", typeof(long));
            var pony = new Table("Pony", new[] { id, friendId });
            pony.AddForeignKey(new ForeignKey("BFFK", new[] { friendId }, new[] { id }));
            var createTable = new CreateTableOperation(pony);
            var addForeignKey = new AddForeignKeyOperation(
                "Pony",
                "BFFK",
                new[] { "FriendId" },
                "Pony",
                new[] { "Id" },
                false);
            var operations = new MigrationOperation[] { createTable, addForeignKey };
            var generator = CreateGenerator();

            var result = generator.FilterOperations(operations);

            Assert.Equal(new[] { createTable }, result);
        }
 public virtual void Visit([NotNull] AddForeignKeyOperation addForeignKeyOperation, [NotNull] TContext context)
 {
     VisitDefault(addForeignKeyOperation, context);
 }
 public override void Generate(
     AddForeignKeyOperation addForeignKeyOperation,
     IndentedStringBuilder stringBuilder)
 {
     // TODO: Rebuild table
     throw new NotImplementedException();
 }