예제 #1
0
        public void Skip_and_take_paging_on_query_returns_all_expected_entities()
        {
            var expectedList = new List <TestEntity1>();

            for (var i = 0; i < LargeListSize; i = i + 2)
            {
                var matchEntity    = new TestEntity1($"id{i}", "match");
                var expectedEntity = new TestEntity1($"id{i}", "match");
                var nomatchEntity  = new TestEntity1($"id{i + 1}", "no match");
                Writer.Add(matchEntity.Identifier, matchEntity);
                Writer.Add(nomatchEntity.Identifier, nomatchEntity);
                expectedList.Add(expectedEntity);
            }

            List <TestEntity1> resultChunk;
            var allResults    = new List <TestEntity1>();
            var resultsToSkip = 0;

            do
            {
                resultChunk =
                    Reader.Query <TestEntity1>()
                    .Where(e => e.Field1 == "match")
                    .Skip(resultsToSkip)
                    .Take(10)
                    .ToList();
                resultsToSkip += resultChunk.Count;
                allResults.AddRange(resultChunk);
            }while (resultChunk.Count > 0);

            foreach (var entity in expectedList)
            {
                Assert.Contains(entity, allResults);
            }

            Assert.AreEqual(expectedList.Count, allResults.Count);
        }