本文整理汇总了C#中Microsoft.OData.Core.UriParser.ODataUriParser.ParseSelectAndExpand方法的典型用法代码示例。如果您正苦于以下问题:C# ODataUriParser.ParseSelectAndExpand方法的具体用法?C# ODataUriParser.ParseSelectAndExpand怎么用?C# ODataUriParser.ParseSelectAndExpand使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.OData.Core.UriParser.ODataUriParser
的用法示例。
在下文中一共展示了ODataUriParser.ParseSelectAndExpand方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: NoneQueryOptionShouldWork
public void NoneQueryOptionShouldWork()
{
var uriParser = new ODataUriParser(HardCodedTestModel.TestModel, ServiceRoot, FullUri);
var path = uriParser.ParsePath();
path.Should().HaveCount(1);
path.LastSegment.ShouldBeEntitySetSegment(HardCodedTestModel.GetPeopleSet());
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();
uriParser.ParseSkipToken().Should().BeNull();
uriParser.ParseDeltaToken().Should().BeNull();
}
示例2: EmptyValueQueryOptionShouldWork
public void EmptyValueQueryOptionShouldWork()
{
var uriParser = new ODataUriParser(HardCodedTestModel.TestModel, ServiceRoot, new Uri(FullUri, "?$filter=&$select=&$expand=&$orderby=&$top=&$skip=&$count=&$search=&$unknow=&$unknowvalue&$skiptoken=&$deltatoken="));
var path = uriParser.ParsePath();
path.Should().HaveCount(1);
path.LastSegment.ShouldBeEntitySetSegment(HardCodedTestModel.GetPeopleSet());
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, ""));
uriParser.ParseSkipToken().Should().BeEmpty();
uriParser.ParseDeltaToken().Should().BeEmpty();
}
示例3: ParseQueryOptionsShouldWork
public void ParseQueryOptionsShouldWork()
{
var parser = new ODataUriParser(HardCodedTestModel.TestModel, new Uri("People?$filter=MyDog/Color eq 'Brown'&$select=ID&$expand=MyDog&$orderby=ID&$top=1&$skip=2&$count=true&$search=FA&$unknow=&$unknowvalue&$skiptoken=abc&$deltatoken=def", UriKind.Relative));
parser.ParseSelectAndExpand().Should().NotBeNull();
parser.ParseFilter().Should().NotBeNull();
parser.ParseOrderBy().Should().NotBeNull();
parser.ParseTop().Should().Be(1);
parser.ParseSkip().Should().Be(2);
parser.ParseCount().Should().Be(true);
parser.ParseSearch().Should().NotBeNull();
parser.ParseSkipToken().Should().Be("abc");
parser.ParseDeltaToken().Should().Be("def");
}
示例4: SelectExpandLimitIsRespectedForSelectExpand
public void SelectExpandLimitIsRespectedForSelectExpand()
{
ODataUriParser parser = new ODataUriParser(HardCodedTestModel.TestModel, ServiceRoot, new Uri("http://host/People?$select=MyDog&$expand=MyDog($select=color)")) { Settings = { SelectExpandLimit = 0 } };
Action parseWithLimit = () => parser.ParseSelectAndExpand();
parseWithLimit.ShouldThrow<ODataException>().WithMessage(ODataErrorStrings.UriQueryExpressionParser_TooDeep);
}
示例5: ParseSelectExpandForContainment
public void ParseSelectExpandForContainment()
{
ODataUriParser parser = new ODataUriParser(HardCodedTestModel.TestModel, ServiceRoot, new Uri("http://host/People?$select=MyContainedDog&$expand=MyContainedDog")) { Settings = { SelectExpandLimit = 5 } };
SelectExpandClause containedSelectExpandClause = parser.ParseSelectAndExpand();
IEnumerator<SelectItem> enumerator = containedSelectExpandClause.SelectedItems.GetEnumerator();
enumerator.MoveNext();
ExpandedNavigationSelectItem expandedNavigationSelectItem = enumerator.Current as ExpandedNavigationSelectItem;
expandedNavigationSelectItem.Should().NotBeNull();
(expandedNavigationSelectItem.NavigationSource is IEdmContainedEntitySet).Should().BeTrue();
}
示例6: MaxExpandCountSettingShouldBeEnforced
public void MaxExpandCountSettingShouldBeEnforced()
{
ODataUriParser parser = new ODataUriParser(HardCodedTestModel.TestModel, new Uri("http://host/"), new Uri("http://host/People?$expand=MyDog,MyLions"));
parser.Settings.MaximumExpansionCount = 1;
Action parse = () => parser.ParseSelectAndExpand();
parse.ShouldThrow<ODataException>().WithMessage(ODataErrorStrings.UriParser_ExpandCountExceeded(2, 1));
}
示例7: GetWriterSettings
protected override ODataMessageWriterSettings GetWriterSettings()
{
ODataMessageWriterSettings settings = new ODataMessageWriterSettings
{
AutoComputePayloadMetadataInJson = true,
PayloadBaseUri = this.ServiceRootUri
};
ODataUriParser uriParser = new ODataUriParser(this.DataSource.Model, ServiceConstants.ServiceBaseUri, originalUri);
settings.ODataUri = new ODataUri()
{
RequestUri = originalUri,
ServiceRoot = this.ServiceRootUri,
Path = uriParser.ParsePath(),
SelectAndExpand = uriParser.ParseSelectAndExpand()
};
// TODO: howang read the encoding from request.
settings.SetContentType(string.IsNullOrEmpty(this.QueryContext.FormatOption) ? this.RequestAcceptHeader : this.QueryContext.FormatOption, Encoding.UTF8.WebName);
return settings;
}
示例8: ExpandedEntryTest
public void ExpandedEntryTest()
{
foreach (var mimeType in this.mimeTypes)
{
foreach (var hasModel in this.hasModelFlagBools)
{
const string selectClause = "CustomerId,Video,Orders";
const string expandClause = "Logins($select=Username;$expand=SentMessages)";
const string expectedClause = "CustomerId,Video,Orders,Logins,Logins(Username,SentMessages)";
var uriParser = new ODataUriParser(WritePayloadHelper.Model, WritePayloadHelper.ServiceUri, new Uri(this.ServiceUri, "Customer?$select=" + selectClause + "&$expand=" + expandClause));
var result = uriParser.ParseSelectAndExpand();
var settings = new ODataMessageWriterSettings();
settings.ODataUri = new ODataUri() { ServiceRoot = this.ServiceUri, SelectAndExpand = result };
settings.PayloadBaseUri = this.ServiceUri;
settings.AutoComputePayloadMetadataInJson = false;
string defaultModeResult = this.WriteAndVerifyExpandedCustomerEntry(settings, mimeType, expectedClause, hasModel);
settings.AutoComputePayloadMetadataInJson = true;
string autoComputeMetadataModeResult = this.WriteAndVerifyExpandedCustomerEntry(settings, mimeType, expectedClause, hasModel);
// For Atom, verify that the result is the same for AutoComputePayloadMetadataInJson=true/false
if (mimeType == MimeTypes.ApplicationAtomXml)
{
WritePayloadHelper.VerifyPayloadString(defaultModeResult, autoComputeMetadataModeResult, mimeType);
}
}
}
}
示例9: 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);
}
}
示例10: ParseWithAllQueryOptionsWithoutAlias
public void ParseWithAllQueryOptionsWithoutAlias()
{
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&$filter=startswith(Color, 'Blue')&$orderby=Color asc"));
parser.ParsePath().FirstSegment.ShouldBeEntitySetSegment(HardCodedTestModel.GetDogsSet());
var myDogSelectedItems = parser.ParseSelectAndExpand().SelectedItems.ToList();
myDogSelectedItems.Count.Should().Be(3);
myDogSelectedItems[1].ShouldBePathSelectionItem(new ODataPath(new PropertySegment(HardCodedTestModel.GetDogColorProp())));
var myPeopleExpansionSelectionItem = myDogSelectedItems[0].ShouldBeSelectedItemOfType<ExpandedNavigationSelectItem>().And;
myPeopleExpansionSelectionItem.PathToNavigationProperty.Single().ShouldBeNavigationPropertySegment(HardCodedTestModel.GetDogMyPeopleNavProp());
myPeopleExpansionSelectionItem.SelectAndExpand.SelectedItems.Should().BeEmpty();
var startsWithArgs = parser.ParseFilter().Expression.ShouldBeSingleValueFunctionCallQueryNode("startswith").And.Parameters.ToList();
startsWithArgs[0].ShouldBeSingleValuePropertyAccessQueryNode(HardCodedTestModel.GetDogColorProp());
startsWithArgs[1].ShouldBeConstantQueryNode("Blue");
var orderby = parser.ParseOrderBy();
orderby.Direction.Should().Be(OrderByDirection.Ascending);
orderby.Expression.ShouldBeSingleValuePropertyAccessQueryNode(HardCodedTestModel.GetDogColorProp());
}