public async Task UpdateWebNotificationHookWithEveryMemberAndGetInstance() { // Create a hook. MetricsAdvisorAdministrationClient adminClient = GetMetricsAdvisorAdministrationClient(); string hookName = Recording.GenerateAlphaNumericId("hook"); var endpoint = "http://contoso.com"; var description = "This hook was created to test the .NET client."; var headers = new Dictionary <string, string>() { { "key1", "value1" }, { "key2", "value2" } }; var hookToCreate = new WebNotificationHook() { Name = hookName, Endpoint = endpoint }; await using var disposableHook = await DisposableNotificationHook.CreateHookAsync(adminClient, hookToCreate); // Update the created hook. var hookToUpdate = (await adminClient.GetHookAsync(disposableHook.Id)).Value as WebNotificationHook; hookToUpdate.Description = description; hookToUpdate.ExternalLink = "http://fake.endpoint.com"; // TODO: add certificate key validation (https://github.com/Azure/azure-sdk-for-net/issues/17485) hookToUpdate.CertificatePassword = "******"; hookToUpdate.Username = "******"; hookToUpdate.Password = "******"; foreach (var header in headers) { hookToUpdate.Headers.Add(header); } await adminClient.UpdateHookAsync(disposableHook.Id, hookToUpdate); // Get the hook and check if updates are in place. var updatedWebHook = (await adminClient.GetHookAsync(disposableHook.Id)).Value as WebNotificationHook; Assert.That(updatedWebHook.Id, Is.EqualTo(disposableHook.Id)); Assert.That(updatedWebHook.Name, Is.EqualTo(hookName)); Assert.That(updatedWebHook.Description, Is.EqualTo(description)); Assert.That(updatedWebHook.ExternalLink, Is.EqualTo("http://fake.endpoint.com")); Assert.That(updatedWebHook.Administrators, Is.Not.Null); Assert.That(updatedWebHook.Administrators.Single(), Is.Not.Null.And.Not.Empty); Assert.That(updatedWebHook.Endpoint, Is.EqualTo(endpoint)); // TODO: add certificate key validation (https://github.com/Azure/azure-sdk-for-net/issues/17485) Assert.That(updatedWebHook.CertificatePassword, Is.EqualTo("certPassword")); Assert.That(updatedWebHook.Username, Is.EqualTo("fakeUsername")); Assert.That(updatedWebHook.Password, Is.EqualTo("fakePassword")); Assert.That(updatedWebHook.Headers, Is.EquivalentTo(headers)); }
public void GetHookValidatesArguments() { MetricsAdvisorAdministrationClient adminClient = GetMetricsAdvisorAdministrationClient(); Assert.That(() => adminClient.GetHookAsync(null), Throws.InstanceOf <ArgumentNullException>()); Assert.That(() => adminClient.GetHookAsync(""), Throws.InstanceOf <ArgumentException>()); Assert.That(() => adminClient.GetHookAsync("hookId"), Throws.InstanceOf <ArgumentException>().With.InnerException.TypeOf(typeof(FormatException))); Assert.That(() => adminClient.GetHook(null), Throws.InstanceOf <ArgumentNullException>()); Assert.That(() => adminClient.GetHook(""), Throws.InstanceOf <ArgumentException>()); Assert.That(() => adminClient.GetHook("hookId"), Throws.InstanceOf <ArgumentException>().With.InnerException.TypeOf(typeof(FormatException))); }
public async Task UpdateHookAsync() { string endpoint = MetricsAdvisorUri; string subscriptionKey = MetricsAdvisorSubscriptionKey; string apiKey = MetricsAdvisorApiKey; var credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey); var adminClient = new MetricsAdvisorAdministrationClient(new Uri(endpoint), credential); string hookId = HookId; Response <NotificationHook> response = await adminClient.GetHookAsync(hookId); NotificationHook hook = response.Value; string originalDescription = hook.Description; hook.Description = "This description was generated by a sample."; response = await adminClient.UpdateHookAsync(hook); NotificationHook updatedHook = response.Value; Console.WriteLine($"Updated description: {updatedHook.Description}"); // Undo the changes to leave the hook unaltered. Skip this step if you intend to keep // the changes. hook.Description = originalDescription; await adminClient.UpdateHookAsync(hook); }
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 CreateAndGetWebNotificationHookWithMinimumSetup() { MetricsAdvisorAdministrationClient adminClient = GetMetricsAdvisorAdministrationClient(); string hookName = Recording.GenerateAlphaNumericId("hook"); var hookToCreate = new WebNotificationHook(hookName, "http://contoso.com"); await using var disposableHook = await DisposableNotificationHook.CreateHookAsync(adminClient, hookToCreate); NotificationHook createdHook = await adminClient.GetHookAsync(disposableHook.Id); Assert.That(createdHook.Id, Is.EqualTo(disposableHook.Id)); Assert.That(createdHook.Name, Is.EqualTo(hookName)); Assert.That(createdHook.Description, Is.Empty); Assert.That(createdHook.ExternalLink, Is.Empty); Assert.That(createdHook.Administrators, Is.Not.Null); Assert.That(createdHook.Administrators.Single(), Is.Not.Null.And.Not.Empty); var createdWebHook = createdHook as WebNotificationHook; Assert.That(createdWebHook, Is.Not.Null); Assert.That(createdWebHook.Endpoint, Is.EqualTo("http://contoso.com")); Assert.That(createdWebHook.CertificateKey, Is.Empty); Assert.That(createdWebHook.CertificatePassword, Is.Empty); Assert.That(createdWebHook.Username, Is.Empty); Assert.That(createdWebHook.Password, Is.Empty); Assert.That(createdWebHook.Headers, Is.Not.Null.And.Empty); }
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)); } } }
public async Task CreateAndGetEmailNotificationHookWithOptionalMembers() { MetricsAdvisorAdministrationClient adminClient = GetMetricsAdvisorAdministrationClient(); string hookName = Recording.GenerateAlphaNumericId("hook"); var emailsToAlert = new List <string>() { "*****@*****.**", "*****@*****.**" }; var description = "This hook was created to test the .NET client."; var hookToCreate = new EmailNotificationHook(hookName, emailsToAlert) { Description = description, ExternalLink = "http://fake.endpoint.com" }; await using var disposableHook = await DisposableNotificationHook.CreateHookAsync(adminClient, hookToCreate); NotificationHook createdHook = await adminClient.GetHookAsync(disposableHook.Id); Assert.That(createdHook.Id, Is.EqualTo(disposableHook.Id)); Assert.That(createdHook.Name, Is.EqualTo(hookName)); Assert.That(createdHook.Description, Is.EqualTo(description)); Assert.That(createdHook.ExternalLink, Is.EqualTo("http://fake.endpoint.com")); Assert.That(createdHook.Administrators, Is.Not.Null); Assert.That(createdHook.Administrators.Single(), Is.Not.Null.And.Not.Empty); var createdEmailHook = createdHook as EmailNotificationHook; Assert.That(createdEmailHook, Is.Not.Null); Assert.That(createdEmailHook.EmailsToAlert, Is.EquivalentTo(emailsToAlert)); }
public async Task CreateAndGetEmailNotificationHookWithMinimumSetup(bool useTokenCredential) { MetricsAdvisorAdministrationClient adminClient = GetMetricsAdvisorAdministrationClient(useTokenCredential); string hookName = Recording.GenerateAlphaNumericId("hook"); var hookToCreate = new EmailNotificationHook() { Name = hookName, EmailsToAlert = { "*****@*****.**", "*****@*****.**" } }; await using var disposableHook = await DisposableNotificationHook.CreateHookAsync(adminClient, hookToCreate); NotificationHook createdHook = await adminClient.GetHookAsync(disposableHook.Id); Assert.That(createdHook.Id, Is.EqualTo(disposableHook.Id)); Assert.That(createdHook.Name, Is.EqualTo(hookName)); Assert.That(createdHook.Description, Is.Empty); Assert.That(createdHook.ExternalLink, Is.Null); Assert.That(createdHook.AdministratorsEmails, Is.Not.Null); Assert.That(createdHook.AdministratorsEmails.Single(), Is.Not.Null.And.Not.Empty); var createdEmailHook = createdHook as EmailNotificationHook; Assert.That(createdEmailHook, Is.Not.Null); Assert.That(createdEmailHook.EmailsToAlert.Count, Is.EqualTo(2)); Assert.That(createdEmailHook.EmailsToAlert.Contains("*****@*****.**")); Assert.That(createdEmailHook.EmailsToAlert.Contains("*****@*****.**")); }
public async Task NotificationHookUpdatesUnknownHook() { MockResponse getResponse = new MockResponse(200); getResponse.SetContent(UnknownHookContent); MockResponse updateResponse = new MockResponse(200); updateResponse.SetContent(UnknownHookContent); MockTransport mockTransport = new MockTransport(getResponse, updateResponse); MetricsAdvisorAdministrationClient adminClient = CreateInstrumentedAdministrationClient(mockTransport); NotificationHook hook = await adminClient.GetHookAsync(FakeGuid); hook.Name = "newHookName"; hook.ExternalUri = new Uri("https://newfakeuri.com/"); hook.Description = "new description"; await adminClient.UpdateHookAsync(hook); MockRequest request = mockTransport.Requests.Last(); string content = ReadContent(request); Assert.That(request.Uri.Path, Contains.Substring(FakeGuid)); Assert.That(content, ContainsJsonString("hookName", "newHookName")); Assert.That(content, ContainsJsonString("hookType", "unknownType")); Assert.That(content, ContainsJsonString("externalLink", "https://newfakeuri.com/")); Assert.That(content, ContainsJsonString("description", "new description")); Assert.That(content, ContainsJsonStringArray("admins", "*****@*****.**")); }
public async Task UpdateEmailNotificationHookWithEveryMemberAndGetInstance() { // Create a hook. MetricsAdvisorAdministrationClient adminClient = GetMetricsAdvisorAdministrationClient(); string hookName = Recording.GenerateAlphaNumericId("hook"); var emailsToAlert = new List <string>() { "*****@*****.**", "*****@*****.**" }; var description = "This hook was created to test the .NET client."; var hookToCreate = new EmailNotificationHook(hookName, emailsToAlert); await using var disposableHook = await DisposableNotificationHook.CreateHookAsync(adminClient, hookToCreate); // Update the created hook. var hookToUpdate = (await adminClient.GetHookAsync(disposableHook.Id)).Value as EmailNotificationHook; hookToUpdate.Description = description; hookToUpdate.ExternalLink = "http://fake.endpoint.com"; hookToUpdate.EmailsToAlert.Add("*****@*****.**"); await adminClient.UpdateHookAsync(disposableHook.Id, hookToUpdate); // Get the hook and check if updates are in place. var updatedEmailHook = (await adminClient.GetHookAsync(disposableHook.Id)).Value as EmailNotificationHook; Assert.That(updatedEmailHook.Id, Is.EqualTo(disposableHook.Id)); Assert.That(updatedEmailHook.Name, Is.EqualTo(hookName)); Assert.That(updatedEmailHook.Description, Is.EqualTo(description)); Assert.That(updatedEmailHook.ExternalLink, Is.EqualTo("http://fake.endpoint.com")); Assert.That(updatedEmailHook.Administrators, Is.Not.Null); Assert.That(updatedEmailHook.Administrators.Single(), Is.Not.Null.And.Not.Empty); var expectedEmailsToAlert = new List <string>() { "*****@*****.**", "*****@*****.**", "*****@*****.**" }; Assert.That(updatedEmailHook.EmailsToAlert, Is.EquivalentTo(expectedEmailsToAlert)); }
public void GetHookRespectsTheCancellationToken() { MetricsAdvisorAdministrationClient adminClient = GetMetricsAdvisorAdministrationClient(); using var cancellationSource = new CancellationTokenSource(); cancellationSource.Cancel(); Assert.That(() => adminClient.GetHookAsync(FakeGuid, cancellationSource.Token), Throws.InstanceOf <OperationCanceledException>()); Assert.That(() => adminClient.GetHook(FakeGuid, cancellationSource.Token), Throws.InstanceOf <OperationCanceledException>()); }
public async Task UpdateEmailNotificationHookWithMinimumSetupAndGetInstance(bool useTokenCredential) { // Create a hook. MetricsAdvisorAdministrationClient adminClient = GetMetricsAdvisorAdministrationClient(useTokenCredential); string hookName = Recording.GenerateAlphaNumericId("hook"); var hookToCreate = new EmailNotificationHook() { Name = hookName, EmailsToAlert = { "*****@*****.**", "*****@*****.**" } }; await using var disposableHook = await DisposableNotificationHook.CreateHookAsync(adminClient, hookToCreate); // Update the created hook. var hookToUpdate = (await adminClient.GetHookAsync(disposableHook.Id)).Value as EmailNotificationHook; hookToUpdate.EmailsToAlert.Add("*****@*****.**"); await adminClient.UpdateHookAsync(disposableHook.Id, hookToUpdate); // Get the hook and check if updates are in place. var updatedEmailHook = (await adminClient.GetHookAsync(disposableHook.Id)).Value as EmailNotificationHook; Assert.That(updatedEmailHook.Id, Is.EqualTo(disposableHook.Id)); Assert.That(updatedEmailHook.Name, Is.EqualTo(hookName)); Assert.That(updatedEmailHook.Description, Is.Empty); Assert.That(updatedEmailHook.ExternalLink, Is.Empty); Assert.That(updatedEmailHook.Administrators, Is.Not.Null); Assert.That(updatedEmailHook.Administrators.Single(), Is.Not.Null.And.Not.Empty); var expectedEmailsToAlert = new List <string>() { "*****@*****.**", "*****@*****.**", "*****@*****.**" }; Assert.That(updatedEmailHook.EmailsToAlert, Is.EquivalentTo(expectedEmailsToAlert)); }
public async Task UpdateWebNotificationHookWithMinimumSetupAndGetInstance() { // Create a hook. MetricsAdvisorAdministrationClient adminClient = GetMetricsAdvisorAdministrationClient(); string hookName = Recording.GenerateAlphaNumericId("hook"); var hookToCreate = new WebNotificationHook() { Name = hookName, Endpoint = "http://contoso.com" }; await using var disposableHook = await DisposableNotificationHook.CreateHookAsync(adminClient, hookToCreate); // Update the created hook. var hookToUpdate = (await adminClient.GetHookAsync(disposableHook.Id)).Value as WebNotificationHook; hookToUpdate.Username = "******"; await adminClient.UpdateHookAsync(disposableHook.Id, hookToUpdate); // Get the hook and check if updates are in place. var updatedWebHook = (await adminClient.GetHookAsync(disposableHook.Id)).Value as WebNotificationHook; Assert.That(updatedWebHook.Id, Is.EqualTo(disposableHook.Id)); Assert.That(updatedWebHook.Name, Is.EqualTo(hookName)); Assert.That(updatedWebHook.Description, Is.Empty); Assert.That(updatedWebHook.ExternalLink, Is.Empty); Assert.That(updatedWebHook.Administrators, Is.Not.Null); Assert.That(updatedWebHook.Administrators.Single(), Is.Not.Null.And.Not.Empty); Assert.That(updatedWebHook.Endpoint, Is.EqualTo("http://contoso.com")); Assert.That(updatedWebHook.CertificateKey, Is.Empty); Assert.That(updatedWebHook.CertificatePassword, Is.Empty); Assert.That(updatedWebHook.Username, Is.EqualTo("fakeUsername")); Assert.That(updatedWebHook.Password, Is.Empty); Assert.That(updatedWebHook.Headers, Is.Not.Null.And.Empty); }
public async Task CreateAndGetWebNotificationHookWithOptionalMembers() { MetricsAdvisorAdministrationClient adminClient = GetMetricsAdvisorAdministrationClient(); string hookName = Recording.GenerateAlphaNumericId("hook"); var endpoint = new Uri("http://contoso.com/"); var description = "This hook was created to test the .NET client."; var headers = new Dictionary <string, string>() { { "key1", "value1" }, { "key2", "value2" } }; var hookToCreate = new WebNotificationHook() { Name = hookName, Endpoint = endpoint, Description = description, ExternalLink = new Uri("http://fake.endpoint.com/"), // TODO: add CertificateKey validation (https://github.com/Azure/azure-sdk-for-net/issues/17485) CertificatePassword = "******", Username = "******", Password = "******" }; foreach (var header in headers) { hookToCreate.Headers.Add(header); } await using var disposableHook = await DisposableNotificationHook.CreateHookAsync(adminClient, hookToCreate); NotificationHook createdHook = await adminClient.GetHookAsync(disposableHook.Id); Assert.That(createdHook.Id, Is.EqualTo(disposableHook.Id)); Assert.That(createdHook.Name, Is.EqualTo(hookName)); Assert.That(createdHook.Description, Is.EqualTo(description)); Assert.That(createdHook.ExternalLink.AbsoluteUri, Is.EqualTo("http://fake.endpoint.com/")); Assert.That(createdHook.AdministratorsEmails, Is.Not.Null); Assert.That(createdHook.AdministratorsEmails.Single(), Is.Not.Null.And.Not.Empty); var createdWebHook = createdHook as WebNotificationHook; Assert.That(createdWebHook, Is.Not.Null); Assert.That(createdWebHook.Endpoint, Is.EqualTo(endpoint)); // TODO: add CertificateKey validation (https://github.com/Azure/azure-sdk-for-net/issues/17485) Assert.That(createdWebHook.CertificatePassword, Is.EqualTo("certPassword")); Assert.That(createdWebHook.Username, Is.EqualTo("fakeUsername")); Assert.That(createdWebHook.Password, Is.EqualTo("fakePassword")); Assert.That(createdWebHook.Headers, Is.EquivalentTo(headers)); }
public async Task NotificationHookGetsUnknownHook() { MockResponse getResponse = new MockResponse(200); getResponse.SetContent(UnknownHookContent); MetricsAdvisorAdministrationClient adminClient = CreateInstrumentedAdministrationClient(getResponse); NotificationHook hook = await adminClient.GetHookAsync(FakeGuid); Assert.That(hook.Id, Is.EqualTo(FakeGuid)); Assert.That(hook.Name, Is.EqualTo("unknownHookName")); Assert.That(hook.ExternalUri.AbsoluteUri, Is.EqualTo("https://fakeuri.com/")); Assert.That(hook.Description, Is.EqualTo("unknown hook description")); Assert.That(hook.Administrators.Single(), Is.EqualTo("*****@*****.**")); }
public async Task GetHookAsync() { string endpoint = MetricsAdvisorUri; string subscriptionKey = MetricsAdvisorSubscriptionKey; string apiKey = MetricsAdvisorApiKey; var credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey); var adminClient = new MetricsAdvisorAdministrationClient(new Uri(endpoint), credential); string hookId = HookId; Response <NotificationHook> response = await adminClient.GetHookAsync(hookId); NotificationHook hook = response.Value; Console.WriteLine($"Hook name: {hook.Name}"); Console.WriteLine($"Hook description: {hook.Description}"); Console.WriteLine($"Hook administrators emails:"); foreach (string admin in hook.AdministratorsEmails) { Console.WriteLine($" - {admin}"); } if (hook.HookType == HookType.Email) { EmailNotificationHook emailHook = hook as EmailNotificationHook; Console.WriteLine("Emails to alert:"); foreach (string email in emailHook.EmailsToAlert) { Console.WriteLine($" - {email}"); } } else if (hook.HookType == HookType.Webhook) { WebNotificationHook webHook = hook as WebNotificationHook; Console.WriteLine($"Username: {webHook.Username}"); } }