Exemplo n.º 1
0
        public void DeleteHookValidatesArguments()
        {
            MetricsAdvisorAdministrationClient adminClient = GetMetricsAdvisorAdministrationClient();

            Assert.That(() => adminClient.DeleteHookAsync(null), Throws.InstanceOf <ArgumentNullException>());
            Assert.That(() => adminClient.DeleteHookAsync(""), Throws.InstanceOf <ArgumentException>());
            Assert.That(() => adminClient.DeleteHookAsync("hookId"), Throws.InstanceOf <ArgumentException>().With.InnerException.TypeOf(typeof(FormatException)));

            Assert.That(() => adminClient.DeleteHook(null), Throws.InstanceOf <ArgumentNullException>());
            Assert.That(() => adminClient.DeleteHook(""), Throws.InstanceOf <ArgumentException>());
            Assert.That(() => adminClient.DeleteHook("hookId"), Throws.InstanceOf <ArgumentException>().With.InnerException.TypeOf(typeof(FormatException)));
        }
        public async Task DeleteNotificationHook(bool useTokenCredential)
        {
            MetricsAdvisorAdministrationClient adminClient = GetMetricsAdvisorAdministrationClient(useTokenCredential);

            string hookName     = Recording.GenerateAlphaNumericId("hook");
            var    hookToCreate = new EmailNotificationHook()
            {
                Name = hookName, EmailsToAlert = { "*****@*****.**" }
            };

            string hookId = null;

            try
            {
                NotificationHook createdHook = await adminClient.CreateHookAsync(hookToCreate);

                hookId = createdHook.Id;

                Assert.That(hookId, Is.Not.Null.And.Not.Empty);
            }
            finally
            {
                if (hookId != null)
                {
                    await adminClient.DeleteHookAsync(hookId);

                    var errorCause = "hookId is invalid";
                    Assert.That(async() => await adminClient.GetHookAsync(hookId), Throws.InstanceOf <RequestFailedException>().With.Message.Contains(errorCause));
                }
            }
        }
        public async Task CreateAndDeleteHookAsync()
        {
            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:CreateHookAsync
            string hookName = "Sample hook";

            var emailHook = new EmailNotificationHook()
            {
                Name = hookName
            };

            emailHook.EmailsToAlert.Add("*****@*****.**");
            emailHook.EmailsToAlert.Add("*****@*****.**");

            Response <NotificationHook> response = await adminClient.CreateHookAsync(emailHook);

            NotificationHook createdHook = response.Value;

            Console.WriteLine($"Hook ID: {createdHook.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(createdHook.Id);
        }
        public async Task DeleteNotificationHook()
        {
            MetricsAdvisorAdministrationClient adminClient = GetMetricsAdvisorAdministrationClient();

            string hookName     = Recording.GenerateAlphaNumericId("hook");
            var    hookToCreate = new WebNotificationHook(hookName, "http://contoso.com");

            string hookId = null;

            try
            {
                hookId = await adminClient.CreateHookAsync(hookToCreate);

                Assert.That(hookId, Is.Not.Null.And.Not.Empty);
            }
            finally
            {
                if (hookId != null)
                {
                    await adminClient.DeleteHookAsync(hookId);

                    var errorCause = "hookId is invalid";
                    Assert.That(async() => await adminClient.GetHookAsync(hookId), Throws.InstanceOf <RequestFailedException>().With.Message.Contains(errorCause));
                }
            }
        }
Exemplo n.º 5
0
        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);
        }
Exemplo n.º 6
0
        public void DeleteHookRespectsTheCancellationToken()
        {
            MetricsAdvisorAdministrationClient adminClient = GetMetricsAdvisorAdministrationClient();

            using var cancellationSource = new CancellationTokenSource();
            cancellationSource.Cancel();

            Assert.That(() => adminClient.DeleteHookAsync(FakeGuid, cancellationSource.Token), Throws.InstanceOf <OperationCanceledException>());
            Assert.That(() => adminClient.DeleteHook(FakeGuid, cancellationSource.Token), Throws.InstanceOf <OperationCanceledException>());
        }
Exemplo n.º 7
0
 /// <summary>
 /// Deletes the hook this instance is associated with.
 /// </summary>
 public async ValueTask DisposeAsync() => await _adminClient.DeleteHookAsync(Hook.Id);