public async Task CRUDTest() { TriggerProperties settings = new TriggerProperties { Id = Guid.NewGuid().ToString(), Body = TriggersTests.GetTriggerFunction(".05"), TriggerOperation = Cosmos.Scripts.TriggerOperation.Create, TriggerType = Cosmos.Scripts.TriggerType.Pre }; TriggerResponse triggerResponse = await this.scripts.CreateTriggerAsync(settings); double reqeustCharge = triggerResponse.RequestCharge; Assert.IsTrue(reqeustCharge > 0); Assert.AreEqual(HttpStatusCode.Created, triggerResponse.StatusCode); Assert.IsNotNull(triggerResponse.Diagnostics); string diagnostics = triggerResponse.Diagnostics.ToString(); Assert.IsFalse(string.IsNullOrEmpty(diagnostics)); Assert.IsTrue(diagnostics.Contains("StatusCode")); TriggersTests.ValidateTriggerSettings(settings, triggerResponse); triggerResponse = await this.scripts.ReadTriggerAsync(settings.Id); reqeustCharge = triggerResponse.RequestCharge; Assert.IsTrue(reqeustCharge > 0); Assert.AreEqual(HttpStatusCode.OK, triggerResponse.StatusCode); Assert.IsNotNull(triggerResponse.Diagnostics); diagnostics = triggerResponse.Diagnostics.ToString(); Assert.IsFalse(string.IsNullOrEmpty(diagnostics)); Assert.IsTrue(diagnostics.Contains("StatusCode")); TriggersTests.ValidateTriggerSettings(settings, triggerResponse); TriggerProperties updatedSettings = triggerResponse.Resource; updatedSettings.Body = TriggersTests.GetTriggerFunction(".42"); TriggerResponse replaceResponse = await this.scripts.ReplaceTriggerAsync(updatedSettings); TriggersTests.ValidateTriggerSettings(updatedSettings, replaceResponse); reqeustCharge = replaceResponse.RequestCharge; Assert.IsTrue(reqeustCharge > 0); Assert.AreEqual(HttpStatusCode.OK, replaceResponse.StatusCode); Assert.IsNotNull(replaceResponse.Diagnostics); diagnostics = replaceResponse.Diagnostics.ToString(); Assert.IsFalse(string.IsNullOrEmpty(diagnostics)); Assert.IsTrue(diagnostics.Contains("StatusCode")); replaceResponse = await this.scripts.DeleteTriggerAsync(updatedSettings.Id); reqeustCharge = replaceResponse.RequestCharge; Assert.IsTrue(reqeustCharge > 0); Assert.AreEqual(HttpStatusCode.NoContent, replaceResponse.StatusCode); Assert.IsNotNull(replaceResponse.Diagnostics); diagnostics = replaceResponse.Diagnostics.ToString(); Assert.IsFalse(string.IsNullOrEmpty(diagnostics)); Assert.IsTrue(diagnostics.Contains("StatusCode")); }
public async Task CRUDTest() { CosmosTriggerSettings settings = new CosmosTriggerSettings { Id = Guid.NewGuid().ToString(), Body = TriggersTests.GetTriggerFunction(".05"), TriggerOperation = Scripts.TriggerOperation.Create, TriggerType = Scripts.TriggerType.Pre }; TriggerResponse triggerResponse = await this.scripts.CreateTriggerAsync(settings); double reqeustCharge = triggerResponse.RequestCharge; Assert.IsTrue(reqeustCharge > 0); Assert.AreEqual(HttpStatusCode.Created, triggerResponse.StatusCode); TriggersTests.ValidateTriggerSettings(settings, triggerResponse); triggerResponse = await this.scripts.ReadTriggerAsync(settings.Id); reqeustCharge = triggerResponse.RequestCharge; Assert.IsTrue(reqeustCharge > 0); Assert.AreEqual(HttpStatusCode.OK, triggerResponse.StatusCode); TriggersTests.ValidateTriggerSettings(settings, triggerResponse); CosmosTriggerSettings updatedSettings = triggerResponse.Resource; updatedSettings.Body = TriggersTests.GetTriggerFunction(".42"); TriggerResponse replaceResponse = await this.scripts.ReplaceTriggerAsync(updatedSettings); TriggersTests.ValidateTriggerSettings(updatedSettings, replaceResponse); reqeustCharge = replaceResponse.RequestCharge; Assert.IsTrue(reqeustCharge > 0); Assert.AreEqual(HttpStatusCode.OK, replaceResponse.StatusCode); replaceResponse = await this.scripts.DeleteTriggerAsync(updatedSettings.Id); reqeustCharge = replaceResponse.RequestCharge; Assert.IsTrue(reqeustCharge > 0); Assert.AreEqual(HttpStatusCode.NoContent, replaceResponse.StatusCode); }