public void SimpleWithExtensions()
        {
            MockContextFactory.SeedAndTestContextFor("FilterInterceptorTests_SimpleWithExtensions", TestSeeders.SimpleSeedScenario, ctx =>
            {
                var queryable = ctx.Orders.AsQueryable();

                var criteria = new QueryCriteria()
                {
                    Filters = new List <IFilter>
                    {
                        new SimpleFilter {
                            Path = "CustomerFirstName", Value = "David", Type = FilterType.Contains
                        }
                    }
                };

                var query = new QueryHandler();
                query.AddInterceptor(new MockFilterInterceptorAWithExtension());
                var result = query.Execute(queryable, criteria);

                var actual   = result.Data.Cast <Order>().ToList();
                var expected = queryable.Where(t => t.Customer.FirstName == "David").ToList();
                Assert.Equal(expected, actual);
            });
        }
        public void SimpleFilter()
        {
            MockContextFactory.SeedAndTestContextFor("AsyncTests_SimpleFilter", TestSeeders.SimpleSeedScenario, async ctx =>
            {
                var resultShouldMatch = ctx.Items.Where(t => t.Name.EndsWith("Cables")).ToList();

                var criteria = new QueryCriteria()
                {
                    Filters = new List <IFilter>
                    {
                        new SimpleFilter
                        {
                            Path  = "Name",
                            Type  = FilterType.EndsWith,
                            Value = "Cables"
                        }
                    }
                };

                var asyncService = new AsyncQueryableService(new[] { new AsyncQueryableHandlerService() });
                var queryHandler = new QueryHandlerAsync(asyncService);
                var result       = await queryHandler.ExecuteAsync(ctx.Items, criteria);
                Assert.Equal(resultShouldMatch, result.Data);
            });
        }
        public void Multi()
        {
            MockContextFactory.SeedAndTestContextFor("FilterInterceptorTests_Multi", TestSeeders.SimpleSeedScenario, ctx =>
            {
                var queryable = ctx.Orders.AsQueryable();

                var criteria = new QueryCriteria()
                {
                    Filters = new List <IFilter>
                    {
                        new SimpleFilter {
                            Path = "CustomerFirstName", Value = "David", Type = FilterType.Contains
                        }
                    }
                };

                var query = new QueryHandler(Enumerable.Empty <IQueryInterceptorProvider>());
                query.AddInterceptor(new MockFilterInterceptorA());
                query.AddInterceptor(new MockFilterInterceptorB());
                var result = query.Execute(queryable, criteria);

                var actual   = result.Data;
                var expected = queryable.Where(t => t.Customer.LastName == "Norris").ToList();
                Assert.Equal(expected, actual);
            });
        }
Exemplo n.º 4
0
        public void TestCollection()
        {
            var serviceProvider = DIService();

            MockContextFactory.SeedAndTestContextFor("CriteriaTests_TestPagging", TestSeeders.SimpleSeedScenario, ctx =>
            {
                // var resultShouldMatch =
                //     ctx.Customers.Include(c => c.Orders); //OrderBy(t => t.Id).Skip(5).Take(5).ToList();

                // query handler that is empty should be the same as running to list.
                var criteria = new QueryCriteria();
                criteria.Filters.AddRange(new List <IFilter>
                {
                    // new SimpleFilter
                    // {
                    //     Path = "RegisterTime",
                    //     Value = "2018-10-1",
                    //     Type = FilterType.GreaterThanOrEqual,
                    //     And = true
                    // },
                    // new SimpleFilter
                    // {
                    //     Path = "RegisterTime",
                    //     Value = "2018-12-1",
                    //     Type = FilterType.LessThanOrEqual,
                    //     And = true
                    // },

                    new CompositeFilter()
                    {
                        And     = true,
                        Type    = FilterType.Composite,
                        Filters = new List <IFilter>
                        {
                            new SimpleFilter
                            {
                                And   = true,
                                Path  = "Orders.Date",
                                Value = "2018-01-03",
                                Type  = FilterType.GreaterThanOrEqual
                            },
                            new SimpleFilter
                            {
                                And   = true,
                                Path  = "Orders.Date",
                                Value = "2018-01-04",
                                Type  = FilterType.LessThanOrEqual
                            }
                        }
                    }
                });
                criteria.Sorts.Add(new Sort("Id"));
                criteria.Page     = 1;
                criteria.PageSize = 15;

                var queryHandler = serviceProvider.GetService <IQueryHandler>();
                var result       = queryHandler.Execute(ctx.Customers.Include(c => c.Orders), criteria);
                var data         = result.Data.Cast <Customer>().ToList();
            });
        }
        public void Simple()
        {
            MockContextFactory.SeedAndTestContextFor("GroupInterceptorTests_Simple", TestSeeders.SimpleSeedScenario, ctx =>
            {
                var expected = ctx.Orders
                               .OrderBy(t => t.Customer.FirstName)
                               .GroupBy(t => t.Customer.FirstName)
                               .Select(t => t.Key)
                               .ToList();

                var criteria = new QueryCriteria();
                criteria.Groups.Add(new Group {
                    Path = "CustomerFirstName"
                });
                var queryHandler = new QueryHandler(Enumerable.Empty <IQueryInterceptorProvider>());
                queryHandler.AddInterceptor(new MockGroupInterceptor());
                var result = queryHandler.Execute(ctx.Orders.Include(t => t.Customer), criteria, new QueryExecutionOptions
                {
                    GroupByInMemory = true
                });

                var groupedResult = result.GroupedResult();
                var actual        = groupedResult.Groups.Select(t => t.GroupValue).ToList();
                Assert.Equal(expected, actual);
            });
        }
