/// <summary>
        /// Binds a <see cref="CollectionPropertyAccessNode"/> to create a LINQ <see cref="Expression"/> that
        /// represents the semantics of the <see cref="CollectionPropertyAccessNode"/>.
        /// </summary>
        /// <param name="propertyAccessNode">The node to bind.</param>
        /// <returns>The LINQ <see cref="Expression"/> created.</returns>
        public virtual Expression BindCollectionPropertyAccessNode(CollectionPropertyAccessNode propertyAccessNode)
        {
            if (propertyAccessNode == null)
            {
                throw Error.ArgumentNull(nameof(propertyAccessNode));
            }

            Expression source = Bind(propertyAccessNode.Source);

            return(CreatePropertyAccessExpression(source, propertyAccessNode.Property));
        }
 /// <summary>
 /// Compares Collection Property Access query 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(CollectionPropertyAccessNode left, CollectionPropertyAccessNode right)
 {
     if (left.Property != right.Property)
     {
         return(false);
     }
     if (left.ItemType != right.ItemType)
     {
         return(false);
     }
     return(this.Compare(left.Source, right.Source));
 }
        private void ValidateCollectionNode(CollectionNode node, ODataValidationSettings settings)
        {
            switch (node.Kind)
            {
            case QueryNodeKind.CollectionPropertyAccess:
                CollectionPropertyAccessNode propertyAccessNode = node as CollectionPropertyAccessNode;
                ValidateCollectionPropertyAccessNode(propertyAccessNode, settings);
                break;

            case QueryNodeKind.CollectionNavigationNode:
                CollectionNavigationNode navigationNode = node as CollectionNavigationNode;
                ValidateNavigationPropertyNode(navigationNode.Source, navigationNode.NavigationProperty, settings);
                break;
            }
        }
        /// <summary>
        /// Override this method to validate collection property accessor.
        /// </summary>
        /// <remarks>
        /// This method is intended to be called from method overrides in subclasses. This method also supports unit-testing scenarios and is not intended to be called from user code.
        /// Call the Validate method to validate a <see cref="FilterQueryOption"/> instance.
        /// </remarks>
        /// <param name="propertyAccessNode"></param>
        /// <param name="settings"></param>
        public virtual void ValidateCollectionPropertyAccessNode(CollectionPropertyAccessNode propertyAccessNode, ODataValidationSettings settings)
        {
            if (propertyAccessNode == null)
            {
                throw Error.ArgumentNull("propertyAccessNode");
            }

            if (settings == null)
            {
                throw Error.ArgumentNull("settings");
            }

            // no default validation logic here
            ValidateQueryNode(propertyAccessNode.Source, settings);
        }
Beispiel #5
0
        /// <summary>
        /// Override this method to validate collection property accessor.
        /// </summary>
        /// <remarks>
        /// This method is intended to be called from method overrides in subclasses. This method also supports unit-testing scenarios and is not intended to be called from user code.
        /// Call the Validate method to validate a <see cref="FilterQueryOption"/> instance.
        /// </remarks>
        /// <param name="propertyAccessNode"></param>
        /// <param name="settings"></param>
        protected virtual void ValidateCollectionPropertyAccessNode(CollectionPropertyAccessNode propertyAccessNode, ODataValidationSettings settings)
        {
            Contract.Assert(propertyAccessNode != null);
            Contract.Assert(settings != null);

            // Check whether the property is filterable.
            IEdmProperty property = propertyAccessNode.Property;

            if (EdmHelpers.IsNotFilterable(property, _property, _structuredType, _model,
                                           _defaultQuerySettings.EnableFilter))
            {
                throw new ODataException(Error.Format(SRResources.NotFilterablePropertyUsedInFilter, property.Name));
            }

            ValidateQueryNode(propertyAccessNode.Source, settings);
        }
Beispiel #6
0
        private void TestProperty <TParam, TReturn>(SingleValueNode source, IEdmProperty property, Expression <Func <TParam, TReturn> > expectedExpression)
        {
            QueryNode node;

            if (property.Type.IsCollection())
            {
                node = new CollectionPropertyAccessNode(source, property);
            }
            else
            {
                node = new SingleValuePropertyAccessNode(source, property);
            }

            var result = this.testSubject.TranslateNode(node);

            CompareExpressions(expectedExpression.Body, result);
        }
