CreateChildDataTable() public static method

public static CreateChildDataTable ( ) : DataTable
return DataTable
Esempio n. 1
0
        public void AddNew()
        {
            //create the source datatable
            DataTable dt = DataProvider.CreateChildDataTable();

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

            int CountView  = dv.Count;
            int CountTable = dt.Rows.Count;

            DataRowView drv = null;

            // AddNew - DataView Row Count
            drv = dv.AddNew();
            Assert.Equal(dv.Count, CountView + 1);

            // AddNew - Table Row Count
            Assert.Equal(dt.Rows.Count, CountTable);

            // AddNew - new row in DataTable
            drv.EndEdit();
            Assert.Equal(dt.Rows.Count, CountTable + 1);

            // AddNew - new row != null
            Assert.Equal(true, drv != null);

            // AddNew - check table
            Assert.Equal(dt, drv.Row.Table);
        }
Esempio n. 2
0
        public void CreateChildView_ByDataRelation()
        {
            //create a dataset with two tables, with a DataRelation between them
            DataTable dtParent = DataProvider.CreateParentDataTable();
            DataTable dtChild  = DataProvider.CreateChildDataTable();
            var       ds       = new DataSet();

            ds.Tables.Add(dtParent);
            ds.Tables.Add(dtChild);
            DataRelation drel = new DataRelation("ParentChild", dtParent.Columns["ParentId"], dtChild.Columns["ParentId"]);

            ds.Relations.Add(drel);

            //DataView dvChild = null;
            DataView dvParent = new DataView(dtParent);

            DataView dvTmp1 = dvParent[0].CreateChildView(drel);
            DataView dvTmp2 = dvParent[3].CreateChildView(drel);

            // ChildView != null
            Assert.NotNull(dvTmp1);

            // Child view table = ChildTable
            Assert.Equal(dtChild, dvTmp1.Table);

            // ChildView1.Table = ChildView2.Table
            Assert.Equal(dvTmp2.Table, dvTmp1.Table);

            //the child dataview are different
            // Child DataViews different
            Assert.False(dvTmp1.Equals(dvTmp2));
        }
Esempio n. 3
0
        public void RelationName()
        {
            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]);

            // RelationName default 1
            Assert.Equal(string.Empty, dRel.RelationName);

            ds.Relations.Add(dRel);

            // RelationName default 2
            Assert.Equal("Relation1", dRel.RelationName);

            dRel.RelationName = "myRelation";

            // RelationName get/set
            Assert.Equal("myRelation", dRel.RelationName);
        }
        public void Ctor_DataColumns()
        {
            Exception tmpEx    = new Exception();
            DataTable dtParent = DataProvider.CreateParentDataTable();

            // Ctor - parent
            UniqueConstraint uc = new UniqueConstraint(new DataColumn[] { dtParent.Columns[0], dtParent.Columns[1] });

            // Ctor - add existing column
            dtParent.Rows.Add(new object[] { 99, "str1", "str2" });
            dtParent.Constraints.Add(uc);
            Assert.Throws <ConstraintException>(() => dtParent.Rows.Add(new object[] { 99, "str1", "str2" }));

            DataTable dtChild = DataProvider.CreateChildDataTable();

            uc = new UniqueConstraint(new DataColumn[] { dtChild.Columns[0], dtChild.Columns[1] });
            dtChild.Constraints.Add(uc);

            dtChild.Constraints.Clear();
            uc = new UniqueConstraint(new DataColumn[] { dtChild.Columns[1], dtChild.Columns[2] });

            //target columnn are not unnique, will throw an exception
            // ArgumentException - child
            AssertExtensions.Throws <ArgumentException>(null, () => dtChild.Constraints.Add(uc));
        }
Esempio n. 5
0
        public void ToStringTest()
        {
            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]);

            // ToString 1
            Assert.Equal(string.Empty, dRel.ToString());

            ds.Relations.Add(dRel);

            // ToString 2
            Assert.Equal("Relation1", dRel.ToString());

            dRel.RelationName = "myRelation";

            // ToString 3
            Assert.Equal("myRelation", dRel.ToString());
        }
