public void CloneCopy()
{
DataTable table = new DataTable("pTable");
DataTable table1 = new DataTable("cTable");
DataSet set = new DataSet();
set.Tables.Add(table);
set.Tables.Add(table1);
DataColumn col = new DataColumn();
col.ColumnName = "Id";
col.DataType = Type.GetType("System.Int32");
table.Columns.Add(col);
UniqueConstraint uc = new UniqueConstraint("UK1", table.Columns[0]);
table.Constraints.Add(uc);
col = new DataColumn();
col.ColumnName = "Name";
col.DataType = Type.GetType("System.String");
table.Columns.Add(col);
col = new DataColumn();
col.ColumnName = "Id";
col.DataType = Type.GetType("System.Int32");
table1.Columns.Add(col);
col = new DataColumn();
col.ColumnName = "Name";
col.DataType = Type.GetType("System.String");
table1.Columns.Add(col);
ForeignKeyConstraint fc = new ForeignKeyConstraint("FK1", table.Columns[0], table1.Columns[0]);
table1.Constraints.Add(fc);
DataRow row = table.NewRow();
row["Id"] = 147;
row["name"] = "Row1";
row.RowError = "Error#1";
table.Rows.Add(row);
// Set column to RO as commonly used by auto-increment fields.
// ds.Copy() has to omit the RO check when cloning DataRows
table.Columns["Id"].ReadOnly = true;
row = table1.NewRow();
row["Id"] = 147;
row["Name"] = "Row1";
table1.Rows.Add(row);
//Setting properties of DataSet
set.CaseSensitive = true;
set.DataSetName = "My DataSet";
set.EnforceConstraints = false;
set.Namespace = "Namespace#1";
set.Prefix = "Prefix:1";
DataRelation dr = new DataRelation("DR", table.Columns[0], table1.Columns[0]);
set.Relations.Add(dr);
set.ExtendedProperties.Add("TimeStamp", DateTime.Now);
CultureInfo cultureInfo = new CultureInfo("ar-SA");
set.Locale = cultureInfo;
//Testing Copy ()
DataSet copySet = set.Copy();
Assert.Equal(set.CaseSensitive, copySet.CaseSensitive);
Assert.Equal(set.DataSetName, copySet.DataSetName);
Assert.Equal(set.EnforceConstraints, copySet.EnforceConstraints);
Assert.Equal(set.HasErrors, copySet.HasErrors);
Assert.Equal(set.Namespace, copySet.Namespace);
Assert.Equal(set.Prefix, copySet.Prefix);
Assert.Equal(set.Relations.Count, copySet.Relations.Count);
Assert.Equal(set.Tables.Count, copySet.Tables.Count);
Assert.Equal(set.ExtendedProperties["TimeStamp"], copySet.ExtendedProperties["TimeStamp"]);
for (int i = 0; i < copySet.Tables.Count; i++)
{
Assert.Equal(set.Tables[i].Rows.Count, copySet.Tables[i].Rows.Count);
Assert.Equal(set.Tables[i].Columns.Count, copySet.Tables[i].Columns.Count);
}
//Testing Clone ()
copySet = set.Clone();
Assert.Equal(set.CaseSensitive, copySet.CaseSensitive);
Assert.Equal(set.DataSetName, copySet.DataSetName);
Assert.Equal(set.EnforceConstraints, copySet.EnforceConstraints);
Assert.False(copySet.HasErrors);
Assert.Equal(set.Namespace, copySet.Namespace);
Assert.Equal(set.Prefix, copySet.Prefix);
Assert.Equal(set.Relations.Count, copySet.Relations.Count);
Assert.Equal(set.Tables.Count, copySet.Tables.Count);
Assert.Equal(set.ExtendedProperties["TimeStamp"], copySet.ExtendedProperties["TimeStamp"]);
for (int i = 0; i < copySet.Tables.Count; i++)
{
Assert.Equal(0, copySet.Tables[i].Rows.Count);
Assert.Equal(set.Tables[i].Columns.Count, copySet.Tables[i].Columns.Count);
}
}