Example #1
0
        public async Task WhenPaginatedQueryExecutesWithSkipTake_ThenPaginatedResultsAreReturnedCorrectly()
        {
            var cats = new List <Cat>();

            for (var i = 0; i < 15; i++)
            {
                var cat = new Cat {
                    Name = $"Cat {i}"
                };
                var created = await _cosmonautClient.CreateDocumentAsync(_databaseId, _collectionName, cat);

                cats.Add(created.Entity);
            }
            cats = cats.OrderBy(x => x.Name).ToList();

            var firstPage = await _cosmonautClient.Query <Cat>(_databaseId, _collectionName).Where(x => x.Name.StartsWith("Cat")).WithPagination(1, 5).OrderBy(x => x.Name).ToListAsync();

            var secondPage = await _cosmonautClient.Query <Cat>(_databaseId, _collectionName).Where(x => x.Name.StartsWith("Cat")).WithPagination(2, 5).OrderBy(x => x.Name).ToListAsync();

            var thirdPage = await _cosmonautClient.Query <Cat>(_databaseId, _collectionName).Where(x => x.Name.StartsWith("Cat")).WithPagination(3, 5).OrderBy(x => x.Name).ToListAsync();

            var fourthPage = await _cosmonautClient.Query <Cat>(_databaseId, _collectionName).Where(x => x.Name.StartsWith("Cat")).WithPagination(4, 5).OrderBy(x => x.Name).ToListAsync();


            firstPage.Should().BeInAscendingOrder(x => x.Name).And.BeEquivalentTo(cats.Take(5), ExcludeEtagCheck());
            secondPage.Should().BeInAscendingOrder(x => x.Name).And.BeEquivalentTo(cats.Skip(5).Take(5), ExcludeEtagCheck());
            thirdPage.Should().BeInAscendingOrder(x => x.Name).And.BeEquivalentTo(cats.Skip(10).Take(5), ExcludeEtagCheck());
            fourthPage.Should().BeEmpty();
        }