CreateParentDataTable() public static method

public static CreateParentDataTable ( ) : DataTable
return DataTable
示例#1
0
        public void RemoveAt_Integer()
        {
            DataTable dt = DataProvider.CreateParentDataTable();

            dt.Columns.CollectionChanged += new CollectionChangeEventHandler(Columns_CollectionChanged1);
            int originalColumnCount = dt.Columns.Count;

            dt.Columns.RemoveAt(0);
            Assert.Equal(originalColumnCount - 1, dt.Columns.Count);
            Assert.True(_eventOccurred);

            Assert.Throws <IndexOutOfRangeException>(() =>
            {
                dt.Columns.RemoveAt(-1);
            });
        }
        public void constraintName()
        {
            DataTable dtParent = DataProvider.CreateParentDataTable();

            UniqueConstraint uc = null;

            uc = new UniqueConstraint(dtParent.Columns[0]);

            // default
            Assert.Equal(string.Empty, uc.ConstraintName);

            uc.ConstraintName = "myConstraint";

            // set/get
            Assert.Equal("myConstraint", uc.ConstraintName);
        }
示例#3
0
        public new void ToString()
        {
            DataTable dtParent = DataProvider.CreateParentDataTable();
            DataTable dtChild  = DataProvider.CreateChildDataTable();

            ForeignKeyConstraint fc = null;

            fc = new ForeignKeyConstraint(dtParent.Columns[0], dtChild.Columns[0]);

            // ToString - default
            Assert.Equal(string.Empty, fc.ToString());

            fc = new ForeignKeyConstraint("myConstraint", dtParent.Columns[0], dtChild.Columns[0]);
            // Tostring - Constraint name
            Assert.Equal("myConstraint", fc.ToString());
        }
        public void CopyTo()
        {
            DataTable dt = DataProvider.CreateParentDataTable();

            DataRow[] arr = new DataRow[dt.Rows.Count];
            dt.Rows.CopyTo(arr, 0);
            Assert.Equal(dt.Rows.Count, arr.Length);

            int index = 0;

            foreach (DataRow dr in dt.Rows)
            {
                Assert.Equal(dr, arr[index]);
                index++;
            }
        }
示例#5
0
        public void Item_Property()
        {
            DataTable dt = DataProvider.CreateParentDataTable();
            DataView  dv = new DataView(dt);

            DataRowView drv = dv[0];

            // Item 'ParentId'
            Assert.Equal(dt.Rows[0]["ParentId"], drv["ParentId"]);

            // Item 'ParentDateTime'
            Assert.Equal(dt.Rows[0]["ParentDateTime"], drv["ParentDateTime"]);

            // Item invalid - excpetion
            AssertExtensions.Throws <ArgumentException>(null, () => drv["something"]);
        }
示例#6
0
        public void Item()
        {
            DataTable dt = DataProvider.CreateParentDataTable();
            DataView  dv = new DataView(dt);

            DataRowView drv = dv[0];

            // Item 0
            Assert.Equal(dt.Rows[0][0], drv[0]);

            // Item 4
            Assert.Equal(dt.Rows[0][4], drv[4]);

            // Item -1 - excpetion
            Assert.Throws <IndexOutOfRangeException>(() => drv[-1]);
        }
