public async Task DeleteDatasourceCredential()
        {
            MetricsAdvisorAdministrationClient adminClient = GetMetricsAdvisorAdministrationClient();

            var credentialName     = Recording.GenerateAlphaNumericId("credential");
            var credentialToCreate = new ServicePrincipalDatasourceCredential(credentialName, "clientId", "clientSecret", "tenantId");

            string credentialId = null;

            try
            {
                DatasourceCredential createdCredential = await adminClient.CreateDatasourceCredentialAsync(credentialToCreate);

                credentialId = createdCredential.Id;

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

                    var errorCause = "credentialId is invalid";
                    Assert.That(async() => await adminClient.GetDatasourceCredentialAsync(credentialId), Throws.InstanceOf <RequestFailedException>().With.Message.Contains(errorCause));
                }
            }
        }
Exemple #2
0
        public void UpdateDatasourceCredentialValidatesArguments()
        {
            MetricsAdvisorAdministrationClient adminClient = GetMetricsAdvisorAdministrationClient();

            Assert.That(() => adminClient.UpdateDatasourceCredentialAsync(null), Throws.InstanceOf <ArgumentNullException>());
            Assert.That(() => adminClient.UpdateDatasourceCredential(null), Throws.InstanceOf <ArgumentNullException>());

            var credentialWithNullId = new ServicePrincipalDatasourceCredential("name", "clientId", "clientSecret", "tenantId");

            Assert.That(() => adminClient.UpdateDatasourceCredentialAsync(credentialWithNullId), Throws.InstanceOf <ArgumentNullException>());
            Assert.That(() => adminClient.UpdateDatasourceCredential(credentialWithNullId), Throws.InstanceOf <ArgumentNullException>());
        }
Exemple #3
0
        public void CreateDatasourceCredentialRespectsTheCancellationToken()
        {
            MetricsAdvisorAdministrationClient adminClient = GetMetricsAdvisorAdministrationClient();

            var credential = new ServicePrincipalDatasourceCredential("credentialName", "clientId", "clientSecret", "tenantId");

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

            Assert.That(() => adminClient.CreateDatasourceCredentialAsync(credential, cancellationSource.Token), Throws.InstanceOf <OperationCanceledException>());
            Assert.That(() => adminClient.CreateDatasourceCredential(credential, cancellationSource.Token), Throws.InstanceOf <OperationCanceledException>());
        }
        public async Task UpdateServicePrincipalDatasourceCredential()
        {
            MetricsAdvisorAdministrationClient adminClient = GetMetricsAdvisorAdministrationClient();

            string credentialName = Recording.GenerateAlphaNumericId("credential");

            DatasourceCredential credentialToCreate = new ServicePrincipalDatasourceCredential(credentialName, "mock", "mock", "mock");

            await using var disposableCredential = await DisposableDatasourceCredential.CreateDatasourceCredentialAsync(adminClient, credentialToCreate);

            var credentialToUpdate = disposableCredential.Credential as ServicePrincipalDatasourceCredential;

            credentialToUpdate.ClientId = ClientId;
            credentialToUpdate.TenantId = TenantId;

            var updatedCredential = (await adminClient.UpdateDatasourceCredentialAsync(credentialToUpdate)).Value as ServicePrincipalDatasourceCredential;

            Assert.That(updatedCredential.ClientId, Is.EqualTo(ClientId));
            Assert.That(updatedCredential.TenantId, Is.EqualTo(TenantId));
        }