Beispiel #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);
        }
Beispiel #2
0
        public void ApplyToQuery_EqualsEnum_CorrectResultReturned()
        {
            var criteria = new EnumSearch();

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

            criteria.SearchTerm = MyEnum.First.ToString();

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