Пример #1
0
		public void HasFilterAddWithFilter()
		{
			var esc = new ExpandSegmentCollection();
			esc.Add (new ExpandSegment ("first", null));

			var param = Expression.Parameter (typeof (bool), "b");
			var filter = Expression.Lambda (param, param);
			var filteredSegment = new ExpandSegment ("second", filter);
			esc.Add (filteredSegment);
			Assert.IsTrue (esc.HasFilter);
		}
        public void TestExpand()
        {
            var qry = this.nhib.Timesheets.Where(t => t.Entries.Count > 0);
            ExpandSegmentCollection segments = new ExpandSegmentCollection(1);
            segments.Add(new ExpandSegment("Entries", null));
            ICollection<ExpandSegmentCollection> segmentCollections = new List<ExpandSegmentCollection>(1);
            segmentCollections.Add(segments);
            IEnumerable expandedQuery = expander.ApplyExpansions(qry, segmentCollections);

            Timesheet ts = expandedQuery.OfType<Timesheet>().FirstOrDefault();

            session.Evict(ts);

            Assert.IsNotNull(ts, "Failed to find Timesheet.");
            Assert.IsTrue(ts.Entries.Count > 0, "Failed to expand Entries");
        }
Пример #3
0
		public void HasFilterAddNull()
		{
			var esc = new ExpandSegmentCollection();
			esc.Add (new ExpandSegment ("first", null));
			Assert.IsFalse (esc.HasFilter);
		}
Пример #4
0
		public void HasFilterInit()
		{
			var esc = new ExpandSegmentCollection();
			Assert.IsFalse (esc.HasFilter);
		}
Пример #5
0
		public void CtorCapacity()
		{
			var esc = new ExpandSegmentCollection (20);
			Assert.AreEqual (20, esc.Capacity);
		}
Пример #6
0
        private ExpandSegmentCollection CheckSingleExpandPath(List<string> path)
        {
            ResourceType targetResourceType = this.description.TargetResourceType;
            ResourceSetWrapper targetContainer = this.description.LastSegmentInfo.TargetContainer;
            ExpandSegmentCollection segments = new ExpandSegmentCollection(path.Count);
            bool flag = false;
            bool previousSegmentIsTypeSegment = false;
            for (int i = 0; i < path.Count; i++)
            {
                string propertyName = path[i];
                ResourcePropertyKind stream = ResourcePropertyKind.Stream;
                ResourceProperty navigationProperty = targetResourceType.TryResolvePropertyName(propertyName, stream);
                if (navigationProperty == null)
                {
                    ResourceType type2 = WebUtil.ResolveTypeIdentifier(this.service.Provider, propertyName, targetResourceType, previousSegmentIsTypeSegment);
                    if (type2 == null)
                    {
                        if (targetResourceType.IsOpenType)
                        {
                            throw DataServiceException.CreateBadRequestError(System.Data.Services.Strings.OpenNavigationPropertiesNotSupportedOnOpenTypes(propertyName));
                        }
						throw DataServiceException.CreateSyntaxError(System.Data.Services.Strings.RequestUriProcessor_PropertyNotFound(targetResourceType.FullName, propertyName));
                    }
                    this.description.VerifyProtocolVersion(RequestDescription.Version3Dot0, this.service);
                    targetResourceType = type2;
                    previousSegmentIsTypeSegment = true;
                }
                else
                {
                    previousSegmentIsTypeSegment = false;
                    if (navigationProperty.TypeKind == ResourceTypeKind.EntityType)
                    {
                        targetContainer = this.service.Provider.GetContainer(targetContainer, targetResourceType, navigationProperty);
                        if (targetContainer == null)
                        {
                            throw DataServiceException.CreateBadRequestError(System.Data.Services.Strings.BadRequest_InvalidPropertyNameSpecified(navigationProperty.Name, targetResourceType.FullName));
                        }
                        bool singleResult = navigationProperty.Kind == ResourcePropertyKind.ResourceReference;
                        DataServiceConfiguration.CheckResourceRightsForRead(targetContainer, singleResult);
                        Expression filter = DataServiceConfiguration.ComposeQueryInterceptors(this.service, targetContainer);
                        if (((targetContainer.PageSize != 0) && !singleResult) && !this.IsCustomPaged)
                        {
                            OrderingInfo orderingInfo = new OrderingInfo(true);
                            ParameterExpression expression = Expression.Parameter(targetContainer.ResourceType.InstanceType, "p");
                            foreach (ResourceProperty property2 in targetContainer.GetKeyPropertiesForOrderBy())
                            {
                                Expression expression3;
                                if (property2.CanReflectOnInstanceTypeProperty)
                                {
                                    expression3 = Expression.Property(expression, targetContainer.ResourceType.GetPropertyInfo(property2));
                                }
                                else
                                {
                                    expression3 = Expression.Convert(Expression.Call(null, DataServiceProviderMethods.GetValueMethodInfo, expression, Expression.Constant(property2)), property2.Type);
                                }
                                orderingInfo.Add(new OrderingExpression(Expression.Lambda(expression3, new ParameterExpression[] { expression }), true));
                            }
                            segments.Add(new ExpandSegment(navigationProperty.Name, filter, targetContainer.PageSize, targetContainer, targetResourceType, navigationProperty, orderingInfo));
                            this.description.VerifyProtocolVersion(RequestDescription.Version2Dot0, this.service);
                            this.description.VerifyAndRaiseResponseVersion(RequestDescription.Version2Dot0, this.service);
                        }
                        else
                        {
                            if (!singleResult && this.IsCustomPaged)
                            {
                                this.CheckAndApplyCustomPaging(null);
                            }
                            segments.Add(new ExpandSegment(navigationProperty.Name, filter, this.service.Configuration.MaxResultsPerCollection, targetContainer, targetResourceType, navigationProperty, null));
                        }
                        this.description.UpdateAndCheckEpmFeatureVersion(targetContainer, this.service);
                        this.description.UpdateVersions(this.service.OperationContext.Host.RequestAccept, targetContainer, this.service);
                        flag = false;
                        targetResourceType = navigationProperty.ResourceType;
                    }
                    else
                    {
                        flag = true;
                    }
                }
            }
            if (previousSegmentIsTypeSegment)
            {
                throw DataServiceException.CreateBadRequestError(System.Data.Services.Strings.RequestQueryProcessor_QueryParametersPathCannotEndInTypeIdentifier("$expand", targetResourceType.FullName));
            }
            if (!flag)
            {
                return segments;
            }
            return null;
        }
