public GetAzureRmActionGroupTests(Xunit.Abstractions.ITestOutputHelper output)
        {
            TestExecutionHelpers.SetUpSessionAndProfile();
            insightsOperationsMock       = new Mock <IActionGroupsOperations>();
            insightsManagementClientMock = new Mock <MonitorManagementClient>()
            {
                CallBase = true
            };
            commandRuntimeMock = new Mock <ICommandRuntime>();
            cmdlet             = new GetAzureRmActionGroupCommand()
            {
                CommandRuntime          = commandRuntimeMock.Object,
                MonitorManagementClient = insightsManagementClientMock.Object
            };

            ActionGroupResource responseObject = ActionGroupsUtilities.CreateActionGroupResource(name: "actiongroup1", shortName: "ag1");

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

            responsePage = new AzureOperationResponse <IEnumerable <ActionGroupResource> >()
            {
                Body = new List <ActionGroupResource> {
                    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 <ActionGroupResource> >(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 <ActionGroupResource> > >(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 <ActionGroupResource> > >(responsePage))
            .Callback((Dictionary <string, List <string> > headers, CancellationToken t) =>
                      { });

            insightsManagementClientMock.SetupGet(f => f.ActionGroups).Returns(this.insightsOperationsMock.Object);
        }
Exemplo n.º 2
0
        public void SetActionGroupCommandParametersProcessing()
        {
            cmdlet.Name = "ActionGroupName";
            cmdlet.ResourceGroupName = Utilities.ResourceGroup;
            cmdlet.ShortName         = "AgShortName";
            cmdlet.Receiver          = new List <PSActionGroupReceiverBase>
            {
                new PSEmailReceiver(ActionGroupsUtilities.CreateEmailReceiver(
                                        name: "email",
                                        emailAddress: "*****@*****.**")),
                new PSSmsReceiver(ActionGroupsUtilities.CreateSmsReceiver(
                                      name: "sms",
                                      phoneNumber: "4254251234")),
                new PSWebhookReceiver(ActionGroupsUtilities.CreateWebhookReceiver(
                                          name: "webhook",
                                          serviceUri: "http://test.com")),
            };
            cmdlet.ExecuteCmdlet();

            Assert.Equal(Utilities.ResourceGroup, this.resourceGroup);
            Assert.Equal("ActionGroupName", this.name);
            Assert.Null(this.createOrUpdatePrms.Id);
            Assert.Equal(Location, this.createOrUpdatePrms.Location);
            Assert.Equal("AgShortName", this.createOrUpdatePrms.GroupShortName);

            Assert.Equal(1, this.createOrUpdatePrms.EmailReceivers.Count);
            Assert.Equal("email", this.createOrUpdatePrms.EmailReceivers[0].Name);
            Assert.Equal("*****@*****.**", this.createOrUpdatePrms.EmailReceivers[0].EmailAddress);

            Assert.Equal(1, this.createOrUpdatePrms.SmsReceivers.Count);
            Assert.Equal("sms", this.createOrUpdatePrms.SmsReceivers[0].Name);
            Assert.Equal("1", this.createOrUpdatePrms.SmsReceivers[0].CountryCode);
            Assert.Equal("4254251234", this.createOrUpdatePrms.SmsReceivers[0].PhoneNumber);

            Assert.Equal(1, this.createOrUpdatePrms.WebhookReceivers.Count);
            Assert.Equal("webhook", this.createOrUpdatePrms.WebhookReceivers[0].Name);
            Assert.Equal("http://test.com", this.createOrUpdatePrms.WebhookReceivers[0].ServiceUri);

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

            cmdlet.DisableGroup = true;
            cmdlet.Tag          = new Dictionary <string, string>();
            cmdlet.ExecuteCmdlet();

            Assert.False(this.createOrUpdatePrms.Enabled);
            Assert.Null(this.createOrUpdatePrms.Type);
            Assert.NotNull(this.createOrUpdatePrms.Tags);
        }
        public AddAzureRmActionGroupTests(Xunit.Abstractions.ITestOutputHelper output)
        {
            TestExecutionHelpers.SetUpSessionAndProfile();
            insightsOperationsMock       = new Mock <IActionGroupsOperations>();
            insightsManagementClientMock = new Mock <MonitorManagementClient>()
            {
                CallBase = true
            };
            commandRuntimeMock = new Mock <ICommandRuntime>();
            cmdlet             = new SetAzureRmActionGroupCommand
            {
                CommandRuntime          = commandRuntimeMock.Object,
                MonitorManagementClient = insightsManagementClientMock.Object
            };

            response = new AzureOperationResponse <ActionGroupResource>()
            {
                Body =
                    ActionGroupsUtilities.CreateActionGroupResource(
                        name: "ActionGroupName",
                        shortName: "AgShortName")
            };

            insightsOperationsMock.Setup(f => f.CreateOrUpdateWithHttpMessagesAsync(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <ActionGroupResource>(), It.IsAny <Dictionary <string, List <string> > >(), It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult(response))
            .Callback((string resourceGrp, string name, ActionGroupResource createOrUpdateParams, Dictionary <string, List <string> > headers, CancellationToken t) =>
            {
                this.resourceGroup      = resourceGrp;
                this.name               = name;
                this.createOrUpdatePrms = createOrUpdateParams;
            });

            insightsManagementClientMock.SetupGet(f => f.ActionGroups).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 SetActionGroupCommandParametersProcessing()
        {
            cmdlet.Name = "ActionGroupName";
            cmdlet.ResourceGroupName = Utilities.ResourceGroup;
            cmdlet.ShortName         = "AgShortName";
            cmdlet.Receiver          = new List <PSActionGroupReceiverBase>
            {
                new PSEmailReceiver(
                    ActionGroupsUtilities.CreateEmailReceiver(name: "email", emailAddress: "*****@*****.**")),

                new PSEmailReceiver(
                    ActionGroupsUtilities.CreateEmailReceiver("email1", "*****@*****.**", true)),

                new PSEmailReceiver(
                    ActionGroupsUtilities.CreateEmailReceiver("email2", "*****@*****.**", false)),

                new PSSmsReceiver(
                    ActionGroupsUtilities.CreateSmsReceiver(name: "sms", phoneNumber: "4254251234")),

                new PSWebhookReceiver(
                    ActionGroupsUtilities.CreateWebhookReceiver(name: "webhook", serviceUri: "http://test.com")),

                new PSWebhookReceiver(
                    ActionGroupsUtilities.CreateWebhookReceiver("webhook1", "http://test1.com", true)),

                new PSWebhookReceiver(
                    ActionGroupsUtilities.CreateWebhookReceiver("webhook2", "http://test2.com", true, false)),

                new PSWebhookReceiver(
                    ActionGroupsUtilities.CreateWebhookReceiver("webhook3", "http://test3.com", true, true, "someObjectId", "someIdentifierId", "someTenantId")),

                new PSItsmReceiver(
                    ActionGroupsUtilities.CreateItsmReceiver("itsm", "someWorkspaceId", "someConnectionId", "sometickerConfiguration", "someRegion")),

                new PSVoiceReceiver(
                    ActionGroupsUtilities.CreateVoiceReceiver("voice", "someCountryCode", "somePhoeNumber")),

                new PSArmRoleReceiver(
                    ActionGroupsUtilities.CreateArmRoleReceiver("armRole", "someRoleId")),

                new PSArmRoleReceiver(
                    ActionGroupsUtilities.CreateArmRoleReceiver("armRole1", "someRoleId1", true)),

                new PSAzureFunctionReceiver(
                    ActionGroupsUtilities.CreateAzureFunctionReceiver("azureFunctionReceiver", "somefuncappresourceId", "somefunctionName", "some trigeerURl")),

                new PSAzureFunctionReceiver(
                    ActionGroupsUtilities.CreateAzureFunctionReceiver("azureFunctionReceiver1", "somefuncappresourceId1", "somefunctionName2", "some trigeerURl2", true)),

                new PSLogicAppReceiver(
                    ActionGroupsUtilities.CreateLogicAppReceiver("logicAppReceveir", "someresourceId", "someCallback")),

                new PSLogicAppReceiver(
                    ActionGroupsUtilities.CreateLogicAppReceiver("logicAppReceveir1", "someresourceId1", "someCallback1", true)),

                new PSAutomationRunbookReceiver(
                    ActionGroupsUtilities.CreateAutomationRunbookReceiver("runbookReceiver", "someAutomationId", "someRunbook", "somewebhookresourceId", false, "someServiceUri")),

                new PSAutomationRunbookReceiver(
                    ActionGroupsUtilities.CreateAutomationRunbookReceiver("runbookReceiver1", "someAutomationId1", "someRunbook1", "somewebhookresourceId1", true, "someServiceUri1", true)),

                new PSAzureAppPushReceiver(
                    ActionGroupsUtilities.CreateAzureAppPushReceiver("apppushreceiver", "someEmailAddress"))
            };



            cmdlet.ExecuteCmdlet();

            Assert.Equal(Utilities.ResourceGroup, this.resourceGroup);
            Assert.Equal("ActionGroupName", this.name);
            Assert.Null(this.createOrUpdatePrms.Id);
            Assert.Equal(Location, this.createOrUpdatePrms.Location);
            Assert.Equal("AgShortName", this.createOrUpdatePrms.GroupShortName);

            Assert.Equal(3, this.createOrUpdatePrms.EmailReceivers.Count);

            Assert.Equal("email", this.createOrUpdatePrms.EmailReceivers[0].Name);
            Assert.Equal("*****@*****.**", this.createOrUpdatePrms.EmailReceivers[0].EmailAddress);
            Assert.False(this.createOrUpdatePrms.EmailReceivers[0].UseCommonAlertSchema);

            Assert.Equal("email1", this.createOrUpdatePrms.EmailReceivers[1].Name);
            Assert.Equal("*****@*****.**", this.createOrUpdatePrms.EmailReceivers[1].EmailAddress);
            Assert.True(this.createOrUpdatePrms.EmailReceivers[1].UseCommonAlertSchema);

            Assert.Equal("email2", this.createOrUpdatePrms.EmailReceivers[2].Name);
            Assert.Equal("*****@*****.**", this.createOrUpdatePrms.EmailReceivers[2].EmailAddress);
            Assert.False(this.createOrUpdatePrms.EmailReceivers[2].UseCommonAlertSchema);


            Assert.Equal(1, this.createOrUpdatePrms.SmsReceivers.Count);

            Assert.Equal("sms", this.createOrUpdatePrms.SmsReceivers[0].Name);
            Assert.Equal("1", this.createOrUpdatePrms.SmsReceivers[0].CountryCode);
            Assert.Equal("4254251234", this.createOrUpdatePrms.SmsReceivers[0].PhoneNumber);

            Assert.Equal(4, this.createOrUpdatePrms.WebhookReceivers.Count);

            Assert.Equal("webhook", this.createOrUpdatePrms.WebhookReceivers[0].Name);
            Assert.Equal("http://test.com", this.createOrUpdatePrms.WebhookReceivers[0].ServiceUri);
            Assert.False(this.createOrUpdatePrms.WebhookReceivers[0].UseCommonAlertSchema);
            Assert.False(this.createOrUpdatePrms.WebhookReceivers[0].UseAadAuth);
            Assert.Equal("", this.createOrUpdatePrms.WebhookReceivers[0].ObjectId);
            Assert.Equal("", this.createOrUpdatePrms.WebhookReceivers[0].IdentifierUri);
            Assert.Equal("", this.createOrUpdatePrms.WebhookReceivers[0].TenantId);

            Assert.Equal("webhook1", this.createOrUpdatePrms.WebhookReceivers[1].Name);
            Assert.Equal("http://test1.com", this.createOrUpdatePrms.WebhookReceivers[1].ServiceUri);
            Assert.True(this.createOrUpdatePrms.WebhookReceivers[1].UseCommonAlertSchema);
            Assert.False(this.createOrUpdatePrms.WebhookReceivers[1].UseAadAuth);
            Assert.Equal("", this.createOrUpdatePrms.WebhookReceivers[1].ObjectId);
            Assert.Equal("", this.createOrUpdatePrms.WebhookReceivers[1].IdentifierUri);
            Assert.Equal("", this.createOrUpdatePrms.WebhookReceivers[1].TenantId);

            Assert.Equal("webhook2", this.createOrUpdatePrms.WebhookReceivers[2].Name);
            Assert.Equal("http://test2.com", this.createOrUpdatePrms.WebhookReceivers[2].ServiceUri);
            Assert.True(this.createOrUpdatePrms.WebhookReceivers[2].UseCommonAlertSchema);
            Assert.False(this.createOrUpdatePrms.WebhookReceivers[2].UseAadAuth);
            Assert.Equal("", this.createOrUpdatePrms.WebhookReceivers[2].ObjectId);
            Assert.Equal("", this.createOrUpdatePrms.WebhookReceivers[2].IdentifierUri);
            Assert.Equal("", this.createOrUpdatePrms.WebhookReceivers[2].TenantId);

            Assert.Equal("webhook3", this.createOrUpdatePrms.WebhookReceivers[3].Name);
            Assert.Equal("http://test3.com", this.createOrUpdatePrms.WebhookReceivers[3].ServiceUri);
            Assert.True(this.createOrUpdatePrms.WebhookReceivers[3].UseCommonAlertSchema);
            Assert.True(this.createOrUpdatePrms.WebhookReceivers[3].UseAadAuth);
            Assert.Equal("someObjectId", this.createOrUpdatePrms.WebhookReceivers[3].ObjectId);
            Assert.Equal("someIdentifierId", this.createOrUpdatePrms.WebhookReceivers[3].IdentifierUri);
            Assert.Equal("someTenantId", this.createOrUpdatePrms.WebhookReceivers[3].TenantId);

            Assert.Equal(1, this.createOrUpdatePrms.ItsmReceivers.Count);

            Assert.Equal("itsm", this.createOrUpdatePrms.ItsmReceivers[0].Name);
            Assert.Equal("someWorkspaceId", this.createOrUpdatePrms.ItsmReceivers[0].WorkspaceId);
            Assert.Equal("someConnectionId", this.createOrUpdatePrms.ItsmReceivers[0].ConnectionId);
            Assert.Equal("sometickerConfiguration", this.createOrUpdatePrms.ItsmReceivers[0].TicketConfiguration);
            Assert.Equal("someRegion", this.createOrUpdatePrms.ItsmReceivers[0].Region);

            Assert.Equal(1, this.createOrUpdatePrms.VoiceReceivers.Count);
            Assert.Equal("voice", this.createOrUpdatePrms.VoiceReceivers[0].Name);
            Assert.Equal("someCountryCode", this.createOrUpdatePrms.VoiceReceivers[0].CountryCode);
            Assert.Equal("somePhoeNumber", this.createOrUpdatePrms.VoiceReceivers[0].PhoneNumber);

            Assert.Equal(2, this.createOrUpdatePrms.ArmRoleReceivers.Count);

            Assert.Equal("armRole", this.createOrUpdatePrms.ArmRoleReceivers[0].Name);
            Assert.Equal("someRoleId", this.createOrUpdatePrms.ArmRoleReceivers[0].RoleId);
            Assert.False(this.createOrUpdatePrms.ArmRoleReceivers[0].UseCommonAlertSchema);

            Assert.Equal("armRole1", this.createOrUpdatePrms.ArmRoleReceivers[1].Name);
            Assert.Equal("someRoleId1", this.createOrUpdatePrms.ArmRoleReceivers[1].RoleId);
            Assert.True(this.createOrUpdatePrms.ArmRoleReceivers[1].UseCommonAlertSchema);

            Assert.Equal(2, this.createOrUpdatePrms.AzureFunctionReceivers.Count);

            Assert.Equal("azureFunctionReceiver", this.createOrUpdatePrms.AzureFunctionReceivers[0].Name);
            Assert.Equal("somefuncappresourceId", this.createOrUpdatePrms.AzureFunctionReceivers[0].FunctionAppResourceId);
            Assert.Equal("somefunctionName", this.createOrUpdatePrms.AzureFunctionReceivers[0].FunctionName);
            Assert.Equal("some trigeerURl", this.createOrUpdatePrms.AzureFunctionReceivers[0].HttpTriggerUrl);
            Assert.False(this.createOrUpdatePrms.AzureFunctionReceivers[0].UseCommonAlertSchema);

            Assert.Equal("azureFunctionReceiver1", this.createOrUpdatePrms.AzureFunctionReceivers[1].Name);
            Assert.Equal("somefuncappresourceId1", this.createOrUpdatePrms.AzureFunctionReceivers[1].FunctionAppResourceId);
            Assert.Equal("somefunctionName2", this.createOrUpdatePrms.AzureFunctionReceivers[1].FunctionName);
            Assert.Equal("some trigeerURl2", this.createOrUpdatePrms.AzureFunctionReceivers[1].HttpTriggerUrl);
            Assert.True(this.createOrUpdatePrms.AzureFunctionReceivers[1].UseCommonAlertSchema);

            Assert.Equal(2, this.createOrUpdatePrms.LogicAppReceivers.Count);

            Assert.Equal("logicAppReceveir", this.createOrUpdatePrms.LogicAppReceivers[0].Name);
            Assert.Equal("someresourceId", this.createOrUpdatePrms.LogicAppReceivers[0].ResourceId);
            Assert.Equal("someCallback", this.createOrUpdatePrms.LogicAppReceivers[0].CallbackUrl);
            Assert.False(this.createOrUpdatePrms.LogicAppReceivers[0].UseCommonAlertSchema);

            Assert.Equal("logicAppReceveir1", this.createOrUpdatePrms.LogicAppReceivers[1].Name);
            Assert.Equal("someresourceId1", this.createOrUpdatePrms.LogicAppReceivers[1].ResourceId);
            Assert.Equal("someCallback1", this.createOrUpdatePrms.LogicAppReceivers[1].CallbackUrl);
            Assert.True(this.createOrUpdatePrms.LogicAppReceivers[1].UseCommonAlertSchema);

            Assert.Equal(2, this.createOrUpdatePrms.AutomationRunbookReceivers.Count);

            Assert.Equal("runbookReceiver", this.createOrUpdatePrms.AutomationRunbookReceivers[0].Name);
            Assert.Equal("someAutomationId", this.createOrUpdatePrms.AutomationRunbookReceivers[0].AutomationAccountId);
            Assert.Equal("someRunbook", this.createOrUpdatePrms.AutomationRunbookReceivers[0].RunbookName);
            Assert.Equal("somewebhookresourceId", this.createOrUpdatePrms.AutomationRunbookReceivers[0].WebhookResourceId);
            Assert.Equal("someServiceUri", this.createOrUpdatePrms.AutomationRunbookReceivers[0].ServiceUri);
            Assert.False(this.createOrUpdatePrms.AutomationRunbookReceivers[0].IsGlobalRunbook);
            Assert.False(this.createOrUpdatePrms.AutomationRunbookReceivers[0].UseCommonAlertSchema);

            Assert.Equal("runbookReceiver1", this.createOrUpdatePrms.AutomationRunbookReceivers[1].Name);
            Assert.Equal("someAutomationId1", this.createOrUpdatePrms.AutomationRunbookReceivers[1].AutomationAccountId);
            Assert.Equal("someRunbook1", this.createOrUpdatePrms.AutomationRunbookReceivers[1].RunbookName);
            Assert.Equal("somewebhookresourceId1", this.createOrUpdatePrms.AutomationRunbookReceivers[1].WebhookResourceId);
            Assert.Equal("someServiceUri1", this.createOrUpdatePrms.AutomationRunbookReceivers[1].ServiceUri);
            Assert.True(this.createOrUpdatePrms.AutomationRunbookReceivers[1].IsGlobalRunbook);
            Assert.True(this.createOrUpdatePrms.AutomationRunbookReceivers[1].UseCommonAlertSchema);

            Assert.Equal(1, this.createOrUpdatePrms.AzureAppPushReceivers.Count);

            Assert.Equal("apppushreceiver", this.createOrUpdatePrms.AzureAppPushReceivers[0].Name);
            Assert.Equal("someEmailAddress", this.createOrUpdatePrms.AzureAppPushReceivers[0].EmailAddress);

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

            cmdlet.DisableGroup = true;
            cmdlet.Tag          = new Dictionary <string, string>();
            cmdlet.ExecuteCmdlet();

            Assert.False(this.createOrUpdatePrms.Enabled);
            Assert.Null(this.createOrUpdatePrms.Type);
            Assert.NotNull(this.createOrUpdatePrms.Tags);
        }