예제 #1
0
        public void EmptyValueQueryOptionShouldWork()
        {
            var uriParser = new ODataUriParser(HardCodedTestModel.TestModel, ServiceRoot, new Uri(FullUri, "?$filter=&$select=&$expand=&$orderby=&$top=&$skip=&$count=&$search=&$unknow=&$unknowvalue&$skiptoken=&$deltatoken="));
            var path      = uriParser.ParsePath();

            path.Should().HaveCount(1);
            path.LastSegment.ShouldBeEntitySetSegment(HardCodedTestModel.GetPeopleSet());
            uriParser.ParseFilter().Should().BeNull();
            var results = uriParser.ParseSelectAndExpand();

            results.AllSelected.Should().BeTrue();
            results.SelectedItems.Should().HaveCount(0);
            uriParser.ParseOrderBy().Should().BeNull();
            Action action = () => uriParser.ParseTop();

            action.ShouldThrow <ODataException>().WithMessage(Strings.SyntacticTree_InvalidTopQueryOptionValue(""));
            action = () => uriParser.ParseSkip();
            action.ShouldThrow <ODataException>().WithMessage(Strings.SyntacticTree_InvalidSkipQueryOptionValue(""));
            action = () => uriParser.ParseCount();
            action.ShouldThrow <ODataException>().WithMessage(Strings.ODataUriParser_InvalidCount(""));
            action = () => uriParser.ParseSearch();
            action.ShouldThrow <ODataException>().WithMessage(Strings.UriQueryExpressionParser_ExpressionExpected(0, ""));
            uriParser.ParseSkipToken().Should().BeEmpty();
            uriParser.ParseDeltaToken().Should().BeEmpty();
        }
예제 #2
0
        protected void ApprovalVerifySearchParser(Uri resourceRoot, string queryOption)
        {
            ODataUriParser parser = this.CreateSearchUriParser(resourceRoot, queryOption);
            var            result = parser.ParseSearch();

            ApprovalVerify(QueryNodeToStringVisitor.GetTestCaseAndResultString(result, queryOption));
        }
예제 #3
0
        public static void ParseFilter(this ODataUriParser query, Query result)
        {
            SearchClause search;

            try
            {
                search = query.ParseSearch();
            }
            catch (ODataException ex)
            {
                throw new ValidationException("Query $search clause not valid.", new ValidationError(ex.Message));
            }

            if (search != null)
            {
                result.FullText = SearchTermVisitor.Visit(search.Expression).ToString();
            }

            FilterClause filter;

            try
            {
                filter = query.ParseFilter();
            }
            catch (ODataException ex)
            {
                throw new ValidationException("Query $filter clause not valid.", new ValidationError(ex.Message));
            }

            if (filter != null)
            {
                result.Filter = FilterVisitor.Visit(filter.Expression);
            }
        }
예제 #4
0
        public void EmptyValueQueryOptionShouldWork(string relativeUriString, bool enableNoDollarQueryOptions)
        {
            var uriParser = new ODataUriParser(HardCodedTestModel.TestModel, ServiceRoot, new Uri(FullUri, relativeUriString));

            uriParser.EnableNoDollarQueryOptions = enableNoDollarQueryOptions;
            var path = uriParser.ParsePath();

            path.Should().HaveCount(1);
            path.LastSegment.ShouldBeEntitySetSegment(HardCodedTestModel.GetPeopleSet());
            uriParser.ParseFilter().Should().BeNull();
            var results = uriParser.ParseSelectAndExpand();

            results.AllSelected.Should().BeTrue();
            results.SelectedItems.Should().HaveCount(0);
            uriParser.ParseOrderBy().Should().BeNull();
            Action action = () => uriParser.ParseTop();

            action.ShouldThrow <ODataException>().WithMessage(Strings.SyntacticTree_InvalidTopQueryOptionValue(""));
            action = () => uriParser.ParseSkip();
            action.ShouldThrow <ODataException>().WithMessage(Strings.SyntacticTree_InvalidSkipQueryOptionValue(""));
            action = () => uriParser.ParseCount();
            action.ShouldThrow <ODataException>().WithMessage(Strings.ODataUriParser_InvalidCount(""));
            action = () => uriParser.ParseSearch();
            action.ShouldThrow <ODataException>().WithMessage(Strings.UriQueryExpressionParser_ExpressionExpected(0, ""));
            uriParser.ParseSkipToken().Should().BeEmpty();
            uriParser.ParseDeltaToken().Should().BeEmpty();
        }
예제 #5
0
        public void ParseNoDollarQueryOptionsShouldReturnNullIfNoDollarQueryOptionsIsNotEnabled()
        {
            var parser = new ODataUriParser(HardCodedTestModel.TestModel, new Uri("People?filter=MyDog/Color eq 'Brown'&select=ID&expand=MyDog&orderby=ID&top=1&skip=2&count=true&search=FA&$unknown=&$unknownvalue&skiptoken=abc&deltatoken=def", UriKind.Relative));

            bool originalValue = parser.EnableNoDollarQueryOptions;

            try
            {
                // Ensure $-sign is required.
                parser.EnableNoDollarQueryOptions = false;

                parser.ParseFilter().Should().BeNull();
                parser.ParseSelectAndExpand().Should().BeNull();
                parser.ParseOrderBy().Should().BeNull();
                parser.ParseTop().Should().Be(null);
                parser.ParseSkip().Should().Be(null);
                parser.ParseCount().Should().Be(null);
                parser.ParseSearch().Should().BeNull();
                parser.ParseSkipToken().Should().BeNull();
                parser.ParseDeltaToken().Should().BeNull();
            }
            finally
            {
                // Restore original value
                parser.EnableNoDollarQueryOptions = originalValue;
            }
        }
        public void ParseQueryOptionsShouldWork()
        {
            var parser = new ODataUriParser(HardCodedTestModel.TestModel, new Uri("People?$filter=MyDog/Color eq 'Brown'&$select=ID&$expand=MyDog&$orderby=ID&$top=1&$skip=2&$count=true&$search=FA&$unknow=&$unknowvalue", UriKind.Relative));

            parser.ParseSelectAndExpand().Should().NotBeNull();
            parser.ParseFilter().Should().NotBeNull();
            parser.ParseOrderBy().Should().NotBeNull();
            parser.ParseTop().Should().Be(1);
            parser.ParseSkip().Should().Be(2);
            parser.ParseCount().Should().Be(true);
            parser.ParseSearch().Should().NotBeNull();
        }
