Ejemplo n.º 1
0
            public void ShouldBeTheSameWithEnumeratorMoveNextCurrent()
            {
                var records   = RecordCreator.CreateRecords(2);
                var recordSet = new ListBasedRecordSet(records);

                IRecord record;
                IEnumerator <IRecord> enumerator;

                for (int i = 0; i < 2; i++)
                {
                    record = recordSet.Peek();
                    record.Should().NotBeNull();
                    record[0].ValueAs <string>().Should().Be($"record{i}:key0");

                    enumerator = recordSet.Records().GetEnumerator();
                    enumerator.MoveNext().Should().BeTrue();

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

                record = recordSet.Peek();
                record.Should().BeNull();

                enumerator = recordSet.Records().GetEnumerator();
                enumerator.MoveNext().Should().BeFalse();
                enumerator.Current.Should().BeNull();
            }
            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();
            }
            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();
            }
            public static StatementResult CreateResult(int keySize, int recordSize = 1,
                Func<IResultSummary> getSummaryFunc = null)
            {
                var keys = RecordCreator.CreateKeys(keySize);
                var records = RecordCreator.CreateRecords(recordSize, keys);

                return new StatementResult(keys, new ListBasedRecordSet(records), getSummaryFunc);
            }
Ejemplo n.º 5
0
            public void EnumeratorResetShouldDoNothing()
            {
                var records   = RecordCreator.CreateRecords(5);
                var recordSet = new ListBasedRecordSet(records);

                var ex = Xunit.Record.Exception(() => recordSet.Records().GetEnumerator().Reset());

                ex.Should().BeOfType <NotSupportedException>();
            }
Ejemplo n.º 6
0
            public static StatementResultCursor CreateResultReader(int keySize, int recordSize = 1,
                                                                   Func <Task <IResultSummary> > getSummaryFunc = null)
            {
                var keys        = RecordCreator.CreateKeys(keySize);
                var records     = RecordCreator.CreateRecords(recordSize, keys);
                var recordsEnum = records.GetEnumerator();

                return(new StatementResultCursor(keys, () => NextRecordFromEnum(recordsEnum), getSummaryFunc));
            }
Ejemplo n.º 7
0
            public static InternalResult CreateResult(int keySize, int recordSize          = 1,
                                                      Func <IResultSummary> getSummaryFunc = null)
            {
                var keys    = RecordCreator.CreateKeys(keySize);
                var records = RecordCreator.CreateRecords(recordSize, keys);

                return(new InternalResult(new ListBasedRecordCursor(keys, () => records, getSummaryFunc),
                                          new BlockingExecutor()));
            }
            public static StatementResultCursor CreateResultReader(int keySize, int recordSize = 1,
                                                                   Func <Task <IResultSummary> > getSummaryFunc    = null,
                                                                   CancellationTokenSource cancellationTokenSource = null)
            {
                var keys        = RecordCreator.CreateKeys(keySize);
                var records     = RecordCreator.CreateRecords(recordSize, keys);
                var recordsEnum = records.GetEnumerator();

                return(new StatementResultCursor(() => Task.FromResult(keys.ToArray()),
                                                 () => NextRecordFromEnum(recordsEnum), getSummaryFunc, cancellationTokenSource));
            }
Ejemplo n.º 9
0
            public void ShouldReturnRecordsInOrder()
            {
                var records   = RecordCreator.CreateRecords(5);
                var recordSet = new ListBasedRecordSet(records);

                int i = 0;

                foreach (var record in recordSet.Records())
                {
                    record[0].ValueAs <string>().Should().Be($"record{i++}:key0");
                }
                i.Should().Be(5);
            }
Ejemplo n.º 10
0
            public void ShouldGetTheFirstRecordAndMoveToNextPosition()
            {
                var records      = RecordCreator.CreateRecords(5);
                var recordSet    = new ListBasedRecordSet(records);
                var recordStream = recordSet.Records();

                var record = recordStream.First();

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

                record = recordStream.First();
                record[0].ValueAs <string>().Should().Be("record1:key0");
            }
            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);
            }
Ejemplo n.º 12
0
            public void ShouldAlwaysAdvanceRecordPosition()
            {
                var recordSet    = new ListBasedRecordSet(RecordCreator.CreateRecords(5));
                var recordStream = recordSet.Records();

                var enumerable = recordStream.Take(1);
                var records    = recordStream.Take(2).ToList();

                records[0][0].ValueAs <string>().Should().Be("record0:key0");
                records[1][0].ValueAs <string>().Should().Be("record1:key0");

                records = enumerable.ToList();
                records[0][0].ValueAs <string>().Should().Be("record2:key0");
            }
Ejemplo n.º 13
0
            public void ShouldReturnNextRecordWithoutMovingCurrentRecord()
            {
                var records   = RecordCreator.CreateRecords(5);
                var recordSet = new ListBasedRecordSet(records);

                var record = recordSet.Peek();

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

                // not moving further no matter how many times are called
                record = recordSet.Peek();
                record.Should().NotBeNull();
                record[0].ValueAs <string>().Should().Be("record0:key0");
            }
            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");
            }
Ejemplo n.º 15
0
            public static StatementResultCursor CreateResultCursor(int keySize, int recordSize = 1,
                                                                   Func <Task <IResultSummary> > getSummaryFunc    = null,
                                                                   CancellationTokenSource cancellationTokenSource = null)
            {
                var keys        = RecordCreator.CreateKeys(keySize);
                var records     = RecordCreator.CreateRecords(recordSize, keys);
                var recordsEnum = records.GetEnumerator();

                var stream = new Mock <IResultStream>();

                stream.Setup(x => x.GetKeysAsync()).Returns(() => Task.FromResult(keys.ToArray()));
                stream.Setup(x => x.NextRecordAsync()).Returns(() => NextRecordFromEnum(recordsEnum));
                stream.Setup(x => x.SummaryAsync()).Returns(getSummaryFunc);
                stream.Setup(x => x.Cancel()).Callback(() => cancellationTokenSource?.Cancel());

                return(new StatementResultCursor(stream.Object));
            }
Ejemplo n.º 16
0
            public void ShouldReturnRecordsAddedLatter()
            {
                var keys      = RecordCreator.CreateKeys();
                var records   = RecordCreator.CreateRecords(5, keys);
                var recordSet = new ListBasedRecordSet(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;

                foreach (var record in recordSet.Records())
                {
                    record[0].ValueAs <string>().Should().Be($"record{i++}:key0");
                }
                i.Should().Be(6);
            }
            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);
            }
Ejemplo n.º 18
0
            public void ShouldReturnNullIfAtEnd()
            {
                var records   = RecordCreator.CreateRecords(5);
                var recordSet = new ListBasedRecordSet(records);

                recordSet.Records().Take(4).ToList(); // [0, 1, 2, 3]

                var record = recordSet.Peek();

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

                var moveNext = recordSet.Records().GetEnumerator().MoveNext();

                moveNext.Should().BeTrue();

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

                record = recordSet.Peek();
                record.Should().BeNull();
            }