// </CreateBulkInsertScriptArguments> /// <summary> /// If a Stored Procedure is found on the DocumentCollection for the Id supplied it is deleted /// </summary> /// <param name="collectionLink">DocumentCollection to search for the Stored Procedure</param> /// <param name="sprocId">Id of the Stored Procedure to delete</param> /// <returns></returns>\ // <TryDeleteStoredProcedure> private static async Task TryDeleteStoredProcedure(Container container, string sprocId) { Scripts cosmosScripts = container.Scripts; StoredProcedureResponse sproc = await cosmosScripts.ReadStoredProcedureAsync(sprocId); if (sproc != null) { await cosmosScripts.DeleteStoredProcedureAsync(sprocId); } }
public async Task ExecuteNonePkTest() { // Create a container in v2 without a partition key string containerId = "SprocPkNone" + Guid.NewGuid().ToString(); ContainerInternal 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); }
public async Task DeleteStoreProcedure(string spName) { string message = $"Delete SP {spName}"; Printer.PrintLine(message: message); Scripts scripts = _container.Scripts; await scripts.DeleteStoredProcedureAsync(spName); WriteLine($"Stored Procedure: {spName} delted"); Printer.PrintLine(noOfTimes: (101 + message.Length)); }
// </CreateBulkInsertScriptArguments> /// <summary> /// If a Stored Procedure is found on the DocumentCollection for the Id supplied it is deleted /// </summary> /// <param name="collectionLink">DocumentCollection to search for the Stored Procedure</param> /// <param name="sprocId">Id of the Stored Procedure to delete</param> /// <returns></returns>\ // <TryDeleteStoredProcedure> private static async Task TryDeleteStoredProcedure(Container container, string sprocId) { Scripts cosmosScripts = container.Scripts; try { StoredProcedureResponse sproc = await cosmosScripts.ReadStoredProcedureAsync(sprocId); await cosmosScripts.DeleteStoredProcedureAsync(sprocId); } catch (CosmosException ex) when(ex.StatusCode == System.Net.HttpStatusCode.NotFound) { //Nothing to delete } }