TableQuery translation result.
Inheritance: ITranslationResult
        public void LinqSelectWithProjectionClass()
        {
            // Arrange
            IQueryable<ProjectionResult> query = GetQueryable()
                .Select(p => new ProjectionResult {Name = p.Name, Continent = p.Continent, Area = p.Area});
            var translator = new SelectTranslator(_nameChanges);
            var translation = new TranslationResult();

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

            Assert.NotNull(translation.TableQuery);
            Assert.NotNull(translation.TableQuery.SelectColumns);
            Assert.Equal(3, translation.TableQuery.SelectColumns.Count);
            Assert.Contains("PartitionKey", translation.TableQuery.SelectColumns);
            Assert.Contains("RowKey", translation.TableQuery.SelectColumns);
            Assert.Contains("Area", translation.TableQuery.SelectColumns);

            object result = translation.PostProcessing.DynamicInvoke(GetList().AsQueryable());

            Assert.NotNull(result);
            Assert.IsAssignableFrom<IEnumerable<ProjectionResult>>(result);

            List<ProjectionResult> entities = ((IEnumerable<ProjectionResult>) result).ToList();
            IEnumerable<string> names = entities.Select(p => p.Name).ToList();

            Assert.Contains(Germany, names);
            Assert.Contains(Spain, names);
        }
        public void CreateTranslationResult()
        {
            // Act
            var result = new TranslationResult();

            // Assert
            Assert.Null(result.PostProcessing);
            Assert.NotNull(result.TableQuery);
            Assert.Null(result.TableQuery.FilterString);
            Assert.Null(result.TableQuery.TakeCount);
            Assert.Null(result.TableQuery.SelectColumns);
        }
        public void AddFilter()
        {
            // Arrange
            var result = new TranslationResult();
            const string filter = "name eq '123'";

            // Act
            result.AddFilter(filter);

            // Assert
            Assert.NotNull(result.TableQuery);
            Assert.Equal(filter, result.TableQuery.FilterString);
        }
Esempio n. 4
0
        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 AddFilterTwice()
        {
            // Arrange
            var result = new TranslationResult();
            const string filter = "name eq '123'";

            // Act
            result.AddFilter(filter);
            result.AddFilter(filter);

            // Assert
            Assert.NotNull(result.TableQuery);
            Assert.Equal(string.Format("{0} and {0}", filter), result.TableQuery.FilterString);
        }
        public void AddFiltersWithComplexAndComplexExpression()
        {
            // Arrange
            var result = new TranslationResult();
            const string filter = "name eq '123' or name eq '222'";

            // Act
            result.AddFilter(filter);
            result.AddFilter(filter);

            // Assert
            Assert.NotNull(result.TableQuery);
            Assert.Equal(string.Format("({0}) and ({1})", filter, filter), result.TableQuery.FilterString);
        }
Esempio n. 7
0
        public void FirstAfterWhere()
        {
            // Arrange
            var translator = new FirstTranslator(_nameChanges);
            Expression<Func<Country>> query = () => _countries.Where(p => !p.IsExists).First();
            var translation = new TranslationResult();

            // Act && Assert
            translator.Translate((MethodCallExpression) query.Body, translation);

            Assert.NotNull(translation.TableQuery);
            Assert.NotNull(translation.TableQuery.FilterString);
            Assert.Equal("not IsExists", translation.TableQuery.FilterString);
        }
        public void SingleOrDefaultWithInvalidMethod()
        {
            // Arrange
            var translator = new SingleOrDefaultTranslator(_nameChanges);
            Expression<Func<Country>> query = () => _countries.Single(p => !p.IsExists);
            var translation = new TranslationResult();

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

            // Assert
            Assert.NotNull(translation.TableQuery);
            Assert.Null(translation.TableQuery.FilterString);
            Assert.Null(translation.PostProcessing);
        }
Esempio n. 9
0
        public void UseWhereOnPartitionKey()
        {
            // Arrange
            var translator = new WhereTranslator(_nameChanges);
            Expression<Func<IQueryable<Country>>> query = () => _countries.Where(p => p.Continent == Europe);
            var translation = new TranslationResult();

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

            // Assert
            Assert.NotNull(translation.TableQuery);
            Assert.NotNull(translation.TableQuery.FilterString);
            Assert.Equal("PartitionKey eq 'Europe'", translation.TableQuery.FilterString);
        }
