Ejemplo n.º 1
0
        public void OrderByTest()
        {
            var repo = ServiceProvider.GetService <FakeRepo>();

            SeedData();

            var filter = new OrderFilter()
            {
                OrderTypeId = 1
            };

            filter.SetOrderBy(x => x.UId); //ascending

            var orders = repo.Filter <Order>(filter);

            orders.Value.First().UserId.Should().Be(1);

            filter.SetOrderBy(x => x.UId, OrderByDirection.Descending); //descending

            orders = repo.Filter <Order>(filter);
            orders.Value.First().UserId.Should().Be(10);

            //default field will be Id since its called Id, but also has a key value
            filter = new OrderFilter()
            {
                OrderTypeId = 1
            };
            orders = repo.Filter <Order>(filter);
            orders.Value.First().Id.Should().Be(1);

            filter.OrderByDirection = OrderByDirection.Descending;
            orders = repo.Filter <Order>(filter);
            orders.Value.First().Id.Should().Be(28);
        }
Ejemplo n.º 2
0
        public void PagingTest()
        {
            var repo = ServiceProvider.GetService <FakeRepo>();

            SeedData();

            var filter = new OrderFilter()
            {
                OrderTypeId = 1, PageNumber = 1, PageSize = 5
            };

            //should be 5, count 25
            var orders = repo.Filter <Order>(filter);

            orders.RecordCount.Should().Be(25);
            orders.Value.Count().Should().Be(5);
            orders.Value.First().UserId.Should().Be(1);

            //advance the page and we should have same record count but starting on the 6th record
            filter.PageNumber = 2;
            filter.PageSize   = 5;
            orders            = repo.Filter <Order>(filter);
            orders.RecordCount.Should().Be(25);
            orders.Value.Count().Should().Be(5);
            orders.Value.First().Id.Should().Be(7);
        }
Ejemplo n.º 3
0
        public void FilterComposeTest()
        {
            var repo = ServiceProvider.GetService <FakeRepo>();

            SeedData();

            var filter1 = new OrderFilter()
            {
                OrderTypeId = 1, PageNumber = 1, PageSize = 1
            };
            var filter2 = new OrderFilter()
            {
                PName = "Shoes", PageNumber = 1, PageSize = 5
            };                                                           //paging should be ignored, we only allow the first filter to decide paging for now

            filter1.SetOrderBy(x => x.UId, OrderByDirection.Descending); //descending

            var orders       = repo.GetQueryable <Order>();
            var firstquery   = orders.Filter(filter1);
            var secondquery  = firstquery.Filter(filter2);
            var actualorders = secondquery.Resolve();

            actualorders.RecordCount.Should().Be(15); //15 pre-paged
            actualorders.Value.Count().Should().Be(1);
            actualorders.Value.First().UserId.Should().Be(10);
        }
Ejemplo n.º 4
0
        public void FilterComposeTestOrderBy()
        {
            var repo = ServiceProvider.GetService <FakeRepo>();
            //special data setup
            var context = ServiceProvider.GetService <TestDbContext>();

            context.Add(new Order()
            {
                Id = 1, UserId = 5, OrderTypeId = 1, ProductName = "B", Value = 100
            });
            context.Add(new Order()
            {
                Id = 2, UserId = 6, OrderTypeId = 1, ProductName = "B", Value = 100
            });
            context.Add(new Order()
            {
                Id = 3, UserId = 3, OrderTypeId = 1, ProductName = "C", Value = 100
            });
            context.Add(new Order()
            {
                Id = 4, UserId = 6, OrderTypeId = 1, ProductName = "A", Value = 100
            });
            context.Add(new Order()
            {
                Id = 5, UserId = 5, OrderTypeId = 1, ProductName = "A", Value = 100
            });
            context.Add(new Order()
            {
                Id = 6, UserId = 3, OrderTypeId = 1, ProductName = "A", Value = 100
            });
            context.SaveChanges();

            var filter1 = new OrderFilter()
            {
                Value = 100, OrderByPropertyName = "UId"
            };

            filter1.SetOrderBy(f => f.UId);

            var filter2 = new OrderFilter()
            {
                OrderByPropertyName = "PName"
            };                                                               //paging should be ignored, we only allow the first filter to decide paging for now

            var orders       = repo.GetQueryable <Order>();
            var firstquery   = orders.Filter(filter1);
            var secondquery  = firstquery.Filter(filter2);
            var actualorders = secondquery.Resolve();
        }
