public async Task <List <Movie> > FilterFieldMapper(List <Movie> movies, List <Filter> filters) { List <Movie> movieFilered = movies; foreach (var filter in filters) { string queryBuilded = this.FilterMapper(filter.FilterField, filter.FilterOperator, filter.FilterValue); var expression = await MovieFilterHelper.ConvertStringToPredicate(queryBuilded); movieFilered = movieFilered.Where(expression).ToList(); } return(Task.Run(() => movieFilered).Result); }
public async void Should_Convert_String_To_Lambda_Predicate_With_Contains_Method() { var filter = "movie => movie.Title.Contains(\"Tes\")"; List <Movie> moviesMock = new List <Movie>(); moviesMock.Add(new Movie(1, "", "Lorem Ipsum", 2021, "", new string[] { "", "" }, "", "", "", "", "", 20, 0.0)); moviesMock.Add(new Movie(1, "", "Test", 2000, "", new string[] { "", "" }, "", "", "", "", "", 20, 0.0)); Func <Movie, bool> movieFiltered = await Task.Run(() => { return(MovieFilterHelper.ConvertStringToPredicate(filter)); }); List <Movie> moviesResult = moviesMock.Where(movieFiltered).ToList(); Assert.Equal(moviesResult.Count, 1); Assert.Equal(moviesResult.First().Title, "Test"); }