private static Microsoft.OData.UriParser.ODataPath GeneratePath(IEdmNavigationSource navigationSource) { Contract.Assert(navigationSource != null); switch (navigationSource.NavigationSourceKind()) { case EdmNavigationSourceKind.EntitySet: return(new Microsoft.OData.UriParser.ODataPath(new EntitySetSegment((IEdmEntitySet)navigationSource))); case EdmNavigationSourceKind.Singleton: return(new Microsoft.OData.UriParser.ODataPath(new SingletonSegment((IEdmSingleton)navigationSource))); case EdmNavigationSourceKind.ContainedEntitySet: IEdmContainedEntitySet containedEntitySet = (IEdmContainedEntitySet)navigationSource; Microsoft.OData.UriParser.ODataPath path = GeneratePath(containedEntitySet.ParentNavigationSource); IList <ODataPathSegment> segments = new List <ODataPathSegment>(); foreach (var item in path) { segments.Add(item); } segments.Add(new NavigationPropertySegment(containedEntitySet.NavigationProperty, containedEntitySet.ParentNavigationSource)); return(new Microsoft.OData.UriParser.ODataPath(segments)); case EdmNavigationSourceKind.None: case EdmNavigationSourceKind.UnknownEntitySet: default: return(null); } }
public void TryEnableNoDollarSignSystemQueryOption(string relativeUri) { // Create parser specifying optional-$-sign setting. var parser = new ODataUriParser(GetModel(), new Uri(relativeUri, UriKind.Relative)) { EnableNoDollarQueryOptions = true }; // Verify path is parsed correctly. Microsoft.OData.UriParser.ODataPath path = parser.ParsePath(); Assert.NotNull(path); Assert.Equal(2, path.Count); // Verify expand & select clause is parsed correctly. SelectExpandClause result = parser.ParseSelectAndExpand(); Assert.NotNull(result); Assert.Single(result.SelectedItems); ExpandedNavigationSelectItem selectItems = (result.SelectedItems.First() as ExpandedNavigationSelectItem); Assert.NotNull(selectItems); Assert.Equal("PermanentAccount", selectItems.NavigationSource.Name); Assert.Equal(2, selectItems.SelectAndExpand.SelectedItems.Count()); }