本文整理汇总了C#中Microsoft.OData.Core.UriParser.ODataUriParser.ParseUri方法的典型用法代码示例。如果您正苦于以下问题:C# ODataUriParser.ParseUri方法的具体用法?C# ODataUriParser.ParseUri怎么用?C# ODataUriParser.ParseUri使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.OData.Core.UriParser.ODataUriParser
的用法示例。
在下文中一共展示了ODataUriParser.ParseUri方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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);
}
示例2: 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);
}
示例3: 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");
}
示例4: 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();
}
示例5: 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);
}
示例6: 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();
}
示例7: 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());
}
示例8: 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();
}
示例9: ParseSelectExpand
public void ParseSelectExpand()
{
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"));
ODataUri parsedUri = parser.ParseUri();
parsedUri.SelectAndExpand.SelectedItems.First().ShouldBePathSelectionItem(new ODataPath(new PropertySegment(HardCodedTestModel.GetDogColorProp())));
var myPeopleExpand = parsedUri.SelectAndExpand.SelectedItems.Last().ShouldBeSelectedItemOfType<ExpandedNavigationSelectItem>().And;
myPeopleExpand.PathToNavigationProperty.Single().ShouldBeNavigationPropertySegment(HardCodedTestModel.GetDogMyPeopleNavProp());
var myPeopleSelectExpand = myPeopleExpand.SelectAndExpand;
myPeopleSelectExpand.AllSelected.Should().BeTrue();
myPeopleSelectExpand.SelectedItems.Should().BeEmpty();
}
示例10: BuildOrderby_AliasInFunction
public void BuildOrderby_AliasInFunction()
{
Uri fullUri = new Uri("http://gobbledygook/People?$orderby=Fully.Qualified.Namespace.HasDog(inOffice%3D%40p1)&@p1=true");
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;
var expectedFunc = HardCodedTestModel.GetAllHasDogFunctionOverloadsForPeople().Single(s => s.Parameters.Count() == 2);
odataUri.OrderBy.Expression.ShouldBeSingleValueFunctionCallQueryNode(expectedFunc).And.Parameters.Last().As<NamedFunctionParameterNode>().Value.ShouldBeParameterAliasNode("@p1", EdmCoreModel.Instance.GetBoolean(false));
aliasNodes["@p1"].ShouldBeConstantQueryNode(true);
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);
}
示例11: BuildFilter_AliasInFunction_WithoutValue
public void BuildFilter_AliasInFunction_WithoutValue()
{
Uri fullUri = new Uri("http://gobbledygook/People?$filter=Fully.Qualified.Namespace.HasDog(inOffice%3D%40p1%2Cname%3D%40p2)");
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.Filter.Expression.ShouldBeSingleValueFunctionCallQueryNode(HardCodedTestModel.GetHasDogOverloadForPeopleWithThreeParameters().As<IEdmFunction>()).And.Parameters.Last().As<NamedFunctionParameterNode>().Value.ShouldBeParameterAliasNode("@p2", null);
aliasNodes["@p1"].Should().BeNull();
aliasNodes["@p2"].Should().BeNull();
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);
}
示例12: BuildFilter_AliasInFunction_BuiltIn
public void BuildFilter_AliasInFunction_BuiltIn()
{
Uri fullUri = new Uri("http://gobbledygook/People?$filter=contains(%40p1%2CName)&@p1=Name");
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.Filter.Expression.As<SingleValueFunctionCallNode>().Parameters.First().ShouldBeParameterAliasNode("@p1", EdmCoreModel.Instance.GetString(true));
aliasNodes["@p1"].ShouldBeSingleValuePropertyAccessQueryNode(HardCodedTestModel.GetPeopleSet().EntityType().FindProperty("Name"));
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);
}
示例13: BuildFilter_AliasInFunction_enum_undefined
public void BuildFilter_AliasInFunction_enum_undefined()
{
Uri fullUri = new Uri("http://gobbledygook/People?$filter=null%20ne%20Fully.Qualified.Namespace.GetPetCount(colorPattern%3D%40p1)&@p1=Fully.Qualified.Namespace.ColorPattern'238563'");
ODataUriParser odataUriParser = new ODataUriParser(HardCodedTestModel.TestModel, serviceRoot, fullUri);
SetODataUriParserSettingsTo(this.settings, odataUriParser.Settings);
odataUriParser.UrlConventions = ODataUrlConventions.Default;
ODataUri odataUri = odataUriParser.ParseUri();
NamedFunctionParameterNode p = odataUri.Filter.Expression.As<BinaryOperatorNode>().Right.As<SingleEntityFunctionCallNode>().Parameters.First().As<NamedFunctionParameterNode>();
p.Value.As<ParameterAliasNode>().Alias.ShouldBeEquivalentTo("@p1");
p.Value.As<ParameterAliasNode>().TypeReference.IsEnum().Should().Be(true);
p.Value.As<ParameterAliasNode>().TypeReference.Definition.FullTypeName().ShouldBeEquivalentTo("Fully.Qualified.Namespace.ColorPattern");
IDictionary<string, SingleValueNode> aliasNodes = odataUri.ParameterAliasNodes;
aliasNodes["@p1"].As<ConstantNode>().Value.As<ODataEnumValue>().TypeName.Should().Be("Fully.Qualified.Namespace.ColorPattern");
aliasNodes["@p1"].As<ConstantNode>().Value.As<ODataEnumValue>().Value.Should().Be("238563");
aliasNodes["@p1"].TypeReference.IsEnum().Should().Be(true);
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);
}
示例14: ParseCount
public void ParseCount()
{
ODataUriParser parser = new ODataUriParser(HardCodedTestModel.TestModel, new Uri("http://www.odata.com/OData"), new Uri("http://www.odata.com/OData/People?$count=false"));
ODataUri parsedUri = parser.ParseUri();
parsedUri.QueryCount.Should().BeFalse();
}
示例15: BuildFilter_AliasInBinaryOp_ValueAsExpression
public void BuildFilter_AliasInBinaryOp_ValueAsExpression()
{
Uri fullUri = new Uri("http://gobbledygook/People?$filter=ID%20eq%20%40p1&@p1=1 add 2");
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.Filter.Expression.ShouldBeBinaryOperatorNode(BinaryOperatorKind.Equal).And.Right.ShouldBeParameterAliasNode("@p1", EdmCoreModel.Instance.GetInt32(false));
aliasNodes["@p1"].ShouldBeBinaryOperatorNode(BinaryOperatorKind.Add).And.Right.ShouldBeConstantQueryNode(2);
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);
}