public void SingleNavigationNodeHandlesNullEntitySetOnParentNode() { var source = new FakeSingleEntityNode(HardCodedTestModel.GetPersonTypeReference(), null); var node = new SingleNavigationNode(HardCodedTestModel.GetPersonMyDogNavProp(), source); node.NavigationSource.Should().BeNull(); }
public void KindIsEntitySet() { var source = FakeSingleEntityNode.CreateFakeSingleEntityNodeForPerson(); var node = new SingleNavigationNode(HardCodedTestModel.GetPersonMyDogNavProp(), source); node.InternalKind.Should().Be(InternalQueryNodeKind.SingleNavigationNode); }
public void EntitySetIsCalculatedCorrectly() { var source = FakeSingleEntityNode.CreateFakeSingleEntityNodeForPerson(); var node = new SingleNavigationNode(HardCodedTestModel.GetPersonMyDogNavProp(), source); node.NavigationSource.Should().BeSameAs(HardCodedTestModel.GetDogsSet()); }
public override Expression Visit(SingleNavigationNode nodeIn) { Expression source; if (nodeIn.Source is SingleNavigationNode) { source = TranslateNode(nodeIn.Source); } else { source = Parameter; } PropertyInfo propertyInfo = source.Type.GetTypeInfo().GetProperty(nodeIn.NavigationProperty.Name); if (propertyInfo == null) { if (TuplePropertyMapper == null) { throw new InvalidOperationException($"Navigation property {nodeIn.NavigationProperty.Name} not found"); } else { throw new TupleNavigationPropertyException(nodeIn.NavigationProperty); } } return(Expression.Property(source, propertyInfo)); }
public void EnsureParentIsEntityForNavPropReturnsSameObjectAsPassedOnOnSuccess() { var parent = new SingleNavigationNode((IEdmEntitySet)null, HardCodedTestModel.GetPersonMyDogNavProp(), new EdmPathExpression("MyDog")); var result = InnerPathTokenBinder.EnsureParentIsResourceForNavProp(parent); Assert.Same(parent, result); }
public void SourceIsSet() { var source = FakeSingleEntityNode.CreateFakeSingleEntityNodeForPerson(); var node = new SingleNavigationNode(source, HardCodedTestModel.GetPersonMyDogNavProp(), new EdmPathExpression("MyDog")); node.Source.Should().BeSameAs(source); }
public void TypeReferenceIsExactlyFromProperty() { var source = FakeSingleEntityNode.CreateFakeSingleEntityNodeForPerson(); var node = new SingleNavigationNode(source, HardCodedTestModel.GetPersonMyDogNavProp(), new EdmPathExpression("MyDog")); node.TypeReference.Should().BeSameAs(HardCodedTestModel.GetPersonMyDogNavProp().Type); }
public override IEnumerable <string> Visit(SingleNavigationNode nodeIn) { Console.WriteLine("SNN"); return(new[] { Combine(nodeIn.Source, nodeIn.NavigationProperty.Name) }); }
public void EntityTypeIsSameAsType() { var source = FakeSingleEntityNode.CreateFakeSingleEntityNodeForPerson(); var node = new SingleNavigationNode(HardCodedTestModel.GetPersonMyDogNavProp(), source); node.EntityTypeReference.Should().BeSameAs(node.TypeReference); }
public void SourceIsSet() { var source = FakeSingleEntityNode.CreateFakeSingleEntityNodeForPerson(); var node = new SingleNavigationNode(HardCodedTestModel.GetPersonMyDogNavProp(), source); node.Source.Should().BeSameAs(source); }
public void EnsureParentIsEntityForNavPropReturnsSameObjectAsPassedOnOnSuccess() { var parent = new SingleNavigationNode(HardCodedTestModel.GetPersonMyDogNavProp(), (IEdmEntitySet)null); var result = InnerPathTokenBinder.EnsureParentIsEntityForNavProp(parent); result.Should().BeSameAs(parent); }
public override SingleValueNode Visit(SingleValuePropertyAccessNode nodeIn) { if (nodeIn.Source != null) { if (nodeIn.Source.Kind == QueryNodeKind.SingleNavigationNode) { SingleNavigationNode singleNavigationNode = nodeIn.Source as SingleNavigationNode; if (EdmLibHelpers.IsNotSortable(nodeIn.Property, singleNavigationNode.NavigationProperty, singleNavigationNode.NavigationProperty.ToEntityType(), _model, _enableOrderBy)) { return(nodeIn); } } else if (nodeIn.Source.Kind == QueryNodeKind.SingleComplexNode) { SingleComplexNode singleComplexNode = nodeIn.Source as SingleComplexNode; if (EdmLibHelpers.IsNotSortable(nodeIn.Property, singleComplexNode.Property, nodeIn.Property.DeclaringType, _model, _enableOrderBy)) { return(nodeIn); } } else if (EdmLibHelpers.IsNotSortable(nodeIn.Property, _property, _structuredType, _model, _enableOrderBy)) { return(nodeIn); } } if (nodeIn.Source != null) { return(nodeIn.Source.Accept(this)); } return(null); }
public void KindIsEntitySet() { var source = FakeSingleEntityNode.CreateFakeSingleEntityNodeForPerson(); var node = new SingleNavigationNode(source, HardCodedTestModel.GetPersonMyDogNavProp(), new EdmPathExpression("MyDog")); Assert.Equal(InternalQueryNodeKind.SingleNavigationNode, node.InternalKind); }
public void SingleNavigationNodeHandlesNullEntitySetOnParentNode() { var source = new FakeSingleEntityNode(HardCodedTestModel.GetPersonTypeReference(), null); var node = new SingleNavigationNode(source, HardCodedTestModel.GetPersonMyDogNavProp(), new EdmPathExpression("MyDog")); Assert.Null(node.NavigationSource); }
public void EntitySetIsCalculatedCorrectly() { var source = FakeSingleEntityNode.CreateFakeSingleEntityNodeForPerson(); var node = new SingleNavigationNode(source, HardCodedTestModel.GetPersonMyDogNavProp(), new EdmPathExpression("MyDog")); Assert.Same(node.NavigationSource, HardCodedTestModel.GetDogsSet()); }
/// <summary> /// Visit a SingleNavigationNode /// </summary> /// <param name="nodeIn">the node to visit</param> /// <returns>true, indicating that the node has been visited.</returns> public override bool Visit(SingleNavigationNode nodeIn) { validate(nodeIn); validate(nodeIn.NavigationProperty); validate(nodeIn.TypeReference.Definition); return(true); }
public override Expression Visit(SingleNavigationNode nodeIn) { Expression source; if (nodeIn.Source is SingleNavigationNode singleNavigationNode) { source = Visit(singleNavigationNode); if (source == null) { return(null); } } else { source = Parameter; } PropertyInfo propertyInfo = source.Type.GetPropertyIgnoreCase(nodeIn.NavigationProperty); if (propertyInfo == null) { return(null); } return(Expression.Property(source, propertyInfo)); }
public void EntityTypeIsSameAsType() { var source = FakeSingleEntityNode.CreateFakeSingleEntityNodeForPerson(); var node = new SingleNavigationNode(source, HardCodedTestModel.GetPersonMyDogNavProp(), new EdmPathExpression("MyDog")); Assert.Same(node.EntityTypeReference, node.TypeReference); }
public void TypeReferenceIsExactlyFromProperty() { var source = FakeSingleEntityNode.CreateFakeSingleEntityNodeForPerson(); var node = new SingleNavigationNode(HardCodedTestModel.GetPersonMyDogNavProp(), source); node.TypeReference.Should().BeSameAs(HardCodedTestModel.GetPersonMyDogNavProp().Type); }
protected string Bind(QueryNode node) { CollectionNode collectionNode = node as CollectionNode; SingleValueNode singleValueNode = node as SingleValueNode; if (collectionNode != null) { switch (node.Kind) { case QueryNodeKind.CollectionNavigationNode: CollectionNavigationNode navigationNode = node as CollectionNavigationNode; return(BindNavigationPropertyNode(navigationNode.Source, navigationNode.NavigationProperty)); case QueryNodeKind.CollectionPropertyAccess: return(BindCollectionPropertyAccessNode(node as CollectionPropertyAccessNode)); } } else if (singleValueNode != null) { switch (node.Kind) { case QueryNodeKind.BinaryOperator: return(BindBinaryOperatorNode(node as BinaryOperatorNode)); case QueryNodeKind.Constant: return(BindConstantNode(node as ConstantNode)); case QueryNodeKind.Convert: return(BindConvertNode(node as ConvertNode)); case QueryNodeKind.EntityRangeVariableReference: return(BindRangeVariable((node as EntityRangeVariableReferenceNode).RangeVariable)); case QueryNodeKind.NonentityRangeVariableReference: return(BindRangeVariable((node as NonentityRangeVariableReferenceNode).RangeVariable)); case QueryNodeKind.SingleValuePropertyAccess: return(BindPropertyAccessQueryNode(node as SingleValuePropertyAccessNode)); case QueryNodeKind.UnaryOperator: return(BindUnaryOperatorNode(node as UnaryOperatorNode)); case QueryNodeKind.SingleValueFunctionCall: return(BindSingleValueFunctionCallNode(node as SingleValueFunctionCallNode)); case QueryNodeKind.SingleNavigationNode: SingleNavigationNode navigationNode = node as SingleNavigationNode; return(BindNavigationPropertyNode(navigationNode.Source, navigationNode.NavigationProperty)); case QueryNodeKind.Any: return(BindAnyNode(node as AnyNode)); case QueryNodeKind.All: return(BindAllNode(node as AllNode)); } } throw new NotSupportedException(String.Format("Nodes of type {0} are not supported", node.Kind)); }
/// <summary> /// We return the <see cref="ResourceRangeVariableReferenceNode"/> within a <see cref="QueryNode"/> /// </summary> /// <param name="node">The node to extract the ResourceRangeVariableReferenceNode.</param> /// <returns>The extracted ResourceRangeVariableReferenceNode.</returns> private ResourceRangeVariableReferenceNode GetResourceRangeVariableReferenceNode(QueryNode node) { if (node == null) { return(null); } switch (node.Kind) { case QueryNodeKind.SingleValuePropertyAccess: SingleValuePropertyAccessNode singleValuePropertyAccessNode = node as SingleValuePropertyAccessNode; return(GetResourceRangeVariableReferenceNode(singleValuePropertyAccessNode.Source)); case QueryNodeKind.Convert: ConvertNode convertNode = node as ConvertNode; return(GetResourceRangeVariableReferenceNode(convertNode.Source)); case QueryNodeKind.Any: AnyNode anyNode = node as AnyNode; return(GetResourceRangeVariableReferenceNode(anyNode.Source)); case QueryNodeKind.SingleValueFunctionCall: SingleValueFunctionCallNode singleValueFunctionCallNode = node as SingleValueFunctionCallNode; return(GetResourceRangeVariableReferenceNode(singleValueFunctionCallNode.Parameters.First())); case QueryNodeKind.ResourceRangeVariableReference: return(node as ResourceRangeVariableReferenceNode); case QueryNodeKind.SingleValueOpenPropertyAccess: SingleValueOpenPropertyAccessNode singleValueOpenPropertyAccessNode = node as SingleValueOpenPropertyAccessNode; return(GetResourceRangeVariableReferenceNode(singleValueOpenPropertyAccessNode.Source)); case QueryNodeKind.SingleComplexNode: SingleComplexNode singleComplexNode = node as SingleComplexNode; return(GetResourceRangeVariableReferenceNode(singleComplexNode.Source)); case QueryNodeKind.CollectionComplexNode: CollectionComplexNode collectionComplexNode = node as CollectionComplexNode; return(GetResourceRangeVariableReferenceNode(collectionComplexNode.Source)); case QueryNodeKind.CollectionNavigationNode: CollectionNavigationNode collectionNavigationNode = node as CollectionNavigationNode; return(GetResourceRangeVariableReferenceNode(collectionNavigationNode.Source)); case QueryNodeKind.SingleNavigationNode: SingleNavigationNode singleNavigationNode = node as SingleNavigationNode; return(GetResourceRangeVariableReferenceNode(singleNavigationNode.Source)); case QueryNodeKind.CollectionResourceFunctionCall: CollectionResourceFunctionCallNode collectionResourceFunctionCallNode = node as CollectionResourceFunctionCallNode; return(GetResourceRangeVariableReferenceNode(collectionResourceFunctionCallNode.Source)); case QueryNodeKind.SingleResourceFunctionCall: SingleResourceFunctionCallNode singleResourceFunctionCallNode = node as SingleResourceFunctionCallNode; return(GetResourceRangeVariableReferenceNode(singleResourceFunctionCallNode.Source)); } return(null); }
/// <summary> /// Translate a SingleNavigationNode. /// </summary> /// <param name="nodeIn">The node to be translated.</param> /// <returns>The translated node.</returns> public override QueryNode Visit(SingleNavigationNode nodeIn) { return(nodeIn.Source == null ? nodeIn : new SingleNavigationNode( nodeIn.NavigationProperty, (SingleEntityNode)nodeIn.Source.Accept(this))); }
public override int Visit(SingleNavigationNode nodeIn) { if (nodeIn.Source is SingleNavigationNode sourceNode) { return(sourceNode.NavigationProperty.Name.GetHashCode()); } return(TranslateNode(nodeIn.Source)); }
/// <summary> /// Translate a SingleNavigationNode. /// </summary> /// <param name="nodeIn">The node to be translated.</param> /// <returns>The translated node.</returns> public override QueryNode Visit(SingleNavigationNode nodeIn) { return(nodeIn.Source == null ? nodeIn : new SingleNavigationNode( (SingleResourceNode)nodeIn.Source.Accept(this), nodeIn.NavigationProperty, nodeIn.BindingPath ?? new EdmPathExpression(nodeIn.NavigationProperty.Name))); }
public void ODataUriBuilderWithKeyAsSegment() { Uri fullUri = new Uri("http://www.example.com/People/1?$filter=MyDog%2FColor%20eq%20%27Brown%27&$select=ID&$expand=MyDog&$top=1&$skip=2&$count=false"); ODataUriParser oDataUriParser = new ODataUriParser(this.GetModel(), serviceRoot, fullUri); oDataUriParser.UrlConventions = ODataUrlConventions.KeyAsSegment; SetODataUriParserSettingsTo(this.settings, oDataUriParser.Settings); ODataUri odataUri = oDataUriParser.ParseUri(); //verify path EntitySetSegment entitySet = (EntitySetSegment)odataUri.Path.FirstSegment; KeySegment keySegment = (KeySegment)odataUri.Path.LastSegment; IEnumerable <KeyValuePair <string, object> > keyValuePairs = keySegment.Keys; Assert.AreEqual(odataUri.Path.Count, 2); Assert.AreEqual(entitySet.EntitySet.Name, "People"); foreach (var keyValuePair in keyValuePairs) { Assert.AreEqual(keyValuePair.Key, "ID"); Assert.AreEqual(keyValuePair.Value, 1); } //verify $filter BinaryOperatorNode binaryOperator = (BinaryOperatorNode)odataUri.Filter.Expression; SingleValuePropertyAccessNode singleValueProperty = (SingleValuePropertyAccessNode)binaryOperator.Left; SingleNavigationNode singleNavigation = (SingleNavigationNode)singleValueProperty.Source; ConstantNode constantNode = (ConstantNode)binaryOperator.Right; Assert.AreEqual(binaryOperator.OperatorKind, BinaryOperatorKind.Equal); Assert.AreEqual(singleValueProperty.Property.Name, "Color"); Assert.AreEqual(singleNavigation.NavigationProperty.Name, "MyDog"); Assert.AreEqual(constantNode.LiteralText, "'Brown'"); //verify $select and $expand IEnumerable <SelectItem> selectItems = odataUri.SelectAndExpand.SelectedItems; foreach (ExpandedNavigationSelectItem selectItem in selectItems) { NavigationPropertySegment navigationProperty = (NavigationPropertySegment)selectItem.PathToNavigationProperty.FirstSegment; Assert.AreEqual(navigationProperty.NavigationProperty.Name, "MyDog"); break; } //verify $top Assert.AreEqual(odataUri.Top, 1); //verify $skip Assert.AreEqual(odataUri.Skip, 2); //verify $count Assert.AreEqual(odataUri.QueryCount, false); ODataUriBuilder uriBuilderWithKeyAsSegment = new ODataUriBuilder(ODataUrlConventions.KeyAsSegment, odataUri); Uri actualUri = uriBuilderWithKeyAsSegment.BuildUri(); Assert.AreEqual(new Uri("http://www.example.com/People/1?$filter=MyDog%2FColor%20eq%20%27Brown%27&$select=ID%2CMyDog&$expand=MyDog&$top=1&$skip=2&$count=false"), actualUri); }
public override QueryNode Visit(SingleNavigationNode nodeIn) { SingleResourceNode?source = nodeIn.Source == null ? null : (SingleResourceNode)Visit(nodeIn.Source); if (nodeIn.Source != source) { nodeIn = new SingleNavigationNode(source, nodeIn.NavigationProperty, nodeIn.BindingPath); } return(nodeIn); }
/// <summary> /// The recursive method that validate most of the query node type is of SingleValueNode type. /// </summary> /// <param name="node"></param> /// <param name="settings"></param> private void ValidateSingleValueNode(SingleValueNode node, ODataValidationSettings settings) { switch (node.Kind) { case QueryNodeKind.BinaryOperator: ValidateBinaryOperatorNode(node as BinaryOperatorNode, settings); break; case QueryNodeKind.Constant: ValidateConstantNode(node as ConstantNode, settings); break; case QueryNodeKind.Convert: ValidateConvertNode(node as ConvertNode, settings); break; case QueryNodeKind.EntityRangeVariableReference: ValidateRangeVariable((node as EntityRangeVariableReferenceNode).RangeVariable, settings); break; case QueryNodeKind.NonentityRangeVariableReference: ValidateRangeVariable((node as NonentityRangeVariableReferenceNode).RangeVariable, settings); break; case QueryNodeKind.SingleValuePropertyAccess: ValidateSingleValuePropertyAccessNode(node as SingleValuePropertyAccessNode, settings); break; case QueryNodeKind.UnaryOperator: ValidateUnaryOperatorNode(node as UnaryOperatorNode, settings); break; case QueryNodeKind.SingleValueFunctionCall: ValidateSingleValueFunctionCallNode(node as SingleValueFunctionCallNode, settings); break; case QueryNodeKind.SingleNavigationNode: SingleNavigationNode navigationNode = node as SingleNavigationNode; ValidateNavigationPropertyNode(navigationNode.Source, navigationNode.NavigationProperty, settings); break; case QueryNodeKind.SingleEntityCast: ValidateSingleEntityCastNode(node as SingleEntityCastNode, settings); break; case QueryNodeKind.Any: ValidateAnyNode(node as AnyNode, settings); break; case QueryNodeKind.All: ValidateAllNode(node as AllNode, settings); break; } }
public override int Visit(SingleNavigationNode nodeIn) { var sourceNode = nodeIn.Source as SingleNavigationNode; if (sourceNode != null) { return(sourceNode.NavigationProperty.Name.GetHashCode()); } return(TranslateNode(nodeIn.Source)); }
public override SingleValueNode Visit(SingleNavigationNode nodeIn) { if (EdmLibHelpers.IsNotSortable(nodeIn.NavigationProperty, _model)) { return(nodeIn); } if (nodeIn.Source != null) { return(nodeIn.Source.Accept(this)); } return(null); }
/// <summary> /// The recursive method that validate most of the query node type is of SingleValueNode type. /// </summary> /// <param name="node"></param> /// <param name="settings"></param> private void ValidateSingleValueNode(SingleValueNode node, ODataValidationSettings settings) { switch (node.Kind) { case QueryNodeKind.BinaryOperator: ValidateBinaryOperatorNode(node as BinaryOperatorNode, settings); break; case QueryNodeKind.Constant: ValidateConstantNode(node as ConstantNode, settings); break; case QueryNodeKind.Convert: ValidateConvertNode(node as ConvertNode, settings); break; case QueryNodeKind.EntityRangeVariableReference: ValidateRangeVariable((node as EntityRangeVariableReferenceNode).RangeVariable, settings); break; case QueryNodeKind.NonentityRangeVariableReference: ValidateRangeVariable((node as NonentityRangeVariableReferenceNode).RangeVariable, settings); break; case QueryNodeKind.SingleValuePropertyAccess: ValidateSingleValuePropertyAccessNode(node as SingleValuePropertyAccessNode, settings); break; case QueryNodeKind.UnaryOperator: ValidateUnaryOperatorNode(node as UnaryOperatorNode, settings); break; case QueryNodeKind.SingleValueFunctionCall: ValidateSingleValueFunctionCallNode(node as SingleValueFunctionCallNode, settings); break; case QueryNodeKind.SingleNavigationNode: SingleNavigationNode navigationNode = node as SingleNavigationNode; ValidateNavigationPropertyNode(navigationNode.Source, navigationNode.NavigationProperty, settings); break; case QueryNodeKind.Any: ValidateAnyNode(node as AnyNode, settings); break; case QueryNodeKind.All: ValidateAllNode(node as AllNode, settings); break; default: throw new ODataException(Error.Format(SRResources.QueryNodeBindingNotSupported, node.Kind, typeof(FilterQueryValidator).Name)); } }
private static List <string> GetReferencePath(this List <string> list, SingleNavigationNode navigationNode) { switch (navigationNode.Source) { case SingleNavigationNode sourceNode: list.GetReferencePath(sourceNode); list.AddRange(navigationNode.BindingPath.PathSegments); return(list); default: list.AddRange(navigationNode.BindingPath.PathSegments); return(list); } }
/// <summary> /// Translate a SingleNavigationNode. /// </summary> /// <param name="nodeIn">The node to be translated.</param> /// <returns>The translated node.</returns> public override QueryNode Visit(SingleNavigationNode nodeIn) { if (nodeIn == null) { throw Error.ArgumentNull(nameof(nodeIn)); } return(nodeIn.Source == null ? nodeIn : new SingleNavigationNode( (SingleResourceNode)nodeIn.Source.Accept(this), nodeIn.NavigationProperty, nodeIn.BindingPath ?? new EdmPathExpression(nodeIn.NavigationProperty.Name))); }
private static void BuildOrderBy() { var productTypeRef = new EdmEntityTypeReference(V4Model.Product, false); var supplierProperty = (IEdmNavigationProperty)V4Model.Product.FindProperty("Supplier"); var nameProperty = V4Model.Supplier.FindProperty("Name"); var topIt = new EntityRangeVariable("$it", productTypeRef, V4Model.ProductsSet); var topItRef = new EntityRangeVariableReferenceNode("$it", topIt); var supplierNavNode = new SingleNavigationNode(supplierProperty, topItRef); var nameNode = new SingleValuePropertyAccessNode(supplierNavNode, nameProperty); var orderby = new OrderByClause(null, nameNode, OrderByDirection.Ascending, topIt); var odataUri = new ODataUri { Path = new ODataPath(new EntitySetSegment(V4Model.ProductsSet)), ServiceRoot = V4Root, OrderBy = orderby }; var builder = new ODataUriBuilder(ODataUrlConventions.Default, odataUri); Console.WriteLine(builder.BuildUri()); // http://services.odata.org/V4/OData/OData.svc/Products?$orderby=Supplier%2FName }
/// <summary> /// Write single navigation node to string. /// </summary> /// <param name="node">Node to write to string</param> /// <returns>String representation of node.</returns> private static string ToString(SingleNavigationNode node) { if (node != null) { return tabHelper.Prefix + "SingleNavigationNode" + tabHelper.Indent(() => tabHelper.Prefix + "NavigationSource = " + node.NavigationSource.Name + tabHelper.Prefix + "Type Reference = " + node.EntityTypeReference + tabHelper.Prefix + "Property = " + node.NavigationProperty.Name + tabHelper.Prefix + "Multiplicity = " + node.TargetMultiplicity + tabHelper.Prefix + "Source = " + ToString(node.Source) ); } return String.Empty; }
public void SingleNavigationNodeHandlesNullSourceSetParameter() { var node = new SingleNavigationNode(HardCodedTestModel.GetPersonMyDogNavProp(), (IEdmEntitySet)null); node.NavigationSource.Should().BeNull(); }
/// <summary> /// Compares single navigation nodes. /// </summary> /// <param name="left">Left side of comparison</param> /// <param name="right">Right side of comparison</param> /// <returns>True if equal, otherwise false</returns> private bool Compare(SingleNavigationNode left, SingleNavigationNode right) { if (left.NavigationSource != right.NavigationSource) return false; if (left.EntityTypeReference != right.EntityTypeReference) return false; if (left.NavigationProperty != right.NavigationProperty) return false; if (left.TargetMultiplicity != right.TargetMultiplicity) return false; if (left.TypeReference != right.TypeReference) return false; return this.Compare(left.Source, right.Source); }