コード例 #1
0
        private static async Task UpdateCommunicationServiceAsync(CommunicationManagementClient acsClient, string resourceGroupName, string resourceName)
        {
            try
            {
                Utilities.Log("\nCommunicationService Update...");

                // Create a CommunicationServiceResource with the updated resource attributes
                var resource = new CommunicationServiceResource {
                    Location = "global", DataLocation = "UnitedStates"
                };

                var tags = new Dictionary <string, string>();
                tags.Add("ExampleTagName1", "ExampleTagValue1");
                tags.Add("ExampleTagName2", "ExampleTagValue2");

                // Update an existing resource in Azure with the attributes in `resource` and wait for a response
                Utilities.Log("Waiting for acsClient.CommunicationService.StartCreateOrUpdateAsync");
                CommunicationServiceCreateOrUpdateOperation operation = await acsClient.CommunicationService.StartCreateOrUpdateAsync(resourceGroupName, resourceName, resource);

                Utilities.Log("Gained the communicationServiceCreateOrUpdateOperation. Waiting for it to complete...");
                Response <CommunicationServiceResource> response = await operation.WaitForCompletionAsync();

                Utilities.Log("\tresponse: " + response.ToString());
                Utilities.Print(response.Value);
            }
            catch (Exception e)
            {
                Utilities.Log("UpdateCommunicationServiceAsync encountered: " + e.Message);
            }
        }
コード例 #2
0
        public async Task LinkNotificationHub()
        {
            // Setup resource group for the test. This resource group is deleted by CleanupResourceGroupsAsync after the test ends
            Subscription sub = await ResourcesManagementClient.GetDefaultSubscriptionAsync();

            var lro = await sub.GetResourceGroups().CreateOrUpdateAsync(
                NotificationHubsResourceGroupName,
                new ResourceGroupData(Location));

            ResourceGroup rg = lro.Value;

            CommunicationManagementClient acsClient = GetCommunicationManagementClient();
            var resourceName = Recording.GenerateAssetName("sdk-test-link-notif-hub-");

            // Create a new resource with a our test parameters
            CommunicationServiceCreateOrUpdateOperation result = await acsClient.CommunicationService.StartCreateOrUpdateAsync(
                rg.Data.Name,
                resourceName,
                new CommunicationServiceResource { Location = ResourceLocation, DataLocation = ResourceDataLocation });

            await result.WaitForCompletionAsync();

            // Check that our resource has been created successfully
            Assert.IsTrue(result.HasCompleted);
            Assert.IsTrue(result.HasValue);
            CommunicationServiceResource resource = result.Value;

            // Retrieve
            var resourceRetrieved = await acsClient.CommunicationService.GetAsync(rg.Data.Name, resourceName);

            Assert.AreEqual(
                resourceName,
                resourceRetrieved.Value.Name);
            Assert.AreEqual(
                "Succeeded",
                resourceRetrieved.Value.ProvisioningState.ToString());

            // Link NotificationHub
            var linkNotificationHubResponse = await acsClient.CommunicationService.LinkNotificationHubAsync(
                rg.Data.Name,
                resourceName,
                new LinkNotificationHubParameters(NotificationHubsResourceId, NotificationHubsConnectionString));

            Assert.AreEqual(NotificationHubsResourceId, linkNotificationHubResponse.Value.ResourceId);

            // Delete
            CommunicationServiceDeleteOperation deleteResult = await acsClient.CommunicationService.StartDeleteAsync(rg.Data.Name, resourceName);

            await deleteResult.WaitForCompletionAsync();

            // Check that our resource has been deleted successfully
            Assert.IsTrue(deleteResult.HasCompleted);
            Assert.IsTrue(deleteResult.HasValue);
        }