Beispiel #7
0
        public override void ValidateCollectionPropertyAccessNode(
            CollectionPropertyAccessNode collectionPropertyAccessNode,
            ODataValidationSettings settings)
        {
            string propertyName = null;

            if (collectionPropertyAccessNode != null)
            {
                propertyName = collectionPropertyAccessNode.Property.Name;
            }

            if (propertyName != null && !allowedProperties.Contains(propertyName))
            {
                throw new ODataException(
                          String.Format("Filter on {0} not allowed", propertyName));
            }
            base.ValidateCollectionPropertyAccessNode(collectionPropertyAccessNode, settings);
        }
Beispiel #8
0
        /// <summary>
        /// Override this method to validate collection property accessor.
        /// </summary>
        /// <remarks>
        /// This method is intended to be called from method overrides in subclasses. This method also supports unit-testing scenarios and is not intended to be called from user code.
        /// Call the Validate method to validate a <see cref="FilterQueryOption"/> instance.
        /// </remarks>
        /// <param name="propertyAccessNode"></param>
        /// <param name="settings"></param>
        public virtual void ValidateCollectionPropertyAccessNode(CollectionPropertyAccessNode propertyAccessNode, ODataValidationSettings settings)
        {
            if (propertyAccessNode == null)
            {
                throw Error.ArgumentNull("propertyAccessNode");
            }

            if (settings == null)
            {
                throw Error.ArgumentNull("settings");
            }

            // Check whether the property is filterable.
            IEdmProperty property = propertyAccessNode.Property;

            if (EdmLibHelpers.IsNotFilterable(property, _model))
            {
                throw new ODataException(Error.Format(SRResources.NotFilterablePropertyUsedInFilter, property.Name));
            }

            ValidateQueryNode(propertyAccessNode.Source, settings);
        }
Beispiel #9
0
 /// <summary>
 /// BGs, DCs are examples of CollectionPropertyAccessNode
 /// </summary>
 private string TranslateCollectionPropertyAccessNode(CollectionPropertyAccessNode collectionPropertyAccessNode)
 {
     return(Translate(collectionPropertyAccessNode.Source) + "." + collectionPropertyAccessNode.Property.Name);
 }
 /// <summary>
 /// Translates a <see cref="CollectionPropertyAccessNode"/> into a corresponding <see cref="string"/>.
 /// </summary>
 /// <param name="node">The node to translate.</param>
 /// <returns>The translated string.</returns>
 public override string Visit(CollectionPropertyAccessNode node)
 {
     return(this.TranslatePropertyAccess(node.Source, node.Property.Name));
 }
 public override void ValidateCollectionPropertyAccessNode(CollectionPropertyAccessNode propertyAccessNode, ODataValidationSettings settings)
 {
     IncrementCount("ValidateCollectionPropertyAccessNode");
     base.ValidateCollectionPropertyAccessNode(propertyAccessNode, settings);
 }
 /// <summary>
 /// Translate a CollectionPropertyAccessNode.
 /// </summary>
 /// <param name="nodeIn">The node to be translated.</param>
 /// <returns>The translated node.</returns>
 public override QueryNode Visit(CollectionPropertyAccessNode nodeIn)
 {
     return(new CollectionPropertyAccessNode(
                (SingleValueNode)nodeIn.Source.Accept(this),
                nodeIn.Property));
 }
