public void SingleResultIsSetCorrectly() { PropertySegment propertySegment1 = new PropertySegment(HardCodedTestModel.GetPersonNameProp()); propertySegment1.SingleResult.Should().BeTrue(); PropertySegment propertySegment2 = new PropertySegment(HardCodedTestModel.GetPersonGeometryCollectionProp()); propertySegment2.SingleResult.Should().BeFalse(); }
public void InequalityCorrect() { PropertySegment propertySegment1 = new PropertySegment(HardCodedTestModel.GetPersonNameProp()); PropertySegment propertySegment2 = new PropertySegment(HardCodedTestModel.GetPersonShoeProp()); BatchSegment batchSegment = BatchSegment.Instance; propertySegment1.Equals(propertySegment2).Should().BeFalse(); propertySegment1.Equals(batchSegment).Should().BeFalse(); }
public void TryMatchMediaType_DoesnotMatchRequest_WithBinaryPropertyRequest() { // Arrange EdmEntityType entity = new EdmEntityType("NS", "Entity"); EdmStructuralProperty property = entity.AddStructuralProperty("Photo", EdmCoreModel.Instance.GetStream(true)); PropertySegment propertySegment = new PropertySegment(property); HttpRequest request = new DefaultHttpContext().Request; request.ODataFeature().Path = new ODataPath(propertySegment); // Act double mapResult = Mapping.TryMatchMediaType(request); // Assert Assert.Equal(0, mapResult); }
public void TryMatch_ReturnsFalse() { // Arrange EdmEntityType entityType = new EdmEntityType("NS", "entity"); IEdmStructuralProperty property1 = entityType.AddStructuralProperty("Name1", EdmPrimitiveTypeKind.String); IEdmStructuralProperty property2 = entityType.AddStructuralProperty("Name2", EdmPrimitiveTypeKind.String); PropertySegmentTemplate template = new PropertySegmentTemplate(new PropertySegment(property1)); PropertySegment segment = new PropertySegment(property2); // Act Dictionary <string, object> values = new Dictionary <string, object>(); bool result = template.TryMatch(segment, values); // Assert Assert.False(result); }
private static ISet <IEdmStructuralProperty> GetPropertiesToIncludeInQuery( SelectExpandClause selectExpandClause, IEdmEntityType entityType, IEdmEntitySet entitySet, IEdmModel model, out ISet <IEdmStructuralProperty> autoSelectedProperties) { autoSelectedProperties = new HashSet <IEdmStructuralProperty>(); HashSet <IEdmStructuralProperty> propertiesToInclude = new HashSet <IEdmStructuralProperty>(); IEnumerable <SelectItem> selectedItems = selectExpandClause.SelectedItems; if (!IsSelectAll(selectExpandClause)) { // only select requested properties and keys. foreach (PathSelectItem pathSelectItem in selectedItems.OfType <PathSelectItem>()) { SelectExpandNode.ValidatePathIsSupported(pathSelectItem.SelectedPath); PropertySegment structuralPropertySegment = pathSelectItem.SelectedPath.LastSegment as PropertySegment; if (structuralPropertySegment != null) { propertiesToInclude.Add(structuralPropertySegment.Property); } } // add keys foreach (IEdmStructuralProperty keyProperty in entityType.Key()) { if (!propertiesToInclude.Contains(keyProperty)) { autoSelectedProperties.Add(keyProperty); } } // add concurrency properties, if not added if (entitySet != null && model != null) { IEnumerable <IEdmStructuralProperty> concurrencyProperties = model.GetConcurrencyProperties(entitySet); foreach (IEdmStructuralProperty concurrencyProperty in concurrencyProperties) { if (!propertiesToInclude.Contains(concurrencyProperty)) { autoSelectedProperties.Add(concurrencyProperty); } } } } return(propertiesToInclude); }
public void TryMatchMediaType_MatchRequest_WithBinaryPrimitivePropertyRequest() { // Arrange EdmEntityType entity = new EdmEntityType("NS", "Entity"); EdmStructuralProperty property = entity.AddStructuralProperty("Data", EdmCoreModel.Instance.GetBinary(true)); PropertySegment propertySegment = new PropertySegment(property); ValueSegment valueSegment = new ValueSegment(property.Type.Definition); HttpRequest request = new DefaultHttpContext().Request; request.ODataFeature().Path = new ODataPath(propertySegment, valueSegment); // Act double mapResult = Mapping.TryMatchMediaType(request); // Assert Assert.Equal(1.0, mapResult); }
public void TryTranslatePropertySegmentTemplate_ReturnsPropertySegment() { // Arrange ODataTemplateTranslateContext context = new ODataTemplateTranslateContext(); EdmEntityType entityType = new EdmEntityType("NS", "Customer"); IEdmStructuralProperty property = entityType.AddStructuralProperty("Name", EdmPrimitiveTypeKind.String); PropertySegmentTemplate propertySegment = new PropertySegmentTemplate(property); // Act bool ok = propertySegment.TryTranslate(context); // Assert Assert.True(ok); ODataPathSegment segment = Assert.Single(context.Segments); PropertySegment odataPropertySegment = Assert.IsType <PropertySegment>(segment); Assert.Equal("Edm.String", odataPropertySegment.EdmType.FullTypeName()); }
/// <summary> /// Finds the appropriate property segment which should be responsible for propagating the expand item. /// For instance, if we are creating the SelectExpandNode for property p2 for the query ~/EnitySet/Key/p1/p2/p3?$expand=NP, we want to return property p3 here. /// </summary> private IEdmStructuralProperty FindNextPropertySegment(ODataPath path) { IEdmStructuralProperty complexProperty = null; // If the current SelectExpandNode is not top-level and has a property associated with it then return the next property segment from the path. if (Property != null) { Debug.Assert(PropertiesInPath != null, "PropertiesInPath should not be null if Property is not null"); Queue <IEdmProperty> propertyQueue = new Queue <IEdmProperty>(PropertiesInPath); foreach (ODataPathSegment segment in path) { PropertySegment propertySegment = segment as PropertySegment; if (propertySegment != null) { complexProperty = propertySegment.Property; if (propertyQueue.Count == 0) { break; } if (propertyQueue.Peek().Name == complexProperty.Name) { propertyQueue.Dequeue(); } else { return(null); } } } } else { // Return the first property if top-level resource PropertySegment segment = path.OfType <PropertySegment>().FirstOrDefault(); if (segment != null) { complexProperty = segment.Property; } } return(complexProperty); }
public void Select_Works_QueryOptionCaseInsensitive() { // Arrange const string select = "$SeLecT=naMe"; // Act ODataQueryOptions queryOptions = GetQueryOptions(select); // Assert Assert.NotNull(queryOptions.SelectExpand); SelectExpandClause selectClause = queryOptions.SelectExpand.SelectExpandClause; SelectItem selectItem = Assert.Single(selectClause.SelectedItems); PathSelectItem pathSelectItem = Assert.IsType <PathSelectItem>(selectItem); Assert.NotNull(pathSelectItem.SelectedPath); PropertySegment segment = Assert.IsType <PropertySegment>(pathSelectItem.SelectedPath.FirstSegment); Assert.Equal("Name", segment.Property.Name); }
public void TryMatchMediaType_MatchRequest_WithPrimitiveRawValueRequest() { // Arrange EdmEnumType colorType = new EdmEnumType("NS", "Color"); EdmEntityType entity = new EdmEntityType("NS", "Entity"); EdmStructuralProperty property = entity.AddStructuralProperty("Color", new EdmEnumTypeReference(colorType, false)); PropertySegment propertySegment = new PropertySegment(property); ValueSegment valueSegment = new ValueSegment(property.Type.Definition); HttpRequest request = new DefaultHttpContext().Request; request.ODataFeature().Path = new ODataPath(propertySegment, valueSegment); // Act double mapResult = Mapping.TryMatchMediaType(request); // Assert Assert.Equal(1.0, mapResult); }
public void TryTranslatePropertyCatchAllSegmentTemplate_ReturnsPropertySegment(string property) { // Arrange RouteValueDictionary routeValueDictionary = new RouteValueDictionary(new { property = $"{property}" }); ODataTemplateTranslateContext context = new ODataTemplateTranslateContext { RouteValues = routeValueDictionary }; PropertyCatchAllSegmentTemplate pathSegment = new PropertyCatchAllSegmentTemplate(_entityType); // Act bool ok = pathSegment.TryTranslate(context); // Assert Assert.True(ok); ODataPathSegment segment = Assert.Single(context.Segments); PropertySegment propertySegment = Assert.IsType <PropertySegment>(segment); Assert.Equal("Title", propertySegment.Property.Name); }
/// <summary> /// Creates an instance of <see cref="SelectItem"/> to represent the selection of the given property. /// </summary> /// <param name="metadataProviderEdmModel">The metadata provider-based edm model.</param> /// <param name="targetResourceType">The resource type the property is being selected for.</param> /// <param name="property">The property being selected.</param> /// <param name="typeSegments">Type segments seen in the path so far.</param> /// <returns>A new <see cref="SelectItem"/> to represent the selection of the given property.</returns> private static SelectItem CreatePropertySelection(MetadataProviderEdmModel metadataProviderEdmModel, ResourceType targetResourceType, ResourceProperty property, ICollection <TypeSegment> typeSegments) { var structuredType = (IEdmStructuredType)metadataProviderEdmModel.EnsureSchemaType(targetResourceType); IEdmProperty edmProperty = structuredType.FindProperty(property.Name); var edmStructuralProperty = edmProperty as IEdmStructuralProperty; Segment lastSegment; if (edmStructuralProperty != null) { lastSegment = new PropertySegment(edmStructuralProperty); } else { lastSegment = new NavigationPropertySegment((IEdmNavigationProperty)edmProperty); } var path = CreatePath(typeSegments, lastSegment); return(new PathSelectItem(path)); }
public void GetFirstNonTypeCastSegment_WorksForSelectPathWithFirstNonTypeSegmentAtBegin() { // Arrange EdmEntityType entityType = new EdmEntityType("NS", "Customer"); IEdmStructuralProperty property = entityType.AddStructuralProperty("Id", EdmPrimitiveTypeKind.String); ODataPathSegment firstPropertySegment = new PropertySegment(property); ODataPathSegment secondPropertySegment = new PropertySegment(property); ODataSelectPath selectPath = new ODataSelectPath(firstPropertySegment, secondPropertySegment); // Act IList <ODataPathSegment> remainingSegments; ODataPathSegment firstNonTypeSegment = selectPath.GetFirstNonTypeCastSegment(out remainingSegments); // Assert Assert.NotNull(firstNonTypeSegment); Assert.Same(firstPropertySegment, firstNonTypeSegment); Assert.NotNull(remainingSegments); Assert.Same(secondPropertySegment, Assert.Single(remainingSegments)); }
public void IsStreamPropertyPath_Returns_CollectBooleanValue() { // Arrange ODataPath path = null; // Act & Assert Assert.False(path.IsStreamPropertyPath()); // Act & Assert path = new ODataPath(MetadataSegment.Instance); Assert.False(path.IsStreamPropertyPath()); // Act & Assert IEdmTypeReference typeRef = EdmCoreModel.Instance.GetStream(false); Mock <IEdmStructuralProperty> mock = new Mock <IEdmStructuralProperty>(); mock.Setup(s => s.Name).Returns("any"); mock.Setup(s => s.Type).Returns(typeRef); PropertySegment segment = new PropertySegment(mock.Object); path = new ODataPath(segment); Assert.True(path.IsStreamPropertyPath()); }
private static bool TryBindAsDeclaredProperty(PathSegmentToken tokenIn, IEdmStructuredType edmType, ODataUriResolver resolver, out ODataPathSegment segment) { IEdmProperty prop = resolver.ResolveProperty(edmType, tokenIn.Identifier); if (prop == null) { segment = null; return(false); } if (prop.PropertyKind == EdmPropertyKind.Structural) { segment = new PropertySegment((IEdmStructuralProperty)prop); return(true); } if (prop.PropertyKind == EdmPropertyKind.Navigation) { segment = new NavigationPropertySegment((IEdmNavigationProperty)prop, null /*TODO set*/); return(true); } throw new ODataException(ODataErrorStrings.SelectExpandBinder_UnknownPropertyType(prop.Name)); }
private void CreatePropertySegment(ODataPathSegment previous, IEdmProperty property, string queryPortion) { if (property.Type.IsStream()) { // The server used to allow arbitrary key expressions after named streams because this check was missing. if (queryPortion != null) { throw ExceptionUtil.CreateSyntaxError(); } this.CreateNamedStreamSegment(previous, property); return; } // Handle a strongly-typed property. ODataPathSegment segment = null; if (property.PropertyKind == EdmPropertyKind.Navigation) { var navigationProperty = (IEdmNavigationProperty)property; IEdmNavigationSource navigationSource = previous.TargetEdmNavigationSource.FindNavigationTarget(navigationProperty); // Relationship between TargetMultiplicity and navigation property: // 1) EdmMultiplicity.Many <=> collection navigation property // 2) EdmMultiplicity.ZeroOrOne <=> nullable singleton navigation property // 3) EdmMultiplicity.One <=> non-nullable singleton navigation property // // According to OData Spec CSDL 7.1.3: // 1) non-nullable singleton navigation property => navigation source required // 2) the other cases => navigation source optional if (navigationProperty.TargetMultiplicity() == EdmMultiplicity.One && navigationSource is IEdmUnknownEntitySet) { // Specifically not throwing ODataUriParserException since it's more an an internal server error throw new ODataException(ODataErrorStrings.RequestUriProcessor_TargetEntitySetNotFound(property.Name)); } segment = new NavigationPropertySegment(navigationProperty, navigationSource); } else { segment = new PropertySegment((IEdmStructuralProperty)property); switch (property.Type.TypeKind()) { case EdmTypeKind.Complex: segment.TargetKind = RequestTargetKind.ComplexObject; break; case EdmTypeKind.Collection: segment.TargetKind = RequestTargetKind.Collection; break; case EdmTypeKind.Enum: segment.TargetKind = RequestTargetKind.Enum; break; default: Debug.Assert(property.Type.IsPrimitive() || property.Type.IsTypeDefinition(), "must be primitive type or type definition property"); segment.TargetKind = RequestTargetKind.Primitive; break; } } this.parsedSegments.Add(segment); if (!(queryPortion == null || property.Type.IsCollection() && property.Type.AsCollection().ElementType().IsEntity())) { throw ExceptionUtil.CreateSyntaxError(); } this.TryBindKeyFromParentheses(queryPortion); }
private static IEdmProperty GetProperty(ODataPath odataPath, ODataRequestMethod method, out string prefix, out TypeSegment cast) { prefix = String.Empty; cast = null; PropertySegment segment = null; if (odataPath.PathTemplate == "~/entityset/key/property" || odataPath.PathTemplate == "~/entityset/key/cast/property" || odataPath.PathTemplate == "~/singleton/property" || odataPath.PathTemplate == "~/singleton/cast/property") { PropertySegment tempSegment = (PropertySegment)odataPath.Segments[odataPath.Segments.Count - 1]; switch (method) { case ODataRequestMethod.Get: prefix = "Get"; segment = tempSegment; break; case ODataRequestMethod.Post: //Allow post only to collection properties if (tempSegment.Property.Type.IsCollection()) { prefix = "PostTo"; segment = tempSegment; } break; case ODataRequestMethod.Put: prefix = "PutTo"; segment = tempSegment; break; case ODataRequestMethod.Patch: // OData Spec: PATCH is not supported for collection properties. if (!tempSegment.Property.Type.IsCollection()) { prefix = "PatchTo"; segment = tempSegment; } break; case ODataRequestMethod.Delete: // OData spec: A successful DELETE request to the edit URL for a structural property, ... sets the property to null. // The request body is ignored and should be empty. // DELETE request to a non-nullable value MUST fail and the service respond with 400 Bad Request or other appropriate error. if (tempSegment.Property.Type.IsNullable) { prefix = "DeleteTo"; segment = tempSegment; } break; } } else if (odataPath.PathTemplate == "~/entityset/key/property/cast" || odataPath.PathTemplate == "~/entityset/key/cast/property/cast" || odataPath.PathTemplate == "~/singleton/property/cast" || odataPath.PathTemplate == "~/singleton/cast/property/cast") { PropertySegment tempSegment = (PropertySegment)odataPath.Segments[odataPath.Segments.Count - 2]; TypeSegment tempCast = (TypeSegment)odataPath.Segments.Last(); switch (method) { case ODataRequestMethod.Get: prefix = "Get"; segment = tempSegment; cast = tempCast; break; case ODataRequestMethod.Post: //Allow post only to collection properties if (tempSegment.Property.Type.IsCollection()) { prefix = "PostTo"; segment = tempSegment; cast = tempCast; } break; case ODataRequestMethod.Put: prefix = "PutTo"; segment = tempSegment; cast = tempCast; break; case ODataRequestMethod.Patch: // PATCH is not supported for collection properties. if (!tempSegment.Property.Type.IsCollection()) { prefix = "PatchTo"; segment = tempSegment; cast = tempCast; } break; } } else if (odataPath.PathTemplate == "~/entityset/key/property/$value" || odataPath.PathTemplate == "~/entityset/key/cast/property/$value" || odataPath.PathTemplate == "~/singleton/property/$value" || odataPath.PathTemplate == "~/singleton/cast/property/$value" || odataPath.PathTemplate == "~/entityset/key/property/$count" || odataPath.PathTemplate == "~/entityset/key/cast/property/$count" || odataPath.PathTemplate == "~/singleton/property/$count" || odataPath.PathTemplate == "~/singleton/cast/property/$count") { PropertySegment tempSegment = (PropertySegment)odataPath.Segments[odataPath.Segments.Count - 2]; switch (method) { case ODataRequestMethod.Get: prefix = "Get"; segment = tempSegment; break; } } return(segment == null ? null : segment.Property); }
/// <inheritdoc/> protected override bool IsMatch(PropertySegment propertySegment) { return(propertySegment != null && propertySegment.Property.Type.IsPrimitive() && !propertySegment.Property.Type.IsBinary()); }
/// <summary> /// Translate a PropertySegment /// </summary> /// <param name="segment">the segment to Translate</param> /// <returns>Translated WebApi path segment.</returns> public override IEnumerable <ODataPathSegment> Translate(PropertySegment segment) { yield return(new PropertyAccessPathSegment(segment.Property)); }
public void EqualityCorrect() { PropertySegment propertySegment1 = new PropertySegment(HardCodedTestModel.GetPersonNameProp()); PropertySegment propertySegment2 = new PropertySegment(HardCodedTestModel.GetPersonNameProp()); propertySegment1.Equals(propertySegment2).Should().BeTrue(); }
/// <summary> /// Translate a PropertySegment /// </summary> /// <param name="segment">the segment to Translate</param> /// <returns>Defined by the implementer.</returns> public virtual T Translate(PropertySegment segment) { throw new NotImplementedException(); }
/// <summary> /// Translate a PropertySegment /// </summary> /// <param name="segment">the segment to Translate</param> /// <returns>Defined by the implementer.</returns> public override string Translate(PropertySegment segment) { Debug.Assert(segment != null, "segment != null"); return("/" + segment.Property.Name); }
public void TargetEdmTypeIsPropertyTypeDefinition() { PropertySegment propertySegment = new PropertySegment(HardCodedTestModel.GetPersonNameProp()); propertySegment.TargetEdmType.Should().BeSameAs(HardCodedTestModel.GetPersonNameProp().Type.Definition); }
public void IdentifierSetToPropertyName() { PropertySegment propertySegment = new PropertySegment(HardCodedTestModel.GetPersonNameProp()); propertySegment.Identifier.Should().Be(HardCodedTestModel.GetPersonNameProp().Name); }
public void Translate_PropertySegment_To_PropertyAccessPathSegment_Works() { // Arrange IEdmEntityType entityType = _model.FindDeclaredType("System.Web.OData.Routing.RoutingCustomer") as IEdmEntityType; IEdmStructuralProperty property = entityType.FindProperty("Name") as IEdmStructuralProperty; PropertySegment segment = new PropertySegment(property); // Act IEnumerable<ODataPathSegment> segments = _translator.Translate(segment); // Assert ODataPathSegment pathSegment = Assert.Single(segments); PropertyAccessPathSegment propertyPathSegment = Assert.IsType<PropertyAccessPathSegment>(pathSegment); Assert.Same(property, propertyPathSegment.Property); }
/// <summary> /// Handle a PropertySegment /// </summary> /// <param name="segment">the segment to Handle</param> public virtual void Handle(PropertySegment segment) { throw new NotImplementedException(); }
public void SelectComplexCollectionPropertyWithCast() { var selectItem = ParseSingleSelectForPerson("PreviousAddresses/Fully.Qualified.Namespace.HomeAddress"); ODataPathSegment[] segments = new ODataPathSegment[2]; segments[0] = new PropertySegment(HardCodedTestModel.GetPersonPreviousAddressesProp()); segments[1] = new TypeSegment(HardCodedTestModel.GetHomeAddressType(), null); selectItem.ShouldBePathSelectionItem(new ODataPath(segments)); }
/// <summary> /// Initializes a new instance of the <see cref="PropertySegmentTemplate" /> class. /// </summary> /// <param name="segment">The property segment.</param> public PropertySegmentTemplate(PropertySegment segment) { Segment = segment ?? throw Error.ArgumentNull(nameof(segment)); }
/// <summary> /// Translate PropertySegment to linq expression. /// </summary> /// <param name="segment">The PropertySegment</param> /// <returns>The linq expression</returns> public override Expression Translate(PropertySegment segment) { // translate to be ResultExpressionFromKeySegment.PropertyName this.ResultExpression = Expression.Property(this.ResultExpression, segment.Property.Name); return(this.ResultExpression); }
public override bool Translate(PropertySegment segment) { PropertySegment propertySegment = GetNextSegment() as PropertySegment; return(propertySegment != null && propertySegment.Property == segment.Property); }
private void BuildSelections( SelectExpandClause selectExpandClause, HashSet<IEdmStructuralProperty> allStructuralProperties, HashSet<IEdmStructuralProperty> allNestedProperties, HashSet<IEdmNavigationProperty> allNavigationProperties, HashSet<IEdmAction> allActions, HashSet<IEdmFunction> allFunctions) { 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); } else if (allNestedProperties.Contains(structuralProperty)) { SelectedComplexProperties.Add(structuralProperty); } continue; } OperationSegment operationSegment = segment as OperationSegment; if (operationSegment != null) { AddOperations(allActions, allFunctions, operationSegment); continue; } DynamicPathSegment dynamicPathSegment = segment as DynamicPathSegment; if (dynamicPathSegment != null) { SelectedDynamicProperties.Add(dynamicPathSegment.Identifier); continue; } throw new ODataException(Error.Format(SRResources.SelectionTypeNotSupported, segment.GetType().Name)); } WildcardSelectItem wildCardSelectItem = selectItem as WildcardSelectItem; if (wildCardSelectItem != null) { SelectedStructuralProperties = allStructuralProperties; SelectedComplexProperties = allNestedProperties; SelectedNavigationProperties = allNavigationProperties; SelectAllDynamicProperties = true; continue; } NamespaceQualifiedWildcardSelectItem wildCardActionSelection = selectItem as NamespaceQualifiedWildcardSelectItem; if (wildCardActionSelection != null) { SelectedActions = allActions; SelectedFunctions = allFunctions; continue; } throw new ODataException(Error.Format(SRResources.SelectionTypeNotSupported, selectItem.GetType().Name)); } }
private static IEdmNavigationSource GetTargetNavigationSource(IEdmNavigationSource previous, ODataPathSegment segment) { if (segment == null) { return(null); } EntitySetSegment entitySet = segment as EntitySetSegment; if (entitySet != null) { return(entitySet.EntitySet); } SingletonSegment singleton = segment as SingletonSegment; if (singleton != null) { return(singleton.Singleton); } TypeSegment cast = segment as TypeSegment; if (cast != null) { return(cast.NavigationSource); } KeySegment key = segment as KeySegment; if (key != null) { return(key.NavigationSource); } OperationSegment opertion = segment as OperationSegment; if (opertion != null) { return(opertion.EntitySet); } OperationImportSegment import = segment as OperationImportSegment; if (import != null) { return(import.EntitySet); } PropertySegment property = segment as PropertySegment; if (property != null) { return(previous); // for property, return the previous, or return null???? } MetadataSegment metadata = segment as MetadataSegment; if (metadata != null) { return(null); } CountSegment count = segment as CountSegment; if (count != null) { return(null); } OperationImportSegment operationImport = segment as OperationImportSegment; if (operationImport != null) { return(null); } throw new Exception("Not supported segment in endpoint routing convention!"); }
private static bool TryBindAsDeclaredProperty(PathSegmentToken tokenIn, IEdmStructuredType edmType, ODataUriResolver resolver, out ODataPathSegment segment) { IEdmProperty prop = resolver.ResolveProperty(edmType, tokenIn.Identifier); if (prop == null) { segment = null; return false; } if (prop.PropertyKind == EdmPropertyKind.Structural) { segment = new PropertySegment((IEdmStructuralProperty)prop); return true; } if (prop.PropertyKind == EdmPropertyKind.Navigation) { segment = new NavigationPropertySegment((IEdmNavigationProperty)prop, null /*TODO: set*/); return true; } throw new ODataException(ODataErrorStrings.SelectExpandBinder_UnknownPropertyType(prop.Name)); }
public void PropertySetCorrectly() { IEdmStructuralProperty prop = ModelBuildingHelpers.BuildValidPrimitiveProperty(); PropertySegment segment = new PropertySegment(prop); segment.Property.Should().Be(prop); }
public override bool Translate(PropertySegment segment) { return(GetNextSegment() is PropertySegment propertySegment && propertySegment.Property == segment.Property); }
/// <summary> /// Creates an instance of <see cref="SelectItem"/> to represent the selection of the given property. /// </summary> /// <param name="metadataProviderEdmModel">The metadata provider-based edm model.</param> /// <param name="targetResourceType">The resource type the property is being selected for.</param> /// <param name="property">The property being selected.</param> /// <param name="typeSegments">Type segments seen in the path so far.</param> /// <returns>A new <see cref="SelectItem"/> to represent the selection of the given property.</returns> private static SelectItem CreatePropertySelection(MetadataProviderEdmModel metadataProviderEdmModel, ResourceType targetResourceType, ResourceProperty property, ICollection<TypeSegment> typeSegments) { var structuredType = (IEdmStructuredType)metadataProviderEdmModel.EnsureSchemaType(targetResourceType); IEdmProperty edmProperty = structuredType.FindProperty(property.Name); var edmStructuralProperty = edmProperty as IEdmStructuralProperty; Segment lastSegment; if (edmStructuralProperty != null) { lastSegment = new PropertySegment(edmStructuralProperty); } else { lastSegment = new NavigationPropertySegment((IEdmNavigationProperty)edmProperty); } var path = CreatePath(typeSegments, lastSegment); return new PathSelectItem(path); }
private void CreatePropertySegment(ODataPathSegment previous, IEdmProperty property, string queryPortion) { if (property.Type.IsStream()) { // The server used to allow arbitrary key expressions after named streams because this check was missing. if (queryPortion != null) { throw ExceptionUtil.CreateSyntaxError(); } this.CreateNamedStreamSegment(previous, property); return; } // Handle a strongly-typed property. ODataPathSegment segment = null; if (property.PropertyKind == EdmPropertyKind.Navigation) { var navigationProperty = (IEdmNavigationProperty)property; IEdmNavigationSource navigationSource = previous.TargetEdmNavigationSource.FindNavigationTarget(navigationProperty); segment = new NavigationPropertySegment(navigationProperty, navigationSource); } else { segment = new PropertySegment((IEdmStructuralProperty)property); switch (property.Type.TypeKind()) { case EdmTypeKind.Complex: segment.TargetKind = RequestTargetKind.ComplexObject; break; case EdmTypeKind.Collection: segment.TargetKind = RequestTargetKind.Collection; break; case EdmTypeKind.Enum: segment.TargetKind = RequestTargetKind.Enum; break; default: Debug.Assert(property.Type.IsPrimitive() || property.Type.IsTypeDefinition(), "must be primitive type or type definition property"); segment.TargetKind = RequestTargetKind.Primitive; break; } } this.parsedSegments.Add(segment); if (!(queryPortion == null || property.Type.IsCollection() && property.Type.AsCollection().ElementType().IsEntity())) { throw ExceptionUtil.CreateSyntaxError(); } this.TryBindKeyFromParentheses(queryPortion); }
/// <summary> /// Creates a named stream segment /// </summary> /// <param name="previous">previous segment info.</param> /// <param name="streamProperty">stream property to create the segment for.</param> private void CreateNamedStreamSegment(ODataPathSegment previous, IEdmProperty streamProperty) { Debug.Assert(streamProperty.Type.IsStream(), "streamProperty.Type.IsStream()"); // Handle Named Stream. ODataPathSegment segment = new PropertySegment((IEdmStructuralProperty)streamProperty); segment.TargetKind = RequestTargetKind.MediaResource; segment.SingleResult = true; segment.TargetEdmType = previous.TargetEdmType; Debug.Assert(segment.Identifier != UriQueryConstants.ValueSegment, "'$value' cannot be the name of a named stream."); this.parsedSegments.Add(segment); }
public void TargetEdmTypeIsPropertyTypeDefinition() { PropertySegment propertySegment = new PropertySegment(HardCodedTestModel.GetPersonNameProp()); Assert.Same(HardCodedTestModel.GetPersonNameProp().Type.Definition, propertySegment.TargetEdmType); }
/// <summary> /// Creates a new instance of the <see cref="SelectExpandIncludedProperty"/> class. /// </summary> /// <param name="propertySegment">The property segment that has this select expand item.</param> public SelectExpandIncludedProperty(PropertySegment propertySegment) : this(propertySegment, null) { }
/// <summary> /// Initializes a new instance of the <see cref="PropertySegmentTemplate" /> class. /// </summary> /// <param name="segment">The property segment.</param> public PropertySegmentTemplate(PropertySegment segment) { Segment = segment ?? throw new ArgumentNullException(nameof(segment)); IsSingle = !segment.Property.Type.IsCollection(); }
/// <summary> /// Translate a PropertySegment /// </summary> /// <param name="segment">the segment to Translate</param> /// <returns>Translated odata path segment.</returns> public override ODataPathSegment Translate(PropertySegment segment) { return(segment); }
public override void Handle(PropertySegment segment) { this.ThrowIfResolved(); this.NavigationSource = null; this.Property = segment.Property; this.Type = segment.EdmType; this.ElementType = this.GetElementType(this.Type); this.PushParentSegment(); this.childSegments.Add(segment); this.canonicalSegments.Add(segment); }