private async Task TestCurratedDocs(string filename)
 {
     IEnumerable <object> documents = BinaryEncodingOverTheWireTests.GetDocumentsFromCurratedDoc(filename);
     await BinaryEncodingOverTheWireTests.CreateIngestQueryDelete(
         documents.Select(x => x.ToString()),
         this.TestCurratedDocs);
 }
        private static async Task <Tuple <DocumentCollection, List <Document> > > CreateCollectionAndIngestDocuments(IEnumerable <string> documents)
        {
            DocumentCollection documentCollection = BinaryEncodingOverTheWireTests.CreateCollection();
            List <Document>    insertedDocuments  = new List <Document>();
            Random             rand = new Random(1234);

            foreach (string document in documents.OrderBy(x => rand.Next()).Take(100))
            {
                insertedDocuments.Add(await Client.CreateDocumentAsync(documentCollection.SelfLink, JsonConvert.DeserializeObject(document)));
            }

            return(new Tuple <DocumentCollection, List <Document> >(documentCollection, insertedDocuments));
        }
 public void TestInitialize()
 {
     BinaryEncodingOverTheWireTests.database = BinaryEncodingOverTheWireTests.CreateDatabase();
 }
 public static void Initialize(TestContext textContext)
 {
     BinaryEncodingOverTheWireTests.CleanUp();
 }
        /// <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));
        }