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 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 HasFilterAddNull() { var esc = new ExpandSegmentCollection(); esc.Add(new ExpandSegment("first", null)); Assert.IsFalse(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"); }
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"); }
public void HasFilterAddNull() { var esc = new ExpandSegmentCollection(); esc.Add (new ExpandSegment ("first", null)); Assert.IsFalse (esc.HasFilter); }
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; }