public void ShouldBePageWithSortOrderByDescending()
        {
            var customers = new Faker <Customer>()
                            .CustomInstantiator(f => new Customer()
            {
                Id = f.Random.Int(0, 100)
            })
                            .Generate(100).AsQueryable();

            Expression <Func <Customer, object> > a = (c) => c.Id;
            var sort = new RSqlSort <Customer>()
            {
                Value = a, IsDescending = true
            };
            var pageable = new RSqlPageable <Customer>(2, 10, sort);

            var expected = QueryableExtensions.Page(customers, pageable);
            var first    = customers.OrderByDescending(c => c.Id).Skip(20).First();

            expected.Number
            .Should().Be(2);
            expected.HasPrevious
            .Should().BeTrue();
            expected.HasNext
            .Should().BeTrue();
            expected.TotalElements
            .Should().Be(customers.Count());
            expected.TotalPages
            .Should().Be(10);
            expected.Content.First()
            .Should().Be(first);
        }
Exemplo n.º 2
0
        public void ShouldBePageWithMultiSort()
        {
            var customerId    = 1;
            var customerFaker = new Faker <Customer>()
                                .CustomInstantiator(_ => new Customer {
                Id = customerId++
            })
                                .RuleFor(o => o.BirthDate, f => f.Date.Past(20))
                                .RuleFor(o => o.Company, f => f.Company.CompanyName())
                                .RuleFor(o => o.Email, f => f.Internet.Email())
                                .RuleFor(o => o.Name, f => f.Name.LastName())
                                .RuleFor(o => o.Phone, f => f.Phone.PhoneNumber())
                                .RuleFor(o => o.Username, f => f.Internet.UserNameUnicode())
                                .RuleFor(o => o.Website, f => f.Internet.Url());


            var parameter    = Expression.Parameter(typeof(Customer), "c");
            var nameProperty = Expression.Property(parameter, "Name");
            var expression   = Expression.Convert(nameProperty, typeof(object));
            var lambda       = Expression.Lambda <Func <Customer, object> >(expression, parameter);

            var sort = new RSqlSort <Customer>()
            {
                Value = lambda, IsDescending = true
            };

            nameProperty = Expression.Property(parameter, "BirthDate");
            expression   = Expression.Convert(nameProperty, typeof(object));
            lambda       = Expression.Lambda <Func <Customer, object> >(expression, parameter);
            sort         = new RSqlSort <Customer>()
            {
                Value = lambda, IsDescending = false, Next = sort
            };

            var obj      = customerFaker.Generate(100);
            var pageable = new RSqlPageable <Customer>(0, 100, sort);

            var expected = QueryableExtensions.Page(obj.AsQueryable(), pageable);
            var actual   = obj.AsQueryable().OrderBy(c => c.BirthDate).ThenByDescending(c => c.Name);

            expected.Content.First()
            .Should().Equals(actual.First());

            expected.Content.Last()
            .Should().Equals(actual.Last());
        }