本文整理汇总了C#中ODataQueryOptions.AddAutoExpandProperties方法的典型用法代码示例。如果您正苦于以下问题:C# ODataQueryOptions.AddAutoExpandProperties方法的具体用法?C# ODataQueryOptions.AddAutoExpandProperties怎么用?C# ODataQueryOptions.AddAutoExpandProperties使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ODataQueryOptions
的用法示例。
在下文中一共展示了ODataQueryOptions.AddAutoExpandProperties方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ProcessLevelsCorrectly_WithAutoExpand
public void ProcessLevelsCorrectly_WithAutoExpand()
{
// Arrange
var model = GetAutoExpandEdmModel();
var context = new ODataQueryContext(
model,
model.FindDeclaredType("System.Web.OData.TestCommon.Models.AutoExpandCustomer"));
var request = new HttpRequestMessage(HttpMethod.Get, "http://test");
var queryOption = new ODataQueryOptions(context, request);
queryOption.AddAutoExpandProperties(new ODataQuerySettings());
var selectExpand = queryOption.SelectExpand;
// Act
SelectExpandClause clause = selectExpand.ProcessLevels();
// Assert
Assert.True(clause.AllSelected);
Assert.Equal(2, clause.SelectedItems.Count());
// Level 1 of Customer.
var cutomer = Assert.Single(
clause.SelectedItems.OfType<ExpandedNavigationSelectItem>().Where(
item => item.PathToNavigationProperty.FirstSegment is NavigationPropertySegment &&
((NavigationPropertySegment)item.PathToNavigationProperty.FirstSegment).NavigationProperty.Name == "Friend")
);
Assert.Null(cutomer.LevelsOption);
var clauseOfCustomer = cutomer.SelectAndExpand;
Assert.True(clauseOfCustomer.AllSelected);
Assert.Equal(1, clauseOfCustomer.SelectedItems.Count());
// Order under Customer.
var order = Assert.IsType<ExpandedNavigationSelectItem>(clauseOfCustomer.SelectedItems.Single());
Assert.Null(order.LevelsOption);
var clauseOfOrder = order.SelectAndExpand;
Assert.True(clauseOfOrder.AllSelected);
Assert.Equal(1, clauseOfOrder.SelectedItems.Count());
// ChoiceOrder under Order.
var choiceOrder = Assert.IsType<ExpandedNavigationSelectItem>(clauseOfOrder.SelectedItems.Single());
Assert.Null(choiceOrder.LevelsOption);
var clauseOfChoiceOrder = choiceOrder.SelectAndExpand;
Assert.True(clauseOfChoiceOrder.AllSelected);
Assert.Equal(0, clauseOfChoiceOrder.SelectedItems.Count());
}