我通过添加Request rate is large
变量修复了CosmosDB中的new ConnectionPolicy()
错误:
var client = new DocumentClient(new Uri(endpointUri), primaryKey, new ConnectionPolicy()
{
MaxConnectionLimit = 100,
ConnectionMode = ConnectionMode.Direct,
ConnectionProtocol = Protocol.Tcp,
RetryOptions = new RetryOptions() { MaxRetryAttemptsOnThrottledRequests = 3, MaxRetryWaitTimeInSeconds = 60 }
});
但是我想知道我们如何进行单元测试以确保它真正起作用?
我正在考虑模拟DocumentClient并进行繁重的设置。但是我不确定语法应该是什么样。
以下是快乐案例的样本单元测试代码:
var mockDocumentQuery = new Mock<IFakeDocumentQuery<BookModel>>();
mockDocumentQuery
.SetupSequence(_ => _.HasMoreResults)
.Returns(true)
.Returns(false);
mockDocumentQuery
.Setup(_ => _.ExecuteNextAsync<BookModel>(It.IsAny<CancellationToken>()))
.ReturnsAsync(response);
var provider = new Mock<IQueryProvider>();
provider
.Setup(_ => _.CreateQuery<BookModel>(It.IsAny<Expression>()))
.Returns(mockDocumentQuery.Object);
mockDocumentQuery.As<IQueryable<BookModel>>().Setup(x => x.Provider).Returns(provider.Object);
mockDocumentQuery.As<IQueryable<BookModel>>().Setup(x => x.Expression).Returns(dataSource.Expression);
mockDocumentQuery.As<IQueryable<BookModel>>().Setup(x => x.ElementType).Returns(dataSource.ElementType);
mockDocumentQuery.As<IQueryable<BookModel>>().Setup(x => x.GetEnumerator()).Returns(() => dataSource.GetEnumerator());
var client = new Mock<IDocumentClient>();
client.Setup(_ => _.CreateDocumentQuery<BookModel>(It.IsAny<Uri>(), It.IsAny<FeedOptions>()))
.Returns(mockDocumentQuery.Object);
在代码的最后一行中,如何设置繁重的DocumentClient?