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


C# UriParser.ODataUriParser类代码示例

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


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

示例1: ParseOrderby

 public void ParseOrderby()
 {
     ODataUriParser parser = new ODataUriParser(HardCodedTestModel.TestModel, new Uri("http://www.odata.com/OData"), new Uri("http://www.odata.com/OData/People?$orderby=Name asc"));
     ODataUri parsedUri = parser.ParseUri();
     parsedUri.OrderBy.Expression.ShouldBeSingleValuePropertyAccessQueryNode(HardCodedTestModel.GetPersonNameProp());
     parsedUri.OrderBy.Direction.Should().Be(OrderByDirection.Ascending);
 }
开发者ID:rossjempson,项目名称:odata.net,代码行数:7,代码来源:FullUriFunctionalTests.cs

示例2: RouteAsync

        public async Task RouteAsync(RouteContext context)
        {
            var request = context.HttpContext.Request;

            Uri uri;
            PathString remaining;
            if (!request.Path.StartsWithSegments(PathString.FromUriComponent("/" + _routePrefix), out remaining))
            {
                // Fallback to other routes.
                return;
            }

            uri = new Uri(remaining.ToString(), UriKind.Relative);
            
            context.HttpContext.ODataProperties().Model = _model;
            var parser = new ODataUriParser(_model, uri);
            var path = parser.ParsePath();
            context.HttpContext.ODataProperties().NewPath = path;
            context.HttpContext.ODataProperties().Path =
                context.HttpContext.ODataPathHandler().Parse(_model, "http://service-root/", remaining.ToString());
            context.HttpContext.ODataProperties().IsValidODataRequest = true;

            await m.RouteAsync(context);
            context.IsHandled = true;
        }
开发者ID:emreolgun,项目名称:WebApi,代码行数:25,代码来源:ODataRoute.cs

示例3: BuildPath_AliasInFunctionImport

        public void BuildPath_AliasInFunctionImport()
        {
            Uri fullUri = new Uri("http://gobbledygook/GetPet4([email protected])[email protected]=1.01M");
            ODataUriParser odataUriParser = new ODataUriParser(HardCodedTestModel.TestModel, serviceRoot, fullUri);
            SetODataUriParserSettingsTo(this.settings, odataUriParser.Settings);
            odataUriParser.UrlConventions = ODataUrlConventions.Default;
            ODataUri odataUri = odataUriParser.ParseUri();

            IDictionary<string, SingleValueNode> aliasNodes = odataUri.ParameterAliasNodes;

            odataUri.Path.LastSegment.ShouldBeOperationImportSegment(HardCodedTestModel.GetFunctionImportForGetPet4()).And.Parameters.First().ShouldHaveParameterAliasNode("id", "@p1", EdmCoreModel.Instance.GetDecimal(false));
            aliasNodes["@p1"].ShouldBeConstantQueryNode(1.01M);

            ODataUriBuilder odataUriBuilder = new ODataUriBuilder(ODataUrlConventions.Default, odataUri);
            Uri actualUri = odataUriBuilder.BuildUri();
            Assert.AreEqual(fullUri, actualUri);

            ODataUriBuilder uriBuilderWithKeyAsSegment = new ODataUriBuilder(ODataUrlConventions.KeyAsSegment, odataUri);
            actualUri = uriBuilderWithKeyAsSegment.BuildUri();
            Assert.AreEqual(fullUri, actualUri);

            ODataUriBuilder uriBuilderWithODataSimplified = new ODataUriBuilder(ODataUrlConventions.ODataSimplified, odataUri);
            actualUri = uriBuilderWithODataSimplified.BuildUri();
            Assert.AreEqual(fullUri, actualUri);
        }
开发者ID:modulexcite,项目名称:odata.net,代码行数:25,代码来源:UrlBuilderWithParameterAliasTests.cs

示例4: PathNavigation

        public void PathNavigation()
        {
            ODataUriParser parser = new ODataUriParser(model, new Uri("http://www.potato.com/"), new Uri("http://www.potato.com/Customers(5)/Orders"));
            var result = parser.ParsePath();
            ApprovalVerify(QueryNodeToStringVisitor.ToString(result));

            this.TestExtensions("CustoMERS(5)/OrDErs");
        }
开发者ID:rossjempson,项目名称:odata.net,代码行数:8,代码来源:PathTests.cs

示例5: PathEntity

        public void PathEntity()
        {
            ODataUriParser parser = new ODataUriParser(model, new Uri("http://www.potato.com/"), new Uri("http://www.potato.com/Orders(2)"));
            var result = parser.ParsePath();
            ApprovalVerify(QueryNodeToStringVisitor.ToString(result));

            this.TestExtensions("OrDERS(2)");
        }
