public void UpdateSettingTest()
        {
            AutoscaleSettingResource resource = CreateAutoscaleSetting(location: "East US", resourceUri: ResourceUri, metricName: "CpuPercentage");

            resource.Tags = new Dictionary <string, string>
            {
                { "key2", "val2" }
            };
            resource.Enabled = false;

            var handler = new RecordedDelegatingHandler();
            var monitorManagementClient = GetMonitorManagementClient(handler);
            var serializedObject        = Microsoft.Rest.Serialization.SafeJsonConvert.SerializeObject(resource, monitorManagementClient.SerializationSettings);

            serializedObject = serializedObject.Replace("{", "{\"name\":\"" + resource.Name + "\",\"id\":\"" + resource.Id + "\",");
            var expectedResponse = new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StringContent(serializedObject)
            };

            handler = new RecordedDelegatingHandler(expectedResponse);
            monitorManagementClient = GetMonitorManagementClient(handler);

            AutoscaleSettingResourcePatch pathResource = new AutoscaleSettingResourcePatch(
                name: resource.Name,
                tags: new Dictionary <string, string>
            {
                { "key2", "val2" }
            },
                notifications: resource.Notifications,
                enabled: false,
                profiles: resource.Profiles,
                targetResourceUri: resource.TargetResourceUri
                );

            var actualResponse = monitorManagementClient.AutoscaleSettings.Update(resourceGroupName: "resourceGroup1", autoscaleSettingName: "setting1", autoscaleSettingResource: pathResource);

            Utilities.AreEqual(resource, actualResponse);
        }