Exemplo n.º 6
0
        public void InterceptorsWithGrouping()
        {
            MockContextFactory.SeedAndTestContextFor("GroupTests_InterceptorsWithGrouping", TestSeeders.SeedTicketScenario, ctx =>
            {
                var criteria = new QueryCriteria()
                {
                    Groups = new List <IGroup>()
                    {
                        new Group {
                            Path = "TicketType"
                        }
                    },
                    Aggregates = new List <IAggregate>()
                    {
                        new Aggregate {
                            Type = AggregateType.Count
                        }
                    }
                };

                var interceptor  = new InterceptorsWithGrouping();
                var queryHandler = new QueryHandler(Enumerable.Empty <IQueryInterceptorProvider>());
                queryHandler.AddInterceptor(interceptor);
                var result = queryHandler.Execute <Ticket, InterceptorWithGroupingFakeModel>(ctx.Tickets, criteria, new QueryExecutionOptions
                {
                    GroupByInMemory = true
                });

                Assert.Equal(4, interceptor.Count);
                Assert.True(interceptor.Test);
                Assert.True(interceptor.Test2);
                Assert.True(interceptor.Test3);
                Assert.True(interceptor.Test4);
            });
        }
Exemplo n.º 7
0
        public void CompositeFilter()
        {
            MockContextFactory.SeedAndTestContextFor("FilterTests_CompositeFilter", TestSeeders.SimpleSeedScenario, ctx =>
            {
                var resultShouldMatch = ctx.Customers.Where(t => t.FirstName == "John" || t.LastName == "Norris").ToList();

                var criteria = new QueryCriteria()
                {
                    Filters = new List <IFilter>
                    {
                        new CompositeFilter()
                        {
                            Type    = FilterType.Composite,
                            Filters = new List <IFilter>
                            {
                                new SimpleFilter()
                                {
                                    Path = "FirstName", Type = FilterType.Equal, Value = "John"
                                },
                                new SimpleFilter()
                                {
                                    Path = "LastName", Type = FilterType.Equal, Value = "Norris"
                                }
                            }
                        }
                    }
                };

                var queryHandler = new QueryHandler(Enumerable.Empty <IQueryInterceptorProvider>());
                var result       = queryHandler.Execute(ctx.Customers, criteria);
                Assert.Equal(resultShouldMatch, result.Data);
            });
        }
