public void ShouldNotTransformAUnsafeHQL() { var dq = new DetachedQuery("select f.Name from Foo f"); using (ISession s = SessionFactory.OpenSession()) { IPaginable <Foo> fp = new PaginableRowsCounterQuery <Foo>(s, dq); Assert.Throws <HibernateException>(() => ((IRowsCounter)fp).GetRowsCount(s), "Should not transform a query with a select clause."); } }
public void PaginableRowsCount() { DetachedQuery dq = new DetachedQuery("from Foo f where f.Name like :p1"); dq.SetString("p1", "N_"); using (ISession s = OpenSession()) { IPaginable <Foo> fp = new PaginableRowsCounterQuery <Foo>(LastOpenedSession, dq); IList <Foo> l = fp.GetPage(5, 1); Assert.AreEqual(5, l.Count); Assert.AreEqual(10, ((IRowsCounter)fp).GetRowsCount(s)); } }
public void ShouldWorkAsPaginatorAndAsRowCounter() { var dq = new DetachedQuery("from Foo f where f.Name like :p1"); dq.SetString("p1", "N_"); using (ISession s = SessionFactory.OpenSession()) { IPaginable <Foo> fp = new PaginableRowsCounterQuery <Foo>(s, dq); IList <Foo> l = fp.GetPage(5, 1); Assert.That(l.Count, Is.EqualTo(5)); Assert.That(((IRowsCounter)fp).GetRowsCount(s), Is.EqualTo(10)); } }
public void HasPages() { string hql = "from Foo where Name = 'N1'"; PaginableRowsCounterQuery<Foo> pag = new PaginableRowsCounterQuery<Foo>(LastOpenedSession, new DetachedQuery(hql)); Paginator<Foo> ptor = new Paginator<Foo>(3, pag); Assert.AreEqual(true, ptor.HasPages); Assert.AreEqual(1, ptor.RowsCount); Assert.AreEqual(false, ptor.HasPrevious); Assert.AreEqual(false, ptor.HasNext); IList<Foo> lpage = ptor.GetPage(1); Assert.AreEqual(1, lpage.Count); }
public void HasNotPages() { string hql = "from Foo where Name = '-N123'"; PaginableRowsCounterQuery<Foo> pag = new PaginableRowsCounterQuery<Foo>(LastOpenedSession, new DetachedQuery(hql)); Paginator<Foo> ptor = new Paginator<Foo>(3, pag); Assert.AreEqual(false, ptor.HasPages); Assert.AreEqual(false, ptor.HasPrevious); Assert.AreEqual(false, ptor.HasNext); Assert.AreEqual(0, ptor.RowsCount.Value); //throw ArgumentOutOfRangeException IList<Foo> lpage = ptor.GetPage(1); }
public void HasNotPages() { string hql = "from Foo where Name = '-N123'"; PaginableRowsCounterQuery <Foo> pag = new PaginableRowsCounterQuery <Foo>(LastOpenedSession, new DetachedQuery(hql)); Paginator <Foo> ptor = new Paginator <Foo>(3, pag); Assert.AreEqual(false, ptor.HasPages); Assert.AreEqual(false, ptor.HasPrevious); Assert.AreEqual(false, ptor.HasNext); Assert.AreEqual(0, ptor.RowsCount.Value); //throw ArgumentOutOfRangeException IList <Foo> lpage = ptor.GetPage(1); }
public void HasPages() { string hql = "from Foo where Name = 'N1'"; PaginableRowsCounterQuery <Foo> pag = new PaginableRowsCounterQuery <Foo>(LastOpenedSession, new DetachedQuery(hql)); Paginator <Foo> ptor = new Paginator <Foo>(3, pag); Assert.AreEqual(true, ptor.HasPages); Assert.AreEqual(1, ptor.RowsCount); Assert.AreEqual(false, ptor.HasPrevious); Assert.AreEqual(false, ptor.HasNext); IList <Foo> lpage = ptor.GetPage(1); Assert.AreEqual(1, lpage.Count); }
public void HasPages() { const string hql = "from Foo where Name = 'N1'"; using (ISession session = SessionFactory.OpenSession()) { var pag = new PaginableRowsCounterQuery <Foo>(session, new DetachedQuery(hql)); var ptor = new Paginator <Foo>(3, pag); Assert.AreEqual(true, ptor.HasPages); Assert.AreEqual(1, ptor.RowsCount); Assert.AreEqual(false, ptor.HasPrevious); Assert.AreEqual(false, ptor.HasNext); IList <Foo> lpage = ptor.GetPage(1); Assert.AreEqual(1, lpage.Count); } }
public void HasNotPages() { const string hql = "from Foo where Name = '-N123'"; using (ISession session = SessionFactory.OpenSession()) { var pag = new PaginableRowsCounterQuery <Foo>(session, new DetachedQuery(hql)); var ptor = new Paginator <Foo>(3, pag); Assert.AreEqual(false, ptor.HasPages); Assert.AreEqual(false, ptor.HasPrevious); Assert.AreEqual(false, ptor.HasNext); Assert.AreEqual(0, ptor.RowsCount.Value); //throw ArgumentOutOfRangeException Assert.Throws <ArgumentOutOfRangeException>(() => ptor.GetPage(1)); } }
public void WithSelfCounter() { DetachedQuery dq = new DetachedQuery("from Foo f where f.Name like :p1"); dq.SetString("p1", "%1_"); IPaginable <Foo> fp = new PaginableRowsCounterQuery <Foo>(LastOpenedSession, dq); Paginator <Foo> ptor = new Paginator <Foo>(2, fp); Assert.IsTrue(ptor.AutoCalcPages); Assert.AreEqual(3, ptor.LastPageNumber); // check page 2 IList <Foo> lpage = ptor.GetPage(2); Assert.AreEqual(2, lpage.Count); Assert.AreEqual(2, ptor.CurrentPageNumber); Assert.AreEqual("N12", lpage[0].Name); Assert.AreEqual("N13", lpage[1].Name); }
public void WithSelfCounter() { DetachedQuery dq = new DetachedQuery("from Foo f where f.Name like :p1"); dq.SetString("p1", "%1_"); IPaginable<Foo> fp = new PaginableRowsCounterQuery<Foo>(LastOpenedSession, dq); Paginator<Foo> ptor = new Paginator<Foo>(2, fp); Assert.IsTrue(ptor.AutoCalcPages); Assert.AreEqual(3, ptor.LastPageNumber); // check page 2 IList<Foo> lpage = ptor.GetPage(2); Assert.AreEqual(2, lpage.Count); Assert.AreEqual(2, ptor.CurrentPageNumber); Assert.AreEqual("N12", lpage[0].Name); Assert.AreEqual("N13", lpage[1].Name); }
public void PaginableRowsCount() { DetachedQuery dq = new DetachedQuery("from Foo f where f.Name like :p1"); dq.SetString("p1", "N_"); using (ISession s = OpenSession()) { IPaginable<Foo> fp = new PaginableRowsCounterQuery<Foo>(LastOpenedSession, dq); IList<Foo> l = fp.GetPage(5, 1); Assert.AreEqual(5, l.Count); Assert.AreEqual(10, ((IRowsCounter) fp).GetRowsCount(s)); } }