コード例 #1
0
        private static AbstractSearch CreateSearchCriterion(Type targetType, Type propertyType, string property)
        {
            AbstractSearch result = null;

            if (propertyType.IsCollectionType())
            {
                propertyType = propertyType.GetGenericArguments().First();
            }

            if (propertyType.Equals(typeof(string)))
            {
                result = new TextSearch();
            }
            else if (propertyType.Equals(typeof(int)) || propertyType.Equals(typeof(int?)))
            {
                result = new NumericSearch();
            }
            else if (propertyType.Equals(typeof(DateTime)) || propertyType.Equals(typeof(DateTime?)))
            {
                result = new DateSearch();
            }
            else if (propertyType.IsEnum)
            {
                result = new EnumSearch(propertyType);
            }

            if (result != null)
            {
                result.Property       = property;
                result.TargetTypeName = targetType.AssemblyQualifiedName;
            }

            return(result);
        }
コード例 #2
0
        public void ApplyToQuery_EqualsNestedNestedText_CorrectResultReturned()
        {
            var criteria = new TextSearch();

            criteria.Property       = "Nested.Nested.TextNested";
            criteria.TargetTypeName = typeof(SomeClass).AssemblyQualifiedName;

            criteria.SearchTerm = "qwerty";
            criteria.Comparator = TextComparators.Equals;

            Assert.AreEqual(0, criteria.ApplyToQuery(new Repository().GetQuery()).Count());
        }
コード例 #3
0
        public void ApplyToQuery_EqualsTextInCollectionComplex_CorrectResultReturned()
        {
            var criteria = new TextSearch();

            criteria.Property       = "CollectionComplex.TextNested";
            criteria.TargetTypeName = typeof(SomeClass).AssemblyQualifiedName;

            criteria.SearchTerm = "complex_678";
            criteria.Comparator = TextComparators.Equals;

            Assert.AreEqual(8, criteria.ApplyToQuery(new Repository().GetQuery()).Count());
        }
コード例 #4
0
        public void ApplyToQuery_ContainsText_CorrectResultReturned()
        {
            var criteria = new TextSearch();

            criteria.Property       = "Text";
            criteria.TargetTypeName = typeof(SomeClass).AssemblyQualifiedName;

            criteria.SearchTerm = "abcdef";
            criteria.Comparator = TextComparators.Contains;

            Assert.AreEqual(2, criteria.ApplyToQuery(new Repository().GetQuery()).Count());
        }