예제 #1
0
        /// <summary>
        /// Override this method if you want to validate casts on single resource.
        /// </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="singleResourceCastNode"></param>
        /// <param name="settings"></param>
        protected virtual void ValidateSingleResourceCastNode(SingleResourceCastNode singleResourceCastNode, ODataValidationSettings settings)
        {
            Contract.Assert(singleResourceCastNode != null);
            Contract.Assert(settings != null);

            ValidateQueryNode(singleResourceCastNode.Source, settings);
        }
        private void TestCast <TParam, TReturn>(SingleResourceNode source, IEdmEntityType cast, Expression <Func <TParam, TReturn> > expectedExpression)
        {
            var node   = new SingleResourceCastNode(source, cast);
            var result = this.testSubject.TranslateNode(node);

            CompareExpressions(expectedExpression.Body, result);
        }
예제 #3
0
 /// <summary>
 /// Translate a SingleResourceCastNode.
 /// </summary>
 /// <param name="nodeIn">The node to be translated.</param>
 /// <returns>The translated node.</returns>
 public override QueryNode Visit(SingleResourceCastNode nodeIn)
 {
     return(nodeIn.Source == null ?
            nodeIn :
            new SingleResourceCastNode(
                (SingleResourceNode)nodeIn.Source.Accept(this),
                (IEdmStructuredType)nodeIn.TypeReference.Definition));
 }
예제 #4
0
        /// <summary>
        /// Override this method if you want to validate casts on single resource.
        /// </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="singleResourceCastNode"></param>
        /// <param name="settings"></param>
        public virtual void ValidateSingleResourceCastNode(SingleResourceCastNode singleResourceCastNode, ODataValidationSettings settings)
        {
            if (singleResourceCastNode == null)
            {
                throw Error.ArgumentNull(nameof(singleResourceCastNode));
            }

            ValidateQueryNode(singleResourceCastNode.Source, settings);
        }
예제 #5
0
        public override QueryNode Visit(SingleResourceCastNode nodeIn)
        {
            SingleResourceNode?source = nodeIn.Source == null ? null : (SingleResourceNode)Visit(nodeIn.Source);

            if (nodeIn.Source != source)
            {
                nodeIn = new SingleResourceCastNode(source, (IEdmStructuredType)nodeIn.StructuredTypeReference.Definition);
            }
            return(nodeIn);
        }
        public void TranslatorShouldRequireProtocolVersionThreeForSingletonTypeSegment()
        {
            ODataProtocolVersion validatedProtocolVersion = ODataProtocolVersion.V4;

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

            QueryNode node = new SingleResourceCastNode(this.EntityParameter <Customer>("o"), this.customerEdmType);

            this.testSubject.TranslateNode(node);
            validatedProtocolVersion.Should().Be(ODataProtocolVersion.V4);
        }
        public void TranslatorShouldConvertWeaklyBackedSingleEntityCast()
        {
            SingleResourceNode source = EntityParameter <Customer>("c");
            QueryNode          node   = new SingleResourceCastNode(source, this.weaklyBackedCustomerEdmType);
            var result = this.testSubject.TranslateNode(node);

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

            CompareExpressions(expected, result);
        }
예제 #8
0
        public void GetNavigationNodeCreatesCollectionNavigationNodeForManyMultiplicityProperty()
        {
            IEdmNavigationSource   navigationSource;
            IEdmNavigationProperty property = HardCodedTestModel.GetDogMyPeopleNavProp();
            SingleResourceNode     parent   = new SingleResourceCastNode(null, HardCodedTestModel.GetDogType());
            BindingState           state    = new BindingState(Configuration);
            KeyBinder keyBinder             = new KeyBinder(FakeBindMethods.BindMethodReturningASingleDog);

            var result = InnerPathTokenBinder.GetNavigationNode(property, parent, null, state, keyBinder, out navigationSource);

            result.ShouldBeCollectionNavigationNode(property);
        }
예제 #9
0
        /// <summary>
        /// Binds a <see cref="SingleResourceCastNode"/> to create a LINQ <see cref="Expression"/> that
        /// represents the semantics of the <see cref="SingleResourceCastNode"/>.
        /// </summary>
        /// <param name="node">The node to bind.</param>
        /// <returns>The LINQ <see cref="Expression"/> created.</returns>
        public virtual Expression BindSingleResourceCastNode(SingleResourceCastNode node)
        {
            IEdmStructuredTypeReference structured = node.StructuredTypeReference;

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

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

            Expression source = BindCastSourceNode(node.Source);

            return(Expression.TypeAs(source, clrType));
        }
        /// <summary>
        /// Translate a SingleResourceCastNode.
        /// </summary>
        /// <param name="nodeIn">The node to be translated.</param>
        /// <returns>The translated node.</returns>
        public override QueryNode Visit(SingleResourceCastNode nodeIn)
        {
            if (nodeIn == null)
            {
                throw Error.ArgumentNull(nameof(nodeIn));
            }

            return(nodeIn.Source == null ?
                   nodeIn :
                   new SingleResourceCastNode(
                       (SingleResourceNode)nodeIn.Source.Accept(this),
                       (IEdmStructuredType)nodeIn.TypeReference.Definition));
        }
