public static void Main() { using (var dataContext = DataContext.CreateInMemory(Guid.NewGuid().ToString())) { dataContext.Migrate(); var service = new ProductService(dataContext); service.AddRange(CreateTestProducts()).Wait(); var filterContext = new ProductFilterContext(service.Entities); var duration = Benchmark.Measure(() => { filterContext.TrySet("Rating", 1, 7); filterContext.TrySet("Name", new[] { "Piza", "Chicken", "Chese", "Fish", "Tun" }); filterContext.TrySet("Sold", 600); PerformAnalysis(filterContext).Wait(); }); Console.WriteLine("Duration {0}", duration); dataContext.Delete(); } Console.ReadLine(); }
private static async Task PerformAnalysis(ProductFilterContext context) { var filterResults = context.ApplyFilters().Take(MAX_PRINTED_RESULTS); var evaluatedFilterResults = filterResults.ToList(); Console.WriteLine(JsonUtils.Convert(evaluatedFilterResults)); var domains = await context.Domains(); Console.WriteLine(JsonUtils.Convert(domains)); }
public async Task Should_Set_Filter_With_TrySet_JsonArray() { var filterContext = new ProductFilterContext(CreateTestProducts().AsQueryable()); filterContext.TrySet(_allArrayObject); var filterResults = filterContext.ApplyFilters(); filterResults.Should().NotContain(entity => entity.Rating < 1 || entity.Rating > 7); filterResults.Should().NotContain(entity => !_allowedNames.Contains(entity.Name)); filterResults.Should().NotContain(entity => entity.Sold <= 600); var domains = await filterContext.Domains(CalculationStrategy.WithoutSelectableValues); domains.Should().HaveCount(3); }
public async Task Should_Set_Filter_With_TrySet() { var filterContext = new ProductFilterContext(CreateTestProducts().AsQueryable()); filterContext.RatingFilter.Set(1, 7); filterContext.NameFilter.Set("Piza", "Chicken", "Chese", "Fish", "Tun"); filterContext.SoldFilter.Set(600); var filterResults = filterContext.ApplyFilters(); filterResults.Should().NotContain(entity => entity.Rating < 1 || entity.Rating > 7); filterResults.Should().NotContain(entity => !_allowedNames.Contains(entity.Name)); filterResults.Should().NotContain(entity => entity.Sold <= 600); var domains = await filterContext.Domains(CalculationStrategy.WithoutSelectableValues); domains.Should().HaveCount(3); }
public async Task Should_Set_Filter_With_Resolver_Instance() { var filterContext = new ProductFilterContext(CreateTestProducts().AsQueryable()); filterContext.TrySet("Rating", 1, 7); filterContext.TrySet("Name", _allowedNames); filterContext.TrySet("Sold", 600); var filterResults = filterContext.ApplyFilters(); filterResults.Should().NotContain(entity => entity.Rating < 1 || entity.Rating > 7); filterResults.Should().NotContain(entity => !_allowedNames.Contains(entity.Name)); filterResults.Should().NotContain(entity => entity.Sold <= 600); var domains = await filterContext.Domains(); domains.Should().HaveCount(3); }
public async Task Should_Set_Filter_With_TrySet_Json() { var filterContext = new ProductFilterContext(CreateTestProducts().AsQueryable()); filterContext.TrySet(_rangeObject); filterContext.TrySet(_listObject); filterContext.TrySet(_greaterThanObject); var filterResults = filterContext.ApplyFilters(); filterResults.Should().NotContain(entity => entity.Rating < 1 || entity.Rating > 7); filterResults.Should().NotContain(entity => !_allowedNames.Contains(entity.Name)); filterResults.Should().NotContain(entity => entity.Sold <= 600); var domains = await filterContext.Domains(); domains.Should().HaveCount(3); }
public void Should_Not_Be_Able_To_Set_Filter_With_Wrong_Name() { var filterContext = new ProductFilterContext(CreateTestProducts().AsQueryable()); filterContext.TrySet(_notExistingFilterObject).Should().BeFalse(); }
public void Should_Not_Be_Able_To_Set_Invalid_Filter() { var filterContext = new ProductFilterContext(CreateTestProducts().AsQueryable()); filterContext.TrySet(_invalidFilterObject).Should().BeFalse(); }