示例#1
0
        public void Subquery()
        {
            var mockQuery = new MockQuery();
            var query     = mockQuery.Query(); // Elements: 1, 2, 3, 4.

            var filterExpression = new FilterExpression <int>();

            filterExpression.Include(x1 => new[] { "a", "aaaaa" }.AsQueryable().Select(s1 => s1.Length).Contains(x1)); // Elements: 1, 5.
            Console.WriteLine(filterExpression.GetFilter());

            filterExpression.Include(x2 => new[] { "aa", "aaaaaa" }.AsQueryable().Select(s2 => s2.Length).Contains(x2)); // Elements: 2, 6.
            Console.WriteLine(filterExpression.GetFilter());

            // Intentionally reusing the previous parameter name in expression (x2) and subquery (s2).
            filterExpression.Include(x2 => new[] { "aaa", "aaaaaaa" }.AsQueryable().Select(s2 => s2.Length).Contains(x2)); // Elements: 3, 7.
            Console.WriteLine(filterExpression.GetFilter());

            var filteredQuery = GetOpt(filterExpression.GetFilter(), query);

            Console.WriteLine(mockQuery.GetWherePart(filteredQuery));

            Assert.AreEqual(0, mockQuery.CallCount);
            Assert.AreEqual("1, 2, 3", TestUtility.Dump(filteredQuery));
            Assert.AreEqual(1, mockQuery.CallCount);
        }
示例#2
0
        public void EmptyFilter()
        {
            var mockQuery = new MockQuery();
            var query     = mockQuery.Query();

            var filterExpression = new FilterExpression <int>();
            var filteredQuery    = GetOpt(filterExpression.GetFilter(), query);

            Assert.AreEqual("New query: System.Int32[]", mockQuery.GetWherePart(filteredQuery), "Result should be a newly constructed empty array");
            Assert.AreEqual("", TestUtility.Dump(filteredQuery));
            Assert.AreEqual(0, mockQuery.CallCount, "Empty filter should be optimized to not use original query.");
        }
示例#3
0
        public void AllowSomeDenyNone()
        {
            var mockQuery = new MockQuery();
            var query     = mockQuery.Query();

            var filterExpression = new FilterExpression <int>();

            filterExpression.Include(x1 => x1 >= 3);
            filterExpression.Exclude(x2 => false);
            var filteredQuery = GetOpt(filterExpression.GetFilter(), query);

            Assert.AreEqual(".Where(x1 => (x1 >= 3))", mockQuery.GetWherePart(filteredQuery));
            Assert.AreEqual("3, 4", TestUtility.Dump(filteredQuery));
            Assert.AreEqual(1, mockQuery.CallCount);
        }
示例#4
0
        public void AllowAllDenyNone()
        {
            var mockQuery = new MockQuery();
            var query     = mockQuery.Query();

            var filterExpression = new FilterExpression <int>();

            filterExpression.Include(x1 => true);
            filterExpression.Exclude(x2 => false);
            var filteredQuery = GetOpt(filterExpression.GetFilter(), query);

            Assert.AreEqual("", mockQuery.GetWherePart(filteredQuery), "Optimized - No where part");
            Assert.AreEqual("1, 2, 3, 4", TestUtility.Dump(filteredQuery));
            Assert.AreEqual(1, mockQuery.CallCount);
        }
示例#5
0
        public void AllowSome2()
        {
            var mockQuery = new MockQuery();
            var query     = mockQuery.Query();

            var filterExpression = new FilterExpression <int>();

            filterExpression.Include(x1 => x1 >= 4);
            filterExpression.Include(x2 => x2 <= 2);
            var filteredQuery = GetOpt(filterExpression.GetFilter(), query);

            Assert.AreEqual(".Where(x1 => ((x1 >= 4) OrElse (x1 <= 2)))", mockQuery.GetWherePart(filteredQuery));
            Assert.AreEqual("1, 2, 4", TestUtility.DumpSorted(filteredQuery));
            Assert.AreEqual(1, mockQuery.CallCount);
        }
示例#6
0
        public void AllowAllDenySome2()
        {
            var mockQuery = new MockQuery();
            var query     = mockQuery.Query();

            var filterExpression = new FilterExpression <int>();

            filterExpression.Include(x1 => true);
            filterExpression.Exclude(x2 => x2 > 2);
            filterExpression.Exclude(x3 => x3 < 2);
            var filteredQuery = GetOpt(filterExpression.GetFilter(), query);

            Assert.AreEqual(".Where(x2 => (Not((x2 > 2)) AndAlso Not((x2 < 2))))", mockQuery.GetWherePart(filteredQuery));
            Assert.AreEqual("2", TestUtility.Dump(filteredQuery));
            Assert.AreEqual(1, mockQuery.CallCount);
        }
