public async Task ExecuteNextAsync_WhenNoTimeout_ExecutesInnerQuery() { var monitor = Mock.Of <IHealthMonitor>(); var innerQuery = Mock.Of <IChangeFeedDocumentQuery <Document> >(); var lease = Mock.Of <ILease>(); var timeoutDecorator = new ChangeFeedQueryTimeoutDecorator(innerQuery, monitor, TimeSpan.FromMinutes(10), lease); var feedResponse = Mock.Of <IFeedResponse <Document> >(); Mock.Get(innerQuery) .Setup(q => q.ExecuteNextAsync <Document>(It.IsAny <CancellationToken>())) .ReturnsAsync(feedResponse); await timeoutDecorator.ExecuteNextAsync <Document>(CancellationToken.None); Mock.Get(innerQuery) .Verify(q => q.ExecuteNextAsync <Document>(It.IsAny <CancellationToken>()), Times.Once); }
public async Task ExecuteNextAsync_WhenTimeout_NotifiesHealthMonitorAndThrows() { var monitor = Mock.Of <IHealthMonitor>(); var innerQuery = Mock.Of <IChangeFeedDocumentQuery <Document> >(); var lease = Mock.Of <ILease>(); var timeoutDecorator = new ChangeFeedQueryTimeoutDecorator(innerQuery, monitor, TimeSpan.FromMilliseconds(1), lease); var feedResponse = Mock.Of <IFeedResponse <Document> >(); Mock.Get(innerQuery) .Setup(q => q.ExecuteNextAsync <Document>(It.IsAny <CancellationToken>())) .Returns(async() => { await Task.Delay(TimeSpan.FromDays(1)); return(feedResponse); }); await Assert.ThrowsAsync <TimeoutException>(() => timeoutDecorator.ExecuteNextAsync <Document>(CancellationToken.None)); Mock.Get(monitor) .Verify(m => m.InspectAsync(It.Is <HealthMonitoringRecord>(record => record.Operation == MonitoredOperation.ReadChangeFeed && record.Lease == lease)), Times.Once); }