System.Data.Tests.DataViewTest2.ToTable_SimpleTest C# (CSharp) Method

ToTable_SimpleTest() private method

private ToTable_SimpleTest ( ) : void
return void
        public void ToTable_SimpleTest()
        {
            var ds = new DataSet();
            ds.Tables.Add("table");
            ds.Tables[0].Columns.Add("col1", typeof(int));
            ds.Tables[0].Columns.Add("col2", typeof(int), "sum(col1)");
            ds.Tables[0].Columns.Add("col3", typeof(int));
            ds.Tables[0].Columns[2].AutoIncrement = true;

            ds.Tables[0].Rows.Add(new object[] { 1 });
            ds.Tables[0].Rows.Add(new object[] { 2 });

            ds.Tables[0].PrimaryKey = new DataColumn[] { ds.Tables[0].Columns[0] };

            DataView view = new DataView(ds.Tables[0]);
            DataTable table = view.ToTable();

            // The rule seems to be : Copy any col property that doesent
            // involve/depend on other columns..
            // Constraints and PrimaryKey info not copied over
            Assert.Equal(0, table.PrimaryKey.Length);
            Assert.Equal(0, table.Constraints.Count);
            // AllowDBNull state is maintained by ms.net
            Assert.False(table.Columns[0].AllowDBNull);
            Assert.True(table.Columns[2].AllowDBNull);
            // Expression is not copied over by ms.net
            Assert.Equal("", table.Columns[1].Expression);
            // AutoIncrement state is maintained by ms.net
            Assert.True(table.Columns[2].AutoIncrement);

            Assert.False(ds.Tables[0] == table);

            Assert.Equal(ds.Tables[0].TableName, table.TableName);
            Assert.Equal(ds.Tables[0].Columns.Count, table.Columns.Count);
            Assert.Equal(ds.Tables[0].Rows.Count, table.Rows.Count);

            for (int i = 0; i < table.Columns.Count; ++i)
            {
                Assert.Equal(ds.Tables[0].Columns[i].ColumnName, table.Columns[i].ColumnName);
                Assert.Equal(ds.Tables[0].Columns[i].DataType, table.Columns[i].DataType);
                for (int j = 0; j < table.Rows.Count; ++j)
                    Assert.Equal(ds.Tables[0].Rows[j][i], table.Rows[j][i]);
            }

            DataTable table1 = view.ToTable("newtable");
            Assert.Equal("newtable", table1.TableName);
        }