Esempio n. 6
0
        public void Ctor_ByNameDataColumnsArrays()
        {
            var       ds       = new DataSet();
            DataTable dtChild  = DataProvider.CreateChildDataTable();
            DataTable dtParent = DataProvider.CreateParentDataTable();

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

            DataRelation dRel;

            //check some exception
            // DataRelation - CTor ArgumentException, two columns child
            AssertExtensions.Throws <ArgumentException>(null, () =>
            {
                dRel = new DataRelation("MyRelation", new DataColumn[] { dtParent.Columns[0] }, new DataColumn[] { dtChild.Columns[0], dtChild.Columns[2] });
            });

            dRel = new DataRelation("MyRelation", new DataColumn[] { dtParent.Columns[0], dtParent.Columns[1] }, new DataColumn[] { dtChild.Columns[0], dtChild.Columns[2] });
            // DataRelation - Add Relation ArgumentException, fail on creating child Constraints
            AssertExtensions.Throws <ArgumentException>(null, () =>
            {
                ds.Relations.Add(dRel);
            });

            // DataRelation ArgumentException - parent Constraints
            Assert.Equal(1, dtParent.Constraints.Count);

            // DataRelation ArgumentException - child Constraints
            Assert.Equal(0, dtChild.Constraints.Count);

            // DataRelation ArgumentException - DataSet.Relation count
            Assert.Equal(1, ds.Relations.Count);

            //begin to check the relation ctor
            dtParent.Constraints.Clear();
            dtChild.Constraints.Clear();
            ds.Relations.Clear();
            dRel = new DataRelation("MyRelation", new DataColumn[] { dtParent.Columns[0] }, new DataColumn[] { dtChild.Columns[0] });
            ds.Relations.Add(dRel);

            // DataSet DataRelation count
            Assert.Equal(1, ds.Relations.Count);

            // DataRelation - parent Constraints
            Assert.Equal(1, dtParent.Constraints.Count);

            // DataRelation - child Constraints
            Assert.Equal(1, dtChild.Constraints.Count);

            // DataRelation - child relations
            Assert.Equal(dRel, dtParent.ChildRelations[0]);

            // DataRelation - parent relations
            Assert.Equal(dRel, dtChild.ParentRelations[0]);

            // DataRelation - name
            Assert.Equal("MyRelation", dRel.RelationName);
        }
Esempio n. 7
0
        public void CopyTo()
        {
            //create the source datatable
            DataTable dt = DataProvider.CreateChildDataTable();

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

            DataRowView[] drvExpected = null;
            DataRowView[] drvResult   = null;

            // ------- Copy from Index=0
            drvExpected = new DataRowView[dv.Count];
            for (int i = 0; i < dv.Count; i++)
            {
                drvExpected[i] = dv[i];
            }

            drvResult = new DataRowView[dv.Count];
            // CopyTo from index 0
            dv.CopyTo(drvResult, 0);
            Assert.Equal(drvResult, drvExpected);

            // ------- Copy from Index=3
            drvExpected = new DataRowView[dv.Count + 3];
            for (int i = 0; i < dv.Count; i++)
            {
                drvExpected[i + 3] = dv[i];
            }

            drvResult = new DataRowView[dv.Count + 3];
            // CopyTo from index 3
            dv.CopyTo(drvResult, 3);
            Assert.Equal(drvResult, drvExpected);

            // ------- Copy from Index=3,larger array
            drvExpected = new DataRowView[dv.Count + 9];
            for (int i = 0; i < dv.Count; i++)
            {
                drvExpected[i + 3] = dv[i];
            }

            drvResult = new DataRowView[dv.Count + 9];
            // CopyTo from index 3,larger array
            dv.CopyTo(drvResult, 3);
            Assert.Equal(drvResult, drvExpected);

            // ------- CopyTo smaller array, check exception
            drvResult = new DataRowView[dv.Count - 1];

            // CopyTo smaller array, check exception
            Assert.Throws <IndexOutOfRangeException>(() =>
            {
                dv.CopyTo(drvResult, 0);
            });
        }
Esempio n. 8
0
        private DataSet GetNewDataSet()
        {
            DataSet ds1 = new DataSet();

            ds1.Tables.Add(DataProvider.CreateParentDataTable());
            ds1.Tables.Add(DataProvider.CreateChildDataTable());
            ds1.Tables[0].PrimaryKey = new DataColumn[] { ds1.Tables[0].Columns[0] };

            return(ds1);
        }
