public void ValidateUriGenerationForResources() { string databaseId = "db1234"; string crId = "cr42"; string spId = "sp9001"; string trId = "tr9002"; string udfId = "udf9003"; CosmosClient mockClient = MockDocumentClient.CreateMockCosmosClient(); CosmosDatabaseCore db = new CosmosDatabaseCore(mockClient, databaseId); Assert.AreEqual(db.LinkUri.OriginalString, "/dbs/" + databaseId); CosmosContainerCore container = new CosmosContainerCore(db, crId); Assert.AreEqual(container.LinkUri.OriginalString, "/dbs/" + databaseId + "/colls/" + crId); CosmosStoredProcedureCore sp = new CosmosStoredProcedureCore(container, spId); Assert.AreEqual(sp.LinkUri.OriginalString, "/dbs/" + databaseId + "/colls/" + crId + "/sprocs/" + spId); CosmosTrigger tr = new CosmosTrigger(container, trId); Assert.AreEqual(tr.LinkUri.OriginalString, "/dbs/" + databaseId + "/colls/" + crId + "/triggers/" + trId); CosmosUserDefinedFunction udf = new CosmosUserDefinedFunction(container, udfId); Assert.AreEqual(udf.LinkUri.OriginalString, "/dbs/" + databaseId + "/colls/" + crId + "/udfs/" + udfId); }
private static TriggerProperties GetProps(CosmosTrigger trigger) => new TriggerProperties { Id = trigger.Id, Body = trigger.Body, TriggerOperation = trigger.Operation, TriggerType = trigger.Type };
public async Task TriggersIteratorTest() { CosmosTrigger cosmosTrigger = await CreateRandomTrigger(); HashSet <string> settings = new HashSet <string>(); CosmosResultSetIterator <CosmosTriggerSettings> iter = this.container.Triggers.GetTriggerIterator();; while (iter.HasMoreResults) { foreach (CosmosTriggerSettings storedProcedureSettingsEntry in await iter.FetchNextSetAsync()) { settings.Add(storedProcedureSettingsEntry.Id); } } Assert.IsTrue(settings.Contains(cosmosTrigger.Id), "The iterator did not return the user defined function definition."); // Delete existing user defined functions. await cosmosTrigger.DeleteAsync(); }
public async Task ValidateTriggersTest() { // Prevent failures if previous test did not clean up correctly await this.container.Triggers["addTax"].DeleteAsync(); ToDoActivity item = new ToDoActivity() { id = Guid.NewGuid().ToString(), cost = 9001, description = "trigger_test_item", status = "Done", taskNum = 1 }; CosmosTrigger cosmosTrigger = await this.container.Triggers.CreateTriggerAsync( new CosmosTriggerSettings { Id = "addTax", Body = TriggersTests.GetTriggerFunction(".20"), TriggerOperation = TriggerOperation.All, TriggerType = Cosmos.TriggerType.Pre }); CosmosItemRequestOptions options = new CosmosItemRequestOptions() { PreTriggers = new List <string>() { cosmosTrigger.Id }, }; CosmosItemResponse <dynamic> createdItem = await this.container.Items.CreateItemAsync <dynamic>(item.status, item, options); double itemTax = createdItem.Resource.tax; Assert.AreEqual(item.cost * .20, itemTax); // Delete existing user defined functions. await cosmosTrigger.DeleteAsync(); }
public void ValidateUriGenerationForResources() { string databaseId = "db1234"; string crId = "cr42"; string spId = "sp9001"; string trId = "tr9002"; string udfId = "udf9003"; CosmosClientContext context = new CosmosClientContextCore( client: null, clientConfiguration: null, cosmosJsonSerializer: null, cosmosResponseFactory: null, requestHandler: null, documentClient: null, documentQueryClient: new Mock <IDocumentQueryClient>().Object); CosmosDatabaseCore db = new CosmosDatabaseCore(context, databaseId); Assert.AreEqual(db.LinkUri.OriginalString, "/dbs/" + databaseId); CosmosContainerCore container = new CosmosContainerCore(context, db, crId); Assert.AreEqual(container.LinkUri.OriginalString, "/dbs/" + databaseId + "/colls/" + crId); CosmosStoredProcedureCore sp = new CosmosStoredProcedureCore(context, container, spId); Assert.AreEqual(sp.LinkUri.OriginalString, "/dbs/" + databaseId + "/colls/" + crId + "/sprocs/" + spId); CosmosTrigger tr = new CosmosTrigger(context, container, trId); Assert.AreEqual(tr.LinkUri.OriginalString, "/dbs/" + databaseId + "/colls/" + crId + "/triggers/" + trId); CosmosUserDefinedFunction udf = new CosmosUserDefinedFunction(context, container, udfId); Assert.AreEqual(udf.LinkUri.OriginalString, "/dbs/" + databaseId + "/colls/" + crId + "/udfs/" + udfId); }
public Task <OperationResult> DeleteTriggerAsync(CosmosTrigger trigger, CancellationToken cancellationToken) => DeleteScript(trigger, _containerGetter().Scripts.DeleteTriggerAsync, cancellationToken);
public Task <OperationResult> ReplaceTriggerAsync(CosmosTrigger trigger, CancellationToken cancellationToken) => ReplaceScript(trigger, GetProps, _containerGetter().Scripts.ReplaceTriggerAsync, cancellationToken);