/// <summary>
        /// Parses the <paramref name="queryUri"/> and binds the query to the metadata provided
        /// then returns a new instance of <see cref="QueryDescriptorQueryNode"/>
        /// describing the query specified by the uri.
        /// </summary>
        /// <param name="queryUri">The absolute URI which holds the query to parse. This must be a path relative to the <paramref name="serviceBaseUri"/>.</param>
        /// <param name="serviceBaseUri">The base URI of the service.</param>
        /// <param name="metadataProvider">The metadata provider to use for binding.</param>
        /// <param name="maxDepth">The maximum depth of any single query part. Security setting to guard against DoS attacks causing stack overflows and such.</param>
        /// <returns>A new instance of <see cref="QueryDescriptorQueryNode"/> which represents the query specified in the <paramref name="queryUri"/>.</returns>
        public static QueryDescriptorQueryNode ParseUri(Uri queryUri, Uri serviceBaseUri, IDataServiceMetadataProvider metadataProvider, int maxDepth)
        {
            ExceptionUtils.CheckArgumentNotNull(metadataProvider, "metadataProvider");

            QueryDescriptorQueryToken queryDescriptorQueryToken = QueryDescriptorQueryToken.ParseUri(queryUri, serviceBaseUri, maxDepth);
            MetadataBinder            metadataBinder            = new MetadataBinder(metadataProvider);

            return(metadataBinder.BindQuery(queryDescriptorQueryToken));
        }
Exemple #2
0
        public void TestParseTypeSetAccess()
        {
            var parseTree = QueryDescriptorQueryToken.ParseUri(new Uri("http://example.org/odata/Films"), new Uri("http://example.org/odata/"));

            Assert.IsNotNull(parseTree);
            Assert.AreEqual(QueryTokenKind.Segment, parseTree.Path.Kind);
            var segment = parseTree.Path as SegmentQueryToken;

            Assert.AreEqual("Films", segment.Name);
            Assert.IsNull(segment.NamedValues);
        }
Exemple #3
0
        public void TestParseInstanceAccess()
        {
            var parseTree = QueryDescriptorQueryToken.ParseUri(
                new Uri("http://example.org/odata/Films('Un_Chien_Andalou')"),
                new Uri("http://example.org/odata/"));

            Assert.IsNotNull(parseTree);
            Assert.IsNotNull(parseTree.Path);
            Assert.AreEqual(QueryTokenKind.Segment, parseTree.Path.Kind);
            Assert.IsInstanceOfType(parseTree.Path, typeof(SegmentQueryToken));
            var sqt = parseTree.Path as SegmentQueryToken;

            Assert.AreEqual("Films", sqt.Name);
            Assert.IsNotNull(sqt.NamedValues);
            var namedValues = sqt.NamedValues.ToList();

            Assert.AreEqual(1, namedValues.Count);
            Assert.IsNull(namedValues[0].Name);
            Assert.IsNotNull(namedValues[0].Value);
            Assert.IsNotNull(namedValues[0].Value.Value);
            Assert.AreEqual(QueryTokenKind.Literal, namedValues[0].Value.Kind);
            Assert.AreEqual("Un_Chien_Andalou", namedValues[0].Value.Value);
        }