Esempio n. 9
0
        private DataSet GetDataSet()
        {
            var       ds  = new DataSet();
            DataTable dt1 = DataProvider.CreateParentDataTable();
            DataTable dt2 = DataProvider.CreateChildDataTable();

            ds.Tables.Add(dt1);
            ds.Tables.Add(dt2);
            return(ds);
        }
        public void AddRange_C2()
        {
            var ds = new DataSet();

            ds.Tables.Add(DataProvider.CreateParentDataTable());
            ds.Tables.Add(DataProvider.CreateChildDataTable());
            ds.Tables[1].Constraints.AddRange(GetConstraintArray(ds)); //Cuz foreign key belongs to child table
            Assert.Equal(2, ds.Tables[1].Constraints.Count);
            Assert.Equal(1, ds.Tables[0].Constraints.Count);
        }
        public void Ctor_NameParentColsChildCols()
        {
            DataTable            dtParent = DataProvider.CreateParentDataTable();
            DataTable            dtChild  = DataProvider.CreateChildDataTable();
            ForeignKeyConstraint fc       = new ForeignKeyConstraint("myForeignKey", new DataColumn[] { dtParent.Columns[0] }, new DataColumn[] { dtChild.Columns[0] });

            // Ctor

            // Ctor - name
            Assert.Equal("myForeignKey", fc.ConstraintName);
        }
Esempio n. 12
0
        public void Sort()
        {
            DataRow[] drArrTable;

            //create the source datatable
            DataTable dt = DataProvider.CreateChildDataTable();

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

            dv.Sort    = "ParentId";
            drArrTable = dt.Select("", "ParentId");
            // sort = ParentId
            Assert.Equal(true, CompareSortedRowsByParentAndChildId(dv, drArrTable));

            dv.Sort    = "ChildId";
            drArrTable = dt.Select("", "ChildId");
            // sort = ChildId
            Assert.Equal(true, CompareSortedRowsByParentAndChildId(dv, drArrTable));

            dv.Sort    = "ParentId Desc, ChildId";
            drArrTable = dt.Select("", "ParentId Desc, ChildId");
            // sort = ParentId Desc, ChildId
            Assert.Equal(true, CompareSortedRowsByParentAndChildId(dv, drArrTable));

            dv.Sort    = "ChildId Asc, ParentId";
            drArrTable = dt.Select("", "ChildId Asc, ParentId");
            // sort = ChildId Asc, ParentId
            Assert.Equal(true, CompareSortedRowsByParentAndChildId(dv, drArrTable));

            dv.Sort    = "ChildId Asc, ChildId Desc";
            drArrTable = dt.Select("", "ChildId Asc, ChildId Desc");
            // sort = ChildId Asc, ChildId Desc
            Assert.Equal(true, CompareSortedRowsByParentAndChildId(dv, drArrTable));

            // IndexOutOfRangeException - 1
            Assert.Throws <IndexOutOfRangeException>(() =>
            {
                dv.Sort = "something";
            });

            // IndexOutOfRangeException - 2
            Assert.Throws <IndexOutOfRangeException>(() =>
            {
                dv.Sort = "ColumnId Desc Asc";
            });

            // IndexOutOfRangeException - 3
            Assert.Throws <IndexOutOfRangeException>(() =>
            {
                dv.Sort = "ColumnId blabla";
            });
        }
        public void CanRemove_PartOfRelation()
        {
            var ds = new DataSet();

            ds.Tables.Add(DataProvider.CreateParentDataTable());
            ds.Tables.Add(DataProvider.CreateChildDataTable());

            ds.Relations.Add("rel", ds.Tables[0].Columns["ParentId"], ds.Tables[1].Columns["ParentId"], false);

            Assert.Equal(false, ds.Tables.CanRemove(ds.Tables[0]));
            Assert.Equal(false, ds.Tables.CanRemove(ds.Tables[1]));
        }
