public async void ShouldWaitForAllRecordsToArrive() { var recordYielder = new TestRecordYielder(5, 10, _output); var recordYielderEnum = recordYielder.Records.GetEnumerator(); var stream = new Mock <IResultStream>(); stream.Setup(x => x.NextRecordAsync()).Returns(() => NextRecordFromEnum(recordYielderEnum)); stream.Setup(x => x.GetKeysAsync()).Returns(() => Task.FromResult(TestRecordYielder.Keys.ToArray())); int count = 0; var cursor = new StatementResultCursor(stream.Object); var t = Task.Factory.StartNew(async() => { // ReSharper disable once LoopCanBeConvertedToQuery while (await cursor.FetchAsync()) { count++; } count.Should().Be(10); }); while (count < 5) { Thread.Sleep(10); } recordYielder.AddNew(5); await t; }
public void ShouldWaitForAllRecordsToArrive() { var recordYielder = new TestRecordYielder(5, 10, _output); int count = 0; var cursor = new InternalResult( new ListBasedRecordCursor(TestRecordYielder.Keys, () => recordYielder.Records), new BlockingExecutor()); var t = Task.Factory.StartNew(() => { // ReSharper disable once LoopCanBeConvertedToQuery foreach (var item in cursor) { count++; } count.Should().Be(10); }); while (count < 5) { Thread.Sleep(10); } recordYielder.AddNew(5); t.Wait(); }