示例#1
0
        public void SortDescriptionTest()
        {
            IBindingListView view = new DataView(_table);

            ListSortDescriptionCollection col = view.SortDescriptions;

            ((DataView)view).Sort = "";
            col = view.SortDescriptions;
            Assert.Equal(0, col.Count);

            ((DataView)view).Sort = null;
            col = view.SortDescriptions;
            Assert.Equal(0, col.Count);

            ((DataView)view).Sort = "col1 DESC, col2 ASC";
            col = view.SortDescriptions;
            Assert.Equal(2, col.Count);
            Assert.Equal("col1", col[0].PropertyDescriptor.Name);
            Assert.Equal(ListSortDirection.Descending, col[0].SortDirection);
            Assert.Equal("col2", col[1].PropertyDescriptor.Name);
            Assert.Equal(ListSortDirection.Ascending, col[1].SortDirection);

            //ApplySort Test
            IBindingListView view1 = new DataView(_table);

            Assert.False(view.Equals(view1));
            view1.ApplySort(col);
            Assert.Equal("[col1] DESC,[col2]", ((DataView)view1).Sort);
            for (int i = 0; i < view.Count; ++i)
            {
                Assert.Equal(((DataView)view)[i].Row, ((DataView)view1)[i].Row);
            }
        }
示例#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));
        }
示例#3
0
        [Test] public void CreateChildView_ByName()
        {
            //create a dataset with two tables, with a DataRelation between them
            DataTable dtParent = DataProvider.CreateParentDataTable();
            DataTable dtChild  = DataProvider.CreateChildDataTable();
            DataSet   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("ParentChild");
            DataView dvTmp2 = dvParent[3].CreateChildView("ParentChild");

            // ChildView != null
            Assert.AreEqual(true, dvTmp1 != null, "DRV14");

            // Child view table = ChildTable
            Assert.AreEqual(dtChild, dvTmp1.Table, "DRV15");

            // ChildView1.Table = ChildView2.Table
            Assert.AreEqual(dvTmp2.Table, dvTmp1.Table, "DRV16");

            //the child dataview are different
            // Child DataViews different
            Assert.AreEqual(false, dvTmp1.Equals(dvTmp2), "DRV17");
        }
        public void run()
        {
            Exception exp = null;

            //create a dataset with two tables, with a DataRelation between them
            DataTable dtParent = GHTUtils.DataProvider.CreateParentDataTable();
            DataTable dtChild  = GHTUtils.DataProvider.CreateChildDataTable();
            DataSet   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);

            try
            {
                BeginCase("ChildView != null");
                Compare(dvTmp1 != null, true);
            }
            catch (Exception ex)     { exp = ex; }
            finally { EndCase(exp); exp = null; }

            try
            {
                BeginCase("Child view table = ChildTable");
                Compare(dvTmp1.Table, dtChild);
            }
            catch (Exception ex)     { exp = ex; }
            finally { EndCase(exp); exp = null; }

            try
            {
                BeginCase("ChildView1.Table = ChildView2.Table");
                Compare(dvTmp1.Table, dvTmp2.Table);
            }
            catch (Exception ex)     { exp = ex; }
            finally { EndCase(exp); exp = null; }


            //the child dataview are different
            try
            {
                BeginCase("Child DataViews different ");
                Compare(dvTmp1.Equals(dvTmp2), false);
            }
            catch (Exception ex)     { exp = ex; }
            finally { EndCase(exp); exp = null; }
        }
