コード例 #1
0
            public async Task ShouldBeTheSameWithEnumeratorMoveNextCurrent()
            {
                var records = RecordCreator.CreateRecords(2);
                var cursor  = new ListBasedRecordCursor(new[] { "key0" }, () => records);

                IRecord record;
                bool    hasNext;

                for (int i = 0; i < 2; i++)
                {
                    record = await cursor.PeekAsync();

                    record.Should().NotBeNull();
                    record[0].As <string>().Should().Be($"record{i}:key0");

                    hasNext = await cursor.FetchAsync();

                    hasNext.Should().BeTrue();

                    // peeked record = current
                    cursor.Current[0].As <string>().Should().Be($"record{i}:key0");
                }

                record = await cursor.PeekAsync();

                record.Should().BeNull();

                hasNext = await cursor.FetchAsync();

                hasNext.Should().BeFalse();
            }
コード例 #2
0
            public async Task ShouldReturnNullIfAtEnd()
            {
                var records = RecordCreator.CreateRecords(5);
                var cursor  = new ListBasedRecordCursor(new[] { "key0" }, () => records);

                // [0, 1, 2, 3]
                await cursor.FetchAsync();

                await cursor.FetchAsync();

                await cursor.FetchAsync();

                await cursor.FetchAsync();

                var record = await cursor.PeekAsync();

                record.Should().NotBeNull();
                record[0].As <string>().Should().Be("record4:key0");

                var moveNext = await cursor.FetchAsync();

                moveNext.Should().BeTrue();

                record.Should().NotBeNull();
                record[0].As <string>().Should().Be("record4:key0");

                record = await cursor.PeekAsync();

                record.Should().BeNull();
            }
コード例 #3
0
            public async Task ShouldReturnRecordsInOrder()
            {
                var records = RecordCreator.CreateRecords(5);
                var cursor  = new ListBasedRecordCursor(new[] { "key1" }, () => records);

                int i = 0;

                while (await cursor.FetchAsync())
                {
                    cursor.Current[0].As <string>().Should().Be($"record{i++}:key0");
                }

                i.Should().Be(5);
            }
コード例 #4
0
            public async Task ShouldReturnNextRecordWithoutMovingCurrentRecord()
            {
                var records = RecordCreator.CreateRecords(5);
                var cursor  = new ListBasedRecordCursor(new[] { "key1" }, () => records);

                var record = await cursor.PeekAsync();

                record.Should().NotBeNull();
                record[0].As <string>().Should().Be("record0:key0");

                // not moving further no matter how many times are called
                record = await cursor.PeekAsync();

                record.Should().NotBeNull();
                record[0].As <string>().Should().Be("record0:key0");
            }
コード例 #5
0
            public async Task ShouldReturnRecordsAddedLatter()
            {
                var keys    = RecordCreator.CreateKeys();
                var records = RecordCreator.CreateRecords(5, keys);
                var cursor  = new ListBasedRecordCursor(keys, () => records);

                // I add a new record after RecordSet is created
                var newRecord = new Record(keys, new object[] { "record5:key0" });

                records.Add(newRecord);

                int i = 0;

                while (await cursor.FetchAsync())
                {
                    cursor.Current[0].As <string>().Should().Be($"record{i++}:key0");
                }

                i.Should().Be(6);
            }