示例#7
0
        public void ApplyDefaultSort()
        {
            DataTable dt = DataProvider.CreateParentDataTable();
            DataView  dv = new DataView(dt);

            // ApplyDefaultSort - default value
            Assert.False(dv.ApplyDefaultSort);

            // ApplyDefaultSort - true
            dv.ApplyDefaultSort = true;
            Assert.True(dv.ApplyDefaultSort);

            // ApplyDefaultSort - false
            dv.ApplyDefaultSort = false;
            Assert.False(dv.ApplyDefaultSort);
        }
        public void DataRowCollection_Find_O3()
        {
            DataTable dt = DataProvider.CreateParentDataTable();

            dt.PrimaryKey = new DataColumn[] { dt.Columns[0], dt.Columns[1] };

            //Prepare values array
            object[] arr = new object[2];
            arr[0] = 2;
            arr[1] = "2-String1";

            Assert.Equal(dt.Rows[1], dt.Rows.Find(arr));

            arr[0] = 8;

            Assert.Equal(null, dt.Rows.Find(arr));
        }
        public void TestContains_ByColumnName()
        {
            DataTable dt = DataProvider.CreateParentDataTable();

            Assert.Equal(true, dt.Columns.Contains("ParentId"));
            Assert.Equal(true, dt.Columns.Contains("String1"));
            Assert.Equal(true, dt.Columns.Contains("ParentBool"));

            Assert.Equal(false, dt.Columns.Contains("ParentId1"));
            dt.Columns.Remove("ParentId");
            Assert.Equal(false, dt.Columns.Contains("ParentId"));

            dt.Columns["String1"].ColumnName = "Temp1";

            Assert.Equal(false, dt.Columns.Contains("String1"));
            Assert.Equal(true, dt.Columns.Contains("Temp1"));
        }
        [Fact] // this [Int32]
        public void Indexer1()
        {
            DataTable  dt = DataProvider.CreateParentDataTable();
            DataColumn col;

            col = dt.Columns[5];
            Assert.NotNull(col);
            Assert.Equal("ParentBool", col.ColumnName);

            col = dt.Columns[0];
            Assert.NotNull(col);
            Assert.Equal("ParentId", col.ColumnName);

            col = dt.Columns[3];
            Assert.NotNull(col);
            Assert.Equal("ParentDateTime", col.ColumnName);
        }
示例#11
0
        public void Ctor_DataColumnPrimary()
        {
            DataTable        dtParent = DataProvider.CreateParentDataTable();
            UniqueConstraint uc       = new UniqueConstraint(dtParent.Columns[0], false);

            dtParent.Constraints.Add(uc);

            // primary key 1
            Assert.Equal(0, dtParent.PrimaryKey.Length);

            dtParent.Constraints.Remove(uc);
            uc = new UniqueConstraint(dtParent.Columns[0], true);
            dtParent.Constraints.Add(uc);

            // primary key 2
            Assert.Equal(1, dtParent.PrimaryKey.Length);
        }
示例#12
0
        public void extendedProperties()
        {
            DataTable dtParent = DataProvider.CreateParentDataTable();
            DataTable dtChild  = DataProvider.CreateParentDataTable();

            ForeignKeyConstraint fc = null;

            fc = new ForeignKeyConstraint(dtParent.Columns[0], dtChild.Columns[0]);

            PropertyCollection pc = fc.ExtendedProperties;

            // Checking ExtendedProperties default
            Assert.Equal(true, fc != null);

            // Checking ExtendedProperties count
            Assert.Equal(0, pc.Count);
        }
        public void DataRowCollection_Contains_O3()
        {
            DataTable dt = DataProvider.CreateParentDataTable();

            dt.PrimaryKey = new DataColumn[] { dt.Columns[0], dt.Columns[1] };

            //Prepare values array
            object[] arr = new object[2];
            arr[0] = 1;
            arr[1] = "1-String1";

            Assert.Equal(true, dt.Rows.Contains(arr));

            arr[0] = 8;

            Assert.Equal(false, dt.Rows.Contains(arr));
        }
        [Fact] // this [String]
        public void Indexer2()
        {
            DataTable            dt   = DataProvider.CreateParentDataTable();
            DataColumnCollection cols = dt.Columns;
            DataColumn           col;

            col = cols["ParentId"];
            Assert.NotNull(col);
            Assert.Equal("ParentId", col.ColumnName);

            col = cols["parentiD"];
            Assert.NotNull(col);
            Assert.Equal("ParentId", col.ColumnName);

            col = cols["DoesNotExist"];
            Assert.Null(col);
        }
        [Fact] // this [String]
        public void Indexer2_Name_Null()
        {
            DataTable dt = DataProvider.CreateParentDataTable();

            try
            {
                DataColumn column = dt.Columns[null];
                Assert.False(true);
            }
            catch (ArgumentNullException ex)
            {
                Assert.Equal(typeof(ArgumentNullException), ex.GetType());
                Assert.Null(ex.InnerException);
                Assert.NotNull(ex.Message);
                Assert.Equal("name", ex.ParamName);
            }
        }
