當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。