public void Can_detect_simple_column_rename() { var modelBuilder = new DbModelBuilder(); modelBuilder.Entity<MigrationsCustomer>(); var model1 = modelBuilder.Build(ProviderInfo); modelBuilder .Entity<MigrationsCustomer>() .Property(p => p.Name) .HasColumnName("col_Name") .HasMaxLength(23); var model2 = modelBuilder.Build(ProviderInfo); var operations = new EdmModelDiffer().Diff(model1.GetModel(), model2.GetModel()); Assert.Equal(2, operations.Count()); var renameColumnOperation = (RenameColumnOperation)operations.First(); Assert.Equal("dbo.MigrationsCustomers", renameColumnOperation.Table); Assert.Equal("Name", renameColumnOperation.Name); Assert.Equal("col_Name", renameColumnOperation.NewName); var alterColumnOperation = (AlterColumnOperation)operations.Last(); Assert.Equal("dbo.MigrationsCustomers", alterColumnOperation.Table); Assert.Equal("col_Name", alterColumnOperation.Column.Name); Assert.Equal(23, alterColumnOperation.Column.MaxLength); }
public void Should_detect_renamed_columns_when_swapped() { var modelBuilder = new DbModelBuilder(); modelBuilder.Entity<TypeWithRenames>().Ignore(t => t.Bazz); var model1 = modelBuilder.Build(ProviderInfo); modelBuilder = new DbModelBuilder(); modelBuilder.Entity<TypeWithRenames>().Property(t => t.Barz).HasColumnName("Bazz"); var model2 = modelBuilder.Build(ProviderInfo); var operations = new EdmModelDiffer().Diff(model1.GetModel(), model2.GetModel()); Assert.Equal(2, operations.Count()); var renameColumnOperation = (RenameColumnOperation)operations.First(); Assert.Equal("Barz", renameColumnOperation.Name); Assert.Equal("Bazz", renameColumnOperation.NewName); var addColumnOperation = (AddColumnOperation)operations.Last(); Assert.Equal("Bazz1", addColumnOperation.Column.Name); }
public void Extended_Table_Is_Added_And_Base_Table_Is_Left_Alone() { var modelBuilder = new DbModelBuilder(); modelBuilder.Entity<PlatformUser>(); modelBuilder.Ignore<PlatformUserExtended>(); var built1 = modelBuilder.Build(ProviderInfo); var model1 = built1.GetModel(); modelBuilder = new DbModelBuilder(); modelBuilder.Entity<PlatformUser>(); modelBuilder.Entity<PlatformUserExtended>(); var built2 = modelBuilder.Build(ProviderInfo); var model2 = built2.GetModel(); var operations = new EdmModelDiffer().Diff(model1, model2); Assert.Equal(3, operations.Count); var createTableOperation = (CreateTableOperation)operations.First(o => o is CreateTableOperation); Assert.Equal("dbo.PlatformUserExtended", createTableOperation.Name); var createIndexOperation = (CreateIndexOperation)operations.First(o => o is CreateIndexOperation); Assert.Equal("IX_Id", createIndexOperation.Name); Assert.Equal("dbo.PlatformUserExtended", createIndexOperation.Table); var addForeignKeyOperation = (AddForeignKeyOperation)operations.First(o => o is AddForeignKeyOperation); Assert.Equal("FK_dbo.PlatformUserExtended_dbo.PlatformUser_Id", addForeignKeyOperation.Name); Assert.Equal("dbo.PlatformUserExtended", addForeignKeyOperation.DependentTable); Assert.Equal("dbo.PlatformUser", addForeignKeyOperation.PrincipalTable); }