示例#16
0
        public void DataSet()
        {
            var       ds       = new DataSet();
            DataTable dtChild  = DataProvider.CreateChildDataTable();
            DataTable dtParent = DataProvider.CreateParentDataTable();

            ds.Tables.Add(dtParent);
            ds.Tables.Add(dtChild);

            DataRelation dRel;

            dRel = new DataRelation("MyRelation", dtParent.Columns[0], dtChild.Columns[0]);
            ds.Relations.Add(dRel);

            // DataSet
            Assert.Equal(ds, dRel.DataSet);
        }
        [Fact] // this [Int32]
        public void Indexer1_Index_Overflow()
        {
            DataTable dt = DataProvider.CreateParentDataTable();

            try
            {
                DataColumn column = dt.Columns[6];
                Assert.False(true);
            }
            catch (IndexOutOfRangeException ex)
            {
                // Cannot find column 6
                Assert.Equal(typeof(IndexOutOfRangeException), ex.GetType());
                Assert.Null(ex.InnerException);
                Assert.NotNull(ex.Message);
            }
        }
示例#18
0
        public void Bug79233()
        {
            DataSet   ds       = new DataSet();
            DataTable dtChild  = DataProvider.CreateChildDataTable();
            DataTable dtParent = DataProvider.CreateParentDataTable();

            ds.Tables.Add(dtParent);
            ds.Tables.Add(dtChild);

            dtParent.Rows.Clear();
            dtChild.Rows.Clear();

            DataRelation dr = dtParent.ChildRelations.Add(dtParent.Columns[0], dtChild.Columns[0]);

            Assert.Equal("Relation1", dr.RelationName);
            dr = dtChild.ChildRelations.Add(dtChild.Columns[0], dtParent.Columns[0]);
            Assert.Equal("Relation2", dr.RelationName);
        }
        public void Ctor_DclmDclm()
        {
            DataTable dtParent = DataProvider.CreateParentDataTable();
            DataTable dtChild  = DataProvider.CreateChildDataTable();
            var       ds       = new DataSet();

            ds.Tables.Add(dtChild);
            ds.Tables.Add(dtParent);
            ForeignKeyConstraint fc = new ForeignKeyConstraint(dtParent.Columns[0], dtChild.Columns[0]);

            Assert.Equal(0, dtChild.Constraints.Count);

            Assert.Equal(0, dtParent.Constraints.Count);

            Assert.Equal(0, ds.Relations.Count);

            dtChild.Constraints.Add(fc);

            Assert.Equal(1, dtChild.Constraints.Count);

            Assert.Equal(1, dtParent.Constraints.Count);

            Assert.Equal(0, ds.Relations.Count);

            Assert.Equal(typeof(UniqueConstraint), dtParent.Constraints[0].GetType());

            Assert.Equal(typeof(ForeignKeyConstraint), dtChild.Constraints[0].GetType());

            Assert.Equal(0, dtParent.PrimaryKey.Length);

            dtChild.Constraints.Clear();
            dtParent.Constraints.Clear();
            ds.Relations.Add(new DataRelation("myRelation", dtParent.Columns[0], dtChild.Columns[0]));

            Assert.Equal(1, dtChild.Constraints.Count);

            Assert.Equal(1, dtParent.Constraints.Count);

            Assert.Equal(typeof(UniqueConstraint), dtParent.Constraints[0].GetType());

            Assert.Equal(typeof(ForeignKeyConstraint), dtChild.Constraints[0].GetType());

            Assert.Equal(0, dtParent.PrimaryKey.Length);
        }