Exemplo n.º 8
0
        public void SimpleFilterCaseInsensitive()
        {
            MockContextFactory.SeedAndTestContextFor("FilterTests_SimpleFilterCaseInsensitive", TestSeeders.SimpleSeedScenario, ctx =>
            {
                var resultShouldMatch = ctx.Items.Where(t => t.Name.ToLower().EndsWith("Cables".ToLower())).ToList();

                var criteria = new QueryCriteria()
                {
                    Filters = new List <IFilter>
                    {
                        new SimpleFilter
                        {
                            Path            = "Name",
                            Type            = FilterType.EndsWith,
                            Value           = "Cables",
                            CaseInsensitive = true
                        }
                    }
                };

                var queryHandler = new QueryHandler(Enumerable.Empty <IQueryInterceptorProvider>());
                var result       = queryHandler.Execute(ctx.Items, criteria);
                Assert.Equal(resultShouldMatch, result.Data);
            });
        }
 public void NonGeneric()
 {
     MockContextFactory.SeedAndTestContextFor("QueryConvertInterceptorTests_NonGeneric", TestSeeders.SimpleSeedScenario, ctx =>
     {
         var criteria     = new QueryCriteria();
         var queryHandler = new QueryHandler();
         queryHandler.AddInterceptor(new MockQueryConvertInterceptor());
         var result = queryHandler.Execute(ctx.Customers, criteria);
         Assert.All(result.Data.Cast <Customer>().ToList(), t => Assert.IsType <CustomerModel>(t));
     });
 }
 public void Generic()
 {
     MockContextFactory.SeedAndTestContextFor("ConvertibleIntereceptorTests_Generic", TestSeeders.SimpleSeedScenario, ctx =>
     {
         var criteria     = new QueryCriteria();
         var queryHandler = new QueryHandler();
         queryHandler.AddInterceptor(new MockQueryConvertGenericInterceptor());
         var result = queryHandler.Execute <Customer, CustomerModel>(ctx.Customers, criteria);
         Assert.All(result.Data, t => Assert.IsType <CustomerModel>(t));
     });
 }
Exemplo n.º 11
0
 public void Simple()
 {
     MockContextFactory.SeedAndTestContextFor("DbContextFactoryPrimaryKeyTests_Simple", TestSeeders.SimpleSeedScenario, ctx =>
     {
         var sw = new Stopwatch();
         sw.Start();
         var factory = new DbContextFactory(ctx);
         var keys    = factory.GetKeyProperties(typeof(Order));
         Assert.Single <PropertyInfo>(keys, t => t.Name == "Id");
         sw.Stop();
         output.WriteLine($"Stop Watch of success took: {sw.Elapsed}");
     });
 }
Exemplo n.º 12
0
        public void TestEmptyCriteria()
        {
            MockContextFactory.SeedAndTestContextFor("CriteriaTests_TestEmptyCriteria", TestSeeders.SimpleSeedScenario, ctx =>
            {
                var resultShouldMatch = ctx.Items.ToList();
                var queryable         = ctx.Items.AsQueryable();

                // query handler that is empty should be the same as running to list.
                var criteria     = new QueryCriteria();
                var queryHandler = new QueryHandler();
                var result       = queryHandler.Execute(queryable, criteria);
                Assert.Equal(resultShouldMatch, result.Data);
            });
        }
Exemplo n.º 13
0
        public void TestEmptyCriteria()
        {
            MockContextFactory.SeedAndTestContextFor("AsyncTests_TestEmptyCriteria", TestSeeders.SimpleSeedScenario, async ctx =>
            {
                var resultShouldMatch = ctx.Items.ToList();
                var queryable         = ctx.Items.AsQueryable();

                // query handler that is empty should be the same as running to list.
                var aqf          = new AsyncQueryableService(new[] { new AsyncQueryableHandlerService() });
                var criteria     = new QueryCriteria();
                var queryHandler = new QueryHandlerAsync(aqf);
                var result       = await queryHandler.ExecuteAsync(queryable, criteria);
                Assert.Equal(resultShouldMatch, result.Data);
            });
        }
 public void Simple()
 {
     MockContextFactory.SeedAndTestContextFor("QueryProviderTests_Simple", TestSeeders.SimpleSeedScenario, ctx =>
     {
         // criteria
         var criteria     = new QueryCriteria();
         var queryHandler = new QueryHandler(new List <IQueryInterceptorProvider> {
             new QueryInterceptorProvider()
         });
         queryHandler.AddInterceptor(new FakeInterceptor());
         var interceptors = queryHandler.ResolveInterceptors <Order, Order>(criteria, ctx.Orders);
         Assert.Equal(1, interceptors.Count);
         Assert.True(interceptors[0].GetType() == typeof(FakeInterceptor));
     });
 }