Esempio n. 14
0
        public void ctor_DataColumn()
        {
            Exception tmpEx = new Exception();

            var       ds       = new DataSet();
            DataTable dtParent = DataProvider.CreateParentDataTable();

            ds.Tables.Add(dtParent);
            ds.EnforceConstraints = true;

            UniqueConstraint uc = null;

            // DataColumn.Unique - without constraint
            Assert.Equal(false, dtParent.Columns[0].Unique);

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

            // Ctor
            Assert.Equal(false, uc == null);

            // DataColumn.Unique - with constraint
            Assert.Equal(false, dtParent.Columns[0].Unique);

            // Ctor - add exisiting column
            dtParent.Rows.Add(new object[] { 99, "str1", "str2" });
            dtParent.Constraints.Add(uc);
            Assert.Throws <ConstraintException>(() => dtParent.Rows.Add(new object[] { 99, "str1", "str2" }));

            DataTable dtChild = DataProvider.CreateChildDataTable();

            uc = new UniqueConstraint(dtChild.Columns[1]);

            //Column[1] is not unique, will throw exception
            // ArgumentException
            Assert.Throws <ArgumentException>(() => dtChild.Constraints.Add(uc));

            //reset the table
            dtParent = DataProvider.CreateParentDataTable();

            // DataColumn.Unique = true, will add UniqueConstraint
            dtParent.Columns[0].Unique = true;
            Assert.Equal(1, dtParent.Constraints.Count);

            // Check the created UniqueConstraint
            dtParent.Columns[0].Unique = true;
            Assert.Equal(typeof(UniqueConstraint).FullName, dtParent.Constraints[0].GetType().FullName);

            // add UniqueConstarint that don't belong to the table
            Assert.Throws <ArgumentException>(() =>
            {
                dtParent.Constraints.Add(uc);
            });
        }
Esempio n. 15
0
        public void ctor_DclmDclm3()
        {
            Assert.Throws <ArgumentException>(() =>
            {
                var ds = new DataSet();
                ds.Tables.Add(DataProvider.CreateParentDataTable());
                ds.Tables.Add(DataProvider.CreateChildDataTable());
                ds.Tables["Child"].Columns["ParentId"].Expression = "2";

                ForeignKeyConstraint fc = new ForeignKeyConstraint(ds.Tables[0].Columns[0], ds.Tables[1].Columns[0]);
            });
        }
        public void AddRange_C3()
        {
            AssertExtensions.Throws <ArgumentException>(null, () =>
            {
                var ds = new DataSet();
                ds.Tables.Add(DataProvider.CreateParentDataTable());
                ds.Tables.Add(DataProvider.CreateChildDataTable());
                Constraint badConstraint = new UniqueConstraint(ds.Tables[0].Columns[0]);

                ds.Tables[1].Constraints.AddRange(new Constraint[] { badConstraint }); //Cuz foreign key belongs to child table
            });
        }
        public void Generate3()
        {
            DataTable tbl      = DataProvider.CreateChildDataTable();
            DataRow   drParent = tbl.Rows[0];

            drParent.Delete();
            tbl.AcceptChanges();

            Assert.Throws <VersionNotFoundException>(() =>
            {
                object obj = drParent[0, DataRowVersion.Original];
            });
        }
Esempio n. 18
0
        public void Expression_AggregateRelation()
        {
            DataTable parent = DataProvider.CreateParentDataTable();
            DataTable child  = DataProvider.CreateChildDataTable();
            var       ds     = new DataSet();

            ds.Tables.Add(parent);
            ds.Tables.Add(child);

            ds.Relations.Add("Relation1", parent.Columns[0], child.Columns[0], false);

            //Create the computed columns

            DataColumn dcComputedParent = new DataColumn("computedParent", typeof(double));

            parent.Columns.Add(dcComputedParent);
            dcComputedParent.Expression = "sum(child(Relation1)." + child.Columns[1].ColumnName + ")";

            double preCalculatedExpression;

            foreach (DataRow dr in parent.Rows)
            {
                object o = child.Compute("sum(" + child.Columns[1].ColumnName + ")",
                                         parent.Columns[0].ColumnName + "=" + dr[0]);
                if (o == DBNull.Value)
                {
                    Assert.Equal(dr["computedParent"], o);
                }
                else
                {
                    preCalculatedExpression = Convert.ToDouble(o);
                    Assert.Equal(dr["computedParent"], preCalculatedExpression);
                }
            }

            DataColumn dcComputedChild = new DataColumn("computedChild", typeof(double));

            child.Columns.Add(dcComputedChild);
            dcComputedChild.Expression = "Parent." + parent.Columns[0].ColumnName;

            int    index = 0;
            double val;

            foreach (DataRow dr in child.Rows)
            {
                val = Convert.ToDouble(dr.GetParentRow("Relation1")[0]);
                Assert.Equal(dr["computedChild"], val);
                index++;
            }
        }
Esempio n. 19
0
        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 = null;

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

            Assert.False(fc == null);

            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);
        }
Esempio n. 20
0
        public void ctor_NameParentColChildCol()
        {
            DataTable dtParent = DataProvider.CreateParentDataTable();
            DataTable dtChild  = DataProvider.CreateChildDataTable();

            ForeignKeyConstraint fc = null;

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

            // Ctor
            Assert.Equal(false, fc == null);

            // Ctor - name
            Assert.Equal("myForeignKey", fc.ConstraintName);
        }