示例#20
0
        public void Expression_Simple()
        {
            DataTable dt = DataProvider.CreateParentDataTable();
            //Simple expression --> not aggregate
            DataColumn dc = new DataColumn("expr", typeof(decimal));

            dt.Columns.Add(dc);
            dt.Columns["expr"].Expression = dt.Columns[0].ColumnName + "*0.52 +" + dt.Columns[0].ColumnName;

            //Check the values
            //double temp;
            string temp;
            string str;

            foreach (DataRow dr in dt.Rows)
            {
                str = (((int)dr[0]) * 0.52 + ((int)dr[0])).ToString();
                if (str.Length > 3)
                {
                    temp = str.Substring(0, 4);
                }
                else
                {
                    temp = str;
                }

                if (dr["expr"].ToString().Length > 3)
                {
                    str = dr["expr"].ToString().Substring(0, 4);
                }
                else
                {
                    str = dr["expr"].ToString();
                }

                if (str == 7.60m.ToString())
                {
                    str = 7.6.ToString();
                }

                Assert.Equal(temp, str);
            }
        }
示例#21
0
        public void Item()
        {
            //create the source datatable
            DataTable dt = DataProvider.CreateParentDataTable();

            //create the dataview for the table
            DataView dv = new DataView(dt);

            // DataView Item 0
            Assert.Equal(dv[0].Row, dt.Rows[0]);

            // DataView Item 4
            Assert.Equal(dv[4].Row, dt.Rows[4]);

            dv.RowFilter = "ParentId in (1,3,6)";

            // DataView Item 0,DataTable with filter
            Assert.Equal(dv[1].Row, dt.Rows[2]);
        }
示例#22
0
        public void IsPrimaryKey()
        {
            DataTable dtParent = DataProvider.CreateParentDataTable();

            UniqueConstraint uc = null;

            uc = new UniqueConstraint(dtParent.Columns[0], false);
            dtParent.Constraints.Add(uc);

            // primary key 1
            Assert.False(uc.IsPrimaryKey);

            dtParent.Constraints.Remove(uc);
            uc = new UniqueConstraint(dtParent.Columns[0], true);
            dtParent.Constraints.Add(uc);

            // primary key 2
            Assert.True(uc.IsPrimaryKey);
        }
        public void DataRowCollection_Add_D1()
        {
            DataTable dt = DataProvider.CreateParentDataTable();

            dt.Rows.Clear();
            DataRow dr = dt.NewRow();

            dr["ParentId"]       = 10;
            dr["String1"]        = "string1";
            dr["String2"]        = string.Empty;
            dr["ParentDateTime"] = new DateTime(2004, 12, 15);
            dr["ParentDouble"]   = 3.14;
            dr["ParentBool"]     = false;

            dt.Rows.Add(dr);

            Assert.Equal(1, dt.Rows.Count);
            Assert.Equal(dr, dt.Rows[0]);
        }
示例#24
0
        public void Columns()
        {
            //int RowCount;
            var       ds       = new DataSet();
            DataTable dtParent = DataProvider.CreateParentDataTable();
            DataTable dtChild  = DataProvider.CreateChildDataTable();

            ds.Tables.Add(dtParent);
            ds.Tables.Add(dtChild);

            ForeignKeyConstraint fc = null;

            fc = new ForeignKeyConstraint(dtParent.Columns[0], dtChild.Columns[0]);

            // Columns
            Assert.Equal(dtChild.Columns[0], fc.Columns[0]);

            // Columns count
            Assert.Equal(1, fc.Columns.Length);
        }
示例#25
0
        public void Equals_O()
        {
            var       ds       = new DataSet();
            DataTable dtParent = DataProvider.CreateParentDataTable();

            ds.Tables.Add(dtParent);

            UniqueConstraint uc1, uc2;

            uc1 = new UniqueConstraint(dtParent.Columns[0]);

            uc2 = new UniqueConstraint(dtParent.Columns[1]);
            // different columnn
            Assert.False(uc1.Equals(uc2));

            //Two System.Data.ForeignKeyConstraint are equal if they constrain the same columns.
            // same column
            uc2 = new UniqueConstraint(dtParent.Columns[0]);
            Assert.True(uc1.Equals(uc2));
        }
