/// <summary>
        /// Task that wraps boiler plate code for query tests (collection create -> ingest documents -> query documents -> delete collections).
        /// Note that this function will take the cross product connectionModes and collectionTypes.
        /// </summary>
        /// <param name="connectionModes">The connection modes to use.</param>
        /// <param name="collectionTypes">The type of collections to create.</param>
        /// <param name="documents">The documents to ingest</param>
        /// <param name="query">
        /// The callback for the queries.
        /// All the standard arguments will be passed in.
        /// Please make sure that this function is idempotent, since a collection will be reused for each connection mode.
        /// </param>
        /// <param name="partitionKey">The partition key for the partition collection.</param>
        /// <param name="testArgs">The optional args that you want passed in to the query.</param>
        /// <returns>A task to await on.</returns>
        private static async Task CreateIngestQueryDelete(
            IEnumerable <string> documents,
            Func <DocumentClient, DocumentCollection, IEnumerable <Document>, dynamic, Task> query,
            dynamic testArgs = null)
        {
            Tuple <DocumentCollection, List <Document> > collectionAndDocuments = await BinaryEncodingOverTheWireTests.CreateCollectionAndIngestDocuments(documents);

            bool succeeded = false;

            while (!succeeded)
            {
                try
                {
                    List <Task> queryTasks = new List <Task>();
                    foreach (DocumentClient documentClient in DocumentClients)
                    {
                        queryTasks.Add(query(documentClient, collectionAndDocuments.Item1, collectionAndDocuments.Item2, testArgs));
                    }

                    await Task.WhenAll(queryTasks);

                    succeeded = true;
                }
                catch (ServiceUnavailableException)
                {
                    // RNTBD throws ServiceUnavailableException every now and then
                }
            }

            await BinaryEncodingOverTheWireTests.Client.DeleteDocumentCollectionAsync(UriFactory.CreateDocumentCollectionUri(database.Id, collectionAndDocuments.Item1.Id));
        }