示例#5
0
        public void TestEquals_SameTableDiffViewProp()
        {
            DataTable table = new DataTable("table");

            table.Columns.Add("col1", typeof(int));
            table.Columns.Add("col2", typeof(int));
            for (int i = 0; i < 5; ++i)
            {
                table.Rows.Add(new object[] { i, 100 + i });
            }

            DataView view1 = new DataView(table);
            DataView view2 = new DataView(table);

            object obj2 = (object)view2;

            Assert.IsFalse(view1.Equals(obj2), "#1");

            Assert.IsTrue(view1.Equals(view1), "#2");
            Assert.IsTrue(view2.Equals(view1), "#3");

            view1.Sort = "col1 ASC";
            Assert.IsFalse(view1.Equals(view2), "#4");
            view2.Sort = "col1 ASC";
            Assert.IsTrue(view1.Equals(view2), "#5");

            view1.RowFilter = "col1 > 100";
            Assert.IsFalse(view1.Equals(view2), "#6");
            view1.RowFilter = "";
            Assert.IsTrue(view1.Equals(view2), "#7");

            view1.RowStateFilter = DataViewRowState.Added;
            Assert.IsFalse(view1.Equals(view2), "#8");
            view1.RowStateFilter = DataViewRowState.CurrentRows;
            Assert.IsTrue(view1.Equals(view2), "#9");

            view1.AllowDelete = !view2.AllowDelete;
            Assert.IsFalse(view1.Equals(view2), "#10");
            view1.AllowDelete = view2.AllowDelete;
            Assert.IsTrue(view1.Equals(view2), "#11");

            view1.AllowEdit = !view2.AllowEdit;
            Assert.IsFalse(view1.Equals(view2), "#12");
            view1.AllowEdit = view2.AllowEdit;
            Assert.IsTrue(view1.Equals(view2), "#13");

            view1.AllowNew = !view2.AllowNew;
            Assert.IsFalse(view1.Equals(view2), "#14");
            view1.AllowNew = view2.AllowNew;
            Assert.IsTrue(view1.Equals(view2), "#15");

            //ApplyDefaultSort doesnet affect the comparision
            view1.ApplyDefaultSort = !view2.ApplyDefaultSort;
            Assert.IsTrue(view1.Equals(view2), "#16");

            DataTable table2 = table.Copy();

            view1.Table = table2;
            Assert.IsFalse(view1.Equals(view2), "#17");

            view1.Table = table;
            //well.. sort is set to null when Table is assigned..
            view1.Sort = view2.Sort;
            Assert.IsTrue(view1.Equals(view2), "#18");
        }
        public void SortDescriptionTest()
        {
            IBindingListView view = new DataView(_table);

            ListSortDescriptionCollection col = view.SortDescriptions;

            ((DataView)view).Sort = "";
            col = view.SortDescriptions;
            Assert.Equal(0, col.Count);

            ((DataView)view).Sort = null;
            col = view.SortDescriptions;
            Assert.Equal(0, col.Count);

            ((DataView)view).Sort = "col1 DESC, col2 ASC";
            col = view.SortDescriptions;
            Assert.Equal(2, col.Count);
            Assert.Equal("col1", col[0].PropertyDescriptor.Name);
            Assert.Equal(ListSortDirection.Descending, col[0].SortDirection);
            Assert.Equal("col2", col[1].PropertyDescriptor.Name);
            Assert.Equal(ListSortDirection.Ascending, col[1].SortDirection);

            //ApplySort Test
            IBindingListView view1 = new DataView(_table);

            Assert.False(view.Equals(view1));
            view1.ApplySort(col);
            Assert.Equal("[col1] DESC,[col2]", ((DataView)view1).Sort);
            for (int i = 0; i < view.Count; ++i)
                Assert.Equal(((DataView)view)[i].Row, ((DataView)view1)[i].Row);
        }
示例#7
-1
        public void TestEquals_SameTableDiffViewProp()
        {
            DataTable table = new DataTable("table");
            table.Columns.Add("col1", typeof(int));
            table.Columns.Add("col2", typeof(int));
            for (int i = 0; i < 5; ++i)
                table.Rows.Add(new object[] { i, 100 + i });

            DataView view1 = new DataView(table);
            DataView view2 = new DataView(table);

            object obj2 = view2;
            Assert.False(view1.Equals(obj2));

            Assert.True(view1.Equals(view1));
            Assert.True(view2.Equals(view1));

            view1.Sort = "col1 ASC";
            Assert.False(view1.Equals(view2));
            view2.Sort = "col1 ASC";
            Assert.True(view1.Equals(view2));

            view1.RowFilter = "col1 > 100";
            Assert.False(view1.Equals(view2));
            view1.RowFilter = "";
            Assert.True(view1.Equals(view2));

            view1.RowStateFilter = DataViewRowState.Added;
            Assert.False(view1.Equals(view2));
            view1.RowStateFilter = DataViewRowState.CurrentRows;
            Assert.True(view1.Equals(view2));

            view1.AllowDelete = !view2.AllowDelete;
            Assert.False(view1.Equals(view2));
            view1.AllowDelete = view2.AllowDelete;
            Assert.True(view1.Equals(view2));

            view1.AllowEdit = !view2.AllowEdit;
            Assert.False(view1.Equals(view2));
            view1.AllowEdit = view2.AllowEdit;
            Assert.True(view1.Equals(view2));

            view1.AllowNew = !view2.AllowNew;
            Assert.False(view1.Equals(view2));
            view1.AllowNew = view2.AllowNew;
            Assert.True(view1.Equals(view2));

            //ApplyDefaultSort doesnet affect the comparision
            view1.ApplyDefaultSort = !view2.ApplyDefaultSort;
            Assert.True(view1.Equals(view2));

            DataTable table2 = table.Copy();
            view1.Table = table2;
            Assert.False(view1.Equals(view2));

            view1.Table = table;
            //well.. sort is set to null when Table is assigned..
            view1.Sort = view2.Sort;
            Assert.True(view1.Equals(view2));
        }