Exemplo n.º 1
0
        public void LinqSelectWithPrivateProjectionClass()
        {
            // Arrange
            IQueryable <InternalProjectionResult> query = GetQueryable()
                                                          .Select(p => new InternalProjectionResult {
                Name = p.Name, Continent = p.Continent
            });
            var translator  = new SelectTranslator(_nameChanges);
            var translation = new TranslationResult();

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

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

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

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

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

            Assert.Contains(Germany, names);
            Assert.Contains(Spain, names);
        }
Exemplo n.º 2
0
        public void LinqSelectWithInvalidMethod()
        {
            // Arrange
            IQueryable <Country> query = GetQueryable().Where(p => p.Name == string.Empty);
            var translator             = new SelectTranslator(_nameChanges);
            var translation            = new TranslationResult();

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

            Assert.NotNull(translation.TableQuery);
            Assert.Null(translation.TableQuery.SelectColumns);
        }
Exemplo n.º 3
0
        public void LinqSelectWithAnonymousType()
        {
            // Arrange
            var query       = GetQueryable().Select(p => new { p.Name, p.Continent });
            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(2, translation.TableQuery.SelectColumns.Count);
            Assert.Contains("PartitionKey", translation.TableQuery.SelectColumns);
            Assert.Contains("RowKey", translation.TableQuery.SelectColumns);

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

            Assert.NotNull(result);
            Assert.IsAssignableFrom <IEnumerable <object> >(result);
        }