コード例 #3
0
        public async Task CheckNameUniqueness()
        {
            // Setup resource group for the test. This resource group is deleted by CleanupResourceGroupsAsync after the test ends
            Subscription sub = await ResourcesManagementClient.GetDefaultSubscriptionAsync();

            var lro = await sub.GetResourceGroups().CreateOrUpdateAsync(
                Recording.GenerateAssetName(ResourceGroupPrefix),
                new ResourceGroupData(Location));

            ResourceGroup rg = lro.Value;

            CommunicationManagementClient acsClient = GetCommunicationManagementClient();
            var resourceName = Recording.GenerateAssetName("sdk-test-name-availablity-");

            // Check if name is unique
            Response <NameAvailability> nameAvailabilityResult = await acsClient.CommunicationService.CheckNameAvailabilityAsync(new NameAvailabilityParameters("Microsoft.Communication/CommunicationServices", resourceName));

            Assert.IsTrue(nameAvailabilityResult.Value.NameAvailable);

            // Create a new resource with a our test parameters
            CommunicationServiceCreateOrUpdateOperation result = await acsClient.CommunicationService.StartCreateOrUpdateAsync(
                rg.Data.Name, resourceName,
                new CommunicationServiceResource { Location = ResourceLocation, DataLocation = ResourceDataLocation });

            await result.WaitForCompletionAsync();

            // Check that our resource has been created successfully
            Assert.IsTrue(result.HasCompleted);
            Assert.IsTrue(result.HasValue);
            CommunicationServiceResource resource = result.Value;

            // Retrieve
            var resourceRetrieved = await acsClient.CommunicationService.GetAsync(rg.Data.Name, resourceName);

            Assert.AreEqual(
                resourceName,
                resourceRetrieved.Value.Name);
            Assert.AreEqual(
                "Succeeded",
                resourceRetrieved.Value.ProvisioningState.ToString());

            // Check if name is unique
            nameAvailabilityResult = await acsClient.CommunicationService.CheckNameAvailabilityAsync(new NameAvailabilityParameters("Microsoft.Communication/CommunicationServices", resourceName));

            Assert.IsFalse(nameAvailabilityResult.Value.NameAvailable);
        }
コード例 #4
0
        public async Task ListByRg()
        {
            // Setup resource group for the test. This resource group is deleted by CleanupResourceGroupsAsync after the test ends
            Subscription sub = await ResourcesManagementClient.GetDefaultSubscriptionAsync();

            var lro = await sub.GetResourceGroups().CreateOrUpdateAsync(
                Recording.GenerateAssetName(ResourceGroupPrefix),
                new ResourceGroupData(Location));

            ResourceGroup rg = lro.Value;

            // Create a new resource with the test parameters
            CommunicationManagementClient acsClient = GetCommunicationManagementClient();
            var resourceName = Recording.GenerateAssetName("sdk-test-list-by-rg-");
            var testResource = new CommunicationServiceResource {
                Location = ResourceLocation, DataLocation = ResourceDataLocation
            };

            CommunicationServiceCreateOrUpdateOperation result = await acsClient.CommunicationService.StartCreateOrUpdateAsync(
                rg.Data.Name,
                resourceName,
                testResource);

            await result.WaitForCompletionAsync();

            Assert.IsTrue(result.HasCompleted);
            Assert.IsTrue(result.HasValue);

            // Verify that the resource we just created is in the list
            var  resources     = acsClient.CommunicationService.ListByResourceGroupAsync(rg.Data.Name);
            bool resourceFound = false;

            await foreach (var resource in resources)
            {
                if (resource.Name.Equals(resourceName))
                {
                    resourceFound = true;
                    break;
                }
            }
            Assert.True(resourceFound);
        }
コード例 #5
0
        public async Task CrudSimpleResource()
        {
            // Setup resource group for the test. This resource group is deleted by CleanupResourceGroupsAsync after the test ends
            ResourceGroup rg = await ResourcesManagementClient.ResourceGroups.CreateOrUpdateAsync(
                Recording.GenerateAssetName(ResourceGroupPrefix),
                new ResourceGroup(Location));

            CommunicationManagementClient acsClient = GetCommunicationManagementClient();
            var resourceName = Recording.GenerateAssetName("sdk-test-crud-simple-");

            // Create a new resource with a our test parameters
            CommunicationServiceCreateOrUpdateOperation result = await acsClient.CommunicationService.StartCreateOrUpdateAsync(
                rg.Name,
                resourceName,
                new CommunicationServiceResource { Location = ResourceLocation, DataLocation = ResourceDataLocation });

            await result.WaitForCompletionAsync();

            // Check that our resource has been created successfully
            Assert.IsTrue(result.HasCompleted);
            Assert.IsTrue(result.HasValue);
            CommunicationServiceResource resource = result.Value;

            // Check that the keys are there.
            // Note: These values have been sanitized.
            var keys = await acsClient.CommunicationService.ListKeysAsync(rg.Name, resourceName);

            Assert.NotNull(keys.Value.PrimaryKey);
            Assert.NotNull(keys.Value.SecondaryKey);
            Assert.NotNull(keys.Value.PrimaryConnectionString);
            Assert.NotNull(keys.Value.SecondaryConnectionString);

            keys = await acsClient.CommunicationService.RegenerateKeyAsync(rg.Name, resourceName, new RegenerateKeyParameters { KeyType = KeyType.Primary });

            Assert.NotNull(keys.Value.PrimaryKey);
            Assert.Null(keys.Value.SecondaryKey);
            Assert.NotNull(keys.Value.PrimaryConnectionString);
            Assert.Null(keys.Value.SecondaryConnectionString);

            keys = await acsClient.CommunicationService.RegenerateKeyAsync(rg.Name, resourceName, new RegenerateKeyParameters { KeyType = KeyType.Secondary });

            Assert.Null(keys.Value.PrimaryKey);
            Assert.NotNull(keys.Value.SecondaryKey);
            Assert.Null(keys.Value.PrimaryConnectionString);
            Assert.NotNull(keys.Value.SecondaryConnectionString);

            // Retrieve
            var resourceRetrieved = await acsClient.CommunicationService.GetAsync(rg.Name, resourceName);

            Assert.AreEqual(
                resourceName,
                resourceRetrieved.Value.Name);
            Assert.AreEqual(
                "Succeeded",
                resourceRetrieved.Value.ProvisioningState.ToString());

            // Update
            CommunicationServiceResource emptyResource = new CommunicationServiceResource();

            resource = await acsClient.CommunicationService.UpdateAsync(
                rg.Name,
                resourceName,
                emptyResource);

            Assert.True(resource.Tags.Count == 0);

            // Delete
            CommunicationServiceDeleteOperation deleteResult = await acsClient.CommunicationService.StartDeleteAsync(rg.Name, resourceName);

            await deleteResult.WaitForCompletionAsync();

            // Check that our resource has been deleted successfully
            Assert.IsTrue(deleteResult.HasCompleted);
            Assert.IsTrue(deleteResult.HasValue);
        }