开发者ID:rossjempson,项目名称:odata.net,代码行数:8,代码来源:PathTests.cs

示例6: GetContextUrlPathString

 private string GetContextUrlPathString(Uri queryUri)
 {
     ODataUriParser odataUriParser = new ODataUriParser(HardCodedTestModel.TestModel, queryUri);
     odataUriParser.UrlConventions = ODataUrlConventions.Default;
     ODataUri odataUri = odataUriParser.ParseUri();
     ODataPath odataPath = odataUri.Path;
    return odataPath.ToContextUrlPathString();
 }
开发者ID:rossjempson,项目名称:odata.net,代码行数:8,代码来源:ContextUrlPathStringTests.cs

示例7: ParseFilter

 public void ParseFilter()
 {
     ODataUriParser parser = new ODataUriParser(HardCodedTestModel.TestModel, new Uri("http://www.odata.com/OData"), new Uri("http://www.odata.com/OData/People?$filter=Name eq 'Bob'"));
     ODataUri parsedUri = parser.ParseUri();
     var equalOperator = parsedUri.Filter.Expression.ShouldBeBinaryOperatorNode(BinaryOperatorKind.Equal).And;
     equalOperator.Left.ShouldBeSingleValuePropertyAccessQueryNode(HardCodedTestModel.GetPersonNameProp());
     equalOperator.Right.ShouldBeConstantQueryNode("Bob");
 }
开发者ID:rossjempson,项目名称:odata.net,代码行数:8,代码来源:FullUriFunctionalTests.cs

示例8: PathComplex

        public void PathComplex()
        {
            ODataUriParser parser = new ODataUriParser(model, new Uri("http://www.potato.com/"), new Uri("http://www.potato.com/Customers(-32)/HomeAddress"));
            var result = parser.ParsePath();
            ApprovalVerify(QueryNodeToStringVisitor.ToString(result));

            this.TestExtensions("CustomErs(-32)/HOMEAddress");
        }
开发者ID:rossjempson,项目名称:odata.net,代码行数:8,代码来源:PathTests.cs

示例9: PathBatch

        public void PathBatch()
        {
            ODataUriParser parser = new ODataUriParser(model, new Uri("http://www.potato.com/"), new Uri("http://www.potato.com/$batch"));
            var result = parser.ParsePath();
            ApprovalVerify(QueryNodeToStringVisitor.ToString(result));

            this.TestExtensions("$BATch");
        }
开发者ID:rossjempson,项目名称:odata.net,代码行数:8,代码来源:PathTests.cs

示例10: ODataUriBuilderWithEntitySet

        public void ODataUriBuilderWithEntitySet()
        {
            Uri fullUri = new Uri("http://www.example.com/People?$filter=MyDog%2FColor%20eq%20%27Brown%27&$select=ID&$expand=MyDog&$orderby=ID&$top=1&$skip=2&$count=true&$search=FA");
            ODataUriParser odataUriParser = new ODataUriParser(this.GetModel(), serviceRoot, fullUri);
            odataUriParser.UrlConventions = ODataUrlConventions.Default;
            SetODataUriParserSettingsTo(this.settings, odataUriParser.Settings);
            ODataUri odataUri = odataUriParser.ParseUri();

            //verify path
            EntitySetSegment entitySet = (EntitySetSegment)odataUri.Path.FirstSegment;
            Assert.AreEqual(entitySet.EntitySet.Name, "People");
            Assert.AreEqual(odataUri.Path.Count, 1);

            //verify $filter
            BinaryOperatorNode binaryOperator = (BinaryOperatorNode)odataUri.Filter.Expression;
            SingleValuePropertyAccessNode singleValueProperty = (SingleValuePropertyAccessNode)binaryOperator.Left;
            SingleNavigationNode singleNavigation = (SingleNavigationNode)singleValueProperty.Source;
            ConstantNode constantNode = (ConstantNode)binaryOperator.Right;

            Assert.AreEqual(binaryOperator.OperatorKind, BinaryOperatorKind.Equal);
            Assert.AreEqual(singleValueProperty.Property.Name, "Color");
            Assert.AreEqual(singleNavigation.NavigationProperty.Name, "MyDog");
            Assert.AreEqual(constantNode.LiteralText, "'Brown'");

            //verify $select and $expand
            IEnumerable<SelectItem> selectItems = odataUri.SelectAndExpand.SelectedItems;
            foreach (ExpandedNavigationSelectItem selectItem in selectItems)
            {
                NavigationPropertySegment navigationProperty = (NavigationPropertySegment)selectItem.PathToNavigationProperty.FirstSegment;
                Assert.AreEqual(navigationProperty.NavigationProperty.Name, "MyDog");
                break;
            }

            //verify $orderby
            SingleValuePropertyAccessNode orderby = (SingleValuePropertyAccessNode)odataUri.OrderBy.Expression;
            Assert.AreEqual(orderby.Property.Name, "ID");

            //verify $top
            Assert.AreEqual(odataUri.Top, 1);

            //verify $skip
            Assert.AreEqual(odataUri.Skip, 2);

            //verify $count
            Assert.AreEqual(odataUri.QueryCount, true);

            //verify $search
            SearchTermNode searchTermNode = (SearchTermNode)odataUri.Search.Expression;
            Assert.AreEqual(searchTermNode.Text, "FA");

            ODataUriBuilder odataUriBuilder = new ODataUriBuilder(ODataUrlConventions.Default, odataUri);
            Uri actualUri = odataUriBuilder.BuildUri();
            Assert.AreEqual(new Uri("http://www.example.com/People?$filter=MyDog%2FColor%20eq%20%27Brown%27&$select=ID%2CMyDog&$expand=MyDog&$orderby=ID&$top=1&$skip=2&$count=true&$search=FA"), actualUri);

            ODataUriBuilder uriBuilderWithKeyAsSegment = new ODataUriBuilder(ODataUrlConventions.KeyAsSegment, odataUri);
            actualUri = uriBuilderWithKeyAsSegment.BuildUri();
            Assert.AreEqual(new Uri("http://www.example.com/People?$filter=MyDog%2FColor%20eq%20%27Brown%27&$select=ID%2CMyDog&$expand=MyDog&$orderby=ID&$top=1&$skip=2&$count=true&$search=FA"), actualUri);
        }
