public void Clone_replicates_instance_and_adds_column_clones_to_cache() { var column0 = new Column("C0", typeof(int)); var column1 = new Column("C1", typeof(int)); var referencedColumn0 = new Column("RC0", typeof(int)); var referencedColumn1 = new Column("RC1", typeof(int)); var foreignKey = new ForeignKey( "FK", new[] { column0, column1 }, new[] { referencedColumn0, referencedColumn1 }, cascadeDelete: true); var cloneContext = new CloneContext(); var clone = foreignKey.Clone(cloneContext); Assert.NotSame(foreignKey, clone); Assert.Equal("FK", clone.Name); Assert.Equal(2, clone.Columns.Count); Assert.NotSame(column0, clone.Columns[0]); Assert.NotSame(column1, clone.Columns[1]); Assert.Equal("C0", clone.Columns[0].Name); Assert.Equal("C1", clone.Columns[1].Name); Assert.Equal(2, clone.ReferencedColumns.Count); Assert.NotSame(referencedColumn0, clone.ReferencedColumns[0]); Assert.NotSame(referencedColumn1, clone.ReferencedColumns[1]); Assert.Equal("RC0", clone.ReferencedColumns[0].Name); Assert.Equal("RC1", clone.ReferencedColumns[1].Name); Assert.True(clone.CascadeDelete); Assert.Same(clone.Columns[0], cloneContext.GetOrAdd(column0, () => null)); Assert.Same(clone.Columns[1], cloneContext.GetOrAdd(column1, () => null)); Assert.Same(clone.ReferencedColumns[0], cloneContext.GetOrAdd(referencedColumn0, () => null)); Assert.Same(clone.ReferencedColumns[1], cloneContext.GetOrAdd(referencedColumn1, () => null)); }
protected internal virtual PrimaryKey Clone(CloneContext cloneContext) { return new PrimaryKey( Name, Columns.Select(column => column.Clone(cloneContext)).ToArray(), IsClustered); }
protected internal virtual Index Clone(CloneContext cloneContext) { return new Index( Name, Columns.Select(column => column.Clone(cloneContext)).ToArray(), IsUnique, IsClustered); }
protected internal virtual ForeignKey Clone(CloneContext cloneContext) { return new ForeignKey( Name, Columns.Select(column => column.Clone(cloneContext)).ToArray(), ReferencedColumns.Select(column => column.Clone(cloneContext)).ToArray(), CascadeDelete); }
public virtual DatabaseModel Clone() { var clone = new DatabaseModel(); var cloneContext = new CloneContext(); clone._sequences.AddRange(Sequences.Select(s => s.Clone(cloneContext))); clone._tables.AddRange(Tables.Select(t => t.Clone(cloneContext))); return clone; }
public void Clone_gets_column_clones_from_cache() { var column0 = new Column("Foo", typeof(int)); var column1 = new Column("Bar", typeof(int)); var index = new Index("IX", new[] { column0, column1 }, isUnique: true, isClustered: true); var cloneContext = new CloneContext(); var columnClone0 = column0.Clone(cloneContext); var columnClone1 = column1.Clone(cloneContext); var clone = index.Clone(cloneContext); Assert.NotSame(index, clone); Assert.Equal(2, clone.Columns.Count); Assert.Same(columnClone0, clone.Columns[0]); Assert.Same(columnClone1, clone.Columns[1]); }
public void Clone_gets_column_clones_from_cache() { var column0 = new Column("Foo", typeof(int)); var column1 = new Column("Bar", typeof(int)); var primaryKey = new PrimaryKey("PK", new[] { column0, column1 }, isClustered: false); var cloneContext = new CloneContext(); var columnClone0 = column0.Clone(cloneContext); var columnClone1 = column1.Clone(cloneContext); var clone = primaryKey.Clone(cloneContext); Assert.NotSame(primaryKey, clone); Assert.Equal(2, clone.Columns.Count); Assert.Same(columnClone0, clone.Columns[0]); Assert.Same(columnClone1, clone.Columns[1]); }
public void Clone_replicates_instance_and_adds_column_clones_to_cache() { var column0 = new Column("Foo", typeof(int)); var column1 = new Column("Bar", typeof(int)); var primaryKey = new PrimaryKey("PK", new[] { column0, column1 }, isClustered: false); var cloneContext = new CloneContext(); var clone = primaryKey.Clone(cloneContext); Assert.NotSame(primaryKey, clone); Assert.Equal("PK", clone.Name); Assert.Equal(2, clone.Columns.Count); Assert.NotSame(column0, clone.Columns[0]); Assert.NotSame(column1, clone.Columns[1]); Assert.Equal("Foo", clone.Columns[0].Name); Assert.Equal("Bar", clone.Columns[1].Name); Assert.False(clone.IsClustered); Assert.Same(clone.Columns[0], cloneContext.GetOrAdd(column0, () => null)); Assert.Same(clone.Columns[1], cloneContext.GetOrAdd(column1, () => null)); }
public void Clone_replicates_instance_and_adds_column_clones_to_cache() { var column0 = new Column("Foo", typeof(int)); var column1 = new Column("Bar", typeof(int)); var index = new Index("IX", new[] { column0, column1 }, isUnique: true, isClustered: true); var cloneContext = new CloneContext(); var clone = index.Clone(cloneContext); Assert.NotSame(index, clone); Assert.Equal("IX", clone.Name); Assert.Equal(2, clone.Columns.Count); Assert.NotSame(column0, clone.Columns[0]); Assert.NotSame(column1, clone.Columns[1]); Assert.Equal("Foo", clone.Columns[0].Name); Assert.Equal("Bar", clone.Columns[1].Name); Assert.True(clone.IsUnique); Assert.True(clone.IsClustered); Assert.Same(clone.Columns[0], cloneContext.GetOrAdd(column0, () => null)); Assert.Same(clone.Columns[1], cloneContext.GetOrAdd(column1, () => null)); }
public void Clone_replicates_instance() { var cloneContext = new CloneContext(); var column = new Column("Foo", typeof(string)) { DataType = "T", IsNullable = false, DefaultValue = "V", DefaultSql = "Sql", ValueGenerationStrategy = ValueGenerationOnSave.WhenInsertingAndUpdating, IsTimestamp = true, MaxLength = 4, Precision = 3, Scale = 2, IsFixedLength = true, IsUnicode = true }; var clone = column.Clone(cloneContext); Assert.NotSame(column, clone); Assert.Equal("Foo", clone.Name); Assert.Same(typeof(string), clone.ClrType); Assert.Equal("T", clone.DataType); Assert.Equal("V", clone.DefaultValue); Assert.Equal("Sql", clone.DefaultSql); Assert.Equal(ValueGenerationOnSave.WhenInsertingAndUpdating, clone.ValueGenerationStrategy); Assert.True(clone.IsTimestamp); Assert.Equal(4, clone.MaxLength.Value); Assert.Equal(3, clone.Precision.Value); Assert.Equal(2, clone.Scale.Value); Assert.True(clone.IsFixedLength.Value); Assert.True(clone.IsUnicode.Value); }
public void Clone_adds_new_clone_to_cache() { var cloneContext = new CloneContext(); var column = new Column("Foo", typeof(string)); var clone = column.Clone(cloneContext); Assert.NotSame(column, clone); Assert.Same(clone, cloneContext.GetOrAdd(column, () => null)); }
public void Clone_gets_existing_clone_from_cache() { var cloneContext = new CloneContext(); var column = new Column("Foo", typeof(string)); var clone = new Column("Foo", typeof(string)); Assert.Same(clone, cloneContext.GetOrAdd(column, () => clone)); Assert.Same(clone, column.Clone(cloneContext)); }
protected internal virtual Table Clone(CloneContext cloneContext) { var clone = new Table(Name, Columns.Select(c => c.Clone(cloneContext))); if (PrimaryKey != null) { clone._primaryKey = PrimaryKey.Clone(cloneContext); } clone._foreignKeys.AddRange(ForeignKeys.Select(fk => fk.Clone(cloneContext))); clone._indexes.AddRange(Indexes.Select(ix => ix.Clone(cloneContext))); return clone; }
protected internal virtual Sequence Clone(CloneContext cloneContext) { return new Sequence(Name, DataType, StartWith, IncrementBy); }
public void Clone_replicates_instance_and_uses_cache() { var column00 = new Column("C00", typeof(int)); var column01 = new Column("C01", typeof(string)); var column10 = new Column("C10", typeof(int)); var column11 = new Column("C11", typeof(string)); var table0 = new Table("dbo.T0", new[] { column00, column01 }); var table1 = new Table("dbo.T1", new[] { column10, column11 }); var primaryKey0 = new PrimaryKey("PK0", new[] { column00 }); var primaryKey1 = new PrimaryKey("PK1", new[] { column10 }); var foreignKey0 = new ForeignKey("FK0", new[] { column01 }, new[] { column10 }); var foreignKey1 = new ForeignKey("FK1", new[] { column11 }, new[] { column00 }); var index0 = new Index("IX0", new[] { column00 }); var index1 = new Index("IX1", new[] { column10 }); table0.PrimaryKey = primaryKey0; table1.PrimaryKey = primaryKey1; table0.AddForeignKey(foreignKey0); table1.AddForeignKey(foreignKey1); table0.AddIndex(index0); table1.AddIndex(index1); var cloneContext = new CloneContext(); var clone0 = table0.Clone(cloneContext); Assert.NotSame(table0, clone0); Assert.Equal("dbo.T0", clone0.Name); Assert.Equal(2, clone0.Columns.Count); Assert.NotSame(column00, clone0.Columns[0]); Assert.NotSame(column01, clone0.Columns[1]); Assert.Equal("C00", clone0.Columns[0].Name); Assert.Equal("C01", clone0.Columns[1].Name); Assert.Equal(typeof(int), clone0.Columns[0].ClrType); Assert.Equal(typeof(string), clone0.Columns[1].ClrType); Assert.NotNull(clone0.PrimaryKey); Assert.NotSame(primaryKey0, clone0.PrimaryKey); Assert.Equal("PK0", clone0.PrimaryKey.Name); Assert.Equal(1, clone0.PrimaryKey.Columns.Count); Assert.Same(clone0.Columns[0], clone0.PrimaryKey.Columns[0]); Assert.Equal(1, clone0.ForeignKeys.Count); Assert.NotSame(foreignKey0, clone0.ForeignKeys[0]); Assert.Equal("FK0", clone0.ForeignKeys[0].Name); Assert.Equal(1, clone0.ForeignKeys[0].Columns.Count); Assert.Equal(1, clone0.ForeignKeys[0].ReferencedColumns.Count); Assert.Same(clone0.Columns[1], clone0.ForeignKeys[0].Columns[0]); Assert.Same(cloneContext.GetOrAdd(column10, () => null), clone0.ForeignKeys[0].ReferencedColumns[0]); Assert.Equal(1, clone0.Indexes.Count); Assert.NotSame(index0, clone0.Indexes[0]); Assert.Equal("IX0", clone0.Indexes[0].Name); Assert.Equal(1, clone0.Indexes[0].Columns.Count); Assert.Same(clone0.Columns[0], clone0.Indexes[0].Columns[0]); Assert.Equal(3, cloneContext.ItemCount); Assert.Same(clone0.Columns[0], cloneContext.GetOrAdd(column00, () => null)); Assert.Same(clone0.Columns[1], cloneContext.GetOrAdd(column01, () => null)); Assert.NotNull(cloneContext.GetOrAdd(column10, () => null)); var clone1 = table1.Clone(cloneContext); Assert.NotSame(table1, clone1); Assert.Equal("dbo.T1", clone1.Name); Assert.Equal(2, clone1.Columns.Count); Assert.NotSame(column10, clone1.Columns[0]); Assert.NotSame(column11, clone1.Columns[1]); Assert.Equal("C10", clone1.Columns[0].Name); Assert.Equal("C11", clone1.Columns[1].Name); Assert.Equal(typeof(int), clone1.Columns[0].ClrType); Assert.Equal(typeof(string), clone1.Columns[1].ClrType); Assert.NotNull(clone1.PrimaryKey); Assert.NotSame(primaryKey1, clone1.PrimaryKey); Assert.Equal("PK1", clone1.PrimaryKey.Name); Assert.Equal(1, clone1.PrimaryKey.Columns.Count); Assert.Same(clone1.Columns[0], clone1.PrimaryKey.Columns[0]); Assert.Equal(1, clone1.ForeignKeys.Count); Assert.NotSame(foreignKey1, clone1.ForeignKeys[0]); Assert.Equal("FK1", clone1.ForeignKeys[0].Name); Assert.Equal(1, clone1.ForeignKeys[0].Columns.Count); Assert.Equal(1, clone1.ForeignKeys[0].ReferencedColumns.Count); Assert.Same(clone1.Columns[1], clone1.ForeignKeys[0].Columns[0]); Assert.Same(clone0.Columns[0], clone1.ForeignKeys[0].ReferencedColumns[0]); Assert.Same(clone1.Columns[0], clone0.ForeignKeys[0].ReferencedColumns[0]); Assert.Equal(1, clone1.Indexes.Count); Assert.NotSame(index1, clone1.Indexes[0]); Assert.Equal("IX1", clone1.Indexes[0].Name); Assert.Equal(1, clone1.Indexes[0].Columns.Count); Assert.Same(clone1.Columns[0], clone1.Indexes[0].Columns[0]); Assert.Equal(4, cloneContext.ItemCount); Assert.Same(clone0.Columns[0], cloneContext.GetOrAdd(column00, () => null)); Assert.Same(clone0.Columns[1], cloneContext.GetOrAdd(column01, () => null)); Assert.Same(clone1.Columns[0], cloneContext.GetOrAdd(column10, () => null)); Assert.Same(clone1.Columns[1], cloneContext.GetOrAdd(column11, () => null)); }
protected internal virtual Column Clone(CloneContext cloneContext) { return (Column)cloneContext.GetOrAdd(this, () => new Column(this)); }
public void Clone_gets_column_clones_from_cache() { var column0 = new Column("C0", typeof(int)); var column1 = new Column("C1", typeof(int)); var referencedColumn0 = new Column("RC0", typeof(int)); var referencedColumn1 = new Column("RC1", typeof(int)); var foreignKey = new ForeignKey( "FK", new[] { column0, column1 }, new[] { referencedColumn0, referencedColumn1 }, cascadeDelete: true); var cloneContext = new CloneContext(); var columnClone0 = column0.Clone(cloneContext); var columnClone1 = column1.Clone(cloneContext); var referencedColumnClone0 = referencedColumn0.Clone(cloneContext); var referencedColumnClone1 = referencedColumn1.Clone(cloneContext); var clone = foreignKey.Clone(cloneContext); Assert.NotSame(foreignKey, clone); Assert.Equal(2, clone.Columns.Count); Assert.Same(columnClone0, clone.Columns[0]); Assert.Same(columnClone1, clone.Columns[1]); Assert.Equal(2, clone.ReferencedColumns.Count); Assert.Same(referencedColumnClone0, clone.ReferencedColumns[0]); Assert.Same(referencedColumnClone1, clone.ReferencedColumns[1]); }