Esempio n. 21
0
        public void RelatedTable()
        {
            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]);

            // RelatedTable
            Assert.Equal(dtParent, fc.RelatedTable);
        }
        public void Generate()
        {
            DataTable dtParent;

            dtParent = DataProvider.CreateParentDataTable();
            Exception tmpEx = new Exception();

            //------ check ForeignKeyConstraint  ---------
            DataTable dtChild = DataProvider.CreateChildDataTable();
            var       ds      = new DataSet();

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

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

            //update to value which is not exists in Parent table
            // InvalidConstraintException - update child row
            Assert.Throws <InvalidConstraintException>(() =>
            {
                dtChild.Rows[0]["ParentId"] = 99;
            });

            //Add another relation to the same column of the existing relation in child table
            // InvalidConstraintException - Add Relation Child
            Assert.Throws <InvalidConstraintException>(() =>
            {
                ds.Relations.Add(new DataRelation("test", dtParent.Columns[2], dtChild.Columns[0], true));
            });

            //Attempt to clear rows from parent table
            // InvalidConstraintException - RowsCollection.Clear
            Assert.Throws <InvalidConstraintException>(() =>
            {
                dtParent.Rows.Clear();
            });

            //try to run commands on two different datasets
            DataSet ds1 = new DataSet();

            ds1.Tables.Add(dtParent.Copy());

            // InvalidConstraintException - Add relation with two DataSets
            Assert.Throws <InvalidConstraintException>(() =>
            {
                ds.Relations.Add(new DataRelation("myRelation", ds1.Tables[0].Columns[0], dtChild.Columns[0], true));
            });
        }
Esempio n. 23
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());
        }
Esempio n. 24
0
        public void FindRows_ByKeys()
        {
            DataRowView[] dvArr = null;

            //create the source datatable
            DataTable dt = DataProvider.CreateChildDataTable();

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

            // FindRows ,no sort - exception
            Assert.Throws <ArgumentException>(() =>
            {
                dvArr = dv.FindRows(new object[] { "3", "3-String1" });
            });

            dv.Sort = "String1,ChildId";
            // Find = wrong sort, can not find
            Assert.Throws <FormatException>(() =>
            {
                dvArr = dv.FindRows(new object[] { "3", "3-String1" });
            });

            dv.Sort = "ChildId,String1";

            //get expected results
            DataRow[] drExpected = dt.Select("ChildId=3 and String1='3-String1'");

            // FindRows - check count
            dvArr = dv.FindRows(new object[] { "3", "3-String1" });
            Assert.Equal(drExpected.Length, dvArr.Length);

            // FindRows - check data

            //check that result is ok
            bool Succeed = true;

            for (int i = 0; i < dvArr.Length; i++)
            {
                Succeed = (int)dvArr[i]["ChildId"] == (int)drExpected[i]["ChildId"];
                if (!Succeed)
                {
                    break;
                }
            }
            Assert.Equal(true, Succeed);
        }
Esempio n. 25
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);
        }
Esempio n. 26
0
        public void FindRows_ByKey()
        {
            DataRowView[] dvArr = null;

            //create the source datatable
            DataTable dt = DataProvider.CreateChildDataTable();

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

            // FindRows ,no sort - exception
            AssertExtensions.Throws <ArgumentException>(null, () =>
            {
                dvArr = dv.FindRows(3);
            });

            dv.Sort = "String1";
            // Find = wrong sort, can not find
            dvArr = dv.FindRows(3);
            Assert.Equal(0, dvArr.Length);

            dv.Sort = "ChildId";

            //get expected results
            DataRow[] drExpected = dt.Select("ChildId=3");

            // FindRows - check count
            dvArr = dv.FindRows(3);
            Assert.Equal(drExpected.Length, dvArr.Length);

            // FindRows - check data

            //check that result is ok
            bool succeed = true;

            for (int i = 0; i < dvArr.Length; i++)
            {
                succeed = (int)dvArr[i]["ChildId"] == (int)drExpected[i]["ChildId"];
                if (!succeed)
                {
                    break;
                }
            }
            Assert.True(succeed);
        }
Esempio n. 27
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);
        }
Esempio n. 28
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);
        }
Esempio n. 29
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);
        }
Esempio n. 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);
        }