Exemplo n.º 15
0
        public void Simple()
        {
            MockContextFactory.SeedAndTestContextFor("GroupTests_Simple", TestSeeders.SimpleSeedScenario, ctx =>
            {
                var shouldResult = ctx.Orders
                                   .OrderBy(t => t.CustomerId)
                                   .ToList()
                                   .GroupBy(t => t.CustomerId)
                                   .Select(t => new
                {
                    CustomerId = t.Key,
                    Orders     = t.ToList()
                })
                                   .ToList();

                // query handler that is empty should be the same as running to list.
                var criteria = new QueryCriteria()
                {
                    Groups = new List <IGroup>
                    {
                        new Group {
                            Path = "CustomerId"
                        }
                    }
                };

                var queryHandler = new QueryHandler(Enumerable.Empty <IQueryInterceptorProvider>());
                var result       = queryHandler.Execute(ctx.Orders, criteria, new QueryExecutionOptions
                {
                    GroupByInMemory          = true,
                    GroupByInMemoryNullCheck = false
                });
                var groupedResult = result.GroupedResult();

                // top level should have same amount of group levels.
                Assert.Equal(groupedResult.Groups.Count, shouldResult.Count);
                for (var i = 0; i < shouldResult.Count; i++)
                {
                    var expected = shouldResult[0];
                    var actual   = groupedResult.Groups[0];
                    Assert.Equal(expected.CustomerId, actual.GroupValue);

                    var expectedOrderIds = expected.Orders.Select(t => t.Id).ToList();
                    var actualOrderIds   = actual.Data.Cast <Order>().Select(t => t.Id).ToList();
                    Assert.Equal(expectedOrderIds, actualOrderIds);
                }
            });
        }
Exemplo n.º 16
0
        public void Simple()
        {
            MockContextFactory.SeedAndTestContextFor("SortInterceptorTests_Simple", TestSeeders.SimpleSeedScenario, ctx =>
            {
                // expected
                var expected = ctx.Orders.OrderBy(t => t.Customer.FirstName).ThenBy(t => t.Customer.LastName).ToList();

                // criteria
                var criteria = new QueryCriteria();
                criteria.Sorts.Add(new Sort("CustomerFullName"));
                var queryHandler = new QueryHandler();
                queryHandler.AddInterceptor(new MockSortInterceptor());
                var result = queryHandler.Execute(ctx.Orders, criteria);
                Assert.Equal(expected, result.Data.Cast <Order>().ToList());
            });
        }
Exemplo n.º 17
0
        public void TestTimeSpanFilter()
        {
            var serviceProvider = DIService();

            MockContextFactory.SeedAndTestContextFor("CriteriaTests_TestPagging", TestSeeders.SimpleSeedScenario, ctx =>
            {
                // var resultShouldMatch =
                //     ctx.Customers.Include(c => c.Orders); //OrderBy(t => t.Id).Skip(5).Take(5).ToList();

                // query handler that is empty should be the same as running to list.
                var criteria = new QueryCriteria();
                criteria.Filters.AddRange(new List <IFilter>
                {
                    new CompositeFilter()
                    {
                        And     = true,
                        Type    = FilterType.Composite,
                        Filters = new List <IFilter>
                        {
                            new SimpleFilter
                            {
                                And   = true,
                                Path  = "birthTime",
                                Value = "12:00",
                                Type  = FilterType.GreaterThanOrEqual
                            },
                            new SimpleFilter
                            {
                                And   = true,
                                Path  = "birthTime",
                                Value = "13:00",
                                Type  = FilterType.LessThanOrEqual
                            }
                        }
                    }
                });
                criteria.Sorts.Add(new Sort("Id"));
                criteria.Page     = 1;
                criteria.PageSize = 15;

                var queryHandler = serviceProvider.GetService <IQueryHandler>();
                var result       = queryHandler.Execute(ctx.Customers.Include(c => c.Orders), criteria);
                var data         = result.Data.Cast <Customer>().ToList();
                Assert.DoesNotContain(data,
                                      c => c.BirthTime <TimeSpan.Parse("12:00") || c.BirthTime> TimeSpan.Parse("13:00"));
            });
        }
