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); }
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); }
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); }
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); }