当前位置: 首页>>代码示例>>C#>>正文


C# ODataUriParser.ParseFilter方法代码示例

本文整理汇总了C#中Microsoft.OData.Core.UriParser.ODataUriParser.ParseFilter方法的典型用法代码示例。如果您正苦于以下问题:C# ODataUriParser.ParseFilter方法的具体用法?C# ODataUriParser.ParseFilter怎么用?C# ODataUriParser.ParseFilter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Microsoft.OData.Core.UriParser.ODataUriParser的用法示例。


在下文中一共展示了ODataUriParser.ParseFilter方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: FilterOnOpenProperty

        private static void FilterOnOpenProperty()
        {
            Console.WriteLine("FilterOnOpenProperty");
            var parser = new ODataUriParser(
                extModel.Model,
                ServiceRoot,
                new Uri("http://demo/odata.svc/Resources?$filter=Name eq 'w'"));

            var filter = parser.ParseFilter();
            Console.WriteLine(filter.Expression.ToLogString());
        }
开发者ID:nickgoodrow,项目名称:ODataSamples,代码行数:11,代码来源:Program.cs

示例2: NoneQueryOptionShouldWork

 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();
     uriParser.ParseSkipToken().Should().BeNull();
     uriParser.ParseDeltaToken().Should().BeNull();
 }
开发者ID:larsenjo,项目名称:odata.net,代码行数:16,代码来源:ODataUriParserTests.cs

示例3: EmptyValueQueryOptionShouldWork

 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();
 }
开发者ID:larsenjo,项目名称:odata.net,代码行数:22,代码来源:ODataUriParserTests.cs

示例4: ParseWithCustomUriFunction

        public void ParseWithCustomUriFunction()
        {
            try
            {
                FunctionSignatureWithReturnType myStringFunction
                    = new FunctionSignatureWithReturnType(EdmCoreModel.Instance.GetBoolean(true), EdmCoreModel.Instance.GetString(true), EdmCoreModel.Instance.GetString(true));

                // Add a custom uri function
                CustomUriFunctions.AddCustomUriFunction("mystringfunction", myStringFunction);

                var fullUri = new Uri("http://www.odata.com/OData/People" + "?$filter=mystringfunction(Name, 'BlaBla')");
                ODataUriParser parser = new ODataUriParser(HardCodedTestModel.TestModel, new Uri("http://www.odata.com/OData/"), fullUri);

                var startsWithArgs = parser.ParseFilter().Expression.ShouldBeSingleValueFunctionCallQueryNode("mystringfunction").And.Parameters.ToList();
                startsWithArgs[0].ShouldBeSingleValuePropertyAccessQueryNode(HardCodedTestModel.GetPersonNameProp());
                startsWithArgs[1].ShouldBeConstantQueryNode("BlaBla");
            }
            finally
            {
                CustomUriFunctions.RemoveCustomUriFunction("mystringfunction").Should().BeTrue();
            }
        }
开发者ID:AlineGuan,项目名称:odata.net,代码行数:22,代码来源:CustomUriFunctionsTests.cs

示例5: FilterLimitIsRespectedForFilter

 public void FilterLimitIsRespectedForFilter()
 {
     ODataUriParser parser = new ODataUriParser(HardCodedTestModel.TestModel, ServiceRoot, new Uri("http://host/People?$filter=1 eq 1")) { Settings = { FilterLimit = 0 } };
     Action parseWithLimit = () => parser.ParseFilter();
     parseWithLimit.ShouldThrow<ODataException>().WithMessage(ODataErrorStrings.UriQueryExpressionParser_TooDeep);
 }
开发者ID:larsenjo,项目名称:odata.net,代码行数:6,代码来源:ODataUriParserTests.cs

示例6: FilterLimitWithInterestingTreeStructures

 public void FilterLimitWithInterestingTreeStructures()
 {
     ODataUriParser parser = new ODataUriParser(HardCodedTestModel.TestModel, ServiceRoot, new Uri("http://host/People?$filter=MyDog/Color eq 'Brown' or MyDog/Color eq 'White'")) { Settings = { FilterLimit = 5 } };
     Action parseWithLimit = () => parser.ParseFilter();
     parseWithLimit.ShouldThrow<ODataException>().WithMessage(ODataErrorStrings.UriQueryExpressionParser_TooDeep);
 }
开发者ID:larsenjo,项目名称:odata.net,代码行数:6,代码来源:ODataUriParserTests.cs

