public void CreateWhereContainsLambdaSuccessfully()
        {
            // Arrange
            var lambda = new LambdaCreator();
            var contains = new ContainsFilterRules {MemberName = "Prop", MemberValue = "2a"};
            var pocos = Enumerable.Range(1, 10).Select(i => new Poco {Prop = string.Format("La {0}a la", i)}).ToList();
            Poco expected = pocos[1];

            // Act
            var mce = lambda.CreateContainsLambda<Poco>(contains.MemberName, contains.MemberValue);


            var res = pocos.AsQueryable().Where(mce);
            var res2 = pocos.Where(p => p.Prop.Contains(contains.MemberValue)).ToList();

            // Assert
            Assert.AreEqual(1, res.Count());
            Assert.AreEqual(expected.Prop, res.First().Prop);
            Assert.AreEqual(res2.First().Prop, res.First().Prop);
            
        }
        public void ThrowBadRequestIfQueriedPropertyIsNotAString()
        {
            // Arrange
            var lambda = new LambdaCreator();
            var contains = new ContainsFilterRules { MemberName = "IntProp", MemberValue = "15" };
            var pocos = Enumerable.Range(1, 10).Select(i => new Poco { Prop = string.Format("La {0}a la", i) }).ToList();

            // Act
            try
            {
                lambda.CreateContainsLambda<Poco>(contains.MemberName, contains.MemberValue);
            // Assert
                Assert.Fail("Should throw exception");
            }
            catch (BadRequestException exception)
            {

            }
            catch (Exception e)
            {
                Assert.Fail("Should throw bad request exception");
            }
        }
        public void ParseObjectExpressionsSuccessfully()
        {
            var rules = new ContainsFilterRules {MemberName = "value", MemberValue = "10"};
            var entities = Enumerable.Range(1, 10).Select(i => new {id = i, value = "lala" + i.ToString(CultureInfo.InvariantCulture)}).ToList();
            var lamdaCreator = new LambdaCreator();
            var filter = new EntityFilter(lamdaCreator);

            var res = filter.FilterWithContains(entities, rules);

            Assert.AreEqual(1, res.Count);
            Assert.AreEqual(10, res[0].id);

        }
        public void FilterByContainsSuccessfully()
        {
            // Arrange
            const int max = 30;
            var contains = new ContainsFilterRules {MemberName = "Description", MemberValue = max.ToString(CultureInfo.InvariantCulture)};

            var entities = Enumerable.Range(1, max)
                           .Select(value => new UserProjectEntity
                           {
                               Created = DateTime.MaxValue - TimeSpan.FromDays(value),
                               Name = value.ToString(CultureInfo.InvariantCulture),
                               Description = (value > 4 && value < 10) 
                                               ? max.ToString(CultureInfo.InvariantCulture) 
                                               : "Other description"
                           })
                           .ToList();
            IFilter filter = new EntityFilter(_lambdaCreator);

            // Act
            var result = filter.FilterWithContains(entities, contains);
            string firstElementName = result.First().Name;


            // Assert
            Assert.IsTrue(result.All(project => project.Description == max.ToString()));
            Assert.AreEqual("5", firstElementName);
            Assert.AreEqual(5, result.Count);
        }
        public void SkipElementOfCollectionIfItsQueriedPropertyIsNull()
        {
            // Arrange
            var lambda = new LambdaCreator();
            var contains = new ContainsFilterRules { MemberName = "Prop", MemberValue = "la" };
            var pocos = Enumerable.Range(1, 10).Select(i => new Poco { Prop = string.Format("La {0}a la", i) }).ToList();
            pocos.Add(new Poco()); // Prop = null.

            // Act
            var mce = lambda.CreateContainsLambda<Poco>(contains.MemberName, contains.MemberValue);
            var result = pocos.AsQueryable().Where(mce).ToList();
            
            // Assert
            Assert.AreEqual(pocos.Count - 1, result.Count);
        }
        public void PerformCaseInsensitiveSearchSuccessfully()
        {
            // Arrange
            var lambda = new LambdaCreator();
            var contains = new ContainsFilterRules { MemberName = "Prop", MemberValue = "10A" };
            var pocos = Enumerable.Range(1, 10).Select(i => new Poco { Prop = string.Format("La {0}a la", i), IntProp = i}).ToList();

            // Act
            var mce = lambda.CreateContainsLambda<Poco>(contains.MemberName, contains.MemberValue);
            var result = pocos.AsQueryable().Where(mce).ToList();

            // Assert
            Assert.AreEqual(10, result.Single().IntProp);
        }