示例#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);
        }
示例#2
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);
        }
示例#3
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();
        }