Exemple #1
0
 private void VisitFirst(bool useDefault)
 {
     if (_takeTranslator != null)
     {
         throw new NotSupportedException("You cannot have more than 1 Take/First/FirstOrDefault in the expression");
     }
     _takeTranslator = TakeTranslator.GetNewFirstTranslator(useDefault);
 }
Exemple #2
0
 private void VisitTake(Expression takeValue)
 {
     if (_takeTranslator != null)
     {
         throw new NotSupportedException("You cannot have more than 1 Take/First/FirstOrDefault in the expression");
     }
     _takeTranslator = new TakeTranslator();
     _takeTranslator.Translate(takeValue);
 }
        public void TakeWithInvalidMethod()
        {
            // Arrange
            var translator             = new TakeTranslator();
            IQueryable <Country> query = GetQueryable().Where(p => p.Name == string.Empty);
            var translation            = new TranslationResult();

            // Act
            Assert.Throws <ArgumentOutOfRangeException>(() => translator.Translate((MethodCallExpression)query.Expression, translation));

            // Assert
            Assert.NotNull(translation.TableQuery);
            Assert.Null(translation.TableQuery.TakeCount);
        }
        public void TakeOneEntityTest()
        {
            // Arrange
            const int            count = 435435;
            IQueryable <Country> query = GetQueryable().Take(count);
            var translator             = new TakeTranslator();
            var translation            = new TranslationResult();

            // Act
            translator.Translate((MethodCallExpression)query.Expression, translation);

            // Assert
            Assert.NotNull(translation.TableQuery);
            Assert.NotNull(translation.TableQuery.TakeCount);
            Assert.Equal(count, translation.TableQuery.TakeCount);
        }
        public void TakeOneEntityAfterWhereMethodTest()
        {
            // Arrange
            const int            count = 555;
            IQueryable <Country> query = GetQueryable()
                                         .Where(p => p.Continent == "Europe").Take(count);
            var translator  = new TakeTranslator();
            var translation = new TranslationResult();

            // Act
            translator.Translate((MethodCallExpression)query.Expression, translation);

            // Assert
            Assert.NotNull(translation.TableQuery);
            Assert.NotNull(translation.TableQuery.TakeCount);
            Assert.Equal(count, translation.TableQuery.TakeCount);
        }
Exemple #6
0
        public Take()
        {
            Func <IQueryable <TSource>, int, IQueryable <TSource> >   f  = Queryable.Take;
            Func <IEnumerable <TSource>, int, IEnumerable <TSource> > f2 = Enumerable.Take;

            var translator = new TakeTranslator();

            AddTranslator(f.Method, translator);
            AddTranslator(f2.Method, translator);

            Func <IQueryable <TSource>, Expression <Func <TSource, bool> >, IQueryable <TSource> > f3 = Queryable.TakeWhile;
            Func <IEnumerable <TSource>, Func <TSource, bool>, IEnumerable <TSource> >             f4 = Enumerable.TakeWhile;

            var translatorWithLambda = new SimpleMethodWithLambdaTranslator();

            AddTranslator(f3.Method, translatorWithLambda);
            AddTranslator(f4.Method, translatorWithLambda);
        }