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_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()); }
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()); }