예제 #1
0
 private async Task TestCurratedDocs(string path)
 {
     IEnumerable <object> documents = BinaryEncodingOverTheWireTests.GetDocumentsFromCurratedDoc(path);
     await BinaryEncodingOverTheWireTests.CreateIngestQueryDelete(
         documents.Select(x => x.ToString()),
         this.TestCurratedDocs);
 }
예제 #2
0
        /// <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,
            Query query)
        {
            Tuple <Container, List <JToken> > collectionAndDocuments = await BinaryEncodingOverTheWireTests.CreateCollectionAndIngestDocuments(documents);

            List <Task> queryTasks = new List <Task>();

            foreach (CosmosClient cosmosClient in BinaryEncodingOverTheWireTests.Clients)
            {
                queryTasks.Add(query(cosmosClient, collectionAndDocuments.Item1, collectionAndDocuments.Item2));
            }

            await Task.WhenAll(queryTasks);

            await collectionAndDocuments.Item1.DeleteContainerAsync();
        }
예제 #3
0
        private static async Task <Tuple <Container, List <JToken> > > CreateCollectionAndIngestDocuments(IEnumerable <string> documents)
        {
            Container container = await BinaryEncodingOverTheWireTests.CreateContainerAsync();

            List <JToken> insertedDocuments = new List <JToken>();
            Random        rand = new Random(1234);

            foreach (string serializedItem in documents.OrderBy(x => rand.Next()).Take(100))
            {
                JToken item = JToken.Parse(serializedItem);
                item["id"] = Guid.NewGuid().ToString();
                JToken createdItem = await container.CreateItemAsync <JToken>(item, new PartitionKey(item["id"].ToString()));

                insertedDocuments.Add(createdItem);
            }

            return(new Tuple <Container, List <JToken> >(container, insertedDocuments));
        }