Beispiel #1
0
        /// <summary>
        /// Override this method if you want to validate casts on resource collections.
        /// </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="collectionResourceCastNode"></param>
        /// <param name="settings"></param>
        protected virtual void ValidateCollectionResourceCastNode(CollectionResourceCastNode collectionResourceCastNode, ODataValidationSettings settings)
        {
            Contract.Assert(collectionResourceCastNode != null);
            Contract.Assert(settings != null);

            ValidateQueryNode(collectionResourceCastNode.Source, settings);
        }
Beispiel #2
0
        public void EntitySetComesFromSource()
        {
            EntitySetNode source = new EntitySetNode(HardCodedTestModel.GetDogsSet());
            CollectionResourceCastNode collectionResourceCastNode = new CollectionResourceCastNode(source, HardCodedTestModel.GetDogType());

            collectionResourceCastNode.NavigationSource.Should().Be(HardCodedTestModel.GetDogsSet());
        }
        public void KindIsCollectionResourceCastNode()
        {
            EntitySetNode source = new EntitySetNode(HardCodedTestModel.GetDogsSet());
            CollectionResourceCastNode collectionResourceCastNode = new CollectionResourceCastNode(source, HardCodedTestModel.GetDogType());

            Assert.Equal(collectionResourceCastNode.InternalKind, InternalQueryNodeKind.CollectionResourceCast);
        }
Beispiel #4
0
        public void ItemTypeReferenceShouldBeCreatedFromConstructorParameter()
        {
            var node = new CollectionResourceCastNode(fakeSource, HardCodedTestModel.GetEmployeeType());

            node.ItemType.Definition.Should().BeSameAs(HardCodedTestModel.GetEmployeeType());
            node.ItemType.IsNullable.Should().BeFalse();
        }
        public void ItemTypeReturnsEdmEntityTypeReference()
        {
            EntitySetNode source = new EntitySetNode(HardCodedTestModel.GetDogsSet());
            CollectionResourceCastNode collectionResourceCastNode = new CollectionResourceCastNode(source, HardCodedTestModel.GetDogType());

            Assert.IsType <EdmEntityTypeReference>(collectionResourceCastNode.ItemType);
        }
Beispiel #6
0
        public void SourceIsSetCorrectly()
        {
            EntitySetNode source = new EntitySetNode(HardCodedTestModel.GetDogsSet());
            CollectionResourceCastNode collectionResourceCastNode = new CollectionResourceCastNode(source, HardCodedTestModel.GetDogType());

            collectionResourceCastNode.Source.ShouldBeEntitySetQueryNode(HardCodedTestModel.GetDogsSet());
        }
Beispiel #7
0
        public void KindIsCollectionResourceCastNode()
        {
            EntitySetNode source = new EntitySetNode(HardCodedTestModel.GetDogsSet());
            CollectionResourceCastNode collectionResourceCastNode = new CollectionResourceCastNode(source, HardCodedTestModel.GetDogType());

            collectionResourceCastNode.InternalKind.Should().Be(InternalQueryNodeKind.CollectionResourceCast);
        }
Beispiel #8
0
        public void ItemTypeReturnsEdmEntityTypeReference()
        {
            EntitySetNode source = new EntitySetNode(HardCodedTestModel.GetDogsSet());
            CollectionResourceCastNode collectionResourceCastNode = new CollectionResourceCastNode(source, HardCodedTestModel.GetDogType());

            collectionResourceCastNode.ItemType.Should().BeOfType <EdmEntityTypeReference>();
        }
Beispiel #9
0
 /// <summary>
 /// Visit an CollectionResourceCastNode
 /// </summary>
 /// <param name="nodeIn">the node to visit</param>
 /// <returns>true, indicating that the node has been visited.</returns>
 public override bool Visit(CollectionResourceCastNode nodeIn)
 {
     validate(nodeIn);
     validate(nodeIn.CollectionType.CollectionDefinition());
     validate(nodeIn.ItemType.Definition);
     return(true);
 }
        private void TestCast <TParam, TReturn>(CollectionResourceNode source, IEdmEntityType cast, Expression <Func <TParam, TReturn> > expectedExpression)
        {
            var node   = new CollectionResourceCastNode(source, cast);
            var result = this.testSubject.TranslateNode(node);

            CompareExpressions(expectedExpression.Body, result);
        }
Beispiel #11
0
        public void EntityItemTypeIsSameAsItemType()
        {
            EntitySetNode source = new EntitySetNode(HardCodedTestModel.GetDogsSet());
            CollectionResourceCastNode collectionResourceCastNode = new CollectionResourceCastNode(source, HardCodedTestModel.GetDogType());

            collectionResourceCastNode.ItemStructuredType.Should().BeSameAs(collectionResourceCastNode.ItemType);
        }
Beispiel #12
0
        /// <summary>
        /// Translate an CollectionResourceCastNode.
        /// </summary>
        /// <param name="nodeIn">The node to be translated.</param>
        /// <returns>The translated node.</returns>
        public override QueryNode Visit(CollectionResourceCastNode nodeIn)
        {
            Contract.Assert(nodeIn != null);

            return(new CollectionResourceCastNode(
                       (CollectionResourceNode)nodeIn.Source.Accept(this),
                       (IEdmStructuredType)nodeIn.ItemType.Definition));
        }
        /// <summary>
        /// Override this method if you want to validate casts on resource collections.
        /// </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="collectionResourceCastNode"></param>
        /// <param name="settings"></param>
        public virtual void ValidateCollectionResourceCastNode(CollectionResourceCastNode collectionResourceCastNode, ODataValidationSettings settings)
        {
            if (collectionResourceCastNode == null)
            {
                throw Error.ArgumentNull(nameof(collectionResourceCastNode));
            }

            ValidateQueryNode(collectionResourceCastNode.Source, settings);
        }
Beispiel #14
0
        public override QueryNode Visit(CollectionResourceCastNode nodeIn)
        {
            CollectionResourceNode?source = nodeIn.Source == null ? null : (CollectionResourceNode)Visit(nodeIn.Source);

            if (nodeIn.Source != source)
            {
                nodeIn = new CollectionResourceCastNode(source, (IEdmStructuredType)nodeIn.ItemStructuredType.Definition);
            }
            return(nodeIn);
        }
        /// <summary>
        /// Translate an CollectionResourceCastNode.
        /// </summary>
        /// <param name="nodeIn">The node to be translated.</param>
        /// <returns>The translated node.</returns>
        public override QueryNode Visit(CollectionResourceCastNode nodeIn)
        {
            if (nodeIn == null)
            {
                throw Error.ArgumentNull(nameof(nodeIn));
            }

            return(new CollectionResourceCastNode(
                       (CollectionResourceNode)nodeIn.Source.Accept(this),
                       (IEdmStructuredType)nodeIn.ItemType.Definition));
        }
        public void TranslatorShouldRequireProtocolVersionThreeForCollectionTypeSegment()
        {
            ODataProtocolVersion validatedProtocolVersion = ODataProtocolVersion.V4;

            this.testSubject = this.CreateTestSubject(verifyProtocolVersion: v => { validatedProtocolVersion = v; }, verifyRequestVersion: v => { throw new Exception("Should not be called."); });

            QueryNode node = new CollectionResourceCastNode(this.CollectionNavigationFromParameter("o"), this.customerEdmType);

            this.testSubject.TranslateNode(node);
            validatedProtocolVersion.Should().Be(ODataProtocolVersion.V4);
        }
Beispiel #17
0
        /// <summary>
        /// Binds a <see cref="CollectionResourceCastNode"/> to create a LINQ <see cref="Expression"/> that
        /// represents the semantics of the <see cref="CollectionResourceCastNode"/>.
        /// </summary>
        /// <param name="node">The node to bind.</param>
        /// <returns>The LINQ <see cref="Expression"/> created.</returns>
        public virtual Expression BindCollectionResourceCastNode(CollectionResourceCastNode node)
        {
            IEdmStructuredTypeReference structured = node.ItemStructuredType;

            Contract.Assert(structured != null, "NS casts can contain only structured types");

            Type clrType = EdmLibHelpers.GetClrType(structured, Model);

            Expression source = BindCastSourceNode(node.Source);

            return(OfType(source, clrType));
        }
        public void TranslatorShouldConvertWeaklyBackedEntityCollectionCast()
        {
            CollectionResourceNode source = this.CollectionNavigationFromParameter("c");
            QueryNode node   = new CollectionResourceCastNode(source, this.weaklyBackedCustomerEdmType);
            var       result = this.testSubject.TranslateNode(node);

            var parameterExpression = Expression.Parameter(typeof(Customer), "c");
            var propertyExpression  = Expression.Property(parameterExpression, "OtherFriends");
            var expected            = Expression.Call(typeof(DataServiceProviderMethods), "OfType", new[] { typeof(Customer), typeof(object) }, propertyExpression, Expression.Constant(this.weaklyBackedDerivedType));

            expected = Expression.Call(typeof(Enumerable), "Cast", new[] { typeof(object) }, expected);
            CompareExpressions(expected, result);
        }
        /// <summary>
        /// Writes entity collection cast node to string.
        /// </summary>
        /// <param name="node">Node to write to string</param>
        /// <returns>String representation of node.</returns>
        private static string ToString(CollectionResourceCastNode node)
        {
            if (node != null)
            {
                return(tabHelper.Prefix + "CollectionResourceCastNode" +
                       tabHelper.Indent(() =>
                                        tabHelper.Prefix + "Entity Item Type = " + node.ItemStructuredType +
                                        tabHelper.Prefix + "NavigationSource = " + node.NavigationSource.Name +
                                        tabHelper.Prefix + "Item Type = " + node.ItemType +
                                        tabHelper.Prefix + "Source = " + ToString(node.Source)
                                        ));
            }

            return(String.Empty);
        }
Beispiel #20
0
 /// <summary>
 /// Compares collection cast 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(CollectionResourceCastNode left, CollectionResourceCastNode right)
 {
     if (left.ItemStructuredType != right.ItemStructuredType)
     {
         return(false);
     }
     if (left.NavigationSource != right.NavigationSource)
     {
         return(false);
     }
     if (left.ItemType != right.ItemType)
     {
         return(false);
     }
     return(this.Compare(left.Source, right.Source));
 }
Beispiel #21
0
        /// <summary>
        /// Binds a <see cref="CollectionResourceCastNode"/> to create a LINQ <see cref="Expression"/> that
        /// represents the semantics of the <see cref="CollectionResourceCastNode"/>.
        /// </summary>
        /// <param name="node">The node to bind.</param>
        /// <returns>The LINQ <see cref="Expression"/> created.</returns>
        public virtual Expression BindCollectionResourceCastNode(CollectionResourceCastNode node)
        {
            if (node == null)
            {
                throw Error.ArgumentNull(nameof(node));
            }

            IEdmStructuredTypeReference structured = node.ItemStructuredType;

            Contract.Assert(structured != null, "NS casts can contain only structured types");

            Type clrType = Model.GetClrType(structured);

            Expression source = BindCastSourceNode(node.Source);

            return(OfType(source, clrType));
        }
Beispiel #22
0
 /// <summary>
 /// Translates a <see cref="CollectionResourceCastNode"/> into a corresponding <see cref="String"/>.
 /// </summary>
 /// <param name="node">The node to translate.</param>
 /// <returns>The translated String of CollectionResourceCastNode.</returns>
 public override String Visit(CollectionResourceCastNode node)
 {
     ExceptionUtils.CheckArgumentNotNull(node, "node");
     return(this.TranslatePropertyAccess(node.Source, node.ItemStructuredType.Definition.ToString()));
 }
 /// <summary>
 /// Visit an CollectionResourceCastNode
 /// </summary>
 /// <param name="nodeIn">The node to visit</param>
 /// <returns>The translated expression</returns>
 public override Expression Visit(CollectionResourceCastNode nodeIn)
 {
     throw new NotImplementedException();
 }
//      public override T Visit(ConstantNode                          nodeIn)  => DebuggerBreakVisited(nodeIn);
//      public override T Visit(ConvertNode                           nodeIn)  => DebuggerBreakVisited(nodeIn);

        public override T Visit(CollectionResourceCastNode nodeIn) => DebuggerBreakVisited(nodeIn);
Beispiel #25
0
 /// <summary>
 /// Visit an CollectionPropertyCastNode
 /// </summary>
 /// <param name="node">the node to visit</param>
 /// <returns>The translated string of CollectionPropertyCastNode</returns>
 public override string Visit(CollectionResourceCastNode node)
 {
     return(this.TranslatePropertyAccess(node.Source, node.CollectionType.Definition.ToString()));
 }
Beispiel #26
0
        public void EntityItemTypeShouldBeSameAsItemType()
        {
            var node = new CollectionResourceCastNode(fakeSource, HardCodedTestModel.GetEmployeeType());

            node.ItemStructuredType.Should().BeSameAs(node.ItemType);
        }
Beispiel #27
0
        public void CollectionTypeShouldBeSaved()
        {
            var node = new CollectionResourceCastNode(fakeSource, HardCodedTestModel.GetEmployeeType());

            node.CollectionType.Should().BeSameAs(node.CollectionType);
        }
Beispiel #28
0
        public void CollectionTypeShouldBeCreatedFromItemType()
        {
            var node = new CollectionResourceCastNode(fakeSource, HardCodedTestModel.GetEmployeeType());

            node.CollectionType.FullName().Should().Be("Collection(Fully.Qualified.Namespace.Employee)");
        }
        public void ItemTypeShouldBeSaved()
        {
            var node = new CollectionResourceCastNode(fakeSource, HardCodedTestModel.GetEmployeeType());

            Assert.Same(node.ItemType, node.ItemType);
        }