Пример #1
0
        private static DocumentClientException CreateDocumentClientException(string requestCharge, string exceptionMessage, HttpStatusCode httpStatusCode)
        {
            var nameValueCollection = new NameValueCollection();

            nameValueCollection.Add("x-ms-request-charge", requestCharge);
            DocumentClientException documentClientException = CosmosDbMockingHelper.CreateDocumentClientException(exceptionMessage, nameValueCollection, httpStatusCode);

            return(documentClientException);
        }
        public async Task GivenAFeedRequests_WhenExecutedAndFails_ThenTheResponseHeadersStillContainTheRequestCharge()
        {
            _innerClient
            .ReadDatabaseFeedAsync(Arg.Any <FeedOptions>())
            .Throws(CosmosDbMockingHelper.CreateDocumentClientException("error", new NameValueCollection {
                { CosmosDbHeaders.RequestCharge, "10" }
            }, (HttpStatusCode?)429));

            await Assert.ThrowsAsync <DocumentClientException>(() => _fhirClient.ReadDatabaseFeedAsync());

            await _cosmosResponseProcessor.Received(1).ProcessException(Arg.Any <DocumentClientException>());
        }
        private static DocumentClientException CreateDocumentClientException(string requestCharge, string exceptionMessage, HttpStatusCode httpStatusCode, string subStatus = null)
        {
            var nameValueCollection = new NameValueCollection();

            nameValueCollection.Add(CosmosDbHeaders.RequestCharge, requestCharge);
            if (subStatus != null)
            {
                nameValueCollection.Add(CosmosDbHeaders.SubStatus, subStatus);
            }

            DocumentClientException documentClientException = CosmosDbMockingHelper.CreateDocumentClientException(exceptionMessage, nameValueCollection, httpStatusCode);

            return(documentClientException);
        }