public void GetPageTest() { // Page count start from 1 using (OpenSession()) { IPaginable<NoFoo> pg = new NoFooPaginable(LastOpenedSession, new DetachedNamedQuery("NoFoo.All")); IList<NoFoo> l = pg.GetPage(3, 2); Assert.AreEqual(3, l.Count); Assert.AreEqual("N3", l[0].Name); Assert.AreEqual("N4", l[1].Name); Assert.AreEqual("N5", l[2].Name); l = pg.GetPage(2, 1); Assert.AreEqual(2, l.Count); Assert.AreEqual("N0", l[0].Name); Assert.AreEqual("N1", l[1].Name); // If pageSize=10 the page 2 have 5 elements l = pg.GetPage(10, 2); Assert.AreEqual(5, l.Count); } // Add an element from other session Foo fAdded; using (ISession s = OpenSession()) { fAdded = new Foo("NZ", "DZ"); s.Save(fAdded); s.Flush(); } // Reload the same page and have the new element using (OpenSession()) { IPaginable<NoFoo> pg = new NoFooPaginable(LastOpenedSession, new DetachedNamedQuery("NoFoo.All")); IList<NoFoo> l = pg.GetPage(10, 2); // If pageSize=10 the page 2 have 6 elements Assert.AreEqual(6, l.Count); } // clean up using (ISession s = OpenSession()) { s.Delete(fAdded); s.Flush(); } }
public void ListAllTest() { using (OpenSession()) { IPaginable<NoFoo> pg = new NoFooPaginable(LastOpenedSession, new DetachedNamedQuery("NoFoo.All")); IList<NoFoo> l = pg.ListAll(); Assert.AreEqual(15, l.Count); } using (OpenSession()) { IPaginable<Foo> pf = new PaginableQuery<Foo>(LastOpenedSession, new DetachedQuery("from Foo")); IList<Foo> l = pf.ListAll(); Assert.AreEqual(15, l.Count); } }