Exemplo n.º 18
0
        public void TestPaging()
        {
            MockContextFactory.SeedAndTestContextFor("CriteriaTests_TestPagging", TestSeeders.SimpleSeedScenario, ctx =>
            {
                var resultShouldMatch = ctx.OrderItems.OrderBy(t => t.Id).Skip(5).Take(5).ToList();

                // query handler that is empty should be the same as running to list.
                var criteria = new QueryCriteria();
                criteria.Sorts.Add(new Sort("Id"));
                criteria.Page     = 2;
                criteria.PageSize = 5;

                var queryHandler = new QueryHandler();
                var result       = queryHandler.Execute(ctx.OrderItems, criteria);
                Assert.Equal(resultShouldMatch, result.Data);
            });
        }
Exemplo n.º 19
0
        public void TestPaging()
        {
            MockContextFactory.SeedAndTestContextFor("AsyncTests_TestPagging", TestSeeders.SimpleSeedScenario, async ctx =>
            {
                var resultShouldMatch = ctx.OrderItems.OrderBy(t => t.Id).Skip(5).Take(5).ToList();

                // query handler that is empty should be the same as running to list.
                var criteria = new QueryCriteria();
                criteria.Sorts.Add(new Sort("Id"));
                criteria.Page     = 2;
                criteria.PageSize = 5;

                var asyncService = new AsyncQueryableService(new[] { new AsyncQueryableHandlerService() });
                var queryHandler = new QueryHandlerAsync(asyncService);
                var result       = await queryHandler.ExecuteAsync(ctx.OrderItems, criteria);
                Assert.Equal(resultShouldMatch, result.Data.Cast <OrderItem>().ToList());
            });
        }
Exemplo n.º 20
0
        public void TestInversionOfControl()
        {
            MockContextFactory.SeedAndTestContextFor("FilterTests_TestInversionOfControl", TestSeeders.SimpleSeedScenario, ctx =>
            {
                var resultShouldMatch = ctx.Customers.Where(t => t.FirstName == "Chuck").ToList();

                var criteria = new QueryCriteria()
                {
                    Filters = new List <IFilter> {
                        new MockIsChuckFilter()
                    }
                };

                var queryHandler = new QueryHandler(Enumerable.Empty <IQueryInterceptorProvider>());
                var result       = queryHandler.Execute(ctx.Customers, criteria);
                Assert.Equal(resultShouldMatch, result.Data);
            });
        }
Exemplo n.º 21
0
        public void Simple()
        {
            MockContextFactory.SeedAndTestContextFor("SortTests_Simple", TestSeeders.SimpleSeedScenario, ctx =>
            {
                var shouldResult = ctx.Orders.OrderBy(t => t.OrderNum).ToList();

                // query handler that is empty should be the same as running to list.
                var criteria = new QueryCriteria()
                {
                    Sorts = new List <ISort>()
                    {
                        new Sort("OrderNum")
                    }
                };

                var queryHandler = new QueryHandler();
                var result       = queryHandler.Execute(ctx.Orders, criteria);
                Assert.Equal(shouldResult, result.Data.Cast <Order>().ToList());
            });
        }
Exemplo n.º 22
0
        public void GroupComplex()
        {
            MockContextFactory.SeedAndTestContextFor("GroupTests_Complex", TestSeeders.SeedTicketScenario, ctx =>
            {
                var criteria = new QueryCriteria()
                {
                    Groups = new List <IGroup>()
                    {
                        new Group {
                            Path = "TicketType"
                        },
                        new Group {
                            Path = "Priority"
                        }
                    },
                    Aggregates = new List <IAggregate>()
                    {
                        new Aggregate {
                            Type = AggregateType.Count
                        }
                    }
                };

                var queryHandler = new QueryHandler(Enumerable.Empty <IQueryInterceptorProvider>());
                var result       = queryHandler.Execute(ctx.Tickets, criteria, new QueryExecutionOptions
                {
                    GroupByInMemory = true
                });

                var groupedResult = result.GroupedResult();

                var firstGroup = groupedResult.Groups.FirstOrDefault();
                Assert.NotNull(firstGroup);
                var secondGroup = groupedResult.Groups.Skip(1).FirstOrDefault();
                Assert.NotNull(secondGroup);

                var expected = ctx.Tickets.Select(t => t.TicketType).Distinct().Count();
                var c        = groupedResult.Groups.Select(t => t.GroupValue).Count();
                Assert.Equal(expected, c);
            });
        }
