public void ReturnValuesWithEmptyOptions() { var result = filterService.Filter(allItems, new FilterOptions()); Assert.IsTrue(allItems.Count() > 0); Assert.AreEqual(allItems.Count(), result.TotalItems); Assert.AreEqual(allItems.Count(), result.Items.Count()); }
public void ReturnValuesSorted() { var options = new FilterOptions { SortModel = new[] { new SortModel { ColId = "Name" } } }; var result = filterService.Filter(allItems, options); Assert.IsTrue(allItems.OrderBy(x => x.Name).First() == result.Items.First()); }
public void DateGreaterThanOrEqualAndNameContains() { var options = new FilterOptions { FilterModels = new Dictionary <string, FilterModel> { { "Creation", new FilterModel { FieldType = "date", Type = "greaterThanOrEqual", Filter = Constants.Today } }, { "Name", new FilterModel { FieldType = "text", Type = "contains", Filter = "if" } }, } }; var result = filterService.Filter(allItems, options); var expectedValues = allItems.Where(x => x.Creation >= Constants.Today && x.Name.Contains("if")); Assert.AreEqual(expectedValues.Count(), result.Items.Count()); Assert.IsFalse(result.Items.Any(x => x.Creation == Constants.LastYear)); Assert.IsFalse(result.Items.Any(x => x.Creation == Constants.Yesterday)); Assert.IsFalse(result.Items.Any(x => x.Creation == Constants.Today)); Assert.IsFalse(result.Items.Any(x => x.Creation == Constants.Tomorrow)); Assert.IsTrue(result.Items.Any(x => x.Name == "Different" && x.Creation == Constants.NextMonth)); Assert.IsTrue(result.Items.Any(x => x.Name == "Different2" && x.Creation == Constants.NextYear)); }
public void Equals() { var options = new FilterOptions { FilterModels = new Dictionary <string, FilterModel> { { "Amount", new FilterModel { FieldType = "number", Type = "equals", Filter = 3 } } } }; var result = filterService.Filter(allItems, options); var expectedValues = allItems.Where(x => x.Amount == 3); Assert.AreEqual(expectedValues.Count(), result.Items.Count()); Assert.IsFalse(result.Items.Any(x => x.Amount == -300)); Assert.IsFalse(result.Items.Any(x => x.Amount == 1)); Assert.IsFalse(result.Items.Any(x => x.Amount == 2)); Assert.IsTrue(result.Items.Any(x => x.Amount == 3)); Assert.IsFalse(result.Items.Any(x => x.Amount == 4)); Assert.IsFalse(result.Items.Any(x => x.Amount == 100)); }
public IEnumerable <City> FiltrData(FiltrData filtrData) { if (!_validator.IsValid(filtrData)) { throw new Exception("данные не валидны"); } IEnumerable <City> result = _service.Filter(filtrData); return(result); }
public void EqualsWithOptions() { var options = new FilterOptions { FilterModels = new Dictionary <string, FilterModel> { { "Name", new FilterModel { FieldType = "text", Type = "equals", Filter = new object[] { "Test1", "Test2" } } } } }; var result = filterService.Filter(allItems, options); var expectedValues = allItems.Where(x => x.Name == "Test1" || x.Name == "Test2"); Assert.AreEqual(expectedValues.Count(), result.Items.Count()); Assert.IsTrue(result.Items.Any(x => x.Name == "Test1")); Assert.IsTrue(result.Items.Any(x => x.Name == "Test2")); Assert.IsFalse(result.Items.Any(x => x.Name == "Test4")); }
protected override Task ExecuteAsync(CancellationToken stoppingToken) { var filters = new Filter[] { new DepartsBeforeCurrentTimeFilter(), new ArrivalDateBeforeDepartureDateFilter(), new OverTwoHoursOnTheGroundFilter(), }; var flights = _filterService.Filter(_flightBuilder.GetFlights(), filters); foreach (var item in flights) { _log.LogInformation(item.Description); } return(Task.CompletedTask); }
public async Task <IActionResult> Index(bool loadAll, int?subcatId, double?minPrice, double?maxPrice, int?page, string searchQuery, PriceSort priceSort) { var currentSubc = TempData["currentSubc"] as int?; if (!subcatId.HasValue && currentSubc.HasValue) { subcatId = currentSubc; } if (loadAll) { subcatId = null; } var vm = new IndexVM { Categories = await db.Categories .Include(c => c.SubCategories) .Select(i => i).ToListAsync(), Products = await filterService.Filter(new Models.Filters.IndexFilter { SubCategoryId = subcatId, MinPrice = minPrice, MaxPrice = maxPrice, Page = page, SearchQuery = searchQuery, PriceSort = priceSort }), PagesCount = filterService.PagesCount }; if (subcatId.HasValue) { TempData["currentSubc"] = subcatId; } return(View(vm)); }
public void ContainsCaseInsensitive() { filterService = new FilterService(TextSearchOption.ForceCaseInsensitive); var options = new FilterOptions { FilterModels = new Dictionary <string, FilterModel> { { "Name", new FilterModel { FieldType = "text", Type = "contains", Filter = "test" } } } }; var result = filterService.Filter(allItems, options); var expectedValues = allItems.Where(x => x.Name.ToLower().Contains("test")); Assert.AreEqual(expectedValues.Count(), result.Items.Count()); Assert.IsTrue(result.Items.Any(x => x.Name == "Test1")); Assert.IsTrue(result.Items.Any(x => x.Name == "Test2")); Assert.IsFalse(result.Items.Any(x => x.Name == "Different")); }
public void Equals() { var options = new FilterOptions { FilterModels = new Dictionary <string, FilterModel> { { "Creation", new FilterModel { FieldType = "date", Type = "equals", Filter = Constants.Today } } } }; var result = filterService.Filter(allItems, options); var expectedValues = allItems.Where(x => x.Creation == Constants.Today); Assert.AreEqual(expectedValues.Count(), result.Items.Count()); Assert.IsTrue(result.Items.Any(x => x.Creation == Constants.Today)); Assert.IsFalse(result.Items.Any(x => x.Creation == Constants.Yesterday)); Assert.IsFalse(result.Items.Any(x => x.Creation == Constants.Tomorrow)); Assert.IsFalse(result.Items.Any(x => x.Creation == Constants.LastYear)); Assert.IsFalse(result.Items.Any(x => x.Creation == Constants.NextYear)); }