Esempio n. 1
0
        public void Succeeds()
        {
            var search = new IntegerSearch(nameof(Item.Value));

            var result = search.ApplyToQuery(Items().AsQueryable()).ToArray();

            result.Length.Should().Be(3);
        }
Esempio n. 2
0
        public void Child_Succeeds()
        {
            Expression <Func <Foo, object> > expression = foo => foo.Bar.Value;
            var property = expression.ToString();
            var search   = new IntegerSearch(property);

            var result = search.ApplyToQuery(Foos().AsQueryable()).ToArray();

            result.Length.Should().Be(2);
            result[0].Id.Should().Be(4);
            result[1].Id.Should().Be(5);
        }
Esempio n. 3
0
        public void Less_Succeeds()
        {
            var search = new IntegerSearch(nameof(Item.Value))
            {
                Term1 = 2,
                Is    = IntegerSearch.Comparer.Less
            };

            var result = search.ApplyToQuery(Items().AsQueryable()).ToArray();

            result.Length.Should().Be(1);
            result[0].Id.Should().Be(1);
        }
Esempio n. 4
0
        public void Children_Equals_Succeeds()
        {
            var search = new IntegerSearch($"Bars.{nameof(Bar.Value)}")
            {
                Is    = IntegerSearch.Comparer.Equal,
                Term1 = 5
            };

            var result = search.ApplyToQuery(Foos2().AsQueryable()).ToArray();

            result.Length.Should().Be(1);
            result[0].Id.Should().Be(6);
        }
Esempio n. 5
0
        public void Child_Equals_Succeeds()
        {
            Expression <Func <Foo, object> > expression = foo => foo.Bar.Value;
            var propert  = expression.GetPropertyPath();
            var property = string.Join(".", PropertyPath <Foo> .Get(x => x.Bar.Value).Select(x => x.Name));

            var search = new IntegerSearch(property)
            {
                Is    = IntegerSearch.Comparer.Equal,
                Term1 = 2
            };
            var result = search.ApplyToQuery(Foos().AsQueryable()).ToArray();

            result.Length.Should().Be(1);
            result[0].Id.Should().Be(5);
        }
Esempio n. 6
0
        private static AbstractSearch CreateSearchCriterion(Type targetType, Type propertyType, string property)
        {
            AbstractSearch result = null;

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

            if (propertyType.IsEnum)
            {
                result = new EnumSearch(propertyType);
            }
            else if (propertyType == typeof(string))
            {
                result = new TextSearch();
            }
            else if (propertyType == typeof(bool) || propertyType == typeof(bool?))
            {
                result = new BooleanSearch();
            }
            else if (propertyType == typeof(byte) || propertyType == typeof(byte?))
            {
                result = new ByteSearch();
            }
            else if (propertyType == typeof(char) || propertyType == typeof(char?))
            {
                result = new CharacterSearch();
            }
            else if (propertyType == typeof(DateTime) || propertyType == typeof(DateTime?))
            {
                result = new DateSearch();
            }
            else if (propertyType == typeof(decimal) || propertyType == typeof(decimal?))
            {
                result = new DecimalSearch();
            }
            else if (propertyType == typeof(double) || propertyType == typeof(double?))
            {
                result = new DoubleSearch();
            }
            else if (propertyType == typeof(float) || propertyType == typeof(float?))
            {
                result = new FloatSearch();
            }
            else if (propertyType == typeof(int) || propertyType == typeof(int?))
            {
                result = new IntegerSearch();
            }
            else if (propertyType == typeof(long) || propertyType == typeof(long?))
            {
                result = new LongSearch();
            }
            else if (propertyType == typeof(sbyte) || propertyType == typeof(sbyte?))
            {
                result = new SByteSearch();
            }
            else if (propertyType == typeof(short) || propertyType == typeof(short?))
            {
                result = new ShortSearch();
            }
            else if (propertyType == typeof(uint) || propertyType == typeof(uint?))
            {
                result = new UnsignedIntegerSearch();
            }
            else if (propertyType == typeof(ulong) || propertyType == typeof(ulong?))
            {
                result = new UnsignedLongSearch();
            }
            else if (propertyType == typeof(ushort) || propertyType == typeof(ushort?))
            {
                result = new UnsignedShortSearch();
            }

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

            return(result);
        }