public async Task Run_ShouldThrowSplit_IfPartitionSplitting() { Mock.Get(documentQuery) .SetupSequence(query => query.ExecuteNextAsync <Document>(It.Is <CancellationToken>(token => token == cancellationTokenSource.Token))) .Throws(DocumentExceptionHelpers.CreateException("Microsoft.Azure.Documents.GoneException", 1007)) .ReturnsAsync(feedResponse); await Assert.ThrowsAsync <PartitionSplitException>(() => partitionProcessor.RunAsync(cancellationTokenSource.Token)); }
public async Task Run_ShouldRethrowReadSessionNotAvailable() { Mock.Get(documentQuery) .SetupSequence(query => query.ExecuteNextAsync <Document>(It.Is <CancellationToken>(token => token == cancellationTokenSource.Token))) .Throws(DocumentExceptionHelpers.CreateException("Microsoft.Azure.Documents.NotFoundException", (int)SubStatusCode.ReadSessionNotAvailable)); Exception exception = await Record.ExceptionAsync(() => partitionProcessor.RunAsync(cancellationTokenSource.Token)); Assert.IsAssignableFrom <ReadSessionNotAvailableException>(exception); }
public async Task Run_ShouldReThrow_IfUnknownNotFoundSubcode() { Mock.Get(documentQuery) .SetupSequence(query => query.ExecuteNextAsync <Document>(It.Is <CancellationToken>(token => token == cancellationTokenSource.Token))) .Throws(DocumentExceptionHelpers.CreateException("Microsoft.Azure.Documents.NotFoundException", 1002)) .ReturnsAsync(feedResponse); Exception exception = await Record.ExceptionAsync(() => partitionProcessor.RunAsync(cancellationTokenSource.Token)); Assert.IsAssignableFrom <DocumentClientException>(exception); }
public async Task UpdateLeaseAsync_ShouldRethrow_WhenReplaceReturnsOtherError() { Exception exception = await TestReplaceException(DocumentExceptionHelpers.CreateException("Microsoft.Azure.Documents.GoneException", 1)); Assert.IsAssignableFrom <DocumentClientException>(exception); }
public async Task Run_ShouldDecreaseMaxItemCountWhenNeeded() { var documents2 = new List <Document> { new Document(), new Document() }; var feedResponse2 = Mock.Of <IFeedResponse <Document> >(); Mock.Get(feedResponse2) .Setup(response => response.Count) .Returns(documents2.Count); Mock.Get(feedResponse2) .Setup(response => response.ResponseContinuation) .Returns("token2"); Mock.Get(feedResponse2) .Setup(response => response.GetEnumerator()) .Returns(documents2.GetEnumerator()); var documents3 = new List <Document> { new Document(), new Document(), new Document() }; var feedResponse3 = Mock.Of <IFeedResponse <Document> >(); Mock.Get(feedResponse3) .Setup(response => response.Count) .Returns(documents3.Count); Mock.Get(feedResponse3) .Setup(response => response.ResponseContinuation) .Returns("token3"); Mock.Get(feedResponse3) .Setup(response => response.GetEnumerator()) .Returns(documents3.GetEnumerator()); Mock.Get(documentQuery) .Reset(); Mock.Get(documentQuery) .SetupSequence(query => query.ExecuteNextAsync <Document>(It.Is <CancellationToken>(token => token == cancellationTokenSource.Token))) .ReturnsAsync(feedResponse) // 1st call is OK. .Throws(DocumentExceptionHelpers.CreateException("Microsoft.Azure.Documents.BadRequestException", 1, "Reduce page size and try again.")) .Throws(DocumentExceptionHelpers.CreateException("Microsoft.Azure.Documents.BadRequestException", 1, "Reduce page size and try again.")) .ReturnsAsync(feedResponse2) // Call with maxItemCount = 1. .ReturnsAsync(feedResponse3); // After restoring query to take default item count. // (accumulator += context.FeedResponse.ResponseContinuation + ".") != null && string accumulator = string.Empty; int observerCallCount = 0; Mock.Get(observer) .Setup(feedObserver => feedObserver .ProcessChangesAsync(It.IsAny <IChangeFeedObserverContext>(), It.IsAny <IReadOnlyList <Document> >(), It.IsAny <CancellationToken>())) .Returns(Task.CompletedTask) .Callback <IChangeFeedObserverContext, IReadOnlyList <Document>, CancellationToken>((context, docs, token) => { accumulator += context.FeedResponse.ResponseContinuation + "."; if (++observerCallCount == 3) { cancellationTokenSource.Cancel(); } }); await Assert.ThrowsAsync <TaskCanceledException>(() => sut.RunAsync(cancellationTokenSource.Token)); Mock.Get(documentQuery) .Verify(query => query.ExecuteNextAsync <Document>(It.Is <CancellationToken>(token => token == cancellationTokenSource.Token)), Times.Exactly(5)); Mock.Get(observer) .Verify(feedObserver => feedObserver .ProcessChangesAsync( It.Is <ChangeFeedObserverContext>(context => context.PartitionKeyRangeId == processorSettings.PartitionKeyRangeId), It.Is <IReadOnlyList <Document> >( list => list.Count == 1 ? list.SequenceEqual(documents) : list.Count == 2 ? list.SequenceEqual(documents2) : list.SequenceEqual(documents3)), It.IsAny <CancellationToken>()), Times.Exactly(3)); Assert.Equal("token.token2.token3.", accumulator); }