Exemple #1
0
        public DisableAzureRmActivityLogAlertTests(Xunit.Abstractions.ITestOutputHelper output)
        {
            ServiceManagemenet.Common.Models.XunitTracingInterceptor.AddToContext(new ServiceManagemenet.Common.Models.XunitTracingInterceptor(output));
            TestExecutionHelpers.SetUpSessionAndProfile();
            insightsOperationsMock = new Mock <IActivityLogAlertsOperations>();
            monitorClientMock      = new Mock <MonitorManagementClient>();
            commandRuntimeMock     = new Mock <ICommandRuntime>();
            cmdlet = new DisableAzureRmActivityLogAlertCommand()
            {
                CommandRuntime          = commandRuntimeMock.Object,
                MonitorManagementClient = monitorClientMock.Object
            };

            response = new AzureOperationResponse <ActivityLogAlertResource>()
            {
                Body = ActivityLogAlertsUtilities.CreateActivityLogAlertResource(location: "westus", name: "alert1")
            };

            insightsOperationsMock.Setup(f => f.UpdateWithHttpMessagesAsync(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <ActivityLogAlertPatchBody>(), It.IsAny <Dictionary <string, List <string> > >(), It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult <AzureOperationResponse <ActivityLogAlertResource> >(response))
            .Callback((string r, string n, ActivityLogAlertPatchBody b, Dictionary <string, List <string> > headers, CancellationToken t) =>
            {
                this.resourceGroup = r;
                this.name          = n;
                this.body          = b;
            });

            monitorClientMock.SetupGet(f => f.ActivityLogAlerts).Returns(this.insightsOperationsMock.Object);

            // Setup Confirmation
            commandRuntimeMock.Setup(f => f.ShouldProcess(It.IsAny <string>())).Returns(true);
            commandRuntimeMock.Setup(f => f.ShouldProcess(It.IsAny <string>(), It.IsAny <string>())).Returns(true);
            commandRuntimeMock.Setup(f => f.ShouldProcess(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>())).Returns(true);
            commandRuntimeMock.Setup(f => f.ShouldContinue(It.IsAny <string>(), It.IsAny <string>())).Returns(true);
        }
Exemple #2
0
        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);

            ActivityLogAlertPatchBody bodyParameter = new ActivityLogAlertPatchBody
            {
                Enabled = true,
                Tags    = null
            };

            ActivityLogAlertResource response = monitorManagementClient.ActivityLogAlerts.Update(
                resourceGroupName: "rg1",
                activityLogAlertName: "name1",
                activityLogAlertPatch: bodyParameter);

            AreEqual(expectedParameters, response);
        }
Exemple #3
0
        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,
                    activityLogAlert: 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
                ActivityLogAlertPatchBody patchBodyParameter = new ActivityLogAlertPatchBody
                {
                    Enabled = true,
                    Tags    = null
                };

                ActivityLogAlertResource patchResponse = null;

                Assert.Throws <ErrorResponseException>(
                    () => patchResponse = insightsClient.ActivityLogAlerts.Update(
                        resourceGroupName: ResourceGroupName,
                        activityLogAlertName: ActivityLogRuleName,
                        activityLogAlertPatch: 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);
                }
            }
        }
Exemple #4
0
 public virtual Response <ActivityLogAlertResource> Update(string resourceGroupName, string activityLogAlertName, ActivityLogAlertPatchBody activityLogAlertPatch, CancellationToken cancellationToken = default)
 {
     using var scope = _clientDiagnostics.CreateScope("ActivityLogAlertsOperations.Update");
     scope.Start();
     try
     {
         return(RestClient.Update(resourceGroupName, activityLogAlertName, activityLogAlertPatch, cancellationToken));
     }
     catch (Exception e)
     {
         scope.Failed(e);
         throw;
     }
 }
Exemple #5
0
 /// <summary>
 /// Updates an existing ActivityLogAlertResource's tags. 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='activityLogAlertName'>
 /// The name of the activity log alert.
 /// </param>
 /// <param name='activityLogAlertPatch'>
 /// 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, ActivityLogAlertPatchBody activityLogAlertPatch, CancellationToken cancellationToken = default(CancellationToken))
 {
     using (var _result = await operations.UpdateWithHttpMessagesAsync(resourceGroupName, activityLogAlertName, activityLogAlertPatch, null, cancellationToken).ConfigureAwait(false))
     {
         return(_result.Body);
     }
 }
Exemple #6
0
 /// <summary>
 /// Updates an existing ActivityLogAlertResource's tags. 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='activityLogAlertName'>
 /// The name of the activity log alert.
 /// </param>
 /// <param name='activityLogAlertPatch'>
 /// Parameters supplied to the operation.
 /// </param>
 public static ActivityLogAlertResource Update(this IActivityLogAlertsOperations operations, string resourceGroupName, string activityLogAlertName, ActivityLogAlertPatchBody activityLogAlertPatch)
 {
     return(operations.UpdateAsync(resourceGroupName, activityLogAlertName, activityLogAlertPatch).GetAwaiter().GetResult());
 }