public void AnnotatableTargetOnEntityTypeReturnsCorrectPropertyValue() { // Arrange const string searchAnnotation = @" <Annotations Target=""NS.Calendar"" > <Annotation Term=""Org.OData.Capabilities.V1.SearchRestrictions""> <Record> <PropertyValue Property=""Searchable"" Bool=""false"" /> <PropertyValue Property=""UnsupportedExpressions""> <EnumMember>Org.OData.Capabilities.V1.SearchExpressions/phrase</EnumMember> </PropertyValue > </Record> </Annotation> </Annotations>"; IEdmModel model = CapabilitiesModelHelper.GetModelOutline(searchAnnotation); IEdmEntityType calendar = model.SchemaElements.OfType <IEdmEntityType>().First(c => c.Name == "Calendar"); // Act SearchRestrictionsType search = model.GetRecord <SearchRestrictionsType>(calendar); // Assert Assert.NotNull(search); Assert.False(search.Searchable); Assert.NotNull(search.UnsupportedExpressions); Assert.Equal(SearchExpressions.phrase, search.UnsupportedExpressions.Value); Assert.False(search.IsUnsupportedExpressions(SearchExpressions.AND)); Assert.True(search.IsUnsupportedExpressions(SearchExpressions.phrase)); }
public void AnnotatableTargetOnEntitySetReturnsCorrectPropertyValue() { // Arrange const string searchAnnotation = @" <Annotations Target=""NS.Default/Calendars"" > <Annotation Term=""Org.OData.Capabilities.V1.SearchRestrictions""> <Record> <PropertyValue Property=""Searchable"" Bool=""false"" /> <PropertyValue Property=""UnsupportedExpressions""> <EnumMember>Org.OData.Capabilities.V1.SearchExpressions/group</EnumMember> </PropertyValue > </Record> </Annotation> </Annotations>"; IEdmModel model = CapabilitiesModelHelper.GetModelOutline(searchAnnotation); IEdmEntitySet calendars = model.EntityContainer.FindEntitySet("Calendars"); // Act SearchRestrictionsType search = model.GetRecord <SearchRestrictionsType>(calendars); // Assert Assert.NotNull(search); Assert.False(search.Searchable); Assert.NotNull(search.UnsupportedExpressions); Assert.Equal(SearchExpressions.group, search.UnsupportedExpressions.Value); Assert.False(search.IsUnsupportedExpressions(SearchExpressions.AND)); Assert.True(search.IsUnsupportedExpressions(SearchExpressions.group)); }
public void InitializSearchRestrictionsTypeWithRecordSuccess() { // Assert EdmModel model = new EdmModel(); IEdmEnumType searchExpressions = model.FindType("Org.OData.Capabilities.V1.SearchExpressions") as IEdmEnumType; Assert.NotNull(searchExpressions); IEdmRecordExpression record = new EdmRecordExpression( new EdmPropertyConstructor("Searchable", new EdmBooleanConstant(false)), new EdmPropertyConstructor("UnsupportedExpressions", new EdmEnumMemberExpression( searchExpressions.Members.First(c => c.Name == "AND"), searchExpressions.Members.First(c => c.Name == "OR"))) ); // Act SearchRestrictionsType search = new SearchRestrictionsType(); search.Initialize(record); // Assert Assert.False(search.Searchable); Assert.NotNull(search.UnsupportedExpressions); Assert.Equal(SearchExpressions.AND | SearchExpressions.OR, search.UnsupportedExpressions.Value); }
/// <summary> /// Create the $search parameter. /// </summary> /// <param name="context">The OData context.</param> /// <param name="target">The Edm annotation target.</param> /// <returns>The created <see cref="OpenApiParameter"/> or null.</returns> public static OpenApiParameter CreateSearch(this ODataContext context, IEdmVocabularyAnnotatable target) { Utils.CheckArgumentNull(context, nameof(context)); Utils.CheckArgumentNull(target, nameof(target)); SearchRestrictionsType search = context.Model.GetRecord <SearchRestrictionsType>(target, CapabilitiesConstants.SearchRestrictions); if (search == null || search.IsSearchable) { return(new OpenApiParameter { Reference = new OpenApiReference { Type = ReferenceType.Parameter, Id = "search" } }); } return(null); }