예제 #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].As <string>().Should().Be($"record{i}:key0");

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

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

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

                enumerator = recordSet.Records().GetEnumerator();
                enumerator.MoveNext().Should().BeFalse();
                enumerator.Current.Should().BeNull();
            }
예제 #2
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>();
            }
예제 #3
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].As <string>().Should().Be($"record{i++}:key0");
                }
                i.Should().Be(5);
            }
예제 #4
0
            public void ShouldGetTheFirstRecordAndMoveToNextPosition()
            {
                var records      = RecordCreator.CreateRecords(5);
                var recordSet    = new ListBasedRecordSet(records);
                var recordStream = recordSet.Records();

                var record = recordStream.First();

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

                record = recordStream.First();
                record[0].As <string>().Should().Be("record1:key0");
            }
예제 #5
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].As <string>().Should().Be("record0:key0");
                records[1][0].As <string>().Should().Be("record1:key0");

                records = enumerable.ToList();
                records[0][0].As <string>().Should().Be("record2:key0");
            }
예제 #6
0
            public void ShouldReturnNextRecordWithoutMovingCurrentRecord()
            {
                var records   = RecordCreator.CreateRecords(5);
                var recordSet = new ListBasedRecordSet(records);

                var record = recordSet.Peek();

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

                // not moving further no matter how many times are called
                record = recordSet.Peek();
                record.Should().NotBeNull();
                record[0].As <string>().Should().Be("record0:key0");
            }
예제 #7
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.ToArray(), new object[] { "record5:key0" });

                records.Add(newRecord);

                int i = 0;

                foreach (var record in recordSet.Records())
                {
                    record[0].As <string>().Should().Be($"record{i++}:key0");
                }
                i.Should().Be(6);
            }
예제 #8
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].As <string>().Should().Be("record4:key0");

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

                moveNext.Should().BeTrue();

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

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