Ejemplo n.º 5
0
        public void NestedPropertyTest()
        {
            var repo = ServiceProvider.GetService <FakeRepo>();

            SeedData();

            var filter = new OrderFilter()
            {
                UId = 1, PName = "Shoes"
            };

            //should be 2
            var orders = repo.Filter <Order>(filter);

            orders.RecordCount.Should().Be(2);
        }
Ejemplo n.º 6
0
        public void FilterExtensionTest()
        {
            var repo = ServiceProvider.GetService <FakeRepo>();

            SeedData();

            var filter = new OrderFilter()
            {
                OrderTypeId = 1, UId = 1
            };

            //should be 3
            var orders = repo.Filter <Order>(filter);

            orders.RecordCount.Should().Be(3);
        }
Ejemplo n.º 7
0
        public void FuzzySearchTermTest()
        {
            var repo = ServiceProvider.GetService <FakeRepo>();
            //special data setup
            var context = ServiceProvider.GetService <TestDbContext>();

            context.Add(new Order()
            {
                Id = 1, UserId = 5, OrderTypeId = 1, ProductName = "new", Value = 100
            });
            context.Add(new Order()
            {
                Id = 2, UserId = 6, OrderTypeId = 1, ProductName = "kindaoldyeah", Value = 100
            });
            context.Add(new Order()
            {
                Id = 3, UserId = 3, OrderTypeId = 1, ProductName = "notold", Value = 100
            });
            context.Add(new Order()
            {
                Id = 4, UserId = 6, OrderTypeId = 1, ProductName = "oldandnew", Value = 100
            });
            context.Add(new Order()
            {
                Id = 5, UserId = 5, OrderTypeId = 1, ProductName = "win", Value = 100
            });
            context.Add(new Order()
            {
                Id = 6, UserId = 3, OrderTypeId = 1, ProductName = "cookie", Value = 100
            });
            context.SaveChanges();

            var filter1 = new OrderFilter()
            {
                FuzzyMatchTerm = "old"
            };


            var orders   = repo.GetQueryable <Order>();
            var filtered = orders.Filter(filter1).Resolve();

            filtered.Value.Count().Should().Be(3);
            filtered.Value.Count(x => x.ProductName == "kindaoldyeah").Should().Be(1);
            filtered.Value.Count(x => x.ProductName == "notold").Should().Be(1);
            filtered.Value.Count(x => x.ProductName == "oldandnew").Should().Be(1);
        }
Ejemplo n.º 8
0
        public void BitwiseAnd()
        {
            var repo = ServiceProvider.GetService <FakeRepo>();
            // special data setup
            var context = ServiceProvider.GetService <TestDbContext>();

            context.Add(new Order()
            {
                Id = 1, UserId = 1, EquipmentTypes = 12
            });
            context.Add(new Order()
            {
                Id = 2, UserId = 2, EquipmentTypes = 8
            });
            context.Add(new Order()
            {
                Id = 3, UserId = 3, EquipmentTypes = 15
            });
            context.Add(new Order()
            {
                Id = 4, UserId = 4, EquipmentTypes = 0
            });

            context.SaveChanges();

            var filter = new OrderFilter {
                EquipmentTypes = 8
            };
            var orders   = repo.GetQueryable <Order>();
            var filtered = orders.Filter(filter).Resolve();

            filtered.Value.Count().Should().Be(3);

            filter = new OrderFilter {
                EquipmentTypes = 3
            };
            orders   = repo.GetQueryable <Order>();
            filtered = orders.Filter(filter).Resolve();
            filtered.Value.Count().Should().Be(1);
        }