public void InitializePager () { DataGridPoker p = new DataGridPoker (); PagedDataSource paged = new PagedDataSource (); DataTable table = new DataTable (); DataGridItem item = new DataGridItem (-1, -1, ListItemType.Pager); ArrayList columns; LinkButton next; LinkButton prev; table.Columns.Add (new DataColumn ("one", typeof (string))); table.Columns.Add (new DataColumn ("two", typeof (string))); table.Columns.Add (new DataColumn ("three", typeof (string))); for (int i = 0; i < 25; i++) table.Rows.Add (new object [] { "1", "2", "3" }); paged.DataSource = new DataView (table); columns = p.CreateColumns (paged, true); p.InitPager (item, columns.Count, paged); // // No where to go // Assert.AreEqual (item.Controls.Count, 1, "A1"); Assert.AreEqual (item.Controls [0].GetType (), typeof (TableCell), "A2"); Assert.AreEqual (item.Controls [0].Controls.Count, 3, "A3"); Assert.AreEqual (item.Controls [0].Controls [0].GetType (), typeof (Label), "A4"); Assert.AreEqual (item.Controls [0].Controls [1].GetType (), typeof (LiteralControl), "A5"); Assert.AreEqual (item.Controls [0].Controls [2].GetType (), typeof (Label), "A6"); Assert.AreEqual (((Label) item.Controls [0].Controls [0]).Text, "<", "A7"); Assert.AreEqual (((LiteralControl) item.Controls [0].Controls [1]).Text, " ", "A7"); Assert.AreEqual (((Label) item.Controls [0].Controls [2]).Text, ">", "A8"); // // Next // item = new DataGridItem (-1, -1, ListItemType.Pager); paged.PageSize = 5; paged.VirtualCount = 25; paged.AllowPaging = true; p.InitPager (item, columns.Count, paged); Assert.AreEqual (item.Controls.Count, 1, "A9"); Assert.AreEqual (item.Controls [0].GetType (), typeof (TableCell), "A10"); Assert.AreEqual (item.Controls [0].Controls.Count, 3, "A11"); Assert.AreEqual (item.Controls [0].Controls [0].GetType (), typeof (Label), "A12"); Assert.AreEqual (item.Controls [0].Controls [1].GetType (), typeof (LiteralControl), "A13"); Assert.AreEqual (((Label) item.Controls [0].Controls [0]).Text, "<", "A14"); Assert.AreEqual (((LiteralControl) item.Controls [0].Controls [1]).Text, " ", "A16"); next = (LinkButton) item.Controls [0].Controls [2]; Assert.AreEqual (next.Text, ">", "A17"); Assert.AreEqual (next.CommandName, "Page", "A18"); Assert.AreEqual (next.CommandArgument, "Next", "A19"); // // Both // item = new DataGridItem (-1, -1, ListItemType.Pager); paged.PageSize = 5; paged.VirtualCount = 25; paged.AllowPaging = true; paged.CurrentPageIndex = 2; p.InitPager (item, columns.Count, paged); Assert.AreEqual (item.Controls.Count, 1, "A20"); Assert.AreEqual (item.Controls [0].GetType (), typeof (TableCell), "A21"); Assert.AreEqual (item.Controls [0].Controls.Count, 3, "A22"); Assert.AreEqual (item.Controls [0].Controls [1].GetType (), typeof (LiteralControl), "A23"); Assert.AreEqual (((LiteralControl) item.Controls [0].Controls [1]).Text, " ", "A24"); // This is failing with an invalidcast right now. It's something related to // the pager thinking that it's on the last page and rendering a label instead next = (LinkButton) item.Controls [0].Controls [2]; Assert.AreEqual (next.Text, ">", "A25"); Assert.AreEqual (next.CommandName, "Page", "A26"); Assert.AreEqual (next.CommandArgument, "Next", "A27"); prev = (LinkButton) item.Controls [0].Controls [0]; Assert.AreEqual (prev.Text, "<", "A28"); Assert.AreEqual (prev.CommandName, "Page", "A29"); Assert.AreEqual (prev.CommandArgument, "Prev", "A30"); // // Back only // item = new DataGridItem (-1, -1, ListItemType.Pager); paged.PageSize = 5; paged.VirtualCount = 25; paged.AllowPaging = true; paged.CurrentPageIndex = 4; p.InitPager (item, columns.Count, paged); Assert.AreEqual (item.Controls.Count, 1, "A31"); Assert.AreEqual (item.Controls [0].GetType (), typeof (TableCell), "A32"); Assert.AreEqual (item.Controls [0].Controls.Count, 3, "A33"); Assert.AreEqual (item.Controls [0].Controls [1].GetType (), typeof (LiteralControl), "A34"); Assert.AreEqual (item.Controls [0].Controls [2].GetType (), typeof (Label), "A35"); Assert.AreEqual (((LiteralControl) item.Controls [0].Controls [1]).Text, " ", "A36"); Assert.AreEqual (((Label) item.Controls [0].Controls [2]).Text, ">", "A37"); prev = (LinkButton) item.Controls [0].Controls [0]; Assert.AreEqual (prev.Text, "<", "A38"); Assert.AreEqual (prev.CommandName, "Page", "A39"); Assert.AreEqual (prev.CommandArgument, "Prev", "A40"); }