Example #1
0
        public void TestDescOrderedPaging()
        {
            PdbResultsWithMetadata values = _helper.Query(null,
                                                          10, SortType.Desc, _publicRoles, 2000, 1);

            AssertOrdering(values.Values, 10, SortType.Desc);
        }
Example #2
0
        public void TestPaging()
        {
            int numPerPage = 10;

            // Note that page numbering is 1-based.
            PdbResultsWithMetadata page1  = _helper.Query(null, _publicRoles, numPerPage, 1);
            PdbResultsWithMetadata page2  = _helper.Query(null, _publicRoles, numPerPage, 2);
            PdbResultsWithMetadata page50 = _helper.Query(null, _publicRoles, numPerPage, 50);

            // Should be the same number regardless of the page, but they shouldn't be the same.

            Assert.AreEqual(numPerPage, page1.Values.Count, "Wrong number of results for page 1.");
            Assert.AreEqual(numPerPage, page2.Values.Count, "Wrong number of results for page 2.");
            Assert.AreEqual(numPerPage, page50.Values.Count, "Wrong number of results for page 50.");
            int UIDIndex = -1;

            for (int x = 0; x < page1.Attrs.Count; x++)
            {
                if (page1.Attrs[x].UID.Equals("UID"))
                {
                    UIDIndex = x;
                    break;
                }
            }
            Assert.AreNotEqual(-1, UIDIndex, "Didn't find the UID column!");
            Assert.AreNotEqual(page1.Values[0][UIDIndex], page2.Values[0][UIDIndex], "Page 1 and 2 had the same first object.");
            Assert.AreNotEqual(page1.Values[0][UIDIndex], page50.Values[0][UIDIndex], "Page 1 and 50 had the same first object.");
            Assert.AreNotEqual(page2.Values[0][UIDIndex], page50.Values[0][UIDIndex], "Page 2 and 50 had the same first object.");
            Assert.Greater(page1.TotalResults, numPerPage, "Total results should have been higher than what is returned on page 1.");
            Assert.Greater(page2.TotalResults, numPerPage, "Total results should have been higher than what is returned on page 2.");
            Assert.Greater(page50.TotalResults, numPerPage, "Total results should have been higher than what is returned on page 50.");
        }
Example #3
0
        public void TestCsvExport()
        {
            PdbResultsWithMetadata values = _helper.Query(null,
                                                          10, null, _publicRoles, 2000, 1);

            string csv = _helper.ResultsAsCsv(values, false);

            Assert.IsNotEmpty(csv, "CSV Export should be populated.");
        }
Example #4
0
        public void TestQueryNoExprsForEveryone()
        {
            // Should be number of cols in the DB attributes tables, but also one for the primary key.
            PdbResultsWithMetadata results = _helper.Query(null, new SecurityRole[] { SecurityRole.@public });

            Assert.AreEqual(612, results.Values.Count,
                            "Wrong number of results for primary + secondary query for all users.");
            Assert.AreEqual(results.Values.Count, results.TotalResults,
                            "Total results did not match the number of results returned.");
        }
Example #5
0
        public void TestPagingPastTheEnd()
        {
            // Should return nothing.
            int numPerPage = 10;
            PdbResultsWithMetadata page500 = _helper.Query(null, _publicRoles, numPerPage, 500);

            DumpResultsWithMetadata(page500);
            Assert.AreEqual(0, page500.Values.Count, "Page 500 should be past the end, so we should get no results.");
            Assert.Greater(page500.TotalResults, numPerPage, "Total results should have been higher than what is returned on page 500.");
        }
Example #6
0
        public void TestSecondaryTableQueryWithLikeExprsForEveryone()
        {
            IExpression[] exprs = new IExpression[] {
                // This one will require some magic since it is on the secondary table.
                new LikeExpression("Building Address", "%bush%")
            };
            PdbResultsWithMetadata results = _helper.Query(exprs, new SecurityRole[] { SecurityRole.@public });

            Assert.AreEqual(1, results.Values.Count,
                            "Wrong number of results for primary + secondary query for all users.");
        }
