public void UpdateActivityLogAlertTest() { ActivityLogAlertResource expectedParameters = GetCreateOrUpdateActivityLogAlertParameter(); var handler = new RecordedDelegatingHandler(); var monitorManagementClient = GetMonitorManagementClient(handler); var serializedObject = Microsoft.Rest.Serialization.SafeJsonConvert.SerializeObject(expectedParameters, monitorManagementClient.SerializationSettings); serializedObject = serializedObject.Replace("{", "{\"name\":\"" + expectedParameters.Name + "\",\"id\":\"" + expectedParameters.Id + "\","); var expectedResponse = new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent(serializedObject) }; handler = new RecordedDelegatingHandler(expectedResponse); monitorManagementClient = GetMonitorManagementClient(handler); AlertRulePatchObject bodyParameter = new AlertRulePatchObject { Enabled = true, Tags = null }; ActivityLogAlertResource response = monitorManagementClient.ActivityLogAlerts.Update( resourceGroupName: "rg1", activityLogAlertName: "name1", activityLogAlertRulePatch: bodyParameter); AreEqual(expectedParameters, response); }
public void CreateGetListUpdateDeleteActivityLogAlert() { using (MockContext context = MockContext.Start(this.GetType())) { var insightsClient = GetMonitorManagementClient(context, handler); this.VerifyExistenceOrCreateResourceGroup(resourceGroupName: ResourceGroupName, location: Location); ActivityLogAlertResource bodyParameter = GetCreateOrUpdateActivityLogAlertParameter(insightsClient.SubscriptionId); ActivityLogAlertResource result = insightsClient.ActivityLogAlerts.CreateOrUpdate( resourceGroupName: ResourceGroupName, activityLogAlertName: ActivityLogRuleName, activityLogAlertRule: bodyParameter); if (!this.IsRecording) { // TODO: Create a Check Assert.False(string.IsNullOrWhiteSpace(result.Id)); Assert.Equal(ActivityLogRuleName, result.Name); Assert.NotNull(result.Actions); Assert.NotNull(result.Condition); Assert.NotNull(result.Scopes); // AreEqual(bodyParameter, result); } ActivityLogAlertResource activityLogAlert = insightsClient.ActivityLogAlerts.Get( resourceGroupName: ResourceGroupName, activityLogAlertName: ActivityLogRuleName); if (!this.IsRecording) { Utilities.AreEqual(result, activityLogAlert); } IEnumerable <ActivityLogAlertResource> actualGroups = insightsClient.ActivityLogAlerts.ListBySubscriptionId(); if (!this.IsRecording) { var listActualGroups = actualGroups.ToList(); Assert.NotNull(listActualGroups); Assert.True(listActualGroups.Count > 0); ActivityLogAlertResource similar = listActualGroups.FirstOrDefault(a => string.Equals(a.Id, activityLogAlert.Id, StringComparison.OrdinalIgnoreCase)); Assert.NotNull(similar); // AreEqual(bodyParameter, actualGroups.ToList()); } actualGroups = insightsClient.ActivityLogAlerts.ListByResourceGroup(resourceGroupName: ResourceGroupName); if (!this.IsRecording) { var listActualGroups = actualGroups.ToList(); Assert.NotNull(listActualGroups); Assert.True(listActualGroups.Count > 0); ActivityLogAlertResource similar = listActualGroups.FirstOrDefault(a => string.Equals(a.Id, activityLogAlert.Id, StringComparison.OrdinalIgnoreCase)); Assert.NotNull(similar); // AreEqual(bodyParameter, actualGroups.ToList()); } // TODO: Verify: Actions cannot be null or the request fails with BadRequest AlertRulePatchObject patchBodyParameter = new AlertRulePatchObject { Enabled = true, Tags = null }; ActivityLogAlertResource patchResponse = null; Assert.Throws <ErrorResponseException>( () => patchResponse = insightsClient.ActivityLogAlerts.Update( resourceGroupName: ResourceGroupName, activityLogAlertName: ActivityLogRuleName, activityLogAlertRulePatch: patchBodyParameter)); if (!this.IsRecording && patchResponse != null) { // Use Check here too Assert.False(string.IsNullOrWhiteSpace(patchResponse.Id)); Assert.Equal(ActivityLogRuleName, patchResponse.Name); Assert.NotNull(patchResponse.Actions); Assert.NotNull(patchResponse.Condition); Assert.NotNull(patchResponse.Scopes); Assert.True(patchResponse.Enabled); Assert.Null(patchResponse.Tags); Assert.Equal(activityLogAlert.Id, patchResponse.Id); // AreEqual(bodyParameter, response); } AzureOperationResponse deleteResponse = insightsClient.ActivityLogAlerts.DeleteWithHttpMessagesAsync( resourceGroupName: ResourceGroupName, activityLogAlertName: ActivityLogRuleName).Result; if (!this.IsRecording) { Assert.Equal(HttpStatusCode.OK, deleteResponse.Response.StatusCode); } } }
/// <summary> /// Updates 'tags' and 'enabled' fields in an existing Alert rule. This method /// is used to update the Alert rule tags, and to enable or disable the Alert /// rule. To update other fields use CreateOrUpdate operation. /// </summary> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='resourceGroupName'> /// The name of the resource group. The name is case insensitive. /// </param> /// <param name='activityLogAlertName'> /// The name of the Activity Log Alert rule. /// </param> /// <param name='activityLogAlertRulePatch'> /// Parameters supplied to the operation. /// </param> /// <param name='cancellationToken'> /// The cancellation token. /// </param> public static async Task <ActivityLogAlertResource> UpdateAsync(this IActivityLogAlertsOperations operations, string resourceGroupName, string activityLogAlertName, AlertRulePatchObject activityLogAlertRulePatch, CancellationToken cancellationToken = default(CancellationToken)) { using (var _result = await operations.UpdateWithHttpMessagesAsync(resourceGroupName, activityLogAlertName, activityLogAlertRulePatch, null, cancellationToken).ConfigureAwait(false)) { return(_result.Body); } }
/// <summary> /// Updates 'tags' and 'enabled' fields in an existing Alert rule. This method /// is used to update the Alert rule tags, and to enable or disable the Alert /// rule. To update other fields use CreateOrUpdate operation. /// </summary> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='resourceGroupName'> /// The name of the resource group. The name is case insensitive. /// </param> /// <param name='activityLogAlertName'> /// The name of the Activity Log Alert rule. /// </param> /// <param name='activityLogAlertRulePatch'> /// Parameters supplied to the operation. /// </param> public static ActivityLogAlertResource Update(this IActivityLogAlertsOperations operations, string resourceGroupName, string activityLogAlertName, AlertRulePatchObject activityLogAlertRulePatch) { return(operations.UpdateAsync(resourceGroupName, activityLogAlertName, activityLogAlertRulePatch).GetAwaiter().GetResult()); }