Пример #1
0
        public void TestGetPageArgumentOutOfRangeOverflow()
        {
            var query       = session.CreateSQLQuery("SELECT Id FROM PeptideSpectrumMatch");
            var queryReader = new NHibernateQueryReader(query, 90)
            {
                PageSize = 30
            };

            queryReader.GetPage(4);
        }
Пример #2
0
        public void TestNhibernateHqlQuery()
        {
            var query    = session.CreateQuery("SELECT psm FROM PeptideSpectrumMatch psm ORDER BY psm.Spectrum, psm.Id");
            int rowCount = 90;

            // sanity check
            Assert.AreEqual(rowCount, session.Query <PeptideSpectrumMatch>().Count());

            NHibernateQueryReader queryReader;
            QueryPage             queryPage;
            string rowArray;

            // test at default page size of 1000 (all 90 psms on one page)
            queryReader = new NHibernateQueryReader(query, rowCount);
            Assert.AreEqual(rowCount, queryReader.RowCount);
            Assert.AreEqual(1, queryReader.PageCount);
            Assert.AreEqual(1000, queryReader.PageSize);
            queryPage = queryReader.GetPage(0);
            Assert.AreEqual(0, queryPage.PageIndex);
            Assert.AreEqual(rowCount, queryPage.Rows.Count);
            Assert.IsInstanceOfType(queryPage.Rows[0], typeof(PeptideSpectrumMatch));

            // test at page size of 30 (3 pages)
            queryReader.PageSize = 30;
            Assert.AreEqual(rowCount, queryReader.RowCount);
            Assert.AreEqual(3, queryReader.PageCount);
            Assert.AreEqual(30, queryReader.PageSize);
            queryPage = queryReader.GetPage(0);
            Assert.AreEqual(0, queryPage.PageIndex);
            Assert.AreEqual(30, queryPage.Rows.Count);
            rowArray = String.Join(" ", queryPage.Rows.Cast <PeptideSpectrumMatch>().Select(o => o.Id.ToString()).ToArray());
            Assert.IsTrue(rowArray.StartsWith("1 2 3 46 47 48 4 5 6 49 50 51"));
            queryPage = queryReader.GetPage(1);
            Assert.AreEqual(1, queryPage.PageIndex);
            Assert.AreEqual(30, queryPage.Rows.Count);
            rowArray = String.Join(" ", queryPage.Rows.Cast <PeptideSpectrumMatch>().Select(o => o.Id.ToString()).ToArray());
            Assert.IsTrue(rowArray.StartsWith("16 17 18 61 62 63 19 20 21 64 65 66"));
            queryPage = queryReader.GetPage(2);
            Assert.AreEqual(2, queryPage.PageIndex);
            Assert.AreEqual(30, queryPage.Rows.Count);
            rowArray = String.Join(" ", queryPage.Rows.Cast <PeptideSpectrumMatch>().Select(o => o.Id.ToString()).ToArray());
            Assert.IsTrue(rowArray.StartsWith("31 32 33 76 77 78 34 35 36 79 80 81"));

            // test at page size of 40 (3 pages)
            queryReader.PageSize = 40;
            Assert.AreEqual(rowCount, queryReader.RowCount);
            Assert.AreEqual(3, queryReader.PageCount);
            Assert.AreEqual(40, queryReader.PageSize);
            queryPage = queryReader.GetPage(0);
            Assert.AreEqual(0, queryPage.PageIndex);
            Assert.AreEqual(40, queryPage.Rows.Count);
            rowArray = String.Join(" ", queryPage.Rows.Cast <PeptideSpectrumMatch>().Select(o => o.Id.ToString()).ToArray());
            Assert.IsTrue(rowArray.StartsWith("1 2 3 46 47 48 4 5 6 49 50 51"));
            queryPage = queryReader.GetPage(1);
            Assert.AreEqual(1, queryPage.PageIndex);
            Assert.AreEqual(40, queryPage.Rows.Count);
            rowArray = String.Join(" ", queryPage.Rows.Cast <PeptideSpectrumMatch>().Select(o => o.Id.ToString()).ToArray());
            Assert.IsTrue(rowArray.StartsWith("65 66 22 23 24 67 68 69 25 26 27 70"));
            queryPage = queryReader.GetPage(2);
            Assert.AreEqual(2, queryPage.PageIndex);
            Assert.AreEqual(10, queryPage.Rows.Count);
            rowArray = String.Join(" ", queryPage.Rows.Cast <PeptideSpectrumMatch>().Select(o => o.Id.ToString()).ToArray());
            Assert.IsTrue(rowArray.StartsWith("42 85 86 87 43 44 45 88 89 90"));

            // test getting page by row index
            queryPage = queryReader.GetPageForRow(0);
            Assert.AreEqual(0, queryPage.PageIndex);
            queryPage = queryReader.GetPageForRow(39);
            Assert.AreEqual(0, queryPage.PageIndex);
            queryPage = queryReader.GetPageForRow(40);
            Assert.AreEqual(1, queryPage.PageIndex);
            queryPage = queryReader.GetPageForRow(79);
            Assert.AreEqual(1, queryPage.PageIndex);
            queryPage = queryReader.GetPageForRow(80);
            Assert.AreEqual(2, queryPage.PageIndex);
            queryPage = queryReader.GetPageForRow(89);
            Assert.AreEqual(2, queryPage.PageIndex);

            // test returning multiple objects
            query       = session.CreateQuery("SELECT psm, psm.Spectrum FROM PeptideSpectrumMatch psm ORDER BY psm.Spectrum, psm.Id");
            queryReader = new NHibernateQueryReader(query, rowCount);
            queryPage   = queryReader.GetPage(0);
            Assert.IsInstanceOfType(queryPage.Rows[0], typeof(object[]));
            Assert.IsInstanceOfType((queryPage.Rows[0] as object[])[0], typeof(PeptideSpectrumMatch));
            Assert.IsInstanceOfType((queryPage.Rows[0] as object[])[1], typeof(Spectrum));
        }
