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")); }
void BeginTask() { ResetUI(); currentTask = GetRandomTask(); currentTask.SetController(controller.Controls); currentTask.Begin(); }
public async Task DeleteTrigger(string triggerName) { string message = "Delete Triggers"; Printer.PrintLine(message: message); Scripts scripts = _container.Scripts; TriggerResponse triggerResponse = await scripts.DeleteTriggerAsync(triggerName); WriteLine($"Delete Trigger, Deleted Trigger with Id: {triggerName}"); Printer.PrintLine(noOfTimes: (100 + message.Length)); }
/// <summary>Validates the given user's application key.</summary> public TriggerResponse GetTriggers() { string url = "http://api.ping.fm/v1/user.triggers"; string postdata = "api_key={0}&user_app_key={1}"; postdata = string.Format(postdata, api_key, user_application_key); string response = GetWebResponse(url, postdata); XmlReader xr = XmlReader.Create(new System.IO.StringReader(response)); TriggerResponse r = (TriggerResponse)DeserializeObject(xr, typeof(TriggerResponse)); xr.Close(); mLastResponse = r; return(r); }
private static async Task <bool> TriggerExists(Container container, string sprocId) { Scripts cosmosScripts = container.Scripts; try { TriggerResponse trigger = await cosmosScripts.ReadTriggerAsync(sprocId); return(true); } catch (CosmosException ex) when(ex.StatusCode == System.Net.HttpStatusCode.NotFound) { return(false); } }
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); }
public async Task CreateTrigger(string triggerName, string triggerType = "Post") { string message = "Create Triggers"; Printer.PrintLine(message: message); var triggerBody = File.ReadAllText($"Triggers/{triggerName}.js"); TriggerType tt = string.Equals(triggerType, "Pre") ? TriggerType.Pre : TriggerType.Post; Scripts scripts = _container.Scripts; TriggerProperties triggerProperties = new TriggerProperties { Id = triggerName, Body = triggerBody, TriggerType = tt, TriggerOperation = TriggerOperation.Create }; TriggerResponse triggerResponse = await scripts.CreateTriggerAsync(triggerProperties); WriteLine($"Trigger Details, Id: {triggerResponse.Resource.Id}, SelfLink: {triggerResponse.Resource.SelfLink},\nTriggerOperation: {triggerResponse.Resource.TriggerOperation}, TriggerType: {triggerResponse.Resource.TriggerType}"); Printer.PrintLine(noOfTimes: (100 + message.Length)); }
private async Task <TriggerResponse> CreateRandomTrigger() { string id = Guid.NewGuid().ToString(); string function = GetTriggerFunction(".05"); TriggerProperties settings = new TriggerProperties { Id = id, Body = function, TriggerOperation = Cosmos.Scripts.TriggerOperation.Create, TriggerType = Cosmos.Scripts.TriggerType.Pre }; //Create a user defined function TriggerResponse createResponse = await this.scripts.CreateTriggerAsync( triggerProperties : settings, cancellationToken : this.cancellationToken); ValidateTriggerSettings(settings, createResponse); return(createResponse); }
private static void ValidateTriggerSettings(TriggerProperties triggerSettings, TriggerResponse cosmosResponse) { TriggerProperties settings = cosmosResponse.Resource; Assert.AreEqual(triggerSettings.Body, settings.Body, "Trigger function do not match"); Assert.AreEqual(triggerSettings.Id, settings.Id, "Trigger id do not match"); Assert.IsTrue(cosmosResponse.RequestCharge > 0); Assert.IsNotNull(cosmosResponse.Headers.GetHeaderValue <string>(Documents.HttpConstants.HttpHeaders.MaxResourceQuota)); Assert.IsNotNull(cosmosResponse.Headers.GetHeaderValue <string>(Documents.HttpConstants.HttpHeaders.CurrentResourceQuotaUsage)); SelflinkValidator.ValidateTriggerSelfLink(cosmosResponse.Resource.SelfLink); }
private static void ValidateTriggerSettings(TriggerProperties triggerSettings, TriggerResponse cosmosResponse) { TriggerProperties settings = cosmosResponse.Resource; Assert.AreEqual(triggerSettings.Body, settings.Body, "Trigger function do not match"); Assert.AreEqual(triggerSettings.Id, settings.Id, "Trigger id do not match"); Assert.IsTrue(cosmosResponse.RequestCharge > 0); Assert.IsNotNull(cosmosResponse.MaxResourceQuota); Assert.IsNotNull(cosmosResponse.CurrentResourceQuotaUsage); }
/// <summary> Setter constructor. </summary> public Trigger(TriggerRequest request) { Request = request; Response = new TriggerResponse(); }
/// <summary> Empty constructor. </summary> public Trigger() { Request = TriggerRequest.Singleton; Response = new TriggerResponse(); }