private async Task RunTest <T>(IEnumerable <IEnumerable <T> > testData) { var cursorMock = new AsyncCursorMock <T>(testData); using (IAsyncEnumerator <T> cursorEnumerator = new AsyncCursorEnumerator <T>(cursorMock)) { CollectionAssert.AreEqual( testData.SelectMany(b => b ?? Enumerable.Empty <T>()).ToArray(), await ReadToEnd(cursorEnumerator), TestResources.AsyncCursorEnumeratorInvalidData); } Assert.IsTrue(cursorMock.Disposed, TestResources.AsyncCursorNotDisposed); }
public void Current_should_return_expected_result_when_there_are_two_batches() { var cursor = Substitute.For<IAsyncCursor<BsonDocument>>(); var firstBatch = new[] { new BsonDocument("_id", 0), new BsonDocument("_id", 1) }; var secondBatch = new[] { new BsonDocument("_id", 2) }; cursor.MoveNext().Returns(true, true, false); cursor.Current.Returns(firstBatch, secondBatch); var subject = new AsyncCursorEnumerator<BsonDocument>(cursor, CancellationToken.None); subject.MoveNext(); subject.Current.Should().Be(new BsonDocument("_id", 0)); subject.MoveNext(); subject.Current.Should().Be(new BsonDocument("_id", 1)); subject.MoveNext(); subject.Current.Should().Be(new BsonDocument("_id", 2)); }
public void Current_should_return_expected_result_when_there_are_two_batches() { var mockCursor = new Mock<IAsyncCursor<BsonDocument>>(); var firstBatch = new[] { new BsonDocument("_id", 0), new BsonDocument("_id", 1) }; var secondBatch = new[] { new BsonDocument("_id", 2) }; mockCursor.SetupSequence(c => c.MoveNext(CancellationToken.None)).Returns(true).Returns(true).Returns(false); mockCursor.SetupSequence(c => c.Current).Returns(firstBatch).Returns(secondBatch); var subject = new AsyncCursorEnumerator<BsonDocument>(mockCursor.Object, CancellationToken.None); subject.MoveNext(); subject.Current.Should().Be(new BsonDocument("_id", 0)); subject.MoveNext(); subject.Current.Should().Be(new BsonDocument("_id", 1)); subject.MoveNext(); subject.Current.Should().Be(new BsonDocument("_id", 2)); }
public void Dispose_should_dispose_cursor() { var cursor = Substitute.For<IAsyncCursor<BsonDocument>>(); var subject = new AsyncCursorEnumerator<BsonDocument>(cursor, CancellationToken.None); subject.Dispose(); cursor.Received(1).Dispose(); }
public void Dispose_should_dispose_cursor() { var mockCursor = new Mock<IAsyncCursor<BsonDocument>>(); var subject = new AsyncCursorEnumerator<BsonDocument>(mockCursor.Object, CancellationToken.None); subject.Dispose(); mockCursor.Verify(c => c.Dispose(), Times.Once); }