コード例 #6
0
        public async Task CrudResourceWithTags()
        {
            // Setup resource group for the test. This resource group is deleted by CleanupResourceGroupsAsync after the test ends
            ResourceGroup rg = await ResourcesManagementClient.ResourceGroups.CreateOrUpdateAsync(
                Recording.GenerateAssetName(ResourceGroupPrefix),
                new ResourceGroup(Location));

            CommunicationManagementClient acsClient = GetCommunicationManagementClient();
            var resourceName = Recording.GenerateAssetName("sdk-test-crud-with-tags-");

            // Create a new resource with a our test parameters
            CommunicationServiceResource serviceResource = new CommunicationServiceResource {
                Location = ResourceLocation, DataLocation = ResourceDataLocation
            };

            serviceResource.Tags.Add("tag1", "tag1val");
            serviceResource.Tags.Add("tag2", "tag2val");
            CommunicationServiceCreateOrUpdateOperation result = await acsClient.CommunicationService.StartCreateOrUpdateAsync(
                rg.Name,
                resourceName,
                serviceResource);

            await result.WaitForCompletionAsync();

            // Check that our resource has been created successfully
            Assert.IsTrue(result.HasCompleted);
            Assert.IsTrue(result.HasValue);
            CommunicationServiceResource resource = result.Value;

            Assert.AreEqual("tag1val", resource.Tags["tag1"]);
            Assert.AreEqual("tag2val", resource.Tags["tag2"]);
            Assert.IsFalse(resource.Tags.ContainsKey("tag3"));

            // Check that the keys are there.
            // Note: These values have been sanitized.
            var keys = await acsClient.CommunicationService.ListKeysAsync(rg.Name, resourceName);

            Assert.NotNull(keys.Value.PrimaryKey);
            Assert.NotNull(keys.Value.SecondaryKey);
            Assert.NotNull(keys.Value.PrimaryConnectionString);
            Assert.NotNull(keys.Value.SecondaryConnectionString);

            // Retrieve
            var resourceRetrieved = await acsClient.CommunicationService.GetAsync(rg.Name, resourceName);

            Assert.AreEqual(
                resourceName,
                resourceRetrieved.Value.Name);
            Assert.AreEqual(
                "Succeeded",
                resourceRetrieved.Value.ProvisioningState.ToString());;
            Assert.AreEqual(
                resource.Tags as IEnumerable <KeyValuePair <string, string> >,
                resourceRetrieved.Value.Tags as IEnumerable <KeyValuePair <string, string> >);

            // Update
            resource.Tags.Remove("tag1");
            resource.Tags["tag2"] = "tag2newval";
            resource.Tags.Add("tag3", "tag3val");

            resource = await acsClient.CommunicationService.UpdateAsync(
                rg.Name,
                resourceName,
                resource);

            Assert.False(resource.Tags.ContainsKey("tag1"));
            Assert.AreEqual("tag2newval", resource.Tags["tag2"]);
            Assert.AreEqual("tag3val", resource.Tags["tag3"]);

            // Delete
            CommunicationServiceDeleteOperation deleteResult = await acsClient.CommunicationService.StartDeleteAsync(rg.Name, resourceName);

            await deleteResult.WaitForCompletionAsync();

            // Check that our resource has been deleted successfully
            Assert.IsTrue(deleteResult.HasCompleted);
            Assert.IsTrue(deleteResult.HasValue);
        }