title: CosmosDB Error 429 Unit Tests: Request Rate is Large
body: <p>I fixed the error of <code>Request rate is large</code> from CosmosDB by adding the <code>new ConnectionPolicy()</code> variable:</p>
  
  <pre><code>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 }
                      });
  </code></pre>
  
  <p>But I was wondering how can we do unit test to make sure it is actually working?</p>
  
  <p><strong>I am thinking of mocking the DocumentClient and set it up with heavy load. But I am not sure what the syntax should be like..</strong> </p>
  
  <p>Here are the sample unit test code for the happy case:</p>
  
  <pre><code> var mockDocumentQuery = new Mock&lt;IFakeDocumentQuery&lt;BookModel&gt;&gt;();
  
              mockDocumentQuery
                  .SetupSequence(_ =&gt; _.HasMoreResults)
                  .Returns(true)
                  .Returns(false);
  
              mockDocumentQuery
                  .Setup(_ =&gt; _.ExecuteNextAsync&lt;BookModel&gt;(It.IsAny&lt;CancellationToken&gt;()))
                  .ReturnsAsync(response);
  
              var provider = new Mock&lt;IQueryProvider&gt;();
              provider
                  .Setup(_ =&gt; _.CreateQuery&lt;BookModel&gt;(It.IsAny&lt;Expression&gt;()))
                  .Returns(mockDocumentQuery.Object);
  
              mockDocumentQuery.As&lt;IQueryable&lt;BookModel&gt;&gt;().Setup(x =&gt; x.Provider).Returns(provider.Object);
              mockDocumentQuery.As&lt;IQueryable&lt;BookModel&gt;&gt;().Setup(x =&gt; x.Expression).Returns(dataSource.Expression);
              mockDocumentQuery.As&lt;IQueryable&lt;BookModel&gt;&gt;().Setup(x =&gt; x.ElementType).Returns(dataSource.ElementType);
              mockDocumentQuery.As&lt;IQueryable&lt;BookModel&gt;&gt;().Setup(x =&gt; x.GetEnumerator()).Returns(() =&gt; dataSource.GetEnumerator());
  
              var client = new Mock&lt;IDocumentClient&gt;();
  
              client.Setup(_ =&gt; _.CreateDocumentQuery&lt;BookModel&gt;(It.IsAny&lt;Uri&gt;(), It.IsAny&lt;FeedOptions&gt;()))
                    .Returns(mockDocumentQuery.Object);
  </code></pre>
  
  <p>In the last line of code, how can I setup the DocumentClient with a heavy load?</p>