コード例 #1
0
        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);
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        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);

        }
コード例 #4
0
        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);
        }