Example #7
0
        public void TestSecondaryTableQueryWithExprsForEveryone()
        {
            IExpression[] exprs = new IExpression[] {
                // This one will require some magic since it is on the secondary table.
                new EqualExpression("Agency", "Housing Development Corporation")
            };
            PdbResultsWithMetadata results = _helper.Query(exprs, new SecurityRole[] { SecurityRole.@public });

            Assert.AreEqual(71, results.Values.Count,
                            "Wrong number of results for primary + secondary query for all users.");
            Assert.AreEqual(results.Values.Count, results.TotalResults,
                            "Total results did not match the number of results returned.");
        }
Example #8
0
        public void TestCsvExportWithGrouping()
        {
            IExpression[] exprs = new IExpression[] {
                // This is a secondary table attribute.
                new EqualExpression("Agency", "U.S. Department of Housing and Urban Development")
            };
            PdbResultsWithMetadata result = _helper.GroupedQuery(exprs,
                                                                 new string[] { "OwnerProfitStatus", "MLStatus", "AffordabilityStatus" },
                                                                 3, SortType.Asc, _publicRoles, 10, 2);

            string csv = _helper.ResultsAsCsv(result, true);

            Assert.IsNotEmpty(csv, "CSV Export should be populated.");
        }
Example #9
0
        public void TestPrimaryTableQueryWithExprsForEveryone()
        {
            IExpression[] exprs = new IExpression[] {
                // This one's pretty straightforward, it is on the primary table.
                new LesserExpression("UnitCount", 25)
            };
            PdbResultsWithMetadata results = _helper.Query(exprs, new SecurityRole[] { SecurityRole.@public });

            // Should be number of cols in the DB attributes tables, but also one for the primary key.
            Assert.AreEqual(52, results.Values.Count,
                            "Wrong number of results for primary + secondary query for all users.");
            Assert.AreEqual(results.Values.Count, results.TotalResults,
                            "Total results did not match the number of results returned.");
        }
Example #10
0
        public void TestSingleGroupBy()
        {
            IExpression[] exprs = new IExpression[] {
                // This is a secondary table attribute.
                new EqualExpression("Agency", "Housing Development Corporation")
            };
            PdbResultsWithMetadata result = _helper.GroupedQuery(exprs,
                                                                 new string[] { "OwnerProfitStatus" },
                                                                 -1, null, _publicRoles, 0, 0);

            DumpAggregateResults(result);
            Assert.AreEqual(3, result.Values.Count, "Wrong number of grouped results.");
            Assert.AreEqual(result.Values.Count, result.TotalResults, "Total results should be the same as number received when no paging specified.");
        }
Example #11
0
        public void TestSecondaryTableQueryWithTwoExprsForEveryone()
        {
            IExpression[] exprs = new IExpression[] {
                // This one will require some magic since it is on the secondary table.
                new PropertyInListExpression("Agency", new [] { "Division of Housing & Community Renewal", "U.S. Department of Housing and Urban Development" }),
                new EqualExpression("Portfolio", "LIHTC 4%")
            };
            PdbResultsWithMetadata results = _helper.Query(exprs, new SecurityRole[] { SecurityRole.@public });

            Assert.AreEqual(19, results.Values.Count,
                            "Wrong number of results for primary + secondary query for all users.");
            Assert.AreEqual(results.Values.Count, results.TotalResults,
                            "Total results did not match the number of results returned.");
        }
Example #12
0
        public void TestDoubleGroupByWithPaging()
        {
            IExpression[] exprs = new IExpression[] {
                // This is a secondary table attribute.
                new EqualExpression("Agency", "Housing Development Corporation")
            };
            PdbResultsWithMetadata result = _helper.GroupedQuery(exprs,
                                                                 new string[] { "OwnerProfitStatus", "Portfolio" },
                                                                 -1, null, _publicRoles, 10, 2);

            DumpAggregateResults(result);
            IList <IList <object> > values = result.Values;

            Assert.AreEqual(10, values.Count, "Wrong number of grouped results.");
        }