Пример #7
0
        /// <summary>
        /// Performs a depth-first walk down the expand tree, copying and adding to the current path as it goes. When the bottom of a path is reached, the path is added to the overall set of paths.
        /// </summary>
        /// <param name="currentPath">The current path so far for this depth-first traversal of the tree. Starts out null.</param>
        /// <param name="currentNode">The current node of the expand tree.</param>
        /// <param name="rootNode">The root node of the expand tree.</param>
        private void ExtractExpandPathSegmentCollections(ExpandSegmentCollection currentPath, ExpandedProjectionNode currentNode, RootProjectionNode rootNode)
        {
            ExpandSegmentCollection nextPath = null;
            foreach (ExpandedNavigationSelectItem expandItem in currentNode.SelectExpandClause.SelectedItems.OfType<ExpandedNavigationSelectItem>())
            {
                rootNode.ExpansionsSpecified = true;

                if (currentPath == null)
                {
                    nextPath = new ExpandSegmentCollection();
                }
                else
                {
                    // create a copy of the current path.
                    nextPath = new ExpandSegmentCollection(currentPath.Count);
                    nextPath.AddRange(currentPath);
                }

                var segment = this.CreateExpandSegment(expandItem, currentNode.ResourceType);
                nextPath.Add(segment);
                ExpandedProjectionNode childNode = currentNode.AddExpandedNode(segment, expandItem.SelectAndExpand);

                // if there are any derived expansions in the tree, set the rootNode.DerivedExpansionsSpecified to true.
                if (currentNode.HasExpandedPropertyOnDerivedType)
                {
                    rootNode.ExpansionOnDerivedTypesSpecified = true;
                }

                this.ExtractExpandPathSegmentCollections(nextPath, childNode, rootNode);
            }

            if (nextPath == null && currentPath != null)
            {
                this.expandPaths.Add(currentPath);
            }
        }