Esempio n. 10
0
        public void UseEnumValueInWhereOnRowKey()
        {
            // Arrange
            var translator = new WhereTranslator(_nameChanges);
            Expression<Func<IQueryable<Country>>> query = () => _countries.Where(p => p.Name == Countries.Germany.ToString());
            var translation = new TranslationResult();

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

            // Assert
            Assert.NotNull(translation.TableQuery);
            Assert.NotNull(translation.TableQuery.FilterString);
            Assert.Equal("RowKey eq 'Germany'", translation.TableQuery.FilterString);
        }
        public void UseCompareOrdinalInWhereOnRowKeyTest()
        {
            // Arrange
            var translator = new WhereTranslator(_nameChanges);
            Expression<Func<IQueryable<Country>>> query = () => _countries.Where(p => String.CompareOrdinal(p.Name, "F") >= 0 && String.CompareOrdinal(p.Name, "G") <= 0);
            var translation = new TranslationResult();

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

            // Assert
            Assert.NotNull(translation.TableQuery);
            Assert.NotNull(translation.TableQuery.FilterString);
            Assert.Equal("RowKey ge 'F' and RowKey le 'G'", translation.TableQuery.FilterString);
        }
        public void AddFiltersWithSimpleAndComplexExpression()
        {
            // Arrange
            var result = new TranslationResult();
            const string simple = "name eq '333'";
            const string complex = "name eq '123' or name eq '222'";

            // Act
            result.AddFilter(simple);
            result.AddFilter(complex);

            // Assert
            Assert.NotNull(result.TableQuery);
            Assert.Equal(string.Format("{0} and ({1})", simple, complex), result.TableQuery.FilterString);
        }
Esempio n. 13
0
        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);
        }
Esempio n. 14
0
        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);
        }
Esempio n. 15
0
        public void UseContainsAndEqualityInWhereOnRowKeyTest()
        {
            // Arrange
            var list = new List<String>
                {
                    "Latvia",
                    "Germany"
                };
            var translator = new WhereTranslator(_nameChanges);
            Expression<Func<IQueryable<Country>>> query = () => _countries.Where(p => list.Contains(p.Name) && p.Continent == "Africa");
            var translation = new TranslationResult();

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

            // Assert
            Assert.NotNull(translation.TableQuery);
            Assert.NotNull(translation.TableQuery.FilterString);
            Assert.Equal("(RowKey eq 'Latvia' or RowKey eq 'Germany') and PartitionKey eq 'Africa'", translation.TableQuery.FilterString);
        }
Esempio n. 16
0
        public void UseNotContainsInWhereOnRowKeyTest()
        {
            // Arrange
            var list = new List<String>
                {
                    "Latvia",
                    "Germany"
                };
            var translator = new WhereTranslator(_nameChanges);
            Expression<Func<IQueryable<Country>>> query = () => _countries.Where(p => !list.Contains(p.Name));
            var translation = new TranslationResult();

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

            // Assert
            Assert.NotNull(translation.TableQuery);
            Assert.NotNull(translation.TableQuery.FilterString);
            Assert.Equal("RowKey ne 'Latvia' or RowKey ne 'Germany'", translation.TableQuery.FilterString);
        }
        public void AddTop()
        {
            // Arrange
            var result = new TranslationResult();
            const int count = 5;

            // Act
            result.AddTop(count);

            // Assert
            Assert.NotNull(result.TableQuery);
            Assert.Equal(count, result.TableQuery.TakeCount);
        }
        public void AddNullPostProcessingExpression()
        {
            // Arrange
            var result = new TranslationResult();

            // Act && Assert
            Assert.Throws<ArgumentNullException>(() => result.AddPostProcesing(null));
        }
Esempio n. 19
0
        public void WhereWithNullableDouble()
        {
            // Arrange
            var translator = new WhereTranslator(_nameChanges);
            var queryable = new EnumerableQuery<EntityWithFields>(new List<EntityWithFields>());
            const double value = .3;
            Expression<Func<IQueryable<EntityWithFields>>> query = () => queryable.Where(p => p.NullableDouble > value);
            var translation = new TranslationResult();

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

            // Assert
            Assert.NotNull(translation.TableQuery);
            Assert.Equal("NullableDouble gt .3", translation.TableQuery.FilterString);
        }
        public void AddPostProcessing()
        {
            // Arrange
            var result = new TranslationResult();
            LambdaExpression expression = Expression.Lambda(Expression.Constant(2));

            // Act
            result.AddPostProcesing(expression);

            // Assert
            Assert.NotNull(result.TableQuery);
            Assert.Equal(expression.Compile().DynamicInvoke(), result.PostProcessing.DynamicInvoke());
        }
        public void AddTwoPostProcessing()
        {
            // Arrange
            var result = new TranslationResult();
            Expression<Func<int>> expression1 = () => 2;
            Expression<Func<int, int>> expression2 = (val) => val + 3;

            // Act
            result.AddPostProcesing(expression1);
            result.AddPostProcesing(expression2);

            // Assert
            Assert.NotNull(result.TableQuery);
            var etalon = expression2.Compile().DynamicInvoke(expression1.Compile().DynamicInvoke());
            Assert.Equal(etalon, result.PostProcessing.DynamicInvoke());
        }
        public void AddColumnTwice()
        {
            // Arrange
            var result = new TranslationResult();
            const string column = "column";

            // Act
            result.AddColumn(column);
            result.AddColumn(column);

            // Assert
            Assert.NotNull(result.TableQuery);
            Assert.NotNull(result.TableQuery.SelectColumns);
            Assert.Equal(2, result.TableQuery.SelectColumns.Count);
            Assert.Equal(column, result.TableQuery.SelectColumns[0]);
            Assert.Equal(column, result.TableQuery.SelectColumns[1]);
        }
        public void AddNullColumn()
        {
            // Arrange
            var result = new TranslationResult();

            // Act && Assert
            Assert.Throws<ArgumentNullException>(() => result.AddColumn(null));
        }