Beispiel #13
0
 public override IEnumerable <string> Visit(CollectionPropertyAccessNode nodeIn)
 {
     return(nodeIn.Source.Accept(this));
 }
        public void CollectionPropertyAccessShouldSetCollectionTypeFromProperty()
        {
            var node = new CollectionPropertyAccessNode(this.fakeDogSource, HardCodedTestModel.GetDogNicknamesProperty());

            node.CollectionType.Should().BeSameAs(HardCodedTestModel.GetDogNicknamesProperty().Type.AsCollection());
        }
        public void PropertyIsSet()
        {
            var node = new CollectionPropertyAccessNode(this.fakeDogSource, HardCodedTestModel.GetDogNicknamesProperty());

            Assert.Same(node.Property, HardCodedTestModel.GetDogNicknamesProperty());
        }
 /// <summary>
 /// Visit a CollectionPropertyAccessNode
 /// </summary>
 /// <param name="nodeIn">the node to visit</param>
 /// <returns>Defined by the implementer</returns>
 public virtual T Visit(CollectionPropertyAccessNode nodeIn)
 {
     throw new NotImplementedException();
 }
//        public override T Visit(SingleValueOpenPropertyAccessNode     nodeIn)  { SkipDebuggerBreak(nodeIn); nodeIn.Source.Accept(this);                            return Visited; }

        #region override Just debuggable // uncommeneted means not researched yet // commented means

//      public override T Visit(AllNode                               nodeIn)  => DebuggerBreakVisited(nodeIn);
//      public override T Visit(AnyNode                               nodeIn)  => DebuggerBreakVisited(nodeIn);
//      public override T Visit(BinaryOperatorNode                    nodeIn)  => DebuggerBreakVisited(nodeIn);
//
//      public override T Visit(CountNode                             nodeIn)  => DebuggerBreakVisited(nodeIn);
//
//      public override T Visit(CollectionNavigationNode              nodeIn)  => DebuggerBreakVisited(nodeIn);
//
//      public override T Visit(ConstantNode                          nodeIn)  => DebuggerBreakVisited(nodeIn);
//      public override T Visit(ConvertNode                           nodeIn)  => DebuggerBreakVisited(nodeIn);
//
//      public override T Visit(ResourceRangeVariableReferenceNode    nodeIn)  => DebuggerBreakVisited(nodeIn);
//
//      public override T Visit(SingleValuePropertyAccessNode         nodeIn)  => DebuggerBreakVisited(nodeIn);


        public override T Visit(CollectionPropertyAccessNode nodeIn) => DebuggerBreakVisited(nodeIn);
Beispiel #18
0
 static string BindCollectionPropertyAccessNode(CollectionPropertyAccessNode collectionPropertyAccessNode, DbUtility dbUtility)
 {
     return(dbUtility.SafeDbObject(collectionPropertyAccessNode.Property.Name));
     //return Bind(collectionPropertyAccessNode.Source) + "." + collectionPropertyAccessNode.Property.Name;
 }
        public void CollectionPropertyAccessShouldSetItemTypeFromProperty()
        {
            var node = new CollectionPropertyAccessNode(this.fakeDogSource, HardCodedTestModel.GetDogNicknamesProperty());

            Assert.Same(node.ItemType, HardCodedTestModel.GetDogNicknamesProperty().Type.AsCollection().CollectionDefinition().ElementType);
        }
        public void CollectionPropertyAccessNodesCanUseGeography()
        {
            CollectionPropertyAccessNode propertyAccessNode = new CollectionPropertyAccessNode(new ConstantNode(2), HardCodedTestModel.GetPersonGeographyCollectionProp());

            Assert.Same(propertyAccessNode.Property, HardCodedTestModel.GetPersonGeographyCollectionProp());
        }
 private string BindCollectionPropertyAccessNode(CollectionPropertyAccessNode collectionPropertyAccessNode, ICollection <BinderNode> nodes)
 {
     return(Bind(collectionPropertyAccessNode.Source, nodes) + "." + collectionPropertyAccessNode.Property.Name);
 }
        public void PropertyIsSet()
        {
            var node = new CollectionPropertyAccessNode(this.fakeDogSource, HardCodedTestModel.GetDogNicknamesProperty());

            node.Property.Should().BeSameAs(HardCodedTestModel.GetDogNicknamesProperty());
        }