예제 #7
0
        public void ParseQueryOptionsShouldWork(string relativeUriString, bool enableNoDollarQueryOptions)
        {
            var parser = new ODataUriParser(HardCodedTestModel.TestModel, new Uri(relativeUriString, UriKind.Relative));

            parser.EnableNoDollarQueryOptions = enableNoDollarQueryOptions;
            parser.ParseSelectAndExpand().Should().NotBeNull();
            parser.ParseFilter().Should().NotBeNull();
            parser.ParseOrderBy().Should().NotBeNull();
            parser.ParseTop().Should().Be(1);
            parser.ParseSkip().Should().Be(2);
            parser.ParseCount().Should().Be(true);
            parser.ParseSearch().Should().NotBeNull();
            parser.ParseSkipToken().Should().Be("abc");
            parser.ParseDeltaToken().Should().Be("def");
        }
        public void NoneQueryOptionShouldWork()
        {
            var uriParser = new ODataUriParser(HardCodedTestModel.TestModel, ServiceRoot, FullUri);
            var path      = uriParser.ParsePath();

            path.Should().HaveCount(1);
            path.LastSegment.ShouldBeEntitySetSegment(HardCodedTestModel.GetPeopleSet());
            uriParser.ParseFilter().Should().BeNull();
            uriParser.ParseSelectAndExpand().Should().BeNull();
            uriParser.ParseOrderBy().Should().BeNull();
            uriParser.ParseTop().Should().Be(null);
            uriParser.ParseSkip().Should().Be(null);
            uriParser.ParseCount().Should().Be(null);
            uriParser.ParseSearch().Should().BeNull();
        }
예제 #9
0
        public static FilterDefinition <MongoContentEntity> Build(ODataUriParser query, Schema schema)
        {
            var search = query.ParseSearch();

            if (search != null)
            {
                return(Filter.Text(SearchTermVisitor.Visit(search.Expression).ToString()));
            }

            var filter = query.ParseFilter();

            if (filter != null)
            {
                return(FilterVisitor.Visit(filter.Expression, schema));
            }

            return(null);
        }
예제 #10
0
        // GET odata/People
        //[EnableQuery(PageSize = Utility.DefaultPageSize)]
        public IHttpActionResult Get(ODataQueryOptions <Person> queryOptions)
        {
            // generate IQueryable for results
            IQueryable <Person> results = TripPinSvcDataSource.Instance.People.AsQueryable();

            // apply standard query options to the IQueryable
            queryOptions.ApplyTo(results);

            // get the original request uri and parse the $search clause
            var parser       = new ODataUriParser(WebApiConfig.Model, new Uri("http://" + Request.RequestUri.Authority), Request.RequestUri);
            var searchClause = parser.ParseSearch();

            // apply the $search clause to the IQueryable
            if (searchClause != null)
            {
                results = applySearch(results, searchClause.Expression);
            }

            return(Ok(results));
        }
예제 #11
0
        public static void ParseFilter(this ODataUriParser query, ClrQuery result)
        {
            SearchClause searchClause;

            try
            {
                searchClause = query.ParseSearch();
            }
            catch (ODataException ex)
            {
                var error = T.Get("common.odataSearchNotValid", new { message = ex.Message });

                throw new ValidationException(error, ex);
            }

            if (searchClause != null)
            {
                result.FullText = SearchTermVisitor.Visit(searchClause.Expression).ToString();
            }

            FilterClause filterClause;

            try
            {
                filterClause = query.ParseFilter();
            }
            catch (ODataException ex)
            {
                var error = T.Get("common.odataFilterNotValid", new { message = ex.Message });

                throw new ValidationException(error, ex);
            }

            if (filterClause != null)
            {
                var filter = FilterVisitor.Visit(filterClause.Expression);

                result.Filter = Optimizer <ClrValue> .Optimize(filter);
            }
        }
예제 #12
0
        public static FilterDefinition <MongoContentEntity> Build(ODataUriParser query, Schema schema)
        {
            SearchClause search;

            try
            {
                search = query.ParseSearch();
            }
            catch (ODataException ex)
            {
                throw new ValidationException("Query $search clause not valid.", new ValidationError(ex.Message));
            }

            if (search != null)
            {
                return(Filter.Text(SearchTermVisitor.Visit(search.Expression).ToString()));
            }

            FilterClause filter;

            try
            {
                filter = query.ParseFilter();
            }
            catch (ODataException ex)
            {
                throw new ValidationException("Query $filter clause not valid.", new ValidationError(ex.Message));
            }

            if (filter != null)
            {
                return(FilterVisitor.Visit(filter.Expression, schema));
            }

            return(null);
        }
예제 #13
0
        private SearchClause ParseSearch(string queryOption)
        {
            ODataUriParser parser = new ODataUriParser(EdmCoreModel.Instance, ResourceRoot, new Uri(ResourceRoot, "?$search=" + queryOption));

            return(parser.ParseSearch());
        }