示例#26
0
        public void Delete()
        {
            DataTable dt = DataProvider.CreateParentDataTable();
            DataView  dv = new DataView(dt);

            DataRowView drv            = dv[0];
            int         tableRowsCount = dt.Rows.Count;
            int         viewRowCount   = dv.Count;

            // DataView Count
            drv.Delete();
            Assert.Equal(viewRowCount - 1, dv.Count);

            //the table count should stay the same until EndEdit is invoked
            // Table Count
            Assert.Equal(tableRowsCount, dt.Rows.Count);

            // DataRowState deleted
            Assert.Equal(DataRowState.Deleted, drv.Row.RowState);
        }
        public void Generate()
        {
            Exception tmpEx = new Exception();

            DataTable tbl = DataProvider.CreateParentDataTable();

            tbl.Columns[0].ReadOnly = true;

            //check for int column
            // ReadOnlyException - EndEdit
            //tbl.Rows[0].BeginEdit();   // this throw an exception but according to MSDN it shouldn't !!!
            //tbl.Rows[0][0] = 99 ;
            Assert.Throws <ReadOnlyException>(() =>
            {
                tbl.Rows[0][0] = 99;
            });

            // ReadOnlyException - ItemArray
            Assert.Throws <ReadOnlyException>(() =>
            {
                tbl.Rows[0].ItemArray = new object[] { 99, "value", "value" };
            });

            //check for string column
            tbl.Columns[0].ReadOnly = false;
            tbl.Columns[1].ReadOnly = true;

            // ReadOnlyException - EndEdit
            //tbl.Rows[0].BeginEdit();   // this throw an exception but according to MSDN it shouldn't !!!
            //tbl.Rows[0][0] = 99 ;
            Assert.Throws <ReadOnlyException>(() =>
            {
                tbl.Rows[0][1] = "NewValue";
            });

            // ReadOnlyException - ItemArray
            Assert.Throws <ReadOnlyException>(() =>
            {
                tbl.Rows[0].ItemArray = new object[] { 99, "value", "value" };
            });
        }
示例#28
0
        public void constraintName()
        {
            var       ds       = new DataSet();
            DataTable dtParent = DataProvider.CreateParentDataTable();
            DataTable dtChild  = DataProvider.CreateChildDataTable();

            ds.Tables.Add(dtParent);
            ds.Tables.Add(dtChild);

            ForeignKeyConstraint fc = null;

            fc = new ForeignKeyConstraint(dtParent.Columns[0], dtChild.Columns[0]);

            // default
            Assert.Equal(string.Empty, fc.ConstraintName);

            fc.ConstraintName = "myConstraint";

            // set/get
            Assert.Equal("myConstraint", fc.ConstraintName);
        }
示例#29
0
        public void RowVersion()
        {
            DataTable dt = DataProvider.CreateParentDataTable();
            DataView  dv = new DataView(dt);

            dt.Columns[1].DefaultValue = "default";
            DataRowView drv = dv[0];

            dt.Rows.Add(new object[] { 99 });
            dt.Rows[1].Delete();
            dt.Rows[2].BeginEdit();
            dt.Rows[2][1] = "aaa";

            dv.RowStateFilter = DataViewRowState.CurrentRows;
            // check Current
            Assert.Equal(DataRowVersion.Current, drv.RowVersion);

            dv.RowStateFilter = DataViewRowState.Deleted;
            // check Original
            Assert.Equal(DataRowVersion.Current, drv.RowVersion);
        }
示例#30
0
        public void Nested()
        {
            var       ds       = new DataSet();
            DataTable dtChild  = DataProvider.CreateChildDataTable();
            DataTable dtParent = DataProvider.CreateParentDataTable();

            ds.Tables.Add(dtParent);
            ds.Tables.Add(dtChild);

            DataRelation dRel;

            dRel = new DataRelation(null, dtParent.Columns[0], dtChild.Columns[0]);
            ds.Relations.Add(dRel);

            // Nested default
            Assert.False(dRel.Nested);

            dRel.Nested = true;

            // Nested get/set
            Assert.True(dRel.Nested);
        }