Beispiel #23
0
        /// <summary>
        /// Binds a DottedIdentifierToken and it's parent node (if needed).
        /// </summary>
        /// <param name="dottedIdentifierToken">Token to bind to metadata.</param>
        /// <param name="state">State of the Binding.</param>
        /// <returns>A bound node representing the cast.</returns>
        internal QueryNode BindDottedIdentifier(DottedIdentifierToken dottedIdentifierToken, BindingState state)
        {
            ExceptionUtils.CheckArgumentNotNull(dottedIdentifierToken, "castToken");
            ExceptionUtils.CheckArgumentNotNull(state, "state");

            QueryNode parent     = null;
            IEdmType  parentType = null;

            if (state.ImplicitRangeVariable != null)
            {
                if (dottedIdentifierToken.NextToken == null)
                {
                    parent     = NodeFactory.CreateRangeVariableReferenceNode(state.ImplicitRangeVariable);
                    parentType = state.ImplicitRangeVariable.TypeReference.Definition;
                }
                else
                {
                    parent     = this.bindMethod(dottedIdentifierToken.NextToken);
                    parentType = parent.GetEdmType();
                }
            }

            SingleEntityNode   parentAsSingleValue = parent as SingleEntityNode;
            IEdmSchemaType     childType           = UriEdmHelpers.FindTypeFromModel(state.Model, dottedIdentifierToken.Identifier);
            IEdmStructuredType childStructuredType = childType as IEdmStructuredType;

            if (childStructuredType == null)
            {
                FunctionCallBinder functionCallBinder = new FunctionCallBinder(bindMethod);
                QueryNode          functionCallNode;
                if (functionCallBinder.TryBindDottedIdentifierAsFunctionCall(dottedIdentifierToken, parentAsSingleValue, state, out functionCallNode))
                {
                    return(functionCallNode);
                }
                else if ((!string.IsNullOrEmpty(dottedIdentifierToken.Identifier)) &&
                         (dottedIdentifierToken.Identifier[dottedIdentifierToken.Identifier.Length - 1] == '\''))
                {
                    // check if it is enum or not
                    EnumBinder enumBinder = new EnumBinder(this.bindMethod);
                    QueryNode  enumNode;
                    if (enumBinder.TryBindDottedIdentifierAsEnum(dottedIdentifierToken, parentAsSingleValue, state, out enumNode))
                    {
                        return(enumNode);
                    }
                    else
                    {
                        throw new ODataException(ODataErrorStrings.Binder_IsNotValidEnumConstant(dottedIdentifierToken.Identifier));
                    }
                }
                else
                {
                    IEdmTypeReference edmTypeReference = UriEdmHelpers.FindTypeFromModel(state.Model, dottedIdentifierToken.Identifier).ToTypeReference();
                    if (edmTypeReference is IEdmPrimitiveTypeReference || edmTypeReference is IEdmEnumTypeReference)
                    {
                        return(new ConstantNode(dottedIdentifierToken.Identifier, dottedIdentifierToken.Identifier));
                    }
                    else
                    {
                        throw new ODataException(ODataErrorStrings.CastBinder_ChildTypeIsNotEntity(dottedIdentifierToken.Identifier));
                    }
                }
            }

            // Check whether childType is a derived type of the type of its parent node
            UriEdmHelpers.CheckRelatedTo(parentType, childType);

            IEdmEntityType childEntityType = childStructuredType as IEdmEntityType;

            if (childEntityType != null)
            {
                EntityCollectionNode parentAsCollection = parent as EntityCollectionNode;
                if (parentAsCollection != null)
                {
                    return(new EntityCollectionCastNode(parentAsCollection, childEntityType));
                }

                // parent can be null for casts on the implicit parameter; this is OK
                if (parent == null)
                {
                    return(new SingleEntityCastNode(null, childEntityType));
                }

                Debug.Assert(parentAsSingleValue != null, "If parent of the cast node was not collection, it should be a single value.");
                return(new SingleEntityCastNode(parentAsSingleValue, childEntityType));
            }
            else
            {
                IEdmComplexType childComplexType = childStructuredType as IEdmComplexType;
                Debug.Assert(childComplexType != null, "If it is not entity type, it should be complex type");

                CollectionPropertyAccessNode parentAsCollectionProperty = parent as CollectionPropertyAccessNode;
                if (parentAsCollectionProperty != null)
                {
                    return(new CollectionPropertyCastNode(parentAsCollectionProperty, childComplexType));
                }

                // parent can be null for casts on the implicit parameter; this is OK
                if (parent == null)
                {
                    return(new SingleValueCastNode(null, childComplexType));
                }

                SingleValueNode parentAsSingleValueNode = parent as SingleValueNode;
                Debug.Assert(parentAsSingleValueNode != null, "If parent of the cast node was not collection, it should be a single value.");
                return(new SingleValueCastNode(parentAsSingleValueNode, childComplexType));
            }
        }
 /// <summary>
 /// Writes collection property access node to string
 /// </summary>
 /// <param name="node">Node to write to string</param>
 /// <returns>String representation of node.</returns>
 private static string ToString(CollectionPropertyAccessNode node)
 {
     return tabHelper.Prefix + "CollectionPropertyAccessNode" +
         tabHelper.Indent(() =>
             tabHelper.Prefix + "Property = " + node.Property.Name +
             tabHelper.Prefix + "ItemType = " + node.ItemType +
             tabHelper.Prefix + "Source = " + ToString(node.Source)
         );
 }
 private string BindCollectionPropertyAccessNode(CollectionPropertyAccessNode collectionPropertyAccessNode)
 {
     return(Bind(collectionPropertyAccessNode.Source) + "." + collectionPropertyAccessNode.Property.Name);
 }
 public void PropertyIsSet()
 {   
     var node = new CollectionPropertyAccessNode(this.fakeDogSource, HardCodedTestModel.GetDogNicknamesProperty());
     node.Property.Should().BeSameAs(HardCodedTestModel.GetDogNicknamesProperty());
 }
