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); }
public void ApplyToQuery_GreaterIntegerNullable_CorrectResultReturned() { var criteria = new NumericSearch(); criteria.Property = "IntegerNullable"; criteria.TargetTypeName = typeof(SomeClass).AssemblyQualifiedName; criteria.SearchTerm = 10; criteria.Comparator = NumericComparators.Greater; Assert.Equal(2, criteria.ApplyToQuery(new Repository().GetQuery()).Count()); }
public void ApplyToQuery_LessOrEqualInteger_CorrectResultReturned() { var criteria = new NumericSearch(); criteria.Property = "Integer"; criteria.TargetTypeName = typeof(SomeClass).AssemblyQualifiedName; criteria.SearchTerm = 80; criteria.Comparator = NumericComparators.LessOrEqual; Assert.Equal(16, criteria.ApplyToQuery(new Repository().GetQuery()).Count()); }