public void CtorName() { var s = new ExpandSegment ("name", null); Assert.AreEqual ("name", s.Name); Assert.AreEqual (null, s.Filter); Assert.IsFalse (s.HasFilter); }
public void PathHasFilter() { var param = Expression.Parameter(typeof(bool), "b"); var filter = Expression.Lambda(param, param); Assert.IsTrue(ExpandSegment.PathHasFilter(new [] { new ExpandSegment("first", null), new ExpandSegment("second", filter), new ExpandSegment("third", null) })); }
public void CtorName() { var s = new ExpandSegment("name", null); Assert.AreEqual("name", s.Name); Assert.AreEqual(null, s.Filter); Assert.IsFalse(s.HasFilter); }
public void CtorFilter() { var param = Expression.Parameter(typeof(bool), "b"); var filter = Expression.Lambda(param, param); var s = new ExpandSegment("name", filter); Assert.AreEqual("name", s.Name); Assert.AreEqual(filter, s.Filter); Assert.IsTrue(s.HasFilter); }
public void CtorFilter() { var param = Expression.Parameter (typeof (bool), "b"); var filter = Expression.Lambda (param, param); var s = new ExpandSegment ("name", filter); Assert.AreEqual ("name", s.Name); Assert.AreEqual (filter, s.Filter); Assert.IsTrue (s.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 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); }
internal ExpandedProjectionNode AddExpandedNode(ExpandSegment segment) { ExpandedProjectionNode node = (ExpandedProjectionNode)this.FindNode(segment.Name); if ((node != null) && (node.Property == segment.ExpandedProperty)) { if (segment.TargetResourceType.IsAssignableFrom(node.TargetResourceType)) { node.TargetResourceType = segment.TargetResourceType; } return(node); } node = new ExpandedProjectionNode(segment.Name, segment.ExpandedProperty, segment.TargetResourceType, segment.Container, segment.OrderingInfo, segment.Filter, null, (segment.Container.PageSize != 0) ? new int?(segment.Container.PageSize) : null, (segment.MaxResultsExpected != 0x7fffffff) ? new int?(segment.MaxResultsExpected) : null); this.AddNode(node); return(node); }
/// <summary> /// Adds the segment as pathedgenode /// </summary> /// <param name="parentNode">The parent node.</param> /// <param name="segments">The segments.</param> /// <param name="currentNodeIndex">The current node index in the segments list.</param> /// <param name="pathElement">The path element.</param> /// <param name="entityType">Type of the entity.</param> /// <remarks>Declared public to avoid medium trust reflection issues.</remarks> public void AddSegment(PathEdgeNode parentNode, IList <ExpandSegment> segments, int currentNodeIndex, IPrefetchPathElementCore pathElement, Type entityType) { if (currentNodeIndex >= segments.Count) { return; } ExpandSegment segment = segments[currentNodeIndex]; PathEdgeNode childNode = null; if (!parentNode.ChildPathEdgeNodes.TryGetValue(segment.Name, out childNode)) { childNode = new PathEdgeNode(entityType, pathElement, segment); parentNode.ChildPathEdgeNodes.Add(segment.Name, childNode); } DecodeSegment(childNode, segments, ++currentNodeIndex, entityType); }
/// <summary> /// Adds a new expanded node with the given segment name, if required. /// </summary> /// <param name="segment">Expand segment as specified in the uri.</param> /// <param name="childSelectExpandClause">The select expand clause for the current node from the URI Parser.</param> /// <returns>An instance of ExpandedProjectionNode - either new or existing one.</returns> internal ExpandedProjectionNode AddExpandedNode(ExpandSegment segment, SelectExpandClause childSelectExpandClause) { Debug.Assert(segment.ExpandedProperty != null, "we do not allow expands on open properties"); Debug.Assert(childSelectExpandClause != null, "childSelectExpandClause != null"); ExpandedProjectionNode childNode = (ExpandedProjectionNode)this.FindNode(segment.Name); // Currently, since we do not have a back pointer in ResourceProperty for the declaring type, // the same resource property instance can belong to 2 completely different types. // Hence doing reference equality on Resource Property instance does not gaurantee that they // refer to the same property. But if the references are not equal, they are gauranteed to be // different. The check of reference equality is to make sure we do the expensive IsAssignableFrom // check, only if the instances are the same, and if the IsAssignable returns true, then we are // gauranteed that the property refers to the same property. if (childNode != null && childNode.Property == segment.ExpandedProperty) { // If the given segment specifies the same property on a super type (or an ancestor), // then we need to change the target type on the segment to the super type (or ancestor), // otherwise we should ignore the segment. // Since IsAssignableFrom returns true, if the instances are the same, we will update the // target resource type to the same instance. It doesn't matter, but having another check // for reference equality makes code less readable. if (segment.TargetResourceType.IsAssignableFrom(childNode.TargetResourceType)) { childNode.TargetResourceType = segment.TargetResourceType; } } else { childNode = new ExpandedProjectionNode( segment.Name, segment.ExpandedProperty, segment.TargetResourceType, segment.Container, segment.OrderingInfo, segment.Filter, null, segment.Container.PageSize != 0 ? (int?)segment.Container.PageSize : null, segment.MaxResultsExpected != Int32.MaxValue ? (int?)segment.MaxResultsExpected : null, childSelectExpandClause); this.AddNode(childNode); } return(childNode); }
public void PathDoesntHaveFilter() { Assert.IsFalse(ExpandSegment.PathHasFilter(new [] { new ExpandSegment("first", null), new ExpandSegment("second", null), new ExpandSegment("third", null) })); }
public void PathHasFilterException() { ExpandSegment.PathHasFilter(null); }
/// <summary> /// Initializes a new instance of the <see cref="PathEdgeNode"/> class. /// </summary> /// <param name="entityType">Type of the entity.</param> /// <param name="pathElement">The path element.</param> /// <param name="segment">The segment.</param> internal PathEdgeNode(Type entityType, IPrefetchPathElementCore pathElement, ExpandSegment segment) { _pathElement = pathElement; _segment = segment; _entityType = entityType; }
/// <summary> /// Adds a new expanded node with the given segment name, if required. /// </summary> /// <param name="segment">Expand segment as specified in the uri.</param> /// <param name="childSelectExpandClause">The select expand clause for the current node from the URI Parser.</param> /// <returns>An instance of ExpandedProjectionNode - either new or existing one.</returns> internal ExpandedProjectionNode AddExpandedNode(ExpandSegment segment, SelectExpandClause childSelectExpandClause) { Debug.Assert(segment.ExpandedProperty != null, "we do not allow expands on open properties"); Debug.Assert(childSelectExpandClause != null, "childSelectExpandClause != null"); ExpandedProjectionNode childNode = (ExpandedProjectionNode)this.FindNode(segment.Name); // Currently, since we do not have a back pointer in ResourceProperty for the declaring type, // the same resource property instance can belong to 2 completely different types. // Hence doing reference equality on Resource Property instance does not gaurantee that they // refer to the same property. But if the references are not equal, they are gauranteed to be // different. The check of reference equality is to make sure we do the expensive IsAssignableFrom // check, only if the instances are the same, and if the IsAssignable returns true, then we are // gauranteed that the property refers to the same property. if (childNode != null && childNode.Property == segment.ExpandedProperty) { // If the given segment specifies the same property on a super type (or an ancestor), // then we need to change the target type on the segment to the super type (or ancestor), // otherwise we should ignore the segment. // Since IsAssignableFrom returns true, if the instances are the same, we will update the // target resource type to the same instance. It doesn't matter, but having another check // for reference equality makes code less readable. if (segment.TargetResourceType.IsAssignableFrom(childNode.TargetResourceType)) { childNode.TargetResourceType = segment.TargetResourceType; } } else { childNode = new ExpandedProjectionNode( segment.Name, segment.ExpandedProperty, segment.TargetResourceType, segment.Container, segment.OrderingInfo, segment.Filter, null, segment.Container.PageSize != 0 ? (int?)segment.Container.PageSize : null, segment.MaxResultsExpected != Int32.MaxValue ? (int?)segment.MaxResultsExpected : null, childSelectExpandClause); this.AddNode(childNode); } return childNode; }