public void PushingANewParameterExpressionResetsTheBasePath() { SelectExpandPathBuilder pathBuilder = new SelectExpandPathBuilder(); ParameterExpression pe1 = Expression.Parameter(typeof(TestEntity), "pe1"); ParameterExpression pe2 = Expression.Parameter(typeof(SubTestEntity1), "pe2"); PropertyInfo navPropInfo = typeof(TestEntity).GetProperties().Single(x => x.Name == "NavProp1"); PropertyInfo subNavPropInfo = typeof(SubTestEntity1).GetProperties().Single(x => x.Name == "NavProp3"); PropertyInfo subTestProperty = typeof(SubTestEntity2).GetProperties().Single(); pathBuilder.PushParamExpression(pe1); pathBuilder.StartNewPath(); pathBuilder.AppendPropertyToPath(navPropInfo, null, dsc); pathBuilder.AppendPropertyToPath(subNavPropInfo, null, dsc); pathBuilder.PushParamExpression(pe2); pathBuilder.StartNewPath(); pathBuilder.AppendPropertyToPath(subTestProperty, null, dsc); pathBuilder.ExpandPaths.Single().Should().Be("NavProp1($expand=NavProp3($select=SubTestProperty))"); }
public void SingleExpansionBecomesExpand() { SelectExpandPathBuilder pathBuilder = new SelectExpandPathBuilder(); ParameterExpression pe = Expression.Parameter((typeof(TestEntity))); pathBuilder.PushParamExpression(pe); PropertyInfo navPropPropertyInfo = typeof(TestEntity).GetProperties().Single(x => x.PropertyType == typeof(SubTestEntity1)); pathBuilder.StartNewPath(); pathBuilder.AppendPropertyToPath(navPropPropertyInfo, null, dsc); pathBuilder.ExpandPaths.Single().Should().Be("NavProp1"); }
public void SingleProjectionBecomesSelect() { PropertyInfo testProperty1Info = typeof(TestEntity).GetProperties().Single(x => x.Name == "TestProperty1"); SelectExpandPathBuilder pathBuilder = new SelectExpandPathBuilder(); ParameterExpression pe = Expression.Parameter(typeof(TestEntity)); pathBuilder.PushParamExpression(pe); pathBuilder.StartNewPath(); pathBuilder.AppendPropertyToPath(testProperty1Info, null, this.dsc); pathBuilder.ProjectionPaths.Single().Should().Be("TestProperty1"); }
public void TypeIsPrePendedAsATypeSegment() { SelectExpandPathBuilder pathBuilder = new SelectExpandPathBuilder(); ParameterExpression pe = Expression.Parameter(typeof(TestEntity)); PropertyInfo testProperty1Info = typeof(TestEntity).GetProperties().Single(x => x.Name == "TestProperty1"); pathBuilder.PushParamExpression(pe); pathBuilder.StartNewPath(); pathBuilder.AppendPropertyToPath(testProperty1Info, typeof(TestEntity), dsc); pathBuilder.ProjectionPaths.Single().Should().Be("Microsoft.OData.Client.Tests.ALinq.SelectExpandPathBuilderTests+TestEntity/TestProperty1"); }
public void ExpansionThroughMultipleNavPropsIsExpressedAsExpandOptions() { SelectExpandPathBuilder pathBuilder = new SelectExpandPathBuilder(); ParameterExpression pe = Expression.Parameter(typeof(TestEntity)); PropertyInfo navPropInfo = typeof(TestEntity).GetProperties().Single(x => x.Name == "NavProp1"); PropertyInfo subNavPropInfo = typeof(SubTestEntity1).GetProperties().Single(x => x.Name == "NavProp3"); pathBuilder.PushParamExpression(pe); pathBuilder.StartNewPath(); pathBuilder.AppendPropertyToPath(navPropInfo, null, dsc); pathBuilder.AppendPropertyToPath(subNavPropInfo, null, dsc); pathBuilder.ExpandPaths.Single().Should().Be("NavProp1($expand=NavProp3)"); }
public void ProjectionThroughMultipleNavPropsBecomeExpandOptions() { SelectExpandPathBuilder pathBuilder = new SelectExpandPathBuilder(); ParameterExpression pe = Expression.Parameter(typeof(TestEntity)); PropertyInfo subTestEntityProperty = typeof(SubTestEntity1).GetProperties().Single(x => x.Name == "SubTestProperty"); PropertyInfo navPropInfo = typeof(TestEntity).GetProperties().Single(x => x.Name == "NavProp1"); pathBuilder.PushParamExpression(pe); pathBuilder.StartNewPath(); pathBuilder.AppendPropertyToPath(navPropInfo, null, dsc); pathBuilder.AppendPropertyToPath(subTestEntityProperty, null, dsc); Assert.Equal("NavProp1($select=SubTestProperty)", pathBuilder.ExpandPaths.Single()); }
public void MultipleSingleLevelExpansionsBecomeExpandClauses() { SelectExpandPathBuilder pathBuilder = new SelectExpandPathBuilder(); ParameterExpression pe = Expression.Parameter(typeof(TestEntity)); pathBuilder.PushParamExpression(pe); foreach (PropertyInfo propertyInfo in typeof(TestEntity).GetProperties().Where(x => x.PropertyType != typeof(string))) { pathBuilder.StartNewPath(); pathBuilder.AppendPropertyToPath(propertyInfo, null, dsc); } pathBuilder.ExpandPaths.Should().HaveCount(2); pathBuilder.ExpandPaths.Should().Contain(x => x == "NavProp1") .And.Contain(x => x == "NavProp2"); }
public void SelectingLowerLevelPropertyIsTranslatedIntoExpandOption() { SelectExpandPathBuilder pathBuilder = new SelectExpandPathBuilder(); ParameterExpression pe = Expression.Parameter(typeof(TestEntity)); PropertyInfo navPropInfo = typeof(TestEntity).GetProperties().Single(x => x.Name == "NavProp1"); PropertyInfo subNavPropInfo = typeof(SubTestEntity1).GetProperties().Single(x => x.Name == "NavProp3"); PropertyInfo subTestProperty = typeof(SubTestEntity2).GetProperties().Single(); pathBuilder.PushParamExpression(pe); pathBuilder.StartNewPath(); pathBuilder.AppendPropertyToPath(navPropInfo, null, dsc); pathBuilder.AppendPropertyToPath(subNavPropInfo, null, dsc); pathBuilder.AppendPropertyToPath(subTestProperty, null, dsc); pathBuilder.ExpandPaths.Single().Should().Be("NavProp1($expand=NavProp3($select=SubTestProperty))"); }
public void MultipleSingleLevelProjectionsBecomeSelectClauses() { SelectExpandPathBuilder pathBuilder = new SelectExpandPathBuilder(); ParameterExpression pe = Expression.Parameter(typeof(TestEntity)); pathBuilder.PushParamExpression(pe); foreach (PropertyInfo propertyInfo in typeof(TestEntity).GetProperties().Where(x => x.PropertyType == typeof(string))) { pathBuilder.StartNewPath(); pathBuilder.AppendPropertyToPath(propertyInfo, null, this.dsc); } Assert.Equal(2, pathBuilder.ProjectionPaths.Count()); Assert.Contains("TestProperty1", pathBuilder.ProjectionPaths); Assert.Contains("TestProperty2", pathBuilder.ProjectionPaths); }
private static void Analyze(LambdaExpression e, SelectExpandPathBuilder pb, DataServiceContext context) { bool knownEntityType = ClientTypeUtil.TypeOrElementTypeIsEntity(e.Body.Type); ParameterExpression pe = e.Parameters.Last(); bool isEntityParameter = ClientTypeUtil.TypeOrElementTypeIsEntity(pe.Type); if (isEntityParameter) { pb.PushParamExpression(pe); } if (!knownEntityType) { NonEntityProjectionAnalyzer.Analyze(e.Body, pb, context); } else { switch (e.Body.NodeType) { case ExpressionType.MemberInit: EntityProjectionAnalyzer.Analyze((MemberInitExpression)e.Body, pb, context); break; case ExpressionType.New: throw new NotSupportedException(Strings.ALinq_CannotConstructKnownEntityTypes); case ExpressionType.Constant: throw new NotSupportedException(Strings.ALinq_CannotCreateConstantEntity); default: // ExpressionType.MemberAccess as a top-level expression is correctly // processed here, as the lambda isn't being member-initialized. NonEntityProjectionAnalyzer.Analyze(e.Body, pb, context); break; } } if (isEntityParameter) { pb.PopParamExpression(); } }
public void ProjectionThroughMultipleNavPropsBecomeExpandOptions() { SelectExpandPathBuilder pathBuilder = new SelectExpandPathBuilder(); ParameterExpression pe = Expression.Parameter(typeof(TestEntity)); PropertyInfo subTestEntityProperty = typeof(SubTestEntity1).GetProperties().Single(x => x.Name == "SubTestProperty"); PropertyInfo navPropInfo = typeof(TestEntity).GetProperties().Single(x => x.Name == "NavProp1"); pathBuilder.PushParamExpression(pe); pathBuilder.StartNewPath(); pathBuilder.AppendPropertyToPath(navPropInfo, null, dsc); pathBuilder.AppendPropertyToPath(subTestEntityProperty, null, dsc); pathBuilder.ExpandPaths.Single().Should().Be("NavProp1($select=SubTestProperty)"); }