Пример #1
0
        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");
            }
        }
Пример #2
0
        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);
        }
Пример #3
0
        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);
        }
Пример #4
0
        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);
            
        }
Пример #5
0
        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");
            }
        }
Пример #6
0
        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);
        }
Пример #7
0
        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);
        }
Пример #8
0
        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);
        }