Beispiel #27
0
 public override object Visit(CollectionPropertyAccessNode nodeIn)
 {
     return(null);
 }
 public void CollectionPropertyAccessNodesCanUseGeography()
 {
     CollectionPropertyAccessNode propertyAccessNode = new CollectionPropertyAccessNode(new ConstantNode(2), HardCodedTestModel.GetPersonGeographyCollectionProp());
     propertyAccessNode.Property.Should().Be(HardCodedTestModel.GetPersonGeographyCollectionProp());
 }
        public void CollectionPropertyAccessNodesCanUseGeography()
        {
            CollectionPropertyAccessNode propertyAccessNode = new CollectionPropertyAccessNode(new ConstantNode(2), HardCodedTestModel.GetPersonGeographyCollectionProp());

            propertyAccessNode.Property.Should().Be(HardCodedTestModel.GetPersonGeographyCollectionProp());
        }
 public void CollectionPropertyAccessNodesCanUseGeometry()
 {
     ConstantNode constant = new ConstantNode(2);
     CollectionPropertyAccessNode propertyAccessNode = new CollectionPropertyAccessNode(constant, HardCodedTestModel.GetPersonGeometryCollectionProp());
     propertyAccessNode.Property.Should().Be(HardCodedTestModel.GetPersonGeometryCollectionProp());
 }
 public override void ValidateCollectionPropertyAccessNode(CollectionPropertyAccessNode propertyAccessNode, ODataValidationSettings settings)
 {
     IncrementCount("ValidateCollectionPropertyAccessNode");
     base.ValidateCollectionPropertyAccessNode(propertyAccessNode, settings);
 }
 public void CollectionPropertyAccessShouldSetCollectionTypeFromProperty()
 {
     var node = new CollectionPropertyAccessNode(this.fakeDogSource, HardCodedTestModel.GetDogNicknamesProperty());
     node.CollectionType.Should().BeSameAs(HardCodedTestModel.GetDogNicknamesProperty().Type.AsCollection());
 }
Beispiel #33
0
 /// <summary>
 /// Compares Collection Property Access query 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(CollectionPropertyAccessNode left, CollectionPropertyAccessNode right)
 {
     if (left.Property != right.Property) return false;
     if (left.ItemType != right.ItemType) return false;
     return this.Compare(left.Source, right.Source);
 }