示例7: CustomUriLiteralPrefix_CannotParseTypeWithWrongLiteralPrefix

        public void CustomUriLiteralPrefix_CannotParseTypeWithWrongLiteralPrefix()
        {
            try
            {
                IEdmTypeReference booleanTypeReference = EdmCoreModel.Instance.GetBoolean(false);
                CustomUriLiteralPrefixes.AddCustomLiteralPrefix(CustomUriLiteralParserUnitTests.BOOLEAN_LITERAL_PREFIX, booleanTypeReference);

                var fullUri = new Uri("http://www.odata.com/OData/People" + string.Format("?$filter=Name eq {0}'{1}'", CustomUriLiteralParserUnitTests.BOOLEAN_LITERAL_PREFIX, CustomUriLiteralParserUnitTests.CUSTOM_PARSER_STRING_VALID_VALUE));
                ODataUriParser parser = new ODataUriParser(HardCodedTestModel.TestModel, new Uri("http://www.odata.com/OData/"), fullUri);

                Action parsingFilterAction = () =>
                    parser.ParseFilter();

                parsingFilterAction.ShouldThrow<ODataException>();
            }
            finally
            {
                CustomUriLiteralPrefixes.RemoveCustomLiteralPrefix(CustomUriLiteralParserUnitTests.BOOLEAN_LITERAL_PREFIX);
            }
        }
开发者ID:TomDu,项目名称:odata.net,代码行数:20,代码来源:CustomUriLiteralPrefixesTests.cs

示例8: FunctionParameterAliasWorksInFilter

        public void FunctionParameterAliasWorksInFilter()
        {
            var uriParser = new ODataUriParser(HardCodedTestModel.TestModel, new Uri("http://host/"), new Uri("http://host/People?$filter=Fully.Qualified.Namespace.HasDog([email protected])&@a=null"));
            var filterClause = uriParser.ParseFilter();
            filterClause.Expression.ShouldBeSingleValueFunctionCallQueryNode(HardCodedTestModel.GetHasDogOverloadForPeopleWithTwoParameters())
                .And.Parameters.Single().As<NamedFunctionParameterNode>()
                .Value.As<ParameterAliasNode>().Alias.Should().Be("@a");

            // verify alias value node:
            uriParser.ParameterAliasNodes["@a"].ShouldBeConstantQueryNode((object)null);
        }
开发者ID:larsenjo,项目名称:odata.net,代码行数:11,代码来源:FilterAndOrderByFunctionalTests.cs

示例9: ParseUriAndVerify

        private void ParseUriAndVerify(
            Uri uri,
            Action<ODataPath, FilterClause, OrderByClause, SelectExpandClause, IDictionary<string, SingleValueNode>> verifyAction)
        {
            // run 2 test passes:
            // 1. low level api - ODataUriParser instance methods
            {
                List<CustomQueryOptionToken> queries = UriUtils.ParseQueryOptions(uri);
                ODataUriParser parser = new ODataUriParser(HardCodedTestModel.TestModel, new Uri("http://gobbledygook/"), uri);

                ODataPath path = parser.ParsePath();
                IEdmNavigationSource entitySource = ResolveEntitySource(path);
                IEdmEntitySet entitySet = entitySource as IEdmEntitySet;

                var dic = queries.ToDictionary(customQueryOptionToken => customQueryOptionToken.Name, customQueryOptionToken => queries.GetQueryOptionValue(customQueryOptionToken.Name));
                ODataQueryOptionParser queryOptionParser = new ODataQueryOptionParser(HardCodedTestModel.TestModel, entitySet.EntityType(), entitySet, dic)
                {
                    Configuration = { ParameterAliasValueAccessor = parser.ParameterAliasValueAccessor }
                };

                FilterClause filterClause = queryOptionParser.ParseFilter();
                SelectExpandClause selectExpandClause = queryOptionParser.ParseSelectAndExpand();
                OrderByClause orderByClause = queryOptionParser.ParseOrderBy();

                // Two parser should share same ParameterAliasNodes
                verifyAction(path, filterClause, orderByClause, selectExpandClause, parser.ParameterAliasNodes);
                verifyAction(path, filterClause, orderByClause, selectExpandClause, queryOptionParser.ParameterAliasNodes);
            }

            //2. high level api - ParseUri
            {
                ODataUriParser parser = new ODataUriParser(HardCodedTestModel.TestModel, new Uri("http://gobbledygook/"), uri);
                verifyAction(parser.ParsePath(), parser.ParseFilter(), parser.ParseOrderBy(), parser.ParseSelectAndExpand(), parser.ParameterAliasNodes);
            }
        }
开发者ID:rossjempson,项目名称:odata.net,代码行数:35,代码来源:ParameterAliasFunctionalTests.cs