Exemplo n.º 23
0
        public void MultiSort()
        {
            MockContextFactory.SeedAndTestContextFor("SortTests_MultiSort", TestSeeders.SimpleSeedScenario, ctx =>
            {
                var shouldResult = ctx.Orders.OrderBy(t => t.Customer.FirstName).ThenBy(t => t.OrderNum).ToList();

                // query handler that is empty should be the same as running to list.
                var criteria = new QueryCriteria()
                {
                    Sorts = new List <ISort>()
                    {
                        new Sort("Customer.FirstName"),
                        new Sort("OrderNum")
                    }
                };

                var queryHandler = new QueryHandler(Enumerable.Empty <IQueryInterceptorProvider>());
                var result       = queryHandler.Execute(ctx.Orders, criteria);
                Assert.Equal(shouldResult, result.Data);
            });
        }
Exemplo n.º 24
0
        public void Simple()
        {
            MockContextFactory.SeedAndTestContextFor("AggregatorInterceptorTests_Simple", TestSeeders.SimpleSeedScenario, ctx =>
            {
                var expected = ctx.OrderItems.GroupBy(t => true).Select(t => new
                {
                    PriceAtTheTime = t.Average(t2 => t2.Item.Price)
                }).First();

                var criteria = new QueryCriteria();
                criteria.Aggregates.Add(new Aggregate
                {
                    Type = AggregateType.Avg,
                    Path = "ItemPrice"
                });
                var queryHandler = new QueryHandler();
                queryHandler.AddInterceptor(new MockAggregateInterceptor());
                var result = queryHandler.Execute(ctx.OrderItems, criteria);
                Assert.Equal(expected.PriceAtTheTime, result.Aggregates.First().Value);
            });
        }
Exemplo n.º 25
0
        public void SortInterceptor()
        {
            MockContextFactory.SeedAndTestContextFor("SortTests_SortInterceptor", TestSeeders.SimpleSeedScenario, ctx =>
            {
                var shouldResult = ctx.Orders.OrderByDescending(t => t.OrderNum).ToList();

                // query handler that is empty should be the same as running to list.
                var criteria = new QueryCriteria()
                {
                    Sorts = new List <ISort>()
                    {
                        new Sort("OrderNumStr", false)
                    }
                };

                var queryHandler = new QueryHandler(Enumerable.Empty <IQueryInterceptorProvider>());
                queryHandler.AddInterceptor(new MockSortInterceptor());
                var result = queryHandler.Execute(ctx.Orders, criteria);
                Assert.Equal(shouldResult, result.Data);
            });
        }
        public void Simple()
        {
            MockContextFactory.SeedAndTestContextFor("GroupInterceptorTests_Simple", TestSeeders.SimpleSeedScenario, ctx =>
            {
                var expected = ctx.Orders
                               .OrderBy(t => t.Customer.FirstName)
                               .GroupBy(t => t.Customer.FirstName)
                               .Select(t => t.Key)
                               .ToList();

                var criteria = new QueryCriteria();
                criteria.Groups.Add(new Group {
                    Path = "CustomerFirstName"
                });
                var queryHandler = new QueryHandler();
                queryHandler.AddInterceptor(new MockGroupInterceptor());
                var result = queryHandler.Execute(ctx.Orders, criteria);
                var actual = result.Data.Cast <IGroupQueryResult>().Select(t => t.GroupValue).ToList();
                Assert.Equal(expected, actual);
            });
        }
