コード例 #1
0
        public void Apply_FiltersMultipleItems()
        {
            StringEndsWithFilter filter = new StringEndsWithFilter {
                Method = "ends-with", Values = new[] { "est", "ER" }
            };
            Expression <Func <GridModel, String> > expression = (model) => model.Name;

            IQueryable <GridModel> items = new[]
            {
                new GridModel {
                    Name = null
                },
                new GridModel {
                    Name = "Tes"
                },
                new GridModel {
                    Name = "test"
                },
                new GridModel {
                    Name = "TEST"
                },
                new GridModel {
                    Name = "TESTE"
                },
                new GridModel {
                    Name = "TESTEr"
                }
            }.AsQueryable();

            IQueryable expected = items.Where(model => model.Name != null && (model.Name.ToUpper().EndsWith("TEST") || model.Name.ToUpper().EndsWith("ER")));
            IQueryable actual   = items.Where(expression, filter);

            Assert.Equal(expected, actual);
        }
コード例 #2
0
        public void Apply_FiltersItemsWithCaseInsensitiveComparison()
        {
            Expression <Func <GridModel, String> > expression = (model) => model.Name;
            StringEndsWithFilter filter = new StringEndsWithFilter();

            filter.Value = "Test";

            IQueryable <GridModel> items = new[]
            {
                new GridModel {
                    Name = null
                },
                new GridModel {
                    Name = "Tes"
                },
                new GridModel {
                    Name = "test"
                },
                new GridModel {
                    Name = "Test"
                },
                new GridModel {
                    Name = "TEST2"
                }
            }.AsQueryable();

            IQueryable expected = items.Where(model => model.Name != null && model.Name.ToUpper().EndsWith("TEST"));
            IQueryable actual   = Filter(items, filter.Apply(expression.Body), expression);

            Assert.Equal(expected, actual);
        }
コード例 #3
0
        public void Process_FiltersItemsWithCaseInsensitiveComparison()
        {
            StringEndsWithFilter <GridModel>       filter     = new StringEndsWithFilter <GridModel>();
            Expression <Func <GridModel, String> > expression = (model) => model.Name;

            filter.FilteredExpression = expression;
            filter.Value = "Test";

            IQueryable <GridModel> models = new[]
            {
                new GridModel {
                    Name = null
                },
                new GridModel {
                    Name = "Tes"
                },
                new GridModel {
                    Name = "test"
                },
                new GridModel {
                    Name = "Test"
                },
                new GridModel {
                    Name = "TEST2"
                }
            }.AsQueryable();

            IQueryable expected = models.Where(model => model.Name != null && model.Name.ToUpper().EndsWith("TEST"));
            IQueryable actual   = filter.Process(models);

            CollectionAssert.AreEqual(expected, actual);
        }
コード例 #4
0
        public void Apply_FiltersItemsWithCaseInsensitiveComparison()
        {
            Expression<Func<GridModel, String>> expression = (model) => model.Name;
            StringEndsWithFilter filter = new StringEndsWithFilter();
            filter.Value = "Test";

            IQueryable<GridModel> items = new[]
            {
                new GridModel { Name = null },
                new GridModel { Name = "Tes" },
                new GridModel { Name = "test" },
                new GridModel { Name = "Test" },
                new GridModel { Name = "TEST2" }
            }.AsQueryable();

            IQueryable expected = items.Where(model => model.Name != null && model.Name.ToUpper().EndsWith("TEST"));
            IQueryable actual = Filter(items, filter.Apply(expression.Body), expression);

            Assert.Equal(expected, actual);
        }