public void TestExecuteQueryForPaginatedList() { // Get List of all 5 PaginatedList list = sqlMap.QueryForPaginatedList("GetAllAccountsViaResultMap", null, 2); // Test initial state (page 0) Assert.IsFalse(list.IsPreviousPageAvailable); Assert.IsTrue(list.IsNextPageAvailable); AssertAccount1((Account)list[0]); Assert.AreEqual(2, list.Count); Assert.AreEqual(1, ((Account)list[0]).Id); Assert.AreEqual(2, ((Account)list[1]).Id); // Test illegal previous page (no effect, state should be same) list.PreviousPage(); Assert.IsFalse(list.IsPreviousPageAvailable); Assert.IsTrue(list.IsNextPageAvailable); AssertAccount1((Account)list[0]); Assert.AreEqual(2, list.Count); Assert.AreEqual(1, ((Account)list[0]).Id); Assert.AreEqual(2, ((Account)list[1]).Id); // Test next (page 1) list.NextPage(); Assert.IsTrue(list.IsPreviousPageAvailable); Assert.IsTrue(list.IsNextPageAvailable); Assert.AreEqual(2, list.Count); Assert.AreEqual(3, ((Account)list[0]).Id); Assert.AreEqual(4, ((Account)list[1]).Id); // Test next (page 2 -last) list.NextPage(); Assert.IsTrue(list.IsPreviousPageAvailable); Assert.IsFalse(list.IsNextPageAvailable); Assert.AreEqual(1, list.Count); Assert.AreEqual(5, ((Account)list[0]).Id); // Test previous (page 1) list.PreviousPage(); Assert.IsTrue(list.IsPreviousPageAvailable); Assert.IsTrue(list.IsNextPageAvailable); Assert.AreEqual(2, list.Count); Assert.AreEqual(3, ((Account)list[0]).Id); Assert.AreEqual(4, ((Account)list[1]).Id); // Test previous (page 0 -first) list.PreviousPage(); Assert.IsFalse(list.IsPreviousPageAvailable); Assert.IsTrue(list.IsNextPageAvailable); AssertAccount1((Account)list[0]); Assert.AreEqual(2, list.Count); Assert.AreEqual(1, ((Account)list[0]).Id); Assert.AreEqual(2, ((Account)list[1]).Id); // Test goto (page 0) list.GotoPage(0); Assert.IsFalse(list.IsPreviousPageAvailable); Assert.IsTrue(list.IsNextPageAvailable); Assert.AreEqual(2, list.Count); Assert.AreEqual(1, ((Account)list[0]).Id); Assert.AreEqual(2, ((Account)list[1]).Id); // Test goto (page 1) list.GotoPage(1); Assert.IsTrue(list.IsPreviousPageAvailable); Assert.IsTrue(list.IsNextPageAvailable); Assert.AreEqual(2, list.Count); Assert.AreEqual(3, ((Account)list[0]).Id); Assert.AreEqual(4, ((Account)list[1]).Id); // Test goto (page 2) list.GotoPage(2); Assert.IsTrue(list.IsPreviousPageAvailable); Assert.IsFalse(list.IsNextPageAvailable); Assert.AreEqual(1, list.Count); Assert.AreEqual(5, ((Account)list[0]).Id); // Test illegal goto (page 0) list.GotoPage(3); Assert.IsTrue(list.IsPreviousPageAvailable); Assert.IsFalse(list.IsNextPageAvailable); Assert.AreEqual(0, list.Count); list = sqlMap.QueryForPaginatedList("GetNoAccountsViaResultMap", null, 2); // Test empty list Assert.IsFalse(list.IsPreviousPageAvailable); Assert.IsFalse(list.IsNextPageAvailable); Assert.AreEqual(0, list.Count); // Test next list.NextPage(); Assert.IsFalse(list.IsPreviousPageAvailable); Assert.IsFalse(list.IsNextPageAvailable); Assert.AreEqual(0, list.Count); // Test previous list.PreviousPage(); Assert.IsFalse(list.IsPreviousPageAvailable); Assert.IsFalse(list.IsNextPageAvailable); Assert.AreEqual(0, list.Count); // Test previous list.GotoPage(0); Assert.IsFalse(list.IsPreviousPageAvailable); Assert.IsFalse(list.IsNextPageAvailable); Assert.AreEqual(0, list.Count); list = sqlMap.QueryForPaginatedList("GetFewAccountsViaResultMap", null, 2); Assert.IsFalse(list.IsPreviousPageAvailable); Assert.IsFalse(list.IsNextPageAvailable); Assert.AreEqual(1, list.Count); // Test next list.NextPage(); Assert.IsFalse(list.IsPreviousPageAvailable); Assert.IsFalse(list.IsNextPageAvailable); Assert.AreEqual(1, list.Count); // Test previous list.PreviousPage(); Assert.IsFalse(list.IsPreviousPageAvailable); Assert.IsFalse(list.IsNextPageAvailable); Assert.AreEqual(1, list.Count); // Test previous list.GotoPage(0); Assert.IsFalse(list.IsPreviousPageAvailable); Assert.IsFalse(list.IsNextPageAvailable); Assert.AreEqual(1, list.Count); // Test Even - Two Pages try { InitScript(sqlMap.DataSource, ScriptDirectory + "more-account-records.sql"); } catch (Exception e) { Console.WriteLine(e.Message); } list = sqlMap.QueryForPaginatedList("GetAllAccountsViaResultMap", null, 5); Assert.AreEqual(5, list.Count); list.NextPage(); Assert.AreEqual(5, list.Count); bool b = list.IsPreviousPageAvailable; list.PreviousPage(); Assert.AreEqual(5, list.Count); }