示例#1
0
        public void ResourceGroupGetValidateMessage()
        {
            var response = new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StringContent(@"{
                    'id': '/subscriptions/abc123/resourcegroups/csmrgr5mfggio',
                    'name': 'foo',
                    'location': 'WestEurope',
                    'properties': {
                        'provisioningState': 'Succeeded'
                     }
                }")
            };

            response.Headers.Add("x-ms-request-id", "1");
            var handler = new RecordedDelegatingHandler(response)
            {
                StatusCodeToReturn = HttpStatusCode.OK
            };
            var client = GetResourceManagementClient(handler);

            ResourceGroupGetResult result = client.ResourceGroups.Get("foo");

            // Validate headers
            Assert.Equal(HttpMethod.Get, handler.Method);
            Assert.NotNull(handler.RequestHeaders.GetValues("Authorization"));

            // Validate result
            Assert.Equal("/subscriptions/abc123/resourcegroups/csmrgr5mfggio", result.ResourceGroup.Id);
            Assert.Equal("WestEurope", result.ResourceGroup.Location);
            Assert.Equal("foo", result.ResourceGroup.Name);
            Assert.Equal("Succeeded", result.ResourceGroup.ProvisioningState);
            Assert.True(result.ResourceGroup.Properties.Contains("provisioningState"));
        }
        public void TryCreateResourceGroup(string resourceGroupName, string location)
        {
            // get the resource group first
            bool exists = false;
            ResourceGroupGetResult newlyCreatedGroup = null;

            try
            {
                newlyCreatedGroup = resourceManagementClient.ResourceGroups.Get(resourceGroupName);
                exists            = true;
            }
            catch
            {
                // do nothing because it means it doesn't exist
            }

            if (!exists)
            {
                ResourceGroupCreateOrUpdateResult result =
                    resourceManagementClient.ResourceGroups.CreateOrUpdate(resourceGroupName,
                                                                           new ResourceGroup {
                    Location = location
                });
                newlyCreatedGroup = resourceManagementClient.ResourceGroups.Get(resourceGroupName);
            }

            ThrowIfTrue(newlyCreatedGroup == null, "resourceManagementClient.ResourceGroups.Get returned null.");
            ThrowIfTrue(!resourceGroupName.Equals(newlyCreatedGroup.ResourceGroup.Name),
                        string.Format("resourceGroupName is not equal to {0}", resourceGroupName));
        }
示例#3
0
        public async Task GetResourceGroup()
        {
            string token = await GetToken();

            var rmClient = new ResourceManagementClient(new TokenCloudCredentials(adApplication.Subscription, token));
            ResourceGroupGetResult result = await rmClient.ResourceGroups.GetAsync("jatestgroup");
        }