本文整理汇总了C#中Microsoft.OData.Core.UriParser.ODataQueryOptionParser.ParseOrderBy方法的典型用法代码示例。如果您正苦于以下问题:C# ODataQueryOptionParser.ParseOrderBy方法的具体用法?C# ODataQueryOptionParser.ParseOrderBy怎么用?C# ODataQueryOptionParser.ParseOrderBy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.OData.Core.UriParser.ODataQueryOptionParser
的用法示例。
在下文中一共展示了ODataQueryOptionParser.ParseOrderBy方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: QueryOptionWithEmptyValueShouldWork
public void QueryOptionWithEmptyValueShouldWork()
{
var uriParser = new ODataQueryOptionParser(HardCodedTestModel.TestModel, HardCodedTestModel.GetPersonType(), HardCodedTestModel.GetPeopleSet(), new Dictionary<string, string>()
{
{"$filter" , ""},
{"$expand" , ""},
{"$select" , ""},
{"$orderby" , ""},
{"$top" , ""},
{"$skip" , ""},
{"$count" , ""},
{"$search" , ""},
{"$unknow" , ""},
});
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, ""));
}
示例2: EmptyQueryOptionDictionaryShouldWork
public void EmptyQueryOptionDictionaryShouldWork()
{
var uriParser = new ODataQueryOptionParser(HardCodedTestModel.TestModel, HardCodedTestModel.GetPersonType(), HardCodedTestModel.GetPeopleSet(), new Dictionary<string, string>());
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();
}
示例3: TestCaseInsensitive
private static void TestCaseInsensitive()
{
Console.WriteLine("TestCaseInsensitive");
var parser = new ODataUriParser(
extModel.Model,
ServiceRoot,
new Uri("http://demo/odata.svc/People(1)/Pets/TestNS.Fish?$orderby=Color"));
var path = parser.ParsePath();
var clause = parser.ParseOrderBy();
Console.WriteLine(path.ToLogString());
Console.WriteLine(clause.Expression.ToLogString());
var parser2 = new ODataUriParser(
extModel.Model,
ServiceRoot,
new Uri("http://demo/odata.svc/people(1)/pets/testns.fish?$ORDERBY=color"))
{
Resolver = new ODataUriResolver { EnableCaseInsensitive = true }
};
// Identical to path and clause
var path2 = parser2.ParsePath();
var clause2 = parser2.ParseOrderBy();
Console.WriteLine(path2.ToLogString());
Console.WriteLine(clause2.Expression.ToLogString());
// Query option parser also supports custom resolver
var parser3 = new ODataQueryOptionParser(
extModel.Model,
extModel.Fish,
extModel.PetSet,
new Dictionary<string, string>
{
{"$orderby", "color"}
})
{
Resolver = new ODataUriResolver { EnableCaseInsensitive = true }
};
var clause3 = parser3.ParseOrderBy();
Console.WriteLine(clause3.Expression.ToLogString());
}
示例4: CreateCollection_From_OrderByNode_Succeeds
public void CreateCollection_From_OrderByNode_Succeeds()
{
// Arrange
ODataConventionModelBuilder builder = ODataModelBuilderMocks.GetModelBuilderMock<ODataConventionModelBuilder>();
builder.EntitySet<SampleClass>("entityset");
IEdmModel model = builder.GetEdmModel();
IEdmEntityType sampleClassEntityType = model.SchemaElements.Single(t => t.Name == "SampleClass") as IEdmEntityType;
Assert.NotNull(sampleClassEntityType); // Guard
IEdmEntitySet entitySet = model.EntityContainer.FindEntitySet("entityset");
Assert.NotNull(entitySet); // Guard
ODataQueryOptionParser parser = new ODataQueryOptionParser(model, sampleClassEntityType, entitySet,
new Dictionary<string, string> { { "$orderby", "Property1 desc, Property2 asc" } });
OrderByClause orderbyNode = parser.ParseOrderBy();
// Act
ICollection<OrderByNode> nodes = OrderByNode.CreateCollection(orderbyNode);
// Assert
Assert.False(nodes.OfType<OrderByItNode>().Any());
IEnumerable<OrderByPropertyNode> propertyNodes = nodes.OfType<OrderByPropertyNode>();
Assert.Equal(2, propertyNodes.Count());
Assert.Equal("Property1", propertyNodes.First().Property.Name);
Assert.Equal(OrderByDirection.Descending, propertyNodes.First().Direction);
Assert.ReferenceEquals("Property2", propertyNodes.Last().Property.Name);
Assert.Equal(OrderByDirection.Ascending, nodes.Last().Direction);
}
示例5: CreateCollection_CopmplexType_Succeeds
public void CreateCollection_CopmplexType_Succeeds()
{
// Arrange
CustomersModelWithInheritance model = new CustomersModelWithInheritance();
ODataQueryOptionParser parser = new ODataQueryOptionParser(model.Model, model.Customer, model.Customers,
new Dictionary<string, string> { { "$orderby", "Address/Street desc, Address/City asc" } });
OrderByClause orderByNode = parser.ParseOrderBy();
// Act
ICollection<OrderByNode> nodes = OrderByNode.CreateCollection(orderByNode);
// Assert
Assert.Equal(2, nodes.Count());
Assert.Equal("Street", (nodes.ToList()[0] as OrderByPropertyNode).Property.Name);
Assert.Equal(OrderByDirection.Descending, nodes.ToList()[0].Direction);
Assert.Equal("City", (nodes.ToList()[1] as OrderByPropertyNode).Property.Name);
Assert.Equal(OrderByDirection.Ascending, nodes.ToList()[1].Direction);
}
示例6: CreateCollection_PropertyAliased_IfEnabled
public void CreateCollection_PropertyAliased_IfEnabled(bool modelAliasing, string typeName, string propertyName)
{
// Arrange
ODataConventionModelBuilder builder = new ODataConventionModelBuilder { ModelAliasingEnabled = modelAliasing };
builder.EntitySet<PropertyAlias>("entityset");
IEdmModel model = builder.GetEdmModel();
IEdmEntityType entityType = model.SchemaElements.Single(t => t.Name == typeName) as IEdmEntityType;
Assert.NotNull(entityType); // Guard
IEdmEntitySet entitySet = model.EntityContainer.FindEntitySet("entityset");
Assert.NotNull(entitySet); // Guard
ODataQueryOptionParser parser = new ODataQueryOptionParser(model, entityType, entitySet,
new Dictionary<string, string> { { "$orderby", propertyName + " desc, Id asc" } });
OrderByClause orderbyNode = parser.ParseOrderBy();
// Act
ICollection<OrderByNode> nodes = OrderByNode.CreateCollection(orderbyNode);
// Assert
Assert.False(nodes.OfType<OrderByItNode>().Any());
IEnumerable<OrderByPropertyNode> propertyNodes = nodes.OfType<OrderByPropertyNode>();
Assert.Equal(2, propertyNodes.Count());
Assert.Equal(propertyName, propertyNodes.First().Property.Name);
Assert.Equal(OrderByDirection.Descending, propertyNodes.First().Direction);
Assert.ReferenceEquals("Id", propertyNodes.Last().Property.Name);
Assert.Equal(OrderByDirection.Ascending, nodes.Last().Direction);
}
示例7: QueryOptionWithNullValueShouldWork
public void QueryOptionWithNullValueShouldWork()
{
var uriParser = new ODataQueryOptionParser(HardCodedTestModel.TestModel, HardCodedTestModel.GetPersonType(), HardCodedTestModel.GetPeopleSet(), new Dictionary<string, string>()
{
{"$filter" , null},
{"$expand" , null},
{"$select" , null},
{"$orderby" , null},
{"$top" , null},
{"$skip" , null},
{"$count" , null},
{"$search" , null},
{"$unknow" , null},
});
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();
}
示例8: 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);
}
}
示例9: AggregatedPropertiesTreatedAsOpenPropertyInOrderBy
public void AggregatedPropertiesTreatedAsOpenPropertyInOrderBy()
{
var odataQueryOptionParser = new ODataQueryOptionParser(HardCodedTestModel.TestModel,
HardCodedTestModel.GetPersonType(), HardCodedTestModel.GetPeopleSet(),
new Dictionary<string, string>()
{
{"$orderby", "Total asc, Max desc"},
{"$apply", "aggregate(FavoriteNumber with sum as Total, StockQuantity with max as Max)"}
});
odataQueryOptionParser.ParseApply();
var orderByClause = odataQueryOptionParser.ParseOrderBy();
orderByClause.Direction.Should().Be(OrderByDirection.Ascending);
orderByClause.Expression.ShouldBeSingleValueOpenPropertyAccessQueryNode("Total");
orderByClause = orderByClause.ThenBy;
orderByClause.Direction.Should().Be(OrderByDirection.Descending);
orderByClause.Expression.ShouldBeSingleValueOpenPropertyAccessQueryNode("Max");
}