public async Task Test_AsEnumerable()
        {
            var document0 = await _documentClient.InsertAsync(
                DocumentClientTest.NewDocument(), CancellationToken.None);

            var document1 = await _documentClient.InsertAsync(
                DocumentClientTest.NewDocument(), CancellationToken.None);

            var document2 = await _documentClient.InsertAsync(
                DocumentClientTest.NewDocument(), CancellationToken.None);

            var document3 = await _documentClient.InsertAsync(
                DocumentClientTest.NewDocument(), CancellationToken.None);

            var document4 = await _documentClient.InsertAsync(
                DocumentClientTest.NewDocument(), CancellationToken.None);

            await foreach (var document in _documentClient.AsAsyncEnumerable <TestDocument>(
                               nameof(TestDocument), "SELECT * FROM c", null, null, CancellationToken.None))
            {
                Assert.IsNotNull(document);
            }

            await _documentClient.DeleteAsync(document0.Id, document0.PartitionId, CancellationToken.None);

            await _documentClient.DeleteAsync(document1.Id, document1.PartitionId, CancellationToken.None);

            await _documentClient.DeleteAsync(document2.Id, document2.PartitionId, CancellationToken.None);

            await _documentClient.DeleteAsync(document3.Id, document3.PartitionId, CancellationToken.None);

            await _documentClient.DeleteAsync(document4.Id, document4.PartitionId, CancellationToken.None);
        }
        /// <summary>Receives documents from their persistence.</summary>
        /// <typeparam name="TDocument">A type of a document.</typeparam>
        /// <param name="partitionId">A value that represents a partition ID of a document.</param>
        /// <param name="query">A value that represents a condition to query documents.</param>
        /// <param name="parameters">An object that represents a collection of parameters for a query.</param>
        /// <param name="cancellationToken">A value that propagates notification that operations should be canceled.</param>
        /// <returns>An object that represents an async operation.</returns>
        public static async Task <IList <TDocument> > ToListAsync <TDocument>(
            this IDocumentClient documentClient,
            IDocumentCollectionQuery documentCollectionQuery,
            CancellationToken cancellationToken)
            where TDocument : DocumentBase
        {
            var documents = new List <TDocument>();

            await foreach (var document in documentClient.AsAsyncEnumerable <TDocument>(
                               documentCollectionQuery, cancellationToken))
            {
                documents.Add(document);
            }

            return(documents);
        }
        /// <summary>Receives documents from their persistence.</summary>
        /// <typeparam name="TDocument">A type of a document.</typeparam>
        /// <param name="documentClient">An object that provides a simple API to persistence of documents that inherits the <see cref="AzureFunctionsCustomBindingSample.CosmosDb.DocumentBase"/> class.</param>
        /// <param name="query">An object that represents conditions to query a collection of documents.</param>
        /// <param name="cancellationToken">A value that propagates notification that operations should be canceled.</param>
        /// <returns>An object that represents an async operation.</returns>
        public static IAsyncEnumerable <TDocument> AsAsyncEnumerable <TDocument>(
            this IDocumentClient documentClient,
            IDocumentCollectionQuery query,
            CancellationToken cancellationToken)
            where TDocument : DocumentBase
        {
            if (documentClient == null)
            {
                throw new ArgumentNullException(nameof(documentClient));
            }

            if (query == null)
            {
                throw new ArgumentNullException(nameof(query));
            }

            return(documentClient.AsAsyncEnumerable <TDocument>(
                       query.PartitionId, query.Query, query.Parameters, query.ContinuationToken, cancellationToken));
        }
        /// <summary>Receives documents from their persistence.</summary>
        /// <typeparam name="TDocument">A type of a document.</typeparam>
        /// <param name="partitionId">A value that represents a partition ID of a document.</param>
        /// <param name="query">A value that represents a condition to query documents.</param>
        /// <param name="parameters">An object that represents a collection of parameters for a query.</param>
        /// <param name="cancellationToken">A value that propagates notification that operations should be canceled.</param>
        /// <returns>An object that represents an async operation.</returns>
        public static async Task <IList <TDocument> > ToListAsync <TDocument>(
            this IDocumentClient documentClient,
            string partitionId,
            string query,
            IReadOnlyDictionary <string, object> parameters,
            CancellationToken cancellationToken)
            where TDocument : DocumentBase
        {
            if (documentClient == null)
            {
                throw new ArgumentNullException(nameof(documentClient));
            }

            var documents = new List <TDocument>();

            await foreach (var document in documentClient.AsAsyncEnumerable <TDocument>(
                               partitionId, query, parameters, null, cancellationToken))
            {
                documents.Add(document);
            }

            return(documents);
        }