public void Can_get_and_set_rename_properties()
        {
            var renameIndexOperation = new RenameIndexOperation("T", "N", "N'");

            Assert.Equal("T", renameIndexOperation.Table);
            Assert.Equal("N", renameIndexOperation.Name);
            Assert.Equal("N'", renameIndexOperation.NewName);
        }
        public void Inverse_should_produce_rename_column_operation()
        {
            var renameIndexOperation
                = new RenameIndexOperation("T", "N", "N'");

            var inverse = (RenameIndexOperation)renameIndexOperation.Inverse;

            Assert.Equal("T", inverse.Table);
            Assert.Equal("N'", inverse.Name);
            Assert.Equal("N", inverse.NewName);
        }
        public void Generate_should_throw_when_index_rename()
        {
            if (LocalizationTestHelpers.IsEnglishLocale())
            {
                var migrationProvider = new SqlCeMigrationSqlGenerator();
                var renameIndexOperation = new RenameIndexOperation("T", "c", "c'");

                Assert.Equal(
                    Strings.SqlCeIndexRenameNotSupported,
                    Assert.Throws<MigrationsException>(() => migrationProvider.Generate(new[] { renameIndexOperation }, "4.0").ToList()).
                        Message);
            }
        }
 protected virtual IEnumerable<MigrationStatement> Generate(RenameIndexOperation operation)
 {
     throw new NotSupportedException("'RenameIndexOperation' is not supported.");
 }
        /// <summary>
        /// Generates code to perform a <see cref="RenameIndexOperation" />.
        /// </summary>
        /// <param name="renameIndexOperation"> The operation to generate code for. </param>
        /// <param name="writer"> Text writer to add the generated code to. </param>
        protected virtual void Generate(RenameIndexOperation renameIndexOperation, IndentedTextWriter writer)
        {
            Check.NotNull(renameIndexOperation, "renameIndexOperation");
            Check.NotNull(writer, "writer");

            writer.Write("RenameIndex(table := ");
            writer.Write(Quote(renameIndexOperation.Table));
            writer.Write(", name := ");
            writer.Write(Quote(renameIndexOperation.Name));
            writer.Write(", newName := ");
            writer.Write(Quote(renameIndexOperation.NewName));
            writer.WriteLine(")");
        }
        /// <summary>
        /// Generates SQL for a <see cref="RenameIndexOperation" />.
        /// Generated SQL should be added using the Statement method.
        /// </summary>
        /// <param name="renameIndexOperation"> The operation to produce SQL for. </param>
        protected virtual void Generate(RenameIndexOperation renameIndexOperation)
        {
            Check.NotNull(renameIndexOperation, "renameIndexOperation");

            using (var writer = Writer())
            {
                writer.Write("EXECUTE sp_rename @objname = N'");
                writer.Write(Escape(renameIndexOperation.Table));
                writer.Write(".");
                writer.Write(Escape(renameIndexOperation.Name));
                writer.Write("', @newname = N'");
                writer.Write(Escape(renameIndexOperation.NewName));
                writer.Write("', @objtype = N'INDEX'");

                Statement(writer);
            }
        }
        public void Generate_can_output_rename_index_statements()
        {
            var renameIndexOperation = new RenameIndexOperation("dbo.Foo", "Bar", "Baz");

            var migrationSqlGenerator = new SqlServerMigrationSqlGenerator();

            var sql = migrationSqlGenerator.Generate(new[] { renameIndexOperation }, "2008").Join(s => s.Sql, Environment.NewLine);

            Assert.Contains(
                @"EXECUTE sp_rename @objname = N'dbo.Foo.Bar', @newname = N'Baz', @objtype = N'INDEX'", sql);
        }
		protected virtual IEnumerable<MigrationStatement> Generate(RenameIndexOperation operation)
		{
			throw new NotSupportedException("Renaming index is not supported by Firebird.");
		}
        public void Generate_can_output_rename_index_operation()
        {
            var renameIndexOperation
                = new RenameIndexOperation("Foo", "Bar", "Baz");

            var codeGenerator = new CSharpMigrationCodeGenerator();

            var generatedMigration
                = codeGenerator.Generate(
                    "Migration",
                    new MigrationOperation[]
                        {
                            renameIndexOperation
                        },
                    "Source",
                    "Target",
                    "Foo",
                    "Bar");

            Assert.Equal(
                @"namespace Foo
{
    using System;
    using System.Data.Entity.Migrations;
    
    public partial class Bar : DbMigration
    {
        public override void Up()
        {
            RenameIndex(table: ""Foo"", name: ""Bar"", newName: ""Baz"");
        }
        
        public override void Down()
        {
            RenameIndex(table: ""Foo"", name: ""Baz"", newName: ""Bar"");
        }
    }
}
",
                generatedMigration.UserCode);
        }
        public void Generate_can_output_rename_index_operation()
        {
            var renameIndexOperation
                = new RenameIndexOperation("Foo", "Bar", "Baz");

            var codeGenerator = new VisualBasicMigrationCodeGenerator();

            var generatedMigration
                = codeGenerator.Generate(
                    "Migration",
                    new MigrationOperation[]
                        {
                            renameIndexOperation
                        },
                    "Source",
                    "Target",
                    "Foo",
                    "Bar");

            Assert.Equal(
                @"Imports System
Imports System.Data.Entity.Migrations
Imports Microsoft.VisualBasic

Namespace Foo
    Public Partial Class Bar
        Inherits DbMigration
    
        Public Overrides Sub Up()
            RenameIndex(table := ""Foo"", name := ""Bar"", newName := ""Baz"")
        End Sub
        
        Public Overrides Sub Down()
            RenameIndex(table := ""Foo"", name := ""Baz"", newName := ""Bar"")
        End Sub
    End Class
End Namespace
",
                generatedMigration.UserCode);
        }
 /// <summary>
 /// Generates SQL for a <see cref="RenameIndexOperation" />.
 /// Generated SQL should be added using the Statement method.
 /// </summary>
 /// <param name="renameIndexOperation"> The operation to produce SQL for. </param>
 protected virtual void Generate(RenameIndexOperation renameIndexOperation)
 {
     throw Error.SqlCeIndexRenameNotSupported();
 }