Пример #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_InRangeDate_CorrectResultReturned()
        {
            var criteria = new DateSearch();

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

            criteria.SearchTerm  = new System.DateTime(2001, 2, 1);
            criteria.SearchTerm2 = new System.DateTime(2006, 7, 1);
            criteria.Comparator  = DateComparators.InRange;

            Assert.AreEqual(12, criteria.ApplyToQuery(new Repository().GetQuery()).Count());
        }
Пример #3
0
        public void ApplyToQuery_LessOrEqualDateNullable_CorrectResultReturned()
        {
            var criteria = new DateSearch();

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

            criteria.SearchTerm  = new System.DateTime(2007, 8, 1);
            criteria.SearchTerm2 = null;
            criteria.Comparator  = DateComparators.LessOrEqual;

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