Skip to content

Commit 56ef879

Browse files
committed
added unit test for new command creation
1 parent abe1287 commit 56ef879

File tree

3 files changed

+592
-6
lines changed

3 files changed

+592
-6
lines changed

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

Lines changed: 198 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,21 @@
1515

1616
namespace Microsoft.Azure.Commands.Insights.Test.ActionGroups
1717
{
18+
using System;
1819
using System.Collections.Generic;
1920

2021
using Microsoft.Azure.Management.Monitor.Models;
2122

2223
public class ActionGroupsUtilities
2324
{
25+
public const string emptyString = "";
26+
public const bool defaultBoolValue = false;
2427
public static EmailReceiver CreateEmailReceiver(
2528
string name,
26-
string emailAddress)
29+
string emailAddress,
30+
bool useCommonAlertSchema = defaultBoolValue) // not a mandatory field in powershell commandlet - defaults to false if not mentioned
2731
{
28-
return new EmailReceiver { Name = name, EmailAddress = emailAddress };
32+
return new EmailReceiver { Name = name, EmailAddress = emailAddress, UseCommonAlertSchema = useCommonAlertSchema };
2933
}
3034

3135
public static SmsReceiver CreateSmsReceiver(
@@ -37,25 +41,213 @@ public static SmsReceiver CreateSmsReceiver(
3741

3842
public static WebhookReceiver CreateWebhookReceiver(
3943
string name,
40-
string serviceUri)
44+
string serviceUri,
45+
bool useCommonAlertSchema = defaultBoolValue,
46+
bool? useAadAuth = defaultBoolValue,
47+
string objectId = emptyString,
48+
string identifierUri = emptyString,
49+
string tenantId = emptyString
50+
)
4151
{
42-
return new WebhookReceiver { Name = name, ServiceUri = serviceUri };
52+
if(useAadAuth?? true) // if aad auth is enabled , then following fields are mandatory.
53+
{
54+
if((string.IsNullOrWhiteSpace(objectId))
55+
||(string.IsNullOrWhiteSpace(identifierUri))
56+
|| (string.IsNullOrWhiteSpace(tenantId)))
57+
{
58+
throw new ArgumentException("When use AadAuth is set for web hook receiverm then objectid ,identifierUri and tenantId are expected ");
59+
}
60+
}
61+
return new WebhookReceiver {
62+
Name = name,
63+
ServiceUri = serviceUri,
64+
UseCommonAlertSchema = useCommonAlertSchema,
65+
UseAadAuth = useAadAuth,
66+
ObjectId = objectId,
67+
IdentifierUri = identifierUri,
68+
TenantId = tenantId
69+
70+
};
4371
}
4472

73+
public static ItsmReceiver CreateItsmReceiver(
74+
string name,
75+
string workspaceId,
76+
string connectionId,
77+
string ticketConfiguration,
78+
string region
79+
)
80+
{
81+
return new ItsmReceiver
82+
{
83+
Name = name,
84+
WorkspaceId = workspaceId,
85+
ConnectionId = connectionId,
86+
TicketConfiguration = ticketConfiguration,
87+
Region = region
88+
};
89+
}
90+
91+
public static VoiceReceiver CreateVoiceReceiver(
92+
string name,
93+
string countryCode,
94+
string phoneNumber)
95+
{
96+
return new VoiceReceiver
97+
{
98+
Name = name,
99+
CountryCode = countryCode,
100+
PhoneNumber = phoneNumber
101+
};
102+
}
103+
104+
public static ArmRoleReceiver CreateArmRoleReceiver(
105+
string name,
106+
string roleId,
107+
bool useCommonAlertSchema = defaultBoolValue)
108+
{
109+
return new ArmRoleReceiver
110+
{
111+
Name = name,
112+
RoleId = roleId,
113+
UseCommonAlertSchema = useCommonAlertSchema
114+
};
115+
}
116+
117+
public static AzureFunctionReceiver CreateAzureFunctionReceiver(
118+
string name,
119+
string functionAppResourceId,
120+
string functionName,
121+
string httpTriggerUrl,
122+
bool useCommonAlertSchema = defaultBoolValue)
123+
{
124+
return new AzureFunctionReceiver
125+
{
126+
Name = name,
127+
FunctionAppResourceId = functionAppResourceId,
128+
FunctionName = functionName,
129+
HttpTriggerUrl = httpTriggerUrl,
130+
UseCommonAlertSchema = useCommonAlertSchema
131+
};
132+
}
133+
134+
public static LogicAppReceiver CreateLogicAppReceiver(
135+
string name ,
136+
string resourceId,
137+
string callbackUrl,
138+
bool useCommonAlertSchema = defaultBoolValue)
139+
{
140+
return new LogicAppReceiver
141+
{
142+
Name = name,
143+
ResourceId = resourceId,
144+
CallbackUrl = callbackUrl,
145+
UseCommonAlertSchema = useCommonAlertSchema
146+
};
147+
}
148+
149+
public static AutomationRunbookReceiver CreateAutomationRunbookReceiver(
150+
string name ,
151+
string automationAccountId,
152+
string runbookName,
153+
string webhookResourceId,
154+
bool isGlobalRunBook,
155+
string serviceUri,
156+
bool useCommonAlertSchema = defaultBoolValue)
157+
{
158+
return new AutomationRunbookReceiver
159+
{
160+
Name = name,
161+
AutomationAccountId = automationAccountId,
162+
RunbookName = runbookName,
163+
WebhookResourceId = webhookResourceId,
164+
IsGlobalRunbook = isGlobalRunBook,
165+
UseCommonAlertSchema = useCommonAlertSchema,
166+
ServiceUri = serviceUri
167+
};
168+
}
169+
170+
public static AzureAppPushReceiver CreateAzureAppPushReceiver(
171+
string name,
172+
string emailAddress
173+
)
174+
{
175+
return new AzureAppPushReceiver
176+
{
177+
Name = name,
178+
EmailAddress = emailAddress
179+
};
180+
}
181+
182+
45183
public static ActionGroupResource CreateActionGroupResource(
46184
string name,
47185
string shortName)
48186
{
49187
return new ActionGroupResource(
50188
location: "Global",
189+
51190
enabled: true,
191+
52192
name: name,
193+
53194
groupShortName: shortName,
195+
54196
id:
55197
$"/subscriptions/7de05d20-f39f-44d8-83ca-e7d2f12118b0/resourceGroups/testResourceGroup/providers/microsoft.insights/actionGroups/{name}",
56-
emailReceivers: new List<EmailReceiver> { CreateEmailReceiver("email", "[email protected]") },
198+
199+
emailReceivers: new List<EmailReceiver>
200+
{
201+
CreateEmailReceiver("email", "[email protected]") ,
202+
CreateEmailReceiver("email1", "[email protected]", true) ,
203+
CreateEmailReceiver("email2", "[email protected]", false)
204+
},
205+
57206
smsReceivers: new List<SmsReceiver> { CreateSmsReceiver("sms", "4254251234") },
58-
webhookReceivers: new List<WebhookReceiver> { CreateWebhookReceiver("webhook", "http://test.com") });
207+
208+
webhookReceivers: new List<WebhookReceiver>
209+
{
210+
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" )
214+
},
215+
216+
itsmReceivers: new List<ItsmReceiver>
217+
{ CreateItsmReceiver("itsm", "someWorkspaceId", "someConnectionId", "sometickerConfiguration", "someRegion") },
218+
219+
voiceReceivers: new List<VoiceReceiver>
220+
{ CreateVoiceReceiver("voice", "someCountryCode", "somePhoeNumber") },
221+
222+
armRoleReceivers: new List<ArmRoleReceiver>
223+
{
224+
CreateArmRoleReceiver("armRole", "someRoleId"),
225+
CreateArmRoleReceiver("armRole1", "someRoleId", true)
226+
},
227+
228+
azureFunctionReceivers: new List<AzureFunctionReceiver>
229+
{
230+
CreateAzureFunctionReceiver("azureFunctionReceiver","somefuncappresourceId","somefunctionName","some trigeerURl"),
231+
CreateAzureFunctionReceiver("azureFunctionReceiver1","somefuncappresourceId1","somefunctionName2","some trigeerURl2",true)
232+
},
233+
234+
logicAppReceivers: new List<LogicAppReceiver>
235+
{
236+
CreateLogicAppReceiver("logicAppReceveir","someresourceId","someCallback"),
237+
CreateLogicAppReceiver("logicAppReceveir1","someresourceId","someCallback",true),
238+
},
239+
240+
automationRunbookReceivers: new List<AutomationRunbookReceiver>
241+
{
242+
CreateAutomationRunbookReceiver("runbookReceiver","someAutomationId","someRunbook","somewebhookresourceId",false,"someServiceUri"),
243+
CreateAutomationRunbookReceiver("runbookReceiver1","someAutomationId1","someRunbook1","somewebhookresourceId1",true,"someServiceUri1",true),
244+
},
245+
246+
azureAppPushReceivers: new List<AzureAppPushReceiver>
247+
{
248+
CreateAzureAppPushReceiver("apppushreceiver","someEmailAddress")
249+
}
250+
);
59251
}
60252
}
61253
}

0 commit comments

Comments
 (0)