Example #13
0
        public void TestTripleGroupByWithPaging()
        {
            IExpression[] exprs = new IExpression[] {
                // This is a secondary table attribute.
                new EqualExpression("Agency", "U.S. Department of Housing and Urban Development")
            };
            PdbResultsWithMetadata result = _helper.GroupedQuery(exprs,
                                                                 new string[] { "OwnerProfitStatus", "MLStatus", "AffordabilityStatus" },
                                                                 -1, null, _publicRoles, 10, 2);

            DumpAggregateResults(result);
            IList <IList <object> > values = result.Values;

            Assert.AreEqual(6, values.Count, "Wrong number of grouped results.");
        }
Example #14
0
        public void TestSingleGroupByWithPaging()
        {
            IExpression[] exprs = new IExpression[] {
                // This is a secondary table attribute.
                new EqualExpression("Agency", "Housing Development Corporation")
            };
            PdbResultsWithMetadata result = _helper.GroupedQuery(exprs,
                                                                 new string[] { "OwnerProfitStatus" },
                                                                 -1, null, _publicRoles, 2, 2);

            DumpAggregateResults(result);
            IList <IList <object> > values = result.Values;

            Assert.AreEqual(1, values.Count, "Wrong number of grouped results.");
            Assert.Greater(result.TotalResults, result.Values.Count, "Total results should have been higher than what is returned on page 2.");
        }
Example #15
0
        public void TestOrderedDoubleGroupByWithPaging()
        {
            IExpression[] exprs = new IExpression[] {
                // This is a secondary table attribute.
                new EqualExpression("Agency", "Department of Finance")
            };
            PdbResultsWithMetadata result = _helper.GroupedQuery(exprs,
                                                                 new string[] { "OwnerProfitStatus", "Portfolio" },
                                                                 4, SortType.Desc, _publicRoles, 10, 2);

            DumpAggregateResults(result);
            IList <IList <object> > values = result.Values;

            Assert.AreEqual(10, values.Count, "Wrong number of grouped results.");
            AssertOrdering(values, 4, SortType.Desc);
        }
Example #16
0
 private static void DumpAggregateResults(PdbResultsWithMetadata results)
 {
     if (results.Attrs == null)
     {
         Console.WriteLine("Null columns list on aggregated result.");
     }
     else
     {
         StringBuilder output = new StringBuilder();
         foreach (PdbResultAttributeMetadata colName in results.Attrs)
         {
             output.Append(colName.Name.PadRight(ColumnDisplayWidth));
         }
         Console.WriteLine(output);
         DumpResultsWithMetadata(results);
     }
 }
Example #17
0
        public void TestPrimaryTableQueryWithOrExprsForEveryone()
        {
            IList <string> list = new List <string>();

            list.Add("BROOKLYN");
            list.Add("MANHATTAN");

            IExpression[] exprs = new IExpression[] {
                // This one's pretty straightforward, it is on the primary table.
                new PropertyInListExpression("Borough", list)
            };
            PdbResultsWithMetadata results = _helper.Query(exprs, new SecurityRole[] { SecurityRole.@public });

            Assert.AreEqual(374, results.Values.Count,
                            "Wrong number of results for primary + secondary query for all users.");
            Assert.AreEqual(results.Values.Count, results.TotalResults,
                            "Total results did not match the number of results returned.");
        }
        protected override void InternalGET(System.Web.HttpContext context, HandlerTimedCache cache)
        {
            IList <SecurityRole> roles = UserHelper.GetUserRoles(context.User.Identity.Name);

            PdbTwoTableHelper dataHelper = new PdbTwoTableHelper(Config.GetConfig("PDP.Data"), "Properties", PdbEntityType.Properties);

            List <string> ids = new List <string>();
            string        id  = WebUtil.GetParam(context, "id", true);

            if (id != null)
            {
                ids.Add(id);
            }
            else
            {
                string idList = WebUtil.GetParam(context, "ids", false);
                ids.AddRange(idList.Split(','));
            }
            PdbResultsWithMetadata list = dataHelper.Query(ids, roles);

            context.Response.Write(WebUtil.ObjectToJson(list));
        }