Пример #1
0
        public void InterceptWith_TestEqualsToNotEqualsVisitor_FirstAsync()
        {
            var queryEven = Enumerable.Range(0, 10).AsQueryable().Where(n => n % 2 == 0).AsQueryable();

            var visitor  = new EqualsToNotEqualsVisitor();
            var queryOdd = queryEven.InterceptWith(visitor);

            var task = queryOdd.FirstAsync(n => n > 5, CancellationToken.None);

            task.ContinueWith(t => t.Result).Wait();

            Assert.Equal(7, task.Result);
        }
        public void Entities_InterceptWith_EqualsToNotEqualsVisitor()
        {
            PopulateTestData(10, 0);

            IQueryable <Blog> query = _context.Blogs.Where(b => b.BlogId % 2 == 0).AsQueryable();

            var visitor = new EqualsToNotEqualsVisitor();
            IQueryable <Blog> queryIntercepted = query.InterceptWith(visitor);

            Assert.NotNull(queryIntercepted);

            Assert.Equal(new List <int> {
                1, 3, 5, 7, 9
            }, queryIntercepted.Select(b => b.BlogId).OrderBy(id => id).ToList());
        }
Пример #3
0
        public void InterceptWith_TestEqualsToNotEqualsVisitor()
        {
            IQueryable <int> query       = Enumerable.Range(0, 10).AsQueryable().Where(n => n % 2 == 0);
            List <int>       numbersEven = query.ToList();

            Assert.Equal(new List <int> {
                0, 2, 4, 6, 8
            }, numbersEven);

            var        visitor    = new EqualsToNotEqualsVisitor();
            List <int> numbersOdd = query.InterceptWith(visitor).Where(x => x >= 0).ToList();

            Assert.Equal(new List <int> {
                1, 3, 5, 7, 9
            }, numbersOdd);
        }
Пример #4
0
        public void InterceptWith_IQueryable()
        {
            IQueryable <int> query = Enumerable.Range(0, 10).AsQueryable().Where(n => n % 2 == 0);

            var        visitor          = new EqualsToNotEqualsVisitor();
            IQueryable queryIntercepted = query.InterceptWith(visitor);

            Assert.NotNull(queryIntercepted);

            Assert.Equal(typeof(int), queryIntercepted.ElementType);
            Assert.Equal("QueryInterceptor.Core.QueryTranslatorProviderAsync", queryIntercepted.Provider.ToString());

            Expression <Func <int, bool> > predicate = x => x >= 0;
            var queryCreated = queryIntercepted.Provider.CreateQuery(predicate);

            Assert.NotNull(queryCreated);
        }
        public void Entities_InterceptWith_IQueryable()
        {
            PopulateTestData(10, 0);

            IQueryable <Blog> query = _context.Blogs.Where(b => b.BlogId % 2 == 0).AsQueryable();

            var        visitor          = new EqualsToNotEqualsVisitor();
            IQueryable queryIntercepted = query.InterceptWith(visitor);

            Assert.NotNull(queryIntercepted);

            Assert.Equal(typeof(Blog), queryIntercepted.ElementType);
            Assert.Equal("QueryInterceptor.Core.QueryTranslatorProviderAsync", queryIntercepted.Provider.ToString());

            Expression <Func <Blog, bool> > predicate = b => b.BlogId >= 0;
            var queryCreated = queryIntercepted.Provider.CreateQuery(predicate);

            Assert.NotNull(queryCreated);
        }