Exemplo n.º 1
0
        public void 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);
        }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
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.QueryTranslatorProviderAsync", queryIntercepted.Provider.ToString());

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

            Assert.NotNull(queryCreated);
        }