Пример #3
0
        public void TestNhibernateHqlQuery ()
        {
            var query = session.CreateQuery("SELECT psm FROM PeptideSpectrumMatch psm ORDER BY psm.Spectrum, psm.Id");
            int rowCount = 90;

            // sanity check
            Assert.AreEqual(rowCount, session.Query<PeptideSpectrumMatch>().Count());

            NHibernateQueryReader queryReader;
            QueryPage queryPage;
            string rowArray;

            // test at default page size of 1000 (all 90 psms on one page)
            queryReader = new NHibernateQueryReader(query, rowCount);
            Assert.AreEqual(rowCount, queryReader.RowCount);
            Assert.AreEqual(1, queryReader.PageCount);
            Assert.AreEqual(1000, queryReader.PageSize);
            queryPage = queryReader.GetPage(0);
            Assert.AreEqual(0, queryPage.PageIndex);
            Assert.AreEqual(rowCount, queryPage.Rows.Count);
            Assert.IsInstanceOfType(queryPage.Rows[0], typeof(PeptideSpectrumMatch));

            // test at page size of 30 (3 pages)
            queryReader.PageSize = 30;
            Assert.AreEqual(rowCount, queryReader.RowCount);
            Assert.AreEqual(3, queryReader.PageCount);
            Assert.AreEqual(30, queryReader.PageSize);
            queryPage = queryReader.GetPage(0);
            Assert.AreEqual(0, queryPage.PageIndex);
            Assert.AreEqual(30, queryPage.Rows.Count);
            rowArray = String.Join(" ", queryPage.Rows.Cast<PeptideSpectrumMatch>().Select(o => o.Id.ToString()).ToArray());
            Assert.IsTrue(rowArray.StartsWith("1 2 3 46 47 48 4 5 6 49 50 51"));
            queryPage = queryReader.GetPage(1);
            Assert.AreEqual(1, queryPage.PageIndex);
            Assert.AreEqual(30, queryPage.Rows.Count);
            rowArray = String.Join(" ", queryPage.Rows.Cast<PeptideSpectrumMatch>().Select(o => o.Id.ToString()).ToArray());
            Assert.IsTrue(rowArray.StartsWith("16 17 18 61 62 63 19 20 21 64 65 66"));
            queryPage = queryReader.GetPage(2);
            Assert.AreEqual(2, queryPage.PageIndex);
            Assert.AreEqual(30, queryPage.Rows.Count);
            rowArray = String.Join(" ", queryPage.Rows.Cast<PeptideSpectrumMatch>().Select(o => o.Id.ToString()).ToArray());
            Assert.IsTrue(rowArray.StartsWith("31 32 33 76 77 78 34 35 36 79 80 81"));

            // test at page size of 40 (3 pages)
            queryReader.PageSize = 40;
            Assert.AreEqual(rowCount, queryReader.RowCount);
            Assert.AreEqual(3, queryReader.PageCount);
            Assert.AreEqual(40, queryReader.PageSize);
            queryPage = queryReader.GetPage(0);
            Assert.AreEqual(0, queryPage.PageIndex);
            Assert.AreEqual(40, queryPage.Rows.Count);
            rowArray = String.Join(" ", queryPage.Rows.Cast<PeptideSpectrumMatch>().Select(o => o.Id.ToString()).ToArray());
            Assert.IsTrue(rowArray.StartsWith("1 2 3 46 47 48 4 5 6 49 50 51"));
            queryPage = queryReader.GetPage(1);
            Assert.AreEqual(1, queryPage.PageIndex);
            Assert.AreEqual(40, queryPage.Rows.Count);
            rowArray = String.Join(" ", queryPage.Rows.Cast<PeptideSpectrumMatch>().Select(o => o.Id.ToString()).ToArray());
            Assert.IsTrue(rowArray.StartsWith("65 66 22 23 24 67 68 69 25 26 27 70"));
            queryPage = queryReader.GetPage(2);
            Assert.AreEqual(2, queryPage.PageIndex);
            Assert.AreEqual(10, queryPage.Rows.Count);
            rowArray = String.Join(" ", queryPage.Rows.Cast<PeptideSpectrumMatch>().Select(o => o.Id.ToString()).ToArray());
            Assert.IsTrue(rowArray.StartsWith("42 85 86 87 43 44 45 88 89 90"));

            // test getting page by row index
            queryPage = queryReader.GetPageForRow(0);
            Assert.AreEqual(0, queryPage.PageIndex);
            queryPage = queryReader.GetPageForRow(39);
            Assert.AreEqual(0, queryPage.PageIndex);
            queryPage = queryReader.GetPageForRow(40);
            Assert.AreEqual(1, queryPage.PageIndex);
            queryPage = queryReader.GetPageForRow(79);
            Assert.AreEqual(1, queryPage.PageIndex);
            queryPage = queryReader.GetPageForRow(80);
            Assert.AreEqual(2, queryPage.PageIndex);
            queryPage = queryReader.GetPageForRow(89);
            Assert.AreEqual(2, queryPage.PageIndex);

            // test returning multiple objects
            query = session.CreateQuery("SELECT psm, psm.Spectrum FROM PeptideSpectrumMatch psm ORDER BY psm.Spectrum, psm.Id");
            queryReader = new NHibernateQueryReader(query, rowCount);
            queryPage = queryReader.GetPage(0);
            Assert.IsInstanceOfType(queryPage.Rows[0], typeof(object[]));
            Assert.IsInstanceOfType((queryPage.Rows[0] as object[])[0], typeof(PeptideSpectrumMatch));
            Assert.IsInstanceOfType((queryPage.Rows[0] as object[])[1], typeof(Spectrum));
        }
Пример #4
0
 public void TestGetPageArgumentOutOfRangeOverflow ()
 {
     var query = session.CreateSQLQuery("SELECT Id FROM PeptideSpectrumMatch");
     var queryReader = new NHibernateQueryReader(query, 90) { PageSize = 30 };
     queryReader.GetPage(4);
 }