Skip to content

Commit cc1e441

Browse files
committed
adding test for set action groups
1 parent 56ef879 commit cc1e441

File tree

2 files changed

+181
-17
lines changed

2 files changed

+181
-17
lines changed

src/Monitor/Monitor.Test/ActionGroups/ActionGroupsUtilities.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ namespace Microsoft.Azure.Commands.Insights.Test.ActionGroups
1717
{
1818
using System;
1919
using System.Collections.Generic;
20-
20+
using Microsoft.Azure.Commands.Insights.OutputClasses;
2121
using Microsoft.Azure.Management.Monitor.Models;
2222

2323
public class ActionGroupsUtilities
@@ -208,9 +208,9 @@ public static ActionGroupResource CreateActionGroupResource(
208208
webhookReceivers: new List<WebhookReceiver>
209209
{
210210
CreateWebhookReceiver("webhook", "http://test.com"),
211-
CreateWebhookReceiver("webhook1", "http://test.com", true),
212-
CreateWebhookReceiver("webhook2", "http://test.com", true,false),
213-
CreateWebhookReceiver("webhook3", "http://test.com", true,true,"someObjectId","someIdentifierId", "someTenantId" )
211+
CreateWebhookReceiver("webhook1", "http://test1.com", true),
212+
CreateWebhookReceiver("webhook2", "http://test2.com", true,false),
213+
CreateWebhookReceiver("webhook3", "http://test3.com", true,true,"someObjectId","someIdentifierId", "someTenantId" )
214214
},
215215

216216
itsmReceivers: new List<ItsmReceiver>
@@ -222,7 +222,7 @@ public static ActionGroupResource CreateActionGroupResource(
222222
armRoleReceivers: new List<ArmRoleReceiver>
223223
{
224224
CreateArmRoleReceiver("armRole", "someRoleId"),
225-
CreateArmRoleReceiver("armRole1", "someRoleId", true)
225+
CreateArmRoleReceiver("armRole1", "someRoleId1", true)
226226
},
227227

228228
azureFunctionReceivers: new List<AzureFunctionReceiver>
@@ -234,7 +234,7 @@ public static ActionGroupResource CreateActionGroupResource(
234234
logicAppReceivers: new List<LogicAppReceiver>
235235
{
236236
CreateLogicAppReceiver("logicAppReceveir","someresourceId","someCallback"),
237-
CreateLogicAppReceiver("logicAppReceveir1","someresourceId","someCallback",true),
237+
CreateLogicAppReceiver("logicAppReceveir1","someresourceId1","someCallback1",true),
238238
},
239239

240240
automationRunbookReceivers: new List<AutomationRunbookReceiver>

src/Monitor/Monitor.Test/ActionGroups/SetAzureRmActionGroupCommandTests.cs

Lines changed: 175 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -92,16 +92,66 @@ public void SetActionGroupCommandParametersProcessing()
9292
cmdlet.ShortName = "AgShortName";
9393
cmdlet.Receiver = new List<PSActionGroupReceiverBase>
9494
{
95-
new PSEmailReceiver(ActionGroupsUtilities.CreateEmailReceiver(
96-
name: "email",
97-
emailAddress: "[email protected]")),
98-
new PSSmsReceiver(ActionGroupsUtilities.CreateSmsReceiver(
99-
name: "sms",
100-
phoneNumber: "4254251234")),
101-
new PSWebhookReceiver(ActionGroupsUtilities.CreateWebhookReceiver(
102-
name: "webhook",
103-
serviceUri: "http://test.com")),
95+
new PSEmailReceiver(
96+
ActionGroupsUtilities.CreateEmailReceiver(name: "email",emailAddress:"[email protected]")),
97+
98+
new PSEmailReceiver(
99+
ActionGroupsUtilities.CreateEmailReceiver("email1", "[email protected]", true)),
100+
101+
new PSEmailReceiver(
102+
ActionGroupsUtilities.CreateEmailReceiver("email2", "[email protected]", false)),
103+
104+
new PSSmsReceiver(
105+
ActionGroupsUtilities.CreateSmsReceiver(name: "sms", phoneNumber: "4254251234")),
106+
107+
new PSWebhookReceiver(
108+
ActionGroupsUtilities.CreateWebhookReceiver(name: "webhook", serviceUri: "http://test.com")),
109+
110+
new PSWebhookReceiver(
111+
ActionGroupsUtilities.CreateWebhookReceiver("webhook1", "http://test1.com", true)),
112+
113+
new PSWebhookReceiver(
114+
ActionGroupsUtilities.CreateWebhookReceiver("webhook2", "http://test2.com", true,false)),
115+
116+
new PSWebhookReceiver(
117+
ActionGroupsUtilities.CreateWebhookReceiver("webhook3", "http://test3.com", true,true,"someObjectId","someIdentifierId", "someTenantId")),
118+
119+
new PSItsmReceiver(
120+
ActionGroupsUtilities.CreateItsmReceiver("itsm", "someWorkspaceId", "someConnectionId", "sometickerConfiguration", "someRegion")),
121+
122+
new PSVoiceReceiver(
123+
ActionGroupsUtilities.CreateVoiceReceiver("voice", "someCountryCode", "somePhoeNumber")),
124+
125+
new PSArmRoleReceiver(
126+
ActionGroupsUtilities.CreateArmRoleReceiver("armRole", "someRoleId")),
127+
128+
new PSArmRoleReceiver(
129+
ActionGroupsUtilities.CreateArmRoleReceiver("armRole1", "someRoleId1",true)),
130+
131+
new PSAzureFunctionReceiver(
132+
ActionGroupsUtilities.CreateAzureFunctionReceiver("azureFunctionReceiver","somefuncappresourceId","somefunctionName","some trigeerURl")),
133+
134+
new PSAzureFunctionReceiver(
135+
ActionGroupsUtilities.CreateAzureFunctionReceiver("azureFunctionReceiver1","somefuncappresourceId1","somefunctionName2","some trigeerURl2",true)),
136+
137+
new PSLogicAppReceiver(
138+
ActionGroupsUtilities.CreateLogicAppReceiver("logicAppReceveir","someresourceId","someCallback")),
139+
140+
new PSLogicAppReceiver(
141+
ActionGroupsUtilities.CreateLogicAppReceiver("logicAppReceveir1","someresourceId1","someCallback1",true)),
142+
143+
new PSAutomationRunbookReceiver(
144+
ActionGroupsUtilities.CreateAutomationRunbookReceiver("runbookReceiver","someAutomationId","someRunbook","somewebhookresourceId",false,"someServiceUri")),
145+
146+
new PSAutomationRunbookReceiver(
147+
ActionGroupsUtilities.CreateAutomationRunbookReceiver("runbookReceiver1","someAutomationId1","someRunbook1","somewebhookresourceId1",true,"someServiceUri1",true)),
148+
149+
new PSAzureAppPushReceiver(
150+
ActionGroupsUtilities.CreateAzureAppPushReceiver("apppushreceiver","someEmailAddress"))
104151
};
152+
153+
154+
105155
cmdlet.ExecuteCmdlet();
106156

107157
Assert.Equal(Utilities.ResourceGroup, this.resourceGroup);
@@ -110,18 +160,132 @@ public void SetActionGroupCommandParametersProcessing()
110160
Assert.Equal(Location, this.createOrUpdatePrms.Location);
111161
Assert.Equal("AgShortName", this.createOrUpdatePrms.GroupShortName);
112162

113-
Assert.Equal(1, this.createOrUpdatePrms.EmailReceivers.Count);
163+
Assert.Equal(3, this.createOrUpdatePrms.EmailReceivers.Count);
164+
114165
Assert.Equal("email", this.createOrUpdatePrms.EmailReceivers[0].Name);
115166
Assert.Equal("[email protected]", this.createOrUpdatePrms.EmailReceivers[0].EmailAddress);
167+
Assert.False(this.createOrUpdatePrms.EmailReceivers[0].UseCommonAlertSchema);
168+
169+
Assert.Equal("email1", this.createOrUpdatePrms.EmailReceivers[1].Name);
170+
Assert.Equal("[email protected]", this.createOrUpdatePrms.EmailReceivers[1].EmailAddress);
171+
Assert.True(this.createOrUpdatePrms.EmailReceivers[1].UseCommonAlertSchema);
172+
173+
Assert.Equal("email2", this.createOrUpdatePrms.EmailReceivers[2].Name);
174+
Assert.Equal("[email protected]", this.createOrUpdatePrms.EmailReceivers[2].EmailAddress);
175+
Assert.False(this.createOrUpdatePrms.EmailReceivers[2].UseCommonAlertSchema);
176+
116177

117178
Assert.Equal(1, this.createOrUpdatePrms.SmsReceivers.Count);
179+
118180
Assert.Equal("sms", this.createOrUpdatePrms.SmsReceivers[0].Name);
119181
Assert.Equal("1", this.createOrUpdatePrms.SmsReceivers[0].CountryCode);
120182
Assert.Equal("4254251234", this.createOrUpdatePrms.SmsReceivers[0].PhoneNumber);
121183

122-
Assert.Equal(1, this.createOrUpdatePrms.WebhookReceivers.Count);
184+
Assert.Equal(4, this.createOrUpdatePrms.WebhookReceivers.Count);
185+
123186
Assert.Equal("webhook", this.createOrUpdatePrms.WebhookReceivers[0].Name);
124187
Assert.Equal("http://test.com", this.createOrUpdatePrms.WebhookReceivers[0].ServiceUri);
188+
Assert.False(this.createOrUpdatePrms.WebhookReceivers[0].UseCommonAlertSchema);
189+
Assert.False(this.createOrUpdatePrms.WebhookReceivers[0].UseAadAuth);
190+
Assert.Equal("",this.createOrUpdatePrms.WebhookReceivers[0].ObjectId);
191+
Assert.Equal("", this.createOrUpdatePrms.WebhookReceivers[0].IdentifierUri);
192+
Assert.Equal("", this.createOrUpdatePrms.WebhookReceivers[0].TenantId);
193+
194+
Assert.Equal("webhook1", this.createOrUpdatePrms.WebhookReceivers[1].Name);
195+
Assert.Equal("http://test1.com", this.createOrUpdatePrms.WebhookReceivers[1].ServiceUri);
196+
Assert.True(this.createOrUpdatePrms.WebhookReceivers[1].UseCommonAlertSchema);
197+
Assert.False(this.createOrUpdatePrms.WebhookReceivers[1].UseAadAuth);
198+
Assert.Equal("", this.createOrUpdatePrms.WebhookReceivers[1].ObjectId);
199+
Assert.Equal("", this.createOrUpdatePrms.WebhookReceivers[1].IdentifierUri);
200+
Assert.Equal("", this.createOrUpdatePrms.WebhookReceivers[1].TenantId);
201+
202+
Assert.Equal("webhook2", this.createOrUpdatePrms.WebhookReceivers[2].Name);
203+
Assert.Equal("http://test2.com", this.createOrUpdatePrms.WebhookReceivers[2].ServiceUri);
204+
Assert.True(this.createOrUpdatePrms.WebhookReceivers[2].UseCommonAlertSchema);
205+
Assert.False(this.createOrUpdatePrms.WebhookReceivers[2].UseAadAuth);
206+
Assert.Equal("", this.createOrUpdatePrms.WebhookReceivers[2].ObjectId);
207+
Assert.Equal("", this.createOrUpdatePrms.WebhookReceivers[2].IdentifierUri);
208+
Assert.Equal("", this.createOrUpdatePrms.WebhookReceivers[2].TenantId);
209+
210+
Assert.Equal("webhook3", this.createOrUpdatePrms.WebhookReceivers[3].Name);
211+
Assert.Equal("http://test3.com", this.createOrUpdatePrms.WebhookReceivers[3].ServiceUri);
212+
Assert.True(this.createOrUpdatePrms.WebhookReceivers[3].UseCommonAlertSchema);
213+
Assert.True(this.createOrUpdatePrms.WebhookReceivers[3].UseAadAuth);
214+
Assert.Equal("someObjectId", this.createOrUpdatePrms.WebhookReceivers[3].ObjectId);
215+
Assert.Equal("someIdentifierId", this.createOrUpdatePrms.WebhookReceivers[3].IdentifierUri);
216+
Assert.Equal("someTenantId", this.createOrUpdatePrms.WebhookReceivers[3].TenantId);
217+
218+
Assert.Equal(1, this.createOrUpdatePrms.ItsmReceivers.Count);
219+
220+
Assert.Equal("itsm", this.createOrUpdatePrms.ItsmReceivers[0].Name);
221+
Assert.Equal("someWorkspaceId", this.createOrUpdatePrms.ItsmReceivers[0].WorkspaceId);
222+
Assert.Equal("someConnectionId", this.createOrUpdatePrms.ItsmReceivers[0].ConnectionId);
223+
Assert.Equal("sometickerConfiguration", this.createOrUpdatePrms.ItsmReceivers[0].TicketConfiguration);
224+
Assert.Equal("someRegion", this.createOrUpdatePrms.ItsmReceivers[0].Region);
225+
226+
Assert.Equal(1, this.createOrUpdatePrms.VoiceReceivers.Count);
227+
Assert.Equal("voice", this.createOrUpdatePrms.VoiceReceivers[0].Name);
228+
Assert.Equal("someCountryCode", this.createOrUpdatePrms.VoiceReceivers[0].CountryCode);
229+
Assert.Equal("somePhoeNumber", this.createOrUpdatePrms.VoiceReceivers[0].PhoneNumber);
230+
231+
Assert.Equal(2, this.createOrUpdatePrms.ArmRoleReceivers.Count);
232+
233+
Assert.Equal("armRole", this.createOrUpdatePrms.ArmRoleReceivers[0].Name);
234+
Assert.Equal("someRoleId", this.createOrUpdatePrms.ArmRoleReceivers[0].RoleId);
235+
Assert.False(this.createOrUpdatePrms.ArmRoleReceivers[0].UseCommonAlertSchema);
236+
237+
Assert.Equal("armRole1", this.createOrUpdatePrms.ArmRoleReceivers[1].Name);
238+
Assert.Equal("someRoleId1", this.createOrUpdatePrms.ArmRoleReceivers[1].RoleId);
239+
Assert.True(this.createOrUpdatePrms.ArmRoleReceivers[1].UseCommonAlertSchema);
240+
241+
Assert.Equal(2, this.createOrUpdatePrms.AzureFunctionReceivers.Count);
242+
243+
Assert.Equal("azureFunctionReceiver", this.createOrUpdatePrms.AzureFunctionReceivers[0].Name);
244+
Assert.Equal("somefuncappresourceId", this.createOrUpdatePrms.AzureFunctionReceivers[0].FunctionAppResourceId);
245+
Assert.Equal("somefunctionName", this.createOrUpdatePrms.AzureFunctionReceivers[0].FunctionName);
246+
Assert.Equal("some trigeerURl", this.createOrUpdatePrms.AzureFunctionReceivers[0].HttpTriggerUrl);
247+
Assert.False(this.createOrUpdatePrms.AzureFunctionReceivers[0].UseCommonAlertSchema);
248+
249+
Assert.Equal("azureFunctionReceiver1", this.createOrUpdatePrms.AzureFunctionReceivers[1].Name);
250+
Assert.Equal("somefuncappresourceId1", this.createOrUpdatePrms.AzureFunctionReceivers[1].FunctionAppResourceId);
251+
Assert.Equal("somefunctionName2", this.createOrUpdatePrms.AzureFunctionReceivers[1].FunctionName);
252+
Assert.Equal("some trigeerURl2", this.createOrUpdatePrms.AzureFunctionReceivers[1].HttpTriggerUrl);
253+
Assert.True(this.createOrUpdatePrms.AzureFunctionReceivers[1].UseCommonAlertSchema);
254+
255+
Assert.Equal(2, this.createOrUpdatePrms.LogicAppReceivers.Count);
256+
257+
Assert.Equal("logicAppReceveir", this.createOrUpdatePrms.LogicAppReceivers[0].Name);
258+
Assert.Equal("someresourceId", this.createOrUpdatePrms.LogicAppReceivers[0].ResourceId);
259+
Assert.Equal("someCallback", this.createOrUpdatePrms.LogicAppReceivers[0].CallbackUrl);
260+
Assert.False(this.createOrUpdatePrms.LogicAppReceivers[0].UseCommonAlertSchema);
261+
262+
Assert.Equal("logicAppReceveir1", this.createOrUpdatePrms.LogicAppReceivers[1].Name);
263+
Assert.Equal("someresourceId1", this.createOrUpdatePrms.LogicAppReceivers[1].ResourceId);
264+
Assert.Equal("someCallback1", this.createOrUpdatePrms.LogicAppReceivers[1].CallbackUrl);
265+
Assert.True(this.createOrUpdatePrms.LogicAppReceivers[1].UseCommonAlertSchema);
266+
267+
Assert.Equal(2, this.createOrUpdatePrms.AutomationRunbookReceivers.Count);
268+
269+
Assert.Equal("runbookReceiver", this.createOrUpdatePrms.AutomationRunbookReceivers[0].Name);
270+
Assert.Equal("someAutomationId", this.createOrUpdatePrms.AutomationRunbookReceivers[0].AutomationAccountId);
271+
Assert.Equal("someRunbook", this.createOrUpdatePrms.AutomationRunbookReceivers[0].RunbookName);
272+
Assert.Equal("somewebhookresourceId", this.createOrUpdatePrms.AutomationRunbookReceivers[0].WebhookResourceId);
273+
Assert.Equal("someServiceUri", this.createOrUpdatePrms.AutomationRunbookReceivers[0].ServiceUri);
274+
Assert.False(this.createOrUpdatePrms.AutomationRunbookReceivers[0].IsGlobalRunbook);
275+
Assert.False(this.createOrUpdatePrms.AutomationRunbookReceivers[0].UseCommonAlertSchema);
276+
277+
Assert.Equal("runbookReceiver1", this.createOrUpdatePrms.AutomationRunbookReceivers[1].Name);
278+
Assert.Equal("someAutomationId1", this.createOrUpdatePrms.AutomationRunbookReceivers[1].AutomationAccountId);
279+
Assert.Equal("someRunbook1", this.createOrUpdatePrms.AutomationRunbookReceivers[1].RunbookName);
280+
Assert.Equal("somewebhookresourceId1", this.createOrUpdatePrms.AutomationRunbookReceivers[1].WebhookResourceId);
281+
Assert.Equal("someServiceUri1", this.createOrUpdatePrms.AutomationRunbookReceivers[1].ServiceUri);
282+
Assert.True(this.createOrUpdatePrms.AutomationRunbookReceivers[1].IsGlobalRunbook);
283+
Assert.True(this.createOrUpdatePrms.AutomationRunbookReceivers[1].UseCommonAlertSchema);
284+
285+
Assert.Equal(1, this.createOrUpdatePrms.AzureAppPushReceivers.Count);
286+
287+
Assert.Equal("apppushreceiver", this.createOrUpdatePrms.AzureAppPushReceivers[0].Name);
288+
Assert.Equal("someEmailAddress", this.createOrUpdatePrms.AzureAppPushReceivers[0].EmailAddress);
125289

126290
Assert.True(this.createOrUpdatePrms.Enabled);
127291
Assert.Null(this.createOrUpdatePrms.Type);

0 commit comments

Comments
 (0)