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)); }
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)); }
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 uniqueConstraint = new UniqueConstraint("PK", new[] { column0, column1 }); var cloneContext = new CloneContext(); var clone = uniqueConstraint.Clone(cloneContext); Assert.NotSame(uniqueConstraint, 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.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 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 virtual Column Clone([NotNull] CloneContext cloneContext) { Check.NotNull(cloneContext, "cloneContext"); return((Column)cloneContext.GetOrAdd(this, () => new Column(this))); }
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 uniqueConstraint0 = new UniqueConstraint("UC0", new[] { column00, column01 }); var uniqueConstraint1 = new UniqueConstraint("UC1", new[] { column10, column11 }); 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.AddUniqueConstraint(uniqueConstraint0); table1.AddUniqueConstraint(uniqueConstraint1); 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.UniqueConstraints.Count); Assert.NotSame(index0, clone0.UniqueConstraints[0]); Assert.Equal("UC0", clone0.UniqueConstraints[0].Name); Assert.Equal(2, clone0.UniqueConstraints[0].Columns.Count); Assert.Same(clone0.Columns[0], clone0.UniqueConstraints[0].Columns[0]); Assert.Same(clone0.Columns[1], clone0.UniqueConstraints[0].Columns[1]); 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.UniqueConstraints.Count); Assert.NotSame(index1, clone1.UniqueConstraints[0]); Assert.Equal("UC1", clone1.UniqueConstraints[0].Name); Assert.Equal(2, clone1.UniqueConstraints[0].Columns.Count); Assert.Same(clone1.Columns[0], clone1.UniqueConstraints[0].Columns[0]); Assert.Same(clone1.Columns[1], clone1.UniqueConstraints[0].Columns[1]); 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))); }