示例#7
0
        public void AllowSome2DenySome2()
        {
            var mockQuery = new MockQuery();
            var query     = mockQuery.Query();

            var filterExpression = new FilterExpression <int>();

            filterExpression.Include(x1 => x1 >= 2);
            filterExpression.Include(x2 => x2 >= 4);
            filterExpression.Exclude(x3 => x3 >= 4);
            filterExpression.Exclude(x4 => x4 >= 5);
            var filteredQuery = GetOpt(filterExpression.GetFilter(), query);

            Assert.AreEqual(".Where(x1 => (((x1 >= 2) OrElse (x1 >= 4)) AndAlso (Not((x1 >= 4)) AndAlso Not((x1 >= 5)))))", mockQuery.GetWherePart(filteredQuery));
            Assert.AreEqual("2, 3", TestUtility.Dump(filteredQuery));
            Assert.AreEqual(1, mockQuery.CallCount);
        }
示例#8
0
        public void EmptyFilter()
        {
            var mockQuery = new MockQuery();
            var query = mockQuery.Query();

            var filterExpression = new FilterExpression<int>();
            var filteredQuery = GetOpt(filterExpression.GetFilter(), query);

            Assert.AreEqual("New query: System.Int32[]", mockQuery.GetWherePart(filteredQuery), "Result should be a newly constructed empty array");
            Assert.AreEqual("", TestUtility.Dump(filteredQuery));
            Assert.AreEqual(0, mockQuery.CallCount, "Empty filter should be optimized to not use original query.");
        }
示例#9
0
        public void AllowSome2DenySome2()
        {
            var mockQuery = new MockQuery();
            var query = mockQuery.Query();

            var filterExpression = new FilterExpression<int>();
            filterExpression.Include(x1 => x1 >= 2);
            filterExpression.Include(x2 => x2 >= 4);
            filterExpression.Exclude(x3 => x3 >= 4);
            filterExpression.Exclude(x4 => x4 >= 5);
            var filteredQuery = GetOpt(filterExpression.GetFilter(), query);

            Assert.AreEqual(".Where(x1 => (((x1 >= 2) OrElse (x1 >= 4)) AndAlso (Not((x1 >= 4)) AndAlso Not((x1 >= 5)))))", mockQuery.GetWherePart(filteredQuery));
            Assert.AreEqual("2, 3", TestUtility.Dump(filteredQuery));
            Assert.AreEqual(1, mockQuery.CallCount);
        }
示例#10
0
        public void AllowAllDenySome2()
        {
            var mockQuery = new MockQuery();
            var query = mockQuery.Query();

            var filterExpression = new FilterExpression<int>();
            filterExpression.Include(x1 => true);
            filterExpression.Exclude(x2 => x2 > 2);
            filterExpression.Exclude(x3 => x3 < 2);
            var filteredQuery = GetOpt(filterExpression.GetFilter(), query);

            Assert.AreEqual(".Where(x2 => (Not((x2 > 2)) AndAlso Not((x2 < 2))))", mockQuery.GetWherePart(filteredQuery));
            Assert.AreEqual("2", TestUtility.Dump(filteredQuery));
            Assert.AreEqual(1, mockQuery.CallCount);
        }
示例#11
0
        public void AllowSomeDenyNone()
        {
            var mockQuery = new MockQuery();
            var query = mockQuery.Query();

            var filterExpression = new FilterExpression<int>();
            filterExpression.Include(x1 => x1 >= 3);
            filterExpression.Exclude(x2 => false);
            var filteredQuery = GetOpt(filterExpression.GetFilter(), query);

            Assert.AreEqual(".Where(x1 => (x1 >= 3))", mockQuery.GetWherePart(filteredQuery));
            Assert.AreEqual("3, 4", TestUtility.Dump(filteredQuery));
            Assert.AreEqual(1, mockQuery.CallCount);
        }
示例#12
0
        public void AllowAllDenyNone()
        {
            var mockQuery = new MockQuery();
            var query = mockQuery.Query();

            var filterExpression = new FilterExpression<int>();
            filterExpression.Include(x1 => true);
            filterExpression.Exclude(x2 => false);
            var filteredQuery = GetOpt(filterExpression.GetFilter(), query);

            Assert.AreEqual("", mockQuery.GetWherePart(filteredQuery), "Optimized - No where part");
            Assert.AreEqual("1, 2, 3, 4", TestUtility.Dump(filteredQuery));
            Assert.AreEqual(1, mockQuery.CallCount);
        }
示例#13
0
        public void AllowSome2()
        {
            var mockQuery = new MockQuery();
            var query = mockQuery.Query();

            var filterExpression = new FilterExpression<int>();
            filterExpression.Include(x1 => x1 >= 4);
            filterExpression.Include(x2 => x2 <= 2);
            var filteredQuery = GetOpt(filterExpression.GetFilter(), query);

            Assert.AreEqual(".Where(x1 => ((x1 >= 4) OrElse (x1 <= 2)))", mockQuery.GetWherePart(filteredQuery));
            Assert.AreEqual("1, 2, 4", TestUtility.DumpSorted(filteredQuery));
            Assert.AreEqual(1, mockQuery.CallCount);
        }