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(); }