示例#2
0
        public void MetricBasedFixedAndRecurrent()
        {
            using (MockContext context = MockContext.Start(this.GetType()))
            {
                // NOTE: checking the existence of the resource group here is not that useful since the scale set must also exist
                var insightsClient = GetMonitorManagementClient(context, handler);
                this.VerifyExistenceOrCreateResourceGroup(resourceGroupName: ResourceGroup, location: Location);

                AutoscaleSettingResource body = CreateAutoscaleSetting(
                    location: Location,
                    resourceUri: string.Format(
                        provider: CultureInfo.InvariantCulture,
                        format: ResourceUri,
                        args: insightsClient.SubscriptionId),
                    metricName: "Percentage CPU");
                AutoscaleSettingResource actualResponse = insightsClient.AutoscaleSettings.CreateOrUpdate(
                    resourceGroupName: ResourceGroup,
                    autoscaleSettingName: SettingName,
                    parameters: body);

                if (!this.IsRecording)
                {
                    Check(actualResponse);
                }

                // Retrieve the setting created above
                AutoscaleSettingResource recoveredSetting = insightsClient.AutoscaleSettings.Get(
                    resourceGroupName: ResourceGroup,
                    autoscaleSettingName: SettingName);

                if (!this.IsRecording)
                {
                    Check(recoveredSetting);

                    // Compare the two of them
                    Utilities.AreEqual(actualResponse, recoveredSetting);
                }

                var newTags = new Dictionary <string, string>
                {
                    { "key2", "val2" }
                };

                // Update the setting created above
                // TODO: File bug since the request fails due to 'invalid location'
                AutoscaleSettingResourcePatch pathResource = new AutoscaleSettingResourcePatch(
                    name: recoveredSetting.Name,
                    tags: newTags,
                    notifications: recoveredSetting.Notifications,
                    enabled: !recoveredSetting.Enabled,
                    profiles: recoveredSetting.Profiles,
                    targetResourceUri: recoveredSetting.TargetResourceUri
                    );

                AutoscaleSettingResource updatedSetting = null;
                Assert.Throws <ErrorResponseException>(
                    () => updatedSetting = insightsClient.AutoscaleSettings.Update(
                        resourceGroupName: ResourceGroup,
                        autoscaleSettingName: SettingName,
                        autoscaleSettingResource: pathResource));

                if (!this.IsRecording && updatedSetting != null)
                {
                    Check(updatedSetting);

                    // Check the changes from above
                    Assert.NotEqual(recoveredSetting.Tags, updatedSetting.Tags);
                    Assert.True(recoveredSetting.Enabled = !updatedSetting.Enabled);
                    Assert.Equal(recoveredSetting.Name, updatedSetting.Name);
                    Assert.Equal(recoveredSetting.Location, updatedSetting.Location);
                    Assert.Equal(recoveredSetting.Id, updatedSetting.Id);
                }

                // Retrieve again the setting created above
                AutoscaleSettingResource recoveredUpdatedSetting = insightsClient.AutoscaleSettings.Get(
                    resourceGroupName: ResourceGroup,
                    autoscaleSettingName: SettingName);

                if (!this.IsRecording && updatedSetting != null)
                {
                    Check(recoveredUpdatedSetting);

                    // Compare the two of them
                    Assert.NotEqual(recoveredSetting.Tags, recoveredUpdatedSetting.Tags);
                    Assert.True(recoveredSetting.Enabled = !recoveredUpdatedSetting.Enabled);
                    Assert.Equal(recoveredSetting.Name, recoveredUpdatedSetting.Name);
                    Assert.Equal(recoveredSetting.Location, recoveredUpdatedSetting.Location);
                    Assert.Equal(recoveredSetting.Id, recoveredUpdatedSetting.Id);
                }

                // Remove the setting created above
                insightsClient.AutoscaleSettings.Delete(
                    resourceGroupName: ResourceGroup,
                    autoscaleSettingName: SettingName);

                // Retrieve again the setting created above (must fail)
                Assert.Throws <ErrorResponseException>(
                    () => insightsClient.AutoscaleSettings.Get(
                        resourceGroupName: ResourceGroup,
                        autoscaleSettingName: SettingName));
            }
        }
 /// <summary>
 /// Updates an existing AutoscaleSettingsResource. To update other fields use
 /// the CreateOrUpdate method.
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='resourceGroupName'>
 /// The name of the resource group.
 /// </param>
 /// <param name='autoscaleSettingName'>
 /// The autoscale setting name.
 /// </param>
 /// <param name='autoscaleSettingResource'>
 /// Parameters supplied to the operation.
 /// </param>
 /// <param name='cancellationToken'>
 /// The cancellation token.
 /// </param>
 public static async Task <AutoscaleSettingResourceInner> UpdateAsync(this IAutoscaleSettingsOperations operations, string resourceGroupName, string autoscaleSettingName, AutoscaleSettingResourcePatch autoscaleSettingResource, CancellationToken cancellationToken = default(CancellationToken))
 {
     using (var _result = await operations.UpdateWithHttpMessagesAsync(resourceGroupName, autoscaleSettingName, autoscaleSettingResource, null, cancellationToken).ConfigureAwait(false))
     {
         return(_result.Body);
     }
 }
 public virtual Response <AutoscaleSettingResource> Update(string resourceGroupName, string autoscaleSettingName, AutoscaleSettingResourcePatch autoscaleSettingResource, CancellationToken cancellationToken = default)
 {
     using var scope = _clientDiagnostics.CreateScope("AutoscaleSettingsOperations.Update");
     scope.Start();
     try
     {
         return(RestClient.Update(resourceGroupName, autoscaleSettingName, autoscaleSettingResource, cancellationToken));
     }
     catch (Exception e)
     {
         scope.Failed(e);
         throw;
     }
 }
 /// <summary>
 /// Updates an existing AutoscaleSettingsResource. To update other fields use
 /// the CreateOrUpdate method.
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='resourceGroupName'>
 /// The name of the resource group.
 /// </param>
 /// <param name='autoscaleSettingName'>
 /// The autoscale setting name.
 /// </param>
 /// <param name='autoscaleSettingResource'>
 /// Parameters supplied to the operation.
 /// </param>
 public static AutoscaleSettingResource Update(this IAutoscaleSettingsOperations operations, string resourceGroupName, string autoscaleSettingName, AutoscaleSettingResourcePatch autoscaleSettingResource)
 {
     return(operations.UpdateAsync(resourceGroupName, autoscaleSettingName, autoscaleSettingResource).GetAwaiter().GetResult());
 }