예제 #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);
            }
        }
        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);
        }