示例10: CustomUriLiteralPrefix_CannotParseWithCustomLiteralPrefix_IfBuiltInParserDontRecognizeCustomLiteral

        public void CustomUriLiteralPrefix_CannotParseWithCustomLiteralPrefix_IfBuiltInParserDontRecognizeCustomLiteral()
        {
            const string STRING_LITERAL_PREFIX = "myCustomStringLiteralPrefix";

            try
            {
                IEdmTypeReference stringTypeReference = EdmCoreModel.Instance.GetString(true);
                CustomUriLiteralPrefixes.AddCustomLiteralPrefix(STRING_LITERAL_PREFIX, stringTypeReference);

                var fullUri = new Uri("http://www.odata.com/OData/People" + string.Format("?$filter=Name eq {0}'{1}'", STRING_LITERAL_PREFIX, CustomUriLiteralParserUnitTests.CUSTOM_PARSER_STRING_VALID_VALUE));
                ODataUriParser parser = new ODataUriParser(HardCodedTestModel.TestModel, new Uri("http://www.odata.com/OData/"), fullUri);

                Action parsingFilter = () => parser.ParseFilter();
                parsingFilter.ShouldThrow<ODataException>();
            }
            finally
            {
                CustomUriLiteralPrefixes.RemoveCustomLiteralPrefix(STRING_LITERAL_PREFIX);
            }
        }
开发者ID:TomDu,项目名称:odata.net,代码行数:20,代码来源:CustomUriLiteralPrefixesTests.cs

示例11: ParseWithCustomUriFunction_CustomParserThrowsExceptionAndReturnNotNullValue

        public void ParseWithCustomUriFunction_CustomParserThrowsExceptionAndReturnNotNullValue()
        {
            RegisterTestCase("ParseWithCustomUriFunction_CustomParserThrowsExceptionAndReturnNotNullValue");
            IUriLiteralParser customStringLiteralParser = new MyCustomStringUriLiteralParser();
            try
            {
                CustomUriLiteralParsers.AddCustomUriLiteralParser(EdmCoreModel.Instance.GetString(true), customStringLiteralParser);

                var fullUri = new Uri("http://www.odata.com/OData/People" + string.Format("?$filter=Name eq '{0}'", CUSTOM_PARSER_STRING_VALUE_CAUSEBUG));
                ODataUriParser parser = new ODataUriParser(HardCodedTestModel.TestModel, new Uri("http://www.odata.com/OData/"), fullUri);

                Action parseUriAction = () =>
                    parser.ParseFilter();

                parseUriAction.ShouldThrow<ODataException>().
                    WithInnerException<UriLiteralParsingException>();
            }
            finally
            {
                CustomUriLiteralParsers.RemoveCustomUriLiteralParser(customStringLiteralParser).Should().BeTrue();
            }
        }
开发者ID:TomDu,项目名称:odata.net,代码行数:22,代码来源:CustomUriLiteralParserTests.cs

示例12: CustomUriLiteralPrefix_CanSetCustomLiteralWithCustomLiteralParserCustomType

        public void CustomUriLiteralPrefix_CanSetCustomLiteralWithCustomLiteralParserCustomType()
        {
            RegisterTestCase("CustomUriLiteralPrefix_CanSetCustomLiteralWithCustomLiteralParserCustomType");
            const string HEARTBEAT_LITERAL_PREFIX = "myCustomHeartbeatTypePrefixLiteral";
            IUriLiteralParser customHeartbeatUriTypePraser = new HeatBeatCustomUriLiteralParser();
            IEdmTypeReference heartbeatTypeReference = HeatBeatCustomUriLiteralParser.HeartbeatComplexType;

            try
            {
                CustomUriLiteralPrefixes.AddCustomLiteralPrefix(HEARTBEAT_LITERAL_PREFIX, heartbeatTypeReference);
                CustomUriLiteralParsers.AddCustomUriLiteralParser(heartbeatTypeReference, customHeartbeatUriTypePraser);

                var fullUri = new Uri("http://www.odata.com/OData/Lions" + string.Format("?$filter=LionHeartbeat eq {0}'55.9'", HEARTBEAT_LITERAL_PREFIX));
                ODataUriParser parser = new ODataUriParser(HardCodedTestModel.TestModel, new Uri("http://www.odata.com/OData/"), fullUri);

                HeatBeatCustomUriLiteralParser.HeatBeat heartbeatValue =
                  (parser.ParseFilter().Expression.ShouldBeBinaryOperatorNode(BinaryOperatorKind.Equal).And.Right.ShouldBeConvertQueryNode(heartbeatTypeReference).And.Source as ConstantNode).
                  Value.As<HeatBeatCustomUriLiteralParser.HeatBeat>();

                heartbeatValue.Should().NotBeNull();
                heartbeatValue.Frequency.Should().Be(55.9);
            }
            finally
            {
                CustomUriLiteralPrefixes.RemoveCustomLiteralPrefix(HEARTBEAT_LITERAL_PREFIX);
                CustomUriLiteralParsers.RemoveCustomUriLiteralParser(customHeartbeatUriTypePraser);
            }
        }