Exemplo n.º 27
0
        public void MoreComplexCompositeFilter()
        {
            MockContextFactory.SeedAndTestContextFor("FilterTests_MoreComplexCompositeFilter", TestSeeders.SimpleSeedScenario, ctx =>
            {
                var resultShouldMatch = ctx.Customers.Where(t => (t.FirstName == "John" || t.LastName == "Norris") && t.FirstName.Contains("o")).ToList();

                var criteria = new QueryCriteria()
                {
                    Filters = new List <IFilter>
                    {
                        new CompositeFilter()
                        {
                            Type    = FilterType.Composite,
                            Filters = new List <IFilter>
                            {
                                new SimpleFilter()
                                {
                                    Path = "FirstName", Type = FilterType.Equal, Value = "John"
                                },
                                new SimpleFilter()
                                {
                                    Path = "LastName", Type = FilterType.Equal, Value = "Norris"
                                }
                            }
                        },
                        new SimpleFilter()
                        {
                            And   = true,
                            Path  = "FirstName",
                            Type  = FilterType.Contains,
                            Value = "o"
                        }
                    }
                };

                var queryHandler = new QueryHandler();
                var result       = queryHandler.Execute(ctx.Customers, criteria);
                Assert.Equal(resultShouldMatch, result.Data.Cast <Customer>().ToList());
            });
        }
Exemplo n.º 28
0
        public void TestDI()
        {
            var serviceCollection = new ServiceCollection();

            serviceCollection.AddPoweredSoftDynamicQuery();
            var serviceProvider = serviceCollection.BuildServiceProvider();

            MockContextFactory.SeedAndTestContextFor("CriteriaTests_TestPagging", TestSeeders.SimpleSeedScenario, ctx =>
            {
                var resultShouldMatch = ctx.OrderItems.OrderBy(t => t.Id).Skip(5).Take(5).ToList();

                // query handler that is empty should be the same as running to list.
                var criteria = new QueryCriteria();
                criteria.Sorts.Add(new Sort("Id"));
                criteria.Page     = 2;
                criteria.PageSize = 5;
                var queryHandler  = serviceProvider.GetService(typeof(IQueryHandler)) as IQueryHandler;
                var result        = queryHandler.Execute(ctx.OrderItems, criteria);
                var data          = result.Data.Cast <OrderItem>().ToList();
                Assert.Equal(resultShouldMatch, data);
            });
        }
Exemplo n.º 29
0
        public void Simple()
        {
            MockContextFactory.SeedAndTestContextFor("GroupTests_Simple", TestSeeders.SimpleSeedScenario, ctx =>
            {
                var shouldResult = ctx.Orders.OrderBy(t => t.Customer).GroupBy(t => t.Customer).Select(t => new
                {
                    Customer = t.Key,
                    Orders   = t.ToList()
                }).ToList();

                // query handler that is empty should be the same as running to list.
                var criteria = new QueryCriteria()
                {
                    Groups = new List <IGroup>
                    {
                        new Group {
                            Path = "Customer"
                        }
                    }
                };

                var queryHandler = new QueryHandler();
                var result       = queryHandler.Execute(ctx.Orders, criteria);

                var data = result.Data.Cast <Order>().ToList();
                // top level should have same amount of group levels.
                Assert.Equal(data.Count, shouldResult.Count);
                for (var i = 0; i < shouldResult.Count; i++)
                {
                    var expected = shouldResult[0];
                    var actual   = ((IGroupQueryResult)result.Data[0]);
                    Assert.Equal(expected.Customer.Id, (actual.GroupValue as Customer).Id);

                    var expectedOrderIds = expected.Orders.Select(t => t.Id).ToList();
                    var actualOrderIds   = actual.Data.Cast <Order>().Select(t => t.Id).ToList();
                    Assert.Equal(expectedOrderIds, actualOrderIds);
                }
            });
        }
Exemplo n.º 30
0
        public void Generic()
        {
            MockContextFactory.SeedAndTestContextFor("BeforeFilterTests_Generic", TestSeeders.SimpleSeedScenario, ctx =>
            {
                var criteria    = new QueryCriteria();
                var interceptor = new MockBeforeQueryFilterGenericInterceptor();

                // queryable of orders.
                var queryable = ctx.Orders.AsQueryable();

                // pass into the interceptor.
                queryable = interceptor.InterceptBeforeFiltering(criteria, queryable);

                // query handler should pass by the same interceptor.
                var queryHandler = new QueryHandler(Enumerable.Empty <IQueryInterceptorProvider>());
                queryHandler.AddInterceptor(interceptor);
                var result = queryHandler.Execute(ctx.Orders, criteria);

                // compare results.
                var expected = queryable.ToList();
                Assert.Equal(expected, result.Data);
            });
        }