Esempio n. 24
0
        public void WhereWithNullableDateTime()
        {
            // Arrange
            var translator = new WhereTranslator(_nameChanges);
            var queryable = new EnumerableQuery<EntityWithFields>(new List<EntityWithFields>());
            var value = new DateTime(1980, 1, 1);
            Expression<Func<IQueryable<EntityWithFields>>> query = () => queryable.Where(p => p.NullableDateTime < value);
            var translation = new TranslationResult();

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

            // Assert
            Assert.NotNull(translation.TableQuery);
            Assert.Equal("NullableDateTime lt datetime'1980-01-01T00:00:00'", translation.TableQuery.FilterString);
        }
Esempio n. 25
0
        public void WhereWithEnumartionConstantValue()
        {
            // Arrange
            var translator = new WhereTranslator(_nameChanges);
            var queryable = new EnumerableQuery<EntityWithFields>(new List<EntityWithFields>());

            const Countries value = Countries.Germany;

            Expression<Func<IQueryable<EntityWithFields>>> query = () => queryable.Where(p => p.String == value.ToString());
            var translation = new TranslationResult();

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

            // Assert
            Assert.NotNull(translation.TableQuery);
            Assert.Equal(string.Format("String eq '{0}'", value), translation.TableQuery.FilterString);
        }
Esempio n. 26
0
        public void BinaryExpressionWithPrivateMethodCall()
        {
            // Arrange
            var translator = new WhereTranslator(_nameChanges);
            Expression<Func<IQueryable<Country>>> query = () => _countries.Where(p => p.Name == GetName());
            var translation = new TranslationResult();

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

            // Assert
            Assert.NotNull(translation.TableQuery);
            Assert.NotNull(translation.TableQuery.FilterString);
            Assert.Equal("RowKey eq 'new name'", translation.TableQuery.FilterString);
        }
Esempio n. 27
0
        public void UseWhereOnBytes()
        {
            // Arrange
            var translator = new WhereTranslator(_nameChanges);
            Expression<Func<IQueryable<Country>>> query = () => _countries.Where(p => p.TopSecretKey == new byte[] {0xff, 0xee, 0xdd});
            var translation = new TranslationResult();

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

            // Assert
            Assert.NotNull(translation.TableQuery);
            Assert.NotNull(translation.TableQuery.FilterString);
            Assert.Equal("TopSecretKey eq X'ffeedd'", translation.TableQuery.FilterString);
        }
Esempio n. 28
0
        public void UseWhereOnDouble()
        {
            // Arrange
            var translator = new WhereTranslator(_nameChanges);
            Expression<Func<IQueryable<Country>>> query = () => _countries.Where(p => p.Area < 350000);
            var translation = new TranslationResult();

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

            // Assert
            Assert.NotNull(translation.TableQuery);
            Assert.NotNull(translation.TableQuery.FilterString);
            Assert.Equal("Area lt 350000.0", translation.TableQuery.FilterString);
        }
        public void AddNegativeTop()
        {
            // Arrange
            var result = new TranslationResult();

            // Act && Assert
            Assert.Throws<ArgumentOutOfRangeException>(() => result.AddTop(-2));
        }
Esempio n. 30
0
        public void WhereWithInvalidMethod()
        {
            // Arrange
            var translator = new WhereTranslator(_nameChanges);
            Expression<Func<IQueryable<Country>>> query = () => _countries.Take(2);
            var translation = new TranslationResult();

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

            // Assert
            Assert.NotNull(translation.TableQuery);
            Assert.Null(translation.TableQuery.FilterString);
        }