private async Task <IList <ToDoActivity> > CreateRandomItems(ContainerCore container, int pkCount, int perPKItemCount = 1, bool randomPartitionKey = true) { Assert.IsFalse(!randomPartitionKey && perPKItemCount > 1); List <ToDoActivity> createdList = new List <ToDoActivity>(); for (int i = 0; i < pkCount; i++) { string pk = "TBD"; if (randomPartitionKey) { pk += Guid.NewGuid().ToString(); } for (int j = 0; j < perPKItemCount; j++) { ToDoActivity temp = this.CreateRandomToDoActivity(pk); createdList.Add(temp); await container.CreateItemAsync <ToDoActivity>(item : temp); } } return(createdList); }
public async Task ExecuteNonePkTest() { // Create a container in v2 without a partition key string containerId = "SprocPkNone" + Guid.NewGuid().ToString(); ContainerCore containerNonePk = await NonPartitionedContainerHelper.CreateNonPartitionedContainer(this.database, containerId); Scripts scriptsNonePk = containerNonePk.Scripts; string sprocId = Guid.NewGuid().ToString(); string sprocBody = @"function() { var context = getContext(); var response = context.getResponse(); var collection = context.getCollection(); var collectionLink = collection.getSelfLink(); var filterQuery = 'SELECT * FROM c'; collection.queryDocuments(collectionLink, filterQuery, { }, function(err, documents) { response.setBody(documents); } ); }"; StoredProcedureResponse storedProcedureResponse = await scriptsNonePk.CreateStoredProcedureAsync(new StoredProcedureProperties(sprocId, sprocBody)); Assert.AreEqual(HttpStatusCode.Created, storedProcedureResponse.StatusCode); StoredProcedureTests.ValidateStoredProcedureSettings(sprocId, sprocBody, storedProcedureResponse); // Insert document and then query string testPartitionId = Guid.NewGuid().ToString(); var payload = new { id = testPartitionId, user = testPartitionId }; ItemResponse<dynamic> createItemResponse = await containerNonePk.CreateItemAsync<dynamic>(payload); Assert.AreEqual(HttpStatusCode.Created, createItemResponse.StatusCode); StoredProcedureProperties storedProcedure = storedProcedureResponse; StoredProcedureExecuteResponse<JArray> sprocResponse = await scriptsNonePk.ExecuteStoredProcedureAsync<JArray>( sprocId, Cosmos.PartitionKey.None, parameters: null); Assert.AreEqual(HttpStatusCode.OK, sprocResponse.StatusCode); JArray jArray = sprocResponse; Assert.AreEqual(1, jArray.Count); Assert.AreEqual(testPartitionId, jArray[0]["id"]); StoredProcedureResponse deleteResponse = await scriptsNonePk.DeleteStoredProcedureAsync(sprocId); Assert.AreEqual(HttpStatusCode.NoContent, deleteResponse.StatusCode); }
private static async Task <ItemResponse <TestDoc> > CreateItemAsync( ContainerCore containerCore, string dekId, List <string> pathsToEncrypt) { TestDoc testDoc = TestDoc.Create(); ItemResponse <TestDoc> createResponse = await containerCore.CreateItemAsync( testDoc, new PartitionKey(testDoc.PK), EncryptionTests.GetRequestOptions(containerCore, dekId, pathsToEncrypt)); Assert.AreEqual(HttpStatusCode.Created, createResponse.StatusCode); Assert.AreEqual(testDoc, createResponse.Resource); return(createResponse); }