开发者ID:rossjempson,项目名称:odata.net,代码行数:58,代码来源:UriBuilderTests.cs

示例11: ParsePathWithValue

 public void ParsePathWithValue()
 {
     ODataUriParser parser = new ODataUriParser(HardCodedTestModel.TestModel, new Uri("http://www.odata.com/OData"), new Uri("http://www.odata.com/OData/People(1)/$value"));
     ODataUri parsedUri = parser.ParseUri();
     List<ODataPathSegment> path = parsedUri.Path.ToList();
     path[0].ShouldBeEntitySetSegment(HardCodedTestModel.GetPeopleSet());
     path[1].ShouldBeKeySegment(new KeyValuePair<string, object>("ID", 1));
     path[2].ShouldBeValueSegment();
 }
开发者ID:rossjempson,项目名称:odata.net,代码行数:9,代码来源:FullUriFunctionalTests.cs

示例12: ParsePathWithLinks

 public void ParsePathWithLinks()
 {
     ODataUriParser parser = new ODataUriParser(HardCodedTestModel.TestModel, new Uri("http://www.odata.com/OData"), new Uri("http://www.odata.com/OData/People(1)/MyDog/$ref"));
     ODataUri parsedUri = parser.ParseUri();
     List<ODataPathSegment> path = parsedUri.Path.ToList();
     path[0].ShouldBeEntitySetSegment(HardCodedTestModel.GetPeopleSet());
     path[1].ShouldBeKeySegment(new KeyValuePair<string, object>("ID", 1));
     path[2].ShouldBeNavigationPropertyLinkSegment(HardCodedTestModel.GetPersonMyDogNavProp());
 }
开发者ID:rossjempson,项目名称:odata.net,代码行数:9,代码来源:FullUriFunctionalTests.cs

示例13: UriBuilder

        public static Uri UriBuilder(Uri queryUri, ODataUrlConventions urlConventions, ODataUriParserSettings settings)
        {
            ODataUriParser odataUriParser = new ODataUriParser(HardCodedTestModel.TestModel, ServiceRoot, queryUri);
            SetODataUriParserSettingsTo(settings, odataUriParser.Settings);
            odataUriParser.UrlConventions = urlConventions;
            ODataUri odataUri = odataUriParser.ParseUri();

            ODataUriBuilder odataUriBuilder = new ODataUriBuilder(urlConventions, odataUri);
            return odataUriBuilder.BuildUri();
        }
开发者ID:larsenjo,项目名称:odata.net,代码行数:10,代码来源:UriBuilderTestBase.cs

示例14: KeyAfterFunction

        private static void KeyAfterFunction()
        {
            Console.WriteLine("TestKeyAfterFunction");
            var parser = new ODataUriParser(
                extModel.Model,
                ServiceRoot,
                new Uri("http://demo/odata.svc/People(2)/TestNS.GetFriends(2)"));

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

示例15: KeyContainingSpecialChar

        private static void KeyContainingSpecialChar()
        {
            Console.WriteLine("KeyContainingSpecialChar");
            var parser = new ODataUriParser(
                extModel.Model,
                ServiceRoot,
                new Uri("http://demo/odata.svc/Resources('w%23j')"));

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


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