Exemplo n.º 1
0
        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();
        }
Exemplo n.º 2
0
        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));
        }
Exemplo n.º 3
0
        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);
        }
Exemplo n.º 4
0
        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);
        }
Exemplo n.º 5
0
        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);
        }
Exemplo n.º 6
0
        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);
        }
Exemplo n.º 7
0
        public void Should_Not_Be_Able_To_Set_Filter_With_Wrong_Name()
        {
            var filterContext = new ProductFilterContext(CreateTestProducts().AsQueryable());

            filterContext.TrySet(_notExistingFilterObject).Should().BeFalse();
        }
Exemplo n.º 8
0
        public void Should_Not_Be_Able_To_Set_Invalid_Filter()
        {
            var filterContext = new ProductFilterContext(CreateTestProducts().AsQueryable());

            filterContext.TrySet(_invalidFilterObject).Should().BeFalse();
        }