Ejemplo n.º 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);
        }
        public void SetActivityLogAlertCommandParametersProcessing()
        {
            cmdlet.Name = "ActivityLogAlertName";
            cmdlet.ResourceGroupName = Utilities.ResourceGroup;
            cmdlet.Location          = Location;
            cmdlet.Scope             = new List <string> {
                "scope1"
            };
            cmdlet.Action = new List <Management.Monitor.Management.Models.ActivityLogAlertActionGroup>
            {
                ActivityLogAlertsUtilities.CreateActionGroup(
                    id: "ActGrpId",
                    webhooks: new Dictionary <string, string> {
                    { "key1", "value1" }
                })
            };
            cmdlet.Condition = new List <Management.Monitor.Management.Models.ActivityLogAlertLeafCondition>
            {
                ActivityLogAlertsUtilities.CreateLeafCondition(
                    field: "field",
                    equals: "equals")
            };
            cmdlet.ExecuteCmdlet();

            Assert.Equal(Utilities.ResourceGroup, this.resourceGroup);
            Assert.Equal("ActivityLogAlertName", this.name);
            Assert.Null(this.createOrUpdatePrms.Id);
            Assert.Equal(Location, this.createOrUpdatePrms.Location);
            Assert.NotNull(this.createOrUpdatePrms);
            Assert.NotNull(this.createOrUpdatePrms.Actions);
            Assert.NotNull(this.createOrUpdatePrms.Actions.ActionGroups);
            Assert.Equal(1, this.createOrUpdatePrms.Actions.ActionGroups.Count);
            Assert.Equal("ActGrpId", this.createOrUpdatePrms.Actions.ActionGroups[0].ActionGroupId);
            Assert.NotNull(this.createOrUpdatePrms.Actions.ActionGroups[0].WebhookProperties);
            Assert.True(this.createOrUpdatePrms.Actions.ActionGroups[0].WebhookProperties.ContainsKey("key1"));

            Assert.NotNull(this.createOrUpdatePrms.Condition);
            Assert.NotNull(this.createOrUpdatePrms.Condition.AllOf);
            Assert.Equal(1, this.createOrUpdatePrms.Condition.AllOf.Count);
            Assert.Equal("field", this.createOrUpdatePrms.Condition.AllOf[0].Field);
            Assert.Equal("equals", this.createOrUpdatePrms.Condition.AllOf[0].Equals);

            Assert.True(this.createOrUpdatePrms.Enabled);
            Assert.Null(this.createOrUpdatePrms.Description);
            Assert.Null(this.createOrUpdatePrms.Type);
            Assert.Null(this.createOrUpdatePrms.Tags);

            cmdlet.DisableAlert = SwitchParameter.Present;
            cmdlet.Description  = "description";
            cmdlet.Tag          = new Dictionary <string, string>();
            cmdlet.ExecuteCmdlet();

            Assert.False(this.createOrUpdatePrms.Enabled);
            Assert.Equal("description", this.createOrUpdatePrms.Description);
            Assert.Null(this.createOrUpdatePrms.Type);
            Assert.NotNull(this.createOrUpdatePrms.Tags);
        }
        public GetAzureRmActivityLogAlertTests(Xunit.Abstractions.ITestOutputHelper output)
        {
            ServiceManagemenet.Common.Models.XunitTracingInterceptor.AddToContext(new ServiceManagemenet.Common.Models.XunitTracingInterceptor(output));
            TestExecutionHelpers.SetUpSessionAndProfile();
            insightsOperationsMock       = new Mock <IActivityLogAlertsOperations>();
            insightsManagementClientMock = new Mock <MonitorManagementClient>()
            {
                CallBase = true
            };
            commandRuntimeMock = new Mock <ICommandRuntime>();
            cmdlet             = new GetAzureRmActivityLogAlertCommand()
            {
                CommandRuntime          = commandRuntimeMock.Object,
                MonitorManagementClient = insightsManagementClientMock.Object
            };

            ActivityLogAlertResource responseObject = ActivityLogAlertsUtilities.CreateActivityLogAlertResource(location: "westus", name: "alert1");

            responseSimple = new AzureOperationResponse <ActivityLogAlertResource>()
            {
                Body = responseObject
            };

            responsePage = new AzureOperationResponse <IEnumerable <ActivityLogAlertResource> >()
            {
                Body = new List <ActivityLogAlertResource> {
                    responseObject
                }
            };

            insightsOperationsMock.Setup(f => f.GetWithHttpMessagesAsync(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <Dictionary <string, List <string> > >(), It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult <AzureOperationResponse <ActivityLogAlertResource> >(responseSimple))
            .Callback((string resourceGrp, string name, Dictionary <string, List <string> > headers, CancellationToken t) =>
            {
                this.resourceGroup = resourceGrp;
                this.name          = name;
            });

            insightsOperationsMock.Setup(f => f.ListByResourceGroupWithHttpMessagesAsync(It.IsAny <string>(), It.IsAny <Dictionary <string, List <string> > >(), It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult <AzureOperationResponse <IEnumerable <ActivityLogAlertResource> > >(responsePage))
            .Callback((string resourceGrp, Dictionary <string, List <string> > headers, CancellationToken t) =>
            {
                this.resourceGroup = resourceGrp;
            });

            insightsOperationsMock.Setup(f => f.ListBySubscriptionIdWithHttpMessagesAsync(It.IsAny <Dictionary <string, List <string> > >(), It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult <AzureOperationResponse <IEnumerable <ActivityLogAlertResource> > >(responsePage))
            .Callback((Dictionary <string, List <string> > headers, CancellationToken t) =>
                      {});

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