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
            SearchRestrictions search = new SearchRestrictions();
            bool result = search.Load(model, calendars);

            // Assert
            Assert.True(result);
            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 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
            SearchRestrictions search = new SearchRestrictions();
            bool result = search.Load(model, calendar);

            // Assert
            Assert.True(result);
            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 KindPropertyReturnsSearchRestrictionsEnumMember()
        {
            // Arrange & Act
            SearchRestrictions search = new SearchRestrictions();

            // Assert
            Assert.Equal(CapabilitesTermKind.SearchRestrictions, search.Kind);
        }
Esempio n. 4
0
        private static void LuceneCriteria()
        {
            using (IFullTextSession s = Search.CreateFullTextSession(sf.OpenSession())) {
                IList result = s.CreateCriteria(typeof(Book))
                               .Add(SearchRestrictions.Query("Summary:NHibernate or Name:NHibernate"))
                               .List();

                Debug.Assert(result.Count == 2);
            }
        }
        public void UnknownAnnotatableTargetReturnsDefaultPropertyValues()
        {
            // Arrange
            SearchRestrictions search     = new SearchRestrictions();
            EdmEntityType      entityType = new EdmEntityType("NS", "Entity");

            //  Act
            bool result = search.Load(EdmCoreModel.Instance, entityType);

            // Assert
            Assert.False(result);
            Assert.True(search.IsSearchable);
            Assert.Null(search.Searchable);
            Assert.Null(search.UnsupportedExpressions);
        }
Esempio n. 6
0
        /// <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));

            SearchRestrictions search = context.Model.GetSearchRestrictions(target);

            if (search == null || search.IsSearchable)
            {
                return(new OpenApiParameter
                {
                    Reference = new OpenApiReference {
                        Type = ReferenceType.Parameter, Id = "search"
                    }
                });
            }

            return(null);
        }