开发者ID:TomDu,项目名称:odata.net,代码行数:28,代码来源:CustomUriLiteralParserTests.cs

示例13: ParseWithAllQueryOptionsWithAlias

        public void ParseWithAllQueryOptionsWithAlias()
        {
            var fullUri = new Uri("http://www.odata.com/OData/People(1)/Fully.Qualified.Namespace.GetHotPeople([email protected])" + "?$filter=startswith(Name, @p2)&@p1=123&@p3='Blue'&@p2=concat('is_p2',@p3)");
            ODataUriParser parser = new ODataUriParser(HardCodedTestModel.TestModel, new Uri("http://www.odata.com/OData/"), fullUri);

            var startsWithArgs = parser.ParseFilter().Expression.ShouldBeSingleValueFunctionCallQueryNode("startswith").And.Parameters.ToList();
            startsWithArgs[0].ShouldBeSingleValuePropertyAccessQueryNode(HardCodedTestModel.GetPersonNameProp());
            startsWithArgs[1].ShouldBeParameterAliasNode("@p2", EdmCoreModel.Instance.GetString(true));

            // @p1
            parser.ParameterAliasNodes["@p1"].TypeReference.IsInt32().Should().BeTrue();

            // @p2
            List<QueryNode> p2Node = parser.ParameterAliasNodes["@p2"].ShouldBeSingleValueFunctionCallQueryNode("concat").And.Parameters.ToList();
            p2Node[0].ShouldBeConstantQueryNode("is_p2");
            p2Node[1].ShouldBeParameterAliasNode("@p3", EdmCoreModel.Instance.GetString(true));

            // @p3
            parser.ParameterAliasNodes["@p3"].ShouldBeConstantQueryNode("Blue");

        }
开发者ID:rossjempson,项目名称:odata.net,代码行数:21,代码来源:FullUriFunctionalTests.cs

示例14: ParseQueryOptionsShouldWork

 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&$skiptoken=abc&$deltatoken=def", 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();
     parser.ParseSkipToken().Should().Be("abc");
     parser.ParseDeltaToken().Should().Be("def");
 }
开发者ID:larsenjo,项目名称:odata.net,代码行数:13,代码来源:ODataUriParserTests.cs

示例15: ParseWithAllQueryOptionsWithoutAlias

 public void ParseWithAllQueryOptionsWithoutAlias()
 {
     ODataUriParser parser = new ODataUriParser(HardCodedTestModel.TestModel, new Uri("http://www.odata.com/OData/"), new Uri("http://www.odata.com/OData/Dogs?$select=Color, MyPeople&$expand=MyPeople&$filter=startswith(Color, 'Blue')&$orderby=Color asc"));
     parser.ParsePath().FirstSegment.ShouldBeEntitySetSegment(HardCodedTestModel.GetDogsSet());
     var myDogSelectedItems = parser.ParseSelectAndExpand().SelectedItems.ToList();
     myDogSelectedItems.Count.Should().Be(3);
     myDogSelectedItems[1].ShouldBePathSelectionItem(new ODataPath(new PropertySegment(HardCodedTestModel.GetDogColorProp())));
     var myPeopleExpansionSelectionItem = myDogSelectedItems[0].ShouldBeSelectedItemOfType<ExpandedNavigationSelectItem>().And;
     myPeopleExpansionSelectionItem.PathToNavigationProperty.Single().ShouldBeNavigationPropertySegment(HardCodedTestModel.GetDogMyPeopleNavProp());
     myPeopleExpansionSelectionItem.SelectAndExpand.SelectedItems.Should().BeEmpty();
     var startsWithArgs = parser.ParseFilter().Expression.ShouldBeSingleValueFunctionCallQueryNode("startswith").And.Parameters.ToList();
     startsWithArgs[0].ShouldBeSingleValuePropertyAccessQueryNode(HardCodedTestModel.GetDogColorProp());
     startsWithArgs[1].ShouldBeConstantQueryNode("Blue");
     var orderby = parser.ParseOrderBy();
     orderby.Direction.Should().Be(OrderByDirection.Ascending);
     orderby.Expression.ShouldBeSingleValuePropertyAccessQueryNode(HardCodedTestModel.GetDogColorProp());
 }
开发者ID:rossjempson,项目名称:odata.net,代码行数:17,代码来源:FullUriFunctionalTests.cs


注:本文中的Microsoft.OData.Core.UriParser.ODataUriParser.ParseFilter方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。