Beispiel #34
0
        /// <summary>
        /// Binds a <see cref="CollectionPropertyAccessNode"/> to create a LINQ <see cref="Expression"/> that
        /// represents the semantics of the <see cref="CollectionPropertyAccessNode"/>.
        /// </summary>
        /// <param name="propertyAccessNode">The node to bind.</param>
        /// <returns>The LINQ <see cref="Expression"/> created.</returns>
        public virtual Expression BindCollectionPropertyAccessNode(CollectionPropertyAccessNode propertyAccessNode)
        {
            Expression source = Bind(propertyAccessNode.Source);

            return(CreatePropertyAccessExpression(source, propertyAccessNode.Property));
        }
Beispiel #35
0
 /// <summary>
 /// Visit a CollectionPropertyAccessNode
 /// </summary>
 /// <param name="nodeIn">The node to visit</param>
 /// <returns>The translated expression</returns>
 public override Expression Visit(CollectionPropertyAccessNode nodeIn)
 {
     this.CheckArgumentNull(nodeIn, "CollectionPropertyAccessNode");
     return(this.TranslatePropertyAccess(nodeIn.Source, nodeIn.Property));
 }
        /// <summary>
        /// Override this method to validate collection property accessor.
        /// </summary>
        /// <remarks>
        /// This method is intended to be called from method overrides in subclasses. This method also supports unit-testing scenarios and is not intended to be called from user code.
        /// Call the Validate method to validate a <see cref="FilterQueryOption"/> instance.
        /// </remarks>
        /// <param name="propertyAccessNode"></param>
        /// <param name="settings"></param>
        public virtual void ValidateCollectionPropertyAccessNode(CollectionPropertyAccessNode propertyAccessNode, ODataValidationSettings settings)
        {
            if (propertyAccessNode == null)
            {
                throw Error.ArgumentNull("propertyAccessNode");
            }

            if (settings == null)
            {
                throw Error.ArgumentNull("settings");
            }

            // Check whether the property is filterable.
            IEdmProperty property = propertyAccessNode.Property;
            if (EdmLibHelpers.IsNotFilterable(property, _model))
            {
                throw new ODataException(Error.Format(SRResources.NotFilterablePropertyUsedInFilter, property.Name));
            }

            ValidateQueryNode(propertyAccessNode.Source, settings);
        }
        /// <summary>
        /// Override this method to validate collection property accessor.
        /// </summary>
        /// <remarks>
        /// This method is intended to be called from method overrides in subclasses. This method also supports unit-testing scenarios and is not intended to be called from user code.
        /// Call the Validate method to validate a <see cref="FilterQueryOption"/> instance.
        /// </remarks>
        /// <param name="propertyAccessNode"></param>
        /// <param name="settings"></param>
        public virtual void ValidateCollectionPropertyAccessNode(CollectionPropertyAccessNode propertyAccessNode, ODataValidationSettings settings)
        {
            if (propertyAccessNode == null)
            {
                throw Error.ArgumentNull("propertyAccessNode");
            }

            if (settings == null)
            {
                throw Error.ArgumentNull("settings");
            }

            // no default validation logic here 
            ValidateQueryNode(propertyAccessNode.Source, settings);
        }
 private string BindCollectionPropertyAccessNode(CollectionPropertyAccessNode collectionPropertyAccessNode)
 {
     return Bind(collectionPropertyAccessNode.Source) + "." + collectionPropertyAccessNode.Property.Name;
 }
Beispiel #39
0
 /// <summary>
 /// Translates a <see cref="CollectionPropertyAccessNode"/> into a corresponding <see cref="String"/>.
 /// </summary>
 /// <param name="node">The node to translate.</param>
 /// <returns>The translated String.</returns>
 public override String Visit(CollectionPropertyAccessNode node)
 {
     ExceptionUtils.CheckArgumentNotNull(node, "node");
     return(this.TranslatePropertyAccess(node.Source, node.Property.Name));
 }
Beispiel #40
0
        private static readonly string _CM = ","; // comma  - separator (of actual parameters in function call)

        #region override, still not researched or encountered, to move up eventually

        public override string Visit(CollectionPropertyAccessNode nodeIn)
        {
            return(base.Visit(nodeIn));
        }