public void ContainerQualifiedWildcardSelectItemIsNotImplemented()
        {
            FakeHandler handler = new FakeHandler();
            ContainerQualifiedWildcardSelectItem item = new ContainerQualifiedWildcardSelectItem(ModelBuildingHelpers.BuildValidEntityContainer());
            Action visitContainerQualifiedWildcard    = () => item.HandleWith(handler);

            visitContainerQualifiedWildcard.ShouldThrow <NotImplementedException>();
        }
        /// <summary>
        /// Build a wildcard selection item
        /// </summary>
        /// <param name="tokenIn">the token to bind to a wildcard</param>
        /// <param name="model">the model to search for this wildcard</param>
        /// <param name="item">the new wildcard selection item, if we found one</param>
        /// <returns>true if we successfully bound to a wildcard, false otherwise</returns>
        public static bool TryBindAsWildcard(PathSegmentToken tokenIn, IEdmModel model, out SelectItem item)
        {
            bool isTypeToken = tokenIn.IsNamespaceOrContainerQualified();
            bool wildcard    = tokenIn.Identifier.EndsWith("*", StringComparison.Ordinal);

            IEdmEntityContainer container;

            if (isTypeToken && wildcard && UriEdmHelpers.TryGetEntityContainer(tokenIn.Identifier.Substring(0, tokenIn.Identifier.LastIndexOf('.')), model, out container))
            {
                item = new ContainerQualifiedWildcardSelectItem(container);
                return(true);
            }

            if (tokenIn.Identifier == "*")
            {
                item = new WildcardSelectItem();
                return(true);
            }

            item = null;
            return(false);
        }
Esempio n. 3
0
        private void BuildSelections(SelectExpandClause selectExpandClause, HashSet <IEdmStructuralProperty> allStructuralProperties, HashSet <IEdmNavigationProperty> allNavigationProperties, HashSet <IEdmFunctionImport> allActions)
        {
            foreach (SelectItem selectItem in selectExpandClause.SelectedItems)
            {
                if (selectItem is ExpandedNavigationSelectItem)
                {
                    continue;
                }

                PathSelectItem pathSelectItem = selectItem as PathSelectItem;

                if (pathSelectItem != null)
                {
                    ValidatePathIsSupported(pathSelectItem.SelectedPath);
                    ODataPathSegment segment = pathSelectItem.SelectedPath.LastSegment;

                    NavigationPropertySegment navigationPropertySegment = segment as NavigationPropertySegment;
                    if (navigationPropertySegment != null)
                    {
                        IEdmNavigationProperty navigationProperty = navigationPropertySegment.NavigationProperty;
                        if (allNavigationProperties.Contains(navigationProperty))
                        {
                            SelectedNavigationProperties.Add(navigationProperty);
                        }
                        continue;
                    }

                    PropertySegment structuralPropertySegment = segment as PropertySegment;
                    if (structuralPropertySegment != null)
                    {
                        IEdmStructuralProperty structuralProperty = structuralPropertySegment.Property;
                        if (allStructuralProperties.Contains(structuralProperty))
                        {
                            SelectedStructuralProperties.Add(structuralProperty);
                        }
                        continue;
                    }

                    OperationSegment operationSegment = segment as OperationSegment;
                    if (operationSegment != null)
                    {
                        foreach (IEdmFunctionImport action in operationSegment.Operations)
                        {
                            if (allActions.Contains(action))
                            {
                                SelectedActions.Add(action);
                            }
                        }
                        continue;
                    }

                    throw new ODataException(Error.Format(SRResources.SelectionTypeNotSupported, segment.GetType().Name));
                }

                WildcardSelectItem wildCardSelectItem = selectItem as WildcardSelectItem;
                if (wildCardSelectItem != null)
                {
                    SelectedStructuralProperties = allStructuralProperties;
                    SelectedNavigationProperties = allNavigationProperties;
                    continue;
                }

                ContainerQualifiedWildcardSelectItem wildCardActionSelection = selectItem as ContainerQualifiedWildcardSelectItem;
                if (wildCardActionSelection != null)
                {
                    IEnumerable <IEdmFunctionImport> actionsInThisContainer = allActions.Where(a => a.Container == wildCardActionSelection.Container);
                    foreach (IEdmFunctionImport action in actionsInThisContainer)
                    {
                        SelectedActions.Add(action);
                    }
                    continue;
                }

                throw new ODataException(Error.Format(SRResources.SelectionTypeNotSupported, selectItem.GetType().Name));
            }
        }