示例#1
0
        private void RewritingTest(string inputQuery, bool isValid, string expected)
        {
            var context = new TestQueryContext(QuerySettings.AdminSettings, 0, _indexingInfo, new TestQueryEngine(null, null));

            using (SenseNet.Tests.Tools.Swindle(typeof(SnQuery), "_permissionFilterFactory", new EverythingAllowedPermissionFilterFactory()))
            {
                var queryIn    = SnQuery.Parse(inputQuery, context);
                var snQueryAcc = new PrivateType(typeof(SnQuery));
                snQueryAcc.InvokeStatic("PrepareQuery", queryIn, context);

                var     hasError = false;
                var     visitor  = new SharingVisitor();
                SnQuery queryOut = null;
                try
                {
                    queryOut = SnQuery.Create(visitor.Visit(queryIn.QueryTree));
                }
                catch (InvalidContentSharingQueryException)
                {
                    hasError = true;
                }

                Assert.AreNotEqual(isValid, hasError);
                if (!hasError)
                {
                    Assert.AreEqual(expected, queryOut.ToString());
                }
            }
        }
示例#2
0
        public void Sharing_Query_Rewriting_FieldNames()
        {
            var    inputQuery    = "-a:a Sharing:s0 SharedWith:123 SharedBy:s2 SharingMode:s3 SharingLevel:s4";
            var    expectedQuery = "-a:a Sharing:s0 Sharing:I123 Sharing:s2 Sharing:s3 Sharing:s4";
            string actualQuery;

            var context = new TestQueryContext(QuerySettings.AdminSettings, 0, _indexingInfo, new TestQueryEngine(null, null));

            using (SenseNet.Tests.Tools.Swindle(typeof(SnQuery), "_permissionFilterFactory", new EverythingAllowedPermissionFilterFactory()))
            {
                var queryIn    = SnQuery.Parse(inputQuery, context);
                var snQueryAcc = new PrivateType(typeof(SnQuery));
                snQueryAcc.InvokeStatic("PrepareQuery", queryIn, context);

                var visitor = new SharingVisitor();
                var newTree = visitor.Visit(queryIn.QueryTree);

                var snQuery = SnQuery.Create(newTree);
                actualQuery = snQuery.ToString();
            }

            Assert.AreEqual(expectedQuery, actualQuery);
        }