public void GetFirstNonTypeCastSegment_WorksForExpandPathWithPropertySegment() { // Arrange EdmEntityType entityType = new EdmEntityType("NS", "Customer"); IEdmStructuralProperty property = entityType.AddStructuralProperty("Id", EdmPrimitiveTypeKind.String); var navProperty = entityType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { Name = "Nav", Target = entityType, TargetMultiplicity = EdmMultiplicity.One }); EdmEntityContainer container = new EdmEntityContainer("NS", "Container"); EdmEntitySet set = new EdmEntitySet(container, "set", entityType); NavigationPropertySegment navSegment = new NavigationPropertySegment(navProperty, set); TypeSegment typeSegment = new TypeSegment(entityType, null); ODataPathSegment propertySegment = new PropertySegment(property); ODataExpandPath expandPath = new ODataExpandPath(typeSegment, propertySegment, navSegment); // Act IList <ODataPathSegment> remainingSegments; ODataPathSegment firstNonTypeSegment = expandPath.GetFirstNonTypeCastSegment(out remainingSegments); // Assert Assert.NotNull(firstNonTypeSegment); Assert.Same(propertySegment, firstNonTypeSegment); Assert.NotNull(remainingSegments); Assert.Same(navSegment, Assert.Single(remainingSegments)); }
public void GetFirstNonTypeCastSegment_ExpandPath_ThrowsArgumentNull() { // Arrange & Act ODataExpandPath expandPath = null; IList <ODataPathSegment> remainingSegments; // Assert ExceptionAssert.ThrowsArgumentNull(() => expandPath.GetFirstNonTypeCastSegment(out remainingSegments), "expandPath"); }
/// <summary> /// Build the $expand item, it maybe $expand=nav, $expand=complex/nav, $expand=nav/$ref, etc. /// </summary> /// <param name="expandReferenceItem">The expanded reference select item.</param> /// <param name="currentLevelPropertiesInclude">The current properties to include at current level.</param> /// <param name="structuralTypeInfo">The structural type properties.</param> private void BuildExpandItem(ExpandedReferenceSelectItem expandReferenceItem, IDictionary <IEdmStructuralProperty, SelectExpandIncludedProperty> currentLevelPropertiesInclude, EdmStructuralTypeInfo structuralTypeInfo) { Contract.Assert(expandReferenceItem != null && expandReferenceItem.PathToNavigationProperty != null); Contract.Assert(currentLevelPropertiesInclude != null); Contract.Assert(structuralTypeInfo != null); // Verify and process the $expand=abc/xyz/nav. ODataExpandPath expandPath = expandReferenceItem.PathToNavigationProperty; IList <ODataPathSegment> remainingSegments; ODataPathSegment segment = expandPath.GetFirstNonTypeCastSegment(out remainingSegments); PropertySegment firstPropertySegment = segment as PropertySegment; if (firstPropertySegment != null) { // for example: $expand=abc/xyz/nav, the remaining segment can't be null // because at least the last navigation property segment is there. Contract.Assert(remainingSegments != null); if (structuralTypeInfo.IsStructuralPropertyDefined(firstPropertySegment.Property)) { SelectExpandIncludedProperty newPropertySelectItem; if (!currentLevelPropertiesInclude.TryGetValue(firstPropertySegment.Property, out newPropertySelectItem)) { newPropertySelectItem = new SelectExpandIncludedProperty(firstPropertySegment); currentLevelPropertiesInclude[firstPropertySegment.Property] = newPropertySelectItem; } newPropertySelectItem.AddSubExpandItem(remainingSegments, expandReferenceItem); } } else { // for example: $expand=nav, or $expand=NS.SubType/nav, the navigation property segment should be the last segment. // So, the remaining segments should be null. Contract.Assert(remainingSegments == null); NavigationPropertySegment firstNavigationSegment = segment as NavigationPropertySegment; Contract.Assert(firstNavigationSegment != null); if (structuralTypeInfo.IsNavigationPropertyDefined(firstNavigationSegment.NavigationProperty)) { // It's not allowed to have mulitple navigation expanded or referenced. // for example: "$expand=nav($top=2),nav($skip=3)" is not allowed and will be merged (or throw exception) at ODL side. ExpandedNavigationSelectItem expanded = expandReferenceItem as ExpandedNavigationSelectItem; if (expanded != null) { if (ExpandedProperties == null) { ExpandedProperties = new Dictionary <IEdmNavigationProperty, ExpandedNavigationSelectItem>(); } ExpandedProperties[firstNavigationSegment.NavigationProperty] = expanded; } else { // $expand=..../nav/$ref if (ReferencedProperties == null) { ReferencedProperties = new Dictionary <IEdmNavigationProperty, ExpandedReferenceSelectItem>(); } ReferencedProperties[firstNavigationSegment.NavigationProperty] = expandReferenceItem; } } } }