예제 #11
0
        /// <summary>
        /// Writes single entity cast node to string.
        /// </summary>
        /// <param name="node">Node to write to string</param>
        /// <returns>String representation of node.</returns>
        private static string ToString(SingleResourceCastNode node)
        {
            if (node != null)
            {
                return(tabHelper.Prefix + "SingleResourceCastNode" +
                       tabHelper.Indent(() =>
                                        tabHelper.Prefix + "Type Reference = " + node.TypeReference +
                                        tabHelper.Prefix + "NavigationSource = " + node.NavigationSource.Name +
                                        tabHelper.Prefix + "Entity Type Reference = " + node.StructuredTypeReference +
                                        tabHelper.Prefix + "Source = " + ToString(node.Source)
                                        ));
            }

            return(String.Empty);
        }
예제 #12
0
 /// <summary>
 /// Compares single cast 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(SingleResourceCastNode left, SingleResourceCastNode right)
 {
     if (left.NavigationSource != right.NavigationSource)
     {
         return(false);
     }
     if (left.StructuredTypeReference != right.StructuredTypeReference)
     {
         return(false);
     }
     if (left.TypeReference != right.TypeReference)
     {
         return(false);
     }
     return(this.Compare(left.Source, right.Source));
 }
예제 #13
0
        /// <summary>
        /// Binds a <see cref="SingleResourceCastNode"/> to create a LINQ <see cref="Expression"/> that
        /// represents the semantics of the <see cref="SingleResourceCastNode"/>.
        /// </summary>
        /// <param name="node">The node to bind.</param>
        /// <returns>The LINQ <see cref="Expression"/> created.</returns>
        public virtual Expression BindSingleResourceCastNode(SingleResourceCastNode node)
        {
            if (node == null)
            {
                throw Error.ArgumentNull(nameof(node));
            }

            IEdmStructuredTypeReference structured = node.StructuredTypeReference;

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

            Type clrType = Model.GetClrType(structured);

            Expression source = BindCastSourceNode(node.Source);

            return(Expression.TypeAs(source, clrType));
        }
        public void SourceIsSetCorrectly()
        {
            SingleResourceCastNode singleEntityCast = new SingleResourceCastNode(this.singleEntityNode, HardCodedTestModel.GetPersonType());

            Assert.Same(this.singleEntityNode, singleEntityCast.Source);
        }
예제 #15
0
 /// <summary>
 /// Visit a SingleResourceCastNode
 /// </summary>
 /// <param name="nodeIn">The node to visit</param>
 /// <returns>The translated expression</returns>
 public override Expression Visit(SingleResourceCastNode nodeIn)
 {
     this.CheckArgumentNull(nodeIn, "node");
     return(this.TranslateSingleValueCastAccess(nodeIn.Source, nodeIn.TypeReference));
 }
예제 #16
0
 /// <summary>
 /// Translates a <see cref="SingleEntityCastNode"/> into a corresponding <see cref="string"/>.
 /// </summary>
 /// <param name="node">The node to translate.</param>
 /// <returns>The translated string.</returns>
 public override string Visit(SingleResourceCastNode node)
 {
     return(this.TranslatePropertyAccess(node.Source, node.TypeReference.Definition.ToString()));
 }
 public override T Visit(SingleResourceCastNode nodeIn) => DebuggerBreakVisited(nodeIn);
        public void SourceIsSetCorrectly()
        {
            SingleResourceCastNode singleEntityCast = new SingleResourceCastNode(this.singleEntityNode, HardCodedTestModel.GetPersonType());

            singleEntityCast.Source.Should().Be(this.singleEntityNode);
        }
        public void KindIsSingleResourceCastNode()
        {
            SingleResourceCastNode singleEntityCast = new SingleResourceCastNode(this.singleEntityNode, HardCodedTestModel.GetDogType());

            Assert.Equal(InternalQueryNodeKind.SingleResourceCast, singleEntityCast.InternalKind);
        }
        public void EntityTypeReferenceIsSameAsTypeReference()
        {
            SingleResourceCastNode singleEntityCast = new SingleResourceCastNode(this.singleEntityNode, HardCodedTestModel.GetPersonType());

            Assert.Same(singleEntityCast.StructuredTypeReference, singleEntityCast.TypeReference);
        }
        public void KindIsSingleResourceCastNode()
        {
            SingleResourceCastNode singleEntityCast = new SingleResourceCastNode(this.singleEntityNode, HardCodedTestModel.GetDogType());

            singleEntityCast.InternalKind.Should().Be(InternalQueryNodeKind.SingleResourceCast);
        }
예제 #22
0
 /// <summary>
 /// Visit a SingleResourceCastNode
 /// </summary>
 /// <param name="nodeIn">the node to visit</param>
 /// <returns>true, indicating that the node has been visited.</returns>
 public override bool Visit(SingleResourceCastNode nodeIn)
 {
     validate(nodeIn);
     validate(nodeIn.TypeReference.Definition);
     return(true);
 }
예제 #23
0
 /// <summary>
 /// Translates a <see cref="SingleResourceCastNode"/> into a corresponding <see cref="String"/>.
 /// </summary>
 /// <param name="node">The node to translate.</param>
 /// <returns>The translated String.</returns>
 public override String Visit(SingleResourceCastNode node)
 {
     ExceptionUtils.CheckArgumentNotNull(node, "node");
     return(this.TranslatePropertyAccess(node.Source, node.StructuredTypeReference.Definition.ToString()));
 }
        public void TypeReferenceIsSetCorrectly()
        {
            SingleResourceCastNode singleEntityCast = new SingleResourceCastNode(this.singleEntityNode, HardCodedTestModel.GetPersonType());

            Assert.Equal(singleEntityCast.TypeReference.FullName(), HardCodedTestModel.GetPersonType().FullName());
        }