private IEnumerable <TestCaseData> Test_GetReferencedFields_Source() { // Using a Func<StructuredQuery> rather than a straight StructuredQuery to // avoid issues with NUnit and using a CallContext in a TestCaseSource method. yield return(new TestCaseData((Func <StructuredQuery>)(() => TestQueries.Entities()), new string[0])); yield return(new TestCaseData((Func <StructuredQuery>)(() => TestQueries.EntitiesWithNameA()), new[] { "core:name" })); yield return(new TestCaseData((Func <StructuredQuery>)(() => TestQueries.EntitiesWithDescription()), new[] { "core:description" })); yield return(new TestCaseData((Func <StructuredQuery>)(() => TestQueries.EntitiesOrderByDescription()), new[] { "core:description" })); yield return(new TestCaseData((Func <StructuredQuery>)(() => TestQueries.EntitiesWithNameDescription("a", "a")), new[] { "core:name", "core:description" })); yield return(new TestCaseData((Func <StructuredQuery>)(() => TestQueries.EntitiesWithNameAndDescriptionInResults("a")), new [] { "core:name", "core:description" })); yield return(new TestCaseData((Func <StructuredQuery>)(() => TestQueries.AccessRulesWithNamedPermission("read")), new[] { "core:name", "core:accessRuleEnabled" })); yield return(new TestCaseData((Func <StructuredQuery>)(() => TestQueries.ActiveUsersInRole("administrators")), new[] { "core:name", "core:alias" })); }
public void RunReportSomeAccessWithRollup() { // We will group by the name column but secure by the description column // Anything with a D description is allowed // This should give 2 groups containing enties the test has access to. var nameDescList = new List <Tuple <string, string> > { new Tuple <string, string>("Name1", "D"), new Tuple <string, string>("Name1", "X"), new Tuple <string, string>("Name1", "X"), new Tuple <string, string>("Name2", "D"), new Tuple <string, string>("Name2", "D"), new Tuple <string, string>("Name2", "X"), new Tuple <string, string>("Name3", "X"), new Tuple <string, string>("Name3", "X"), new Tuple <string, string>("Name3", "X"), }; // Create the entitues SecurityTestData testData = SetupSecurityTest(nameDescList); var reportingInterface = new ReportingInterface(); // Create an access rule only for entities whose description is D new AccessRuleFactory().AddAllowReadQuery(testData.UserAccount.As <EntityModel.Subject>(), testData.EntityType.As <EntityModel.SecurableEntity>(), TestQueries.EntitiesWithDescription("D", testData.EntityType).ToReport()); // Get the name column id long nameColumnId = testData.Report.ReportColumns.ToList()[1].Id; long descriptionColumnId = testData.Report.ReportColumns.ToList()[2].Id; // Create rollup and aggregate settings // Group by the name column and apply a count to the description column var reportSettings = new ReportSettings { ReportParameters = new ReportParameters { GroupAggregateRules = new ReportMetadataAggregate { IncludeRollup = true, ShowCount = true, ShowGrandTotals = true, ShowSubTotals = true, ShowGroupLabel = true, ShowOptionLabel = true, Groups = new List <Dictionary <long, GroupingDetail> > { new Dictionary <long, GroupingDetail> { { nameColumnId, new GroupingDetail { Style = "groupList" } } } }, Aggregates = new Dictionary <long, List <AggregateDetail> > { { descriptionColumnId, new List <AggregateDetail> { new AggregateDetail { Style = "aggCount" } } } } } } }; ReportResult reportResult; // Run the report for the test user using (new SetUser(testData.UserAccount)) { reportResult = reportingInterface.RunReport(testData.Report, reportSettings); } // Verify the results Assert.AreEqual(nameDescList.Count(i => i.Item2 == "D"), reportResult.GridData.Count); Assert.IsTrue(reportResult.GridData.All(d => d.Values[2].Value == "D")); // Verify the aggregate data List <ReportDataAggregate> aggregateData = reportResult.AggregateData; // Two groups + total Assert.AreEqual(3, aggregateData.Count); ReportDataAggregate name1Agg = aggregateData.First(ad => ad.GroupHeadings[0][nameColumnId].Value == "Name1"); ReportDataAggregate name2Agg = aggregateData.First(ad => ad.GroupHeadings[0][nameColumnId].Value == "Name2"); ReportDataAggregate totalAgg = aggregateData.First(ad => string.IsNullOrEmpty(ad.GroupHeadings[0][nameColumnId].Value)); Assert.AreEqual("1", name1Agg.Aggregates[descriptionColumnId][0].Value); Assert.AreEqual("2", name2Agg.Aggregates[descriptionColumnId][0].Value); Assert.AreEqual("3", totalAgg.Aggregates[descriptionColumnId][0].Value); }