public void CreateHookValidatesArguments() { MetricsAdvisorAdministrationClient adminClient = GetMetricsAdvisorAdministrationClient(); var name = "hookName"; var endpoint = new Uri("http://fakeendpoint.com"); var emailHook = new EmailNotificationHook(name) { Name = null, EmailsToAlert = { "*****@*****.**" } }; var webHook = new WebNotificationHook(name, endpoint) { Name = null }; Assert.That(() => adminClient.CreateHookAsync(null), Throws.InstanceOf <ArgumentNullException>()); Assert.That(() => adminClient.CreateHook(null), Throws.InstanceOf <ArgumentNullException>()); Assert.That(() => adminClient.CreateHookAsync(emailHook), Throws.InstanceOf <ArgumentNullException>()); Assert.That(() => adminClient.CreateHook(emailHook), Throws.InstanceOf <ArgumentNullException>()); emailHook.Name = ""; Assert.That(() => adminClient.CreateHookAsync(emailHook), Throws.InstanceOf <ArgumentException>()); Assert.That(() => adminClient.CreateHook(emailHook), Throws.InstanceOf <ArgumentException>()); Assert.That(() => adminClient.CreateHookAsync(webHook), Throws.InstanceOf <ArgumentNullException>()); Assert.That(() => adminClient.CreateHook(webHook), Throws.InstanceOf <ArgumentNullException>()); webHook.Name = ""; Assert.That(() => adminClient.CreateHookAsync(webHook), Throws.InstanceOf <ArgumentException>()); Assert.That(() => adminClient.CreateHook(webHook), Throws.InstanceOf <ArgumentException>()); }
public async Task CreateHookForReceivingAnomalyAlerts() { string endpoint = MetricsAdvisorUri; string subscriptionKey = MetricsAdvisorSubscriptionKey; string apiKey = MetricsAdvisorApiKey; var credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey); var adminClient = new MetricsAdvisorAdministrationClient(new Uri(endpoint), credential); #region Snippet:CreateHookForReceivingAnomalyAlerts string hookName = "Sample hook"; var emailsToAlert = new List <string>() { "*****@*****.**", "*****@*****.**" }; var emailHook = new EmailHook(hookName, emailsToAlert); Response <AlertingHook> response = adminClient.CreateHook(emailHook); AlertingHook hook = response.Value; Console.WriteLine($"Hook ID: {hook.Id}"); #endregion // Delete the created hook to clean up the Metrics Advisor resource. Do not perform this // step if you intend to keep using the hook. await adminClient.DeleteHookAsync(hook.Id); }
public void CreateHookValidatesArguments() { MetricsAdvisorAdministrationClient adminClient = GetMetricsAdvisorAdministrationClient(); Assert.That(() => adminClient.CreateHookAsync(null), Throws.InstanceOf <ArgumentNullException>()); Assert.That(() => adminClient.CreateHook(null), Throws.InstanceOf <ArgumentNullException>()); }
public void CreateHookRespectsTheCancellationToken() { MetricsAdvisorAdministrationClient adminClient = GetMetricsAdvisorAdministrationClient(); var hook = new EmailNotificationHook("hookName") { EmailsToAlert = { "*****@*****.**" } }; using var cancellationSource = new CancellationTokenSource(); cancellationSource.Cancel(); Assert.That(() => adminClient.CreateHookAsync(hook, cancellationSource.Token), Throws.InstanceOf <OperationCanceledException>()); Assert.That(() => adminClient.CreateHook(hook, cancellationSource.Token), Throws.InstanceOf <OperationCanceledException>()); }