Skip to content

Commit 1c67c5c

Browse files
committed
Add test to cover changes
1 parent caedeb4 commit 1c67c5c

File tree

2 files changed

+254
-0
lines changed

2 files changed

+254
-0
lines changed

src/ApiManagement/ApiManagement.ServiceManagement.Test/ScenarioTests/ApiManagementTests.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,20 @@ public void ApiCrudTest()
6767
RunPowerShellTest("Api-CrudTest");
6868
}
6969

70+
[Fact]
71+
[Trait(Category.AcceptanceType, Category.CheckIn)]
72+
public void ApiCrudGraphQLTest()
73+
{
74+
RunPowerShellTest("Api-CrudGraphQlTest");
75+
}
76+
77+
[Fact]
78+
[Trait(Category.AcceptanceType, Category.CheckIn)]
79+
public void ApiCrudWebSocketTest()
80+
{
81+
RunPowerShellTest("Api-CrudWebSocketTest");
82+
}
83+
7084
[Fact]
7185
[Trait(Category.AcceptanceType, Category.CheckIn)]
7286
public void ApiCloneCrudTest()

src/ApiManagement/ApiManagement.ServiceManagement.Test/ScenarioTests/ApiManagementTests.ps1

Lines changed: 240 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,246 @@ function Api-CrudTest {
165165
}
166166
}
167167

168+
function Api-CrudGraphQlTest {
169+
Param($resourceGroupName, $serviceName)
170+
171+
$context = New-AzApiManagementContext -ResourceGroupName $resourceGroupName -ServiceName $serviceName
172+
173+
# create new api
174+
$newApiId = getAssetName
175+
try {
176+
$newApiName = getAssetName
177+
$newApiDescription = getAssetName
178+
$newApiPath = getAssetName
179+
$newApiServiceUrl = "http://newechoapi.cloudapp.net/newapi"
180+
$subscriptionKeyParametersHeader = getAssetName
181+
$subscriptionKeyQueryStringParamName = getAssetName
182+
$newApiType = "graphql"
183+
$newApiTermsOfServiceUrl = "microsoft.com"
184+
$newApiContactName = getAssetName
185+
$newApiContactUrl = "microsoft.com"
186+
$newApiContactEmail = "[email protected]"
187+
$newApiLicenseName = getAssetName
188+
$newApiLicenseUrl = "microsoft.com"
189+
190+
$newApi = New-AzApiManagementApi -Context $context -ApiId $newApiId -Name $newApiName -Description $newApiDescription `
191+
-Protocols @("http", "https") -Path $newApiPath -ServiceUrl $newApiServiceUrl `
192+
-SubscriptionKeyHeaderName $subscriptionKeyParametersHeader -SubscriptionKeyQueryParamName $subscriptionKeyQueryStringParamName `
193+
-ApiType $newApiType -TermsOfServiceUrl $newApiTermsOfServiceUrl -ContactName $newApiContactName -ContactUrl $newApiContactUrl `
194+
-ContactEmail $newApiContactEmail -LicenseName $newApiLicenseName -LicenseUrl $newApiLicenseUrl
195+
196+
Assert-AreEqual $newApiId $newApi.ApiId
197+
Assert-AreEqual $newApiName $newApi.Name
198+
Assert-AreEqual $newApiDescription.Description
199+
Assert-AreEqual $newApiServiceUrl $newApi.ServiceUrl
200+
Assert-AreEqual $newApiPath $newApi.Path
201+
Assert-AreEqual 2 $newApi.Protocols.Length
202+
Assert-AreEqual http $newApi.Protocols[0]
203+
Assert-AreEqual https $newApi.Protocols[1]
204+
Assert-Null $newApi.AuthorizationServerId
205+
Assert-Null $newApi.AuthorizationScope
206+
Assert-AreEqual $subscriptionKeyParametersHeader $newApi.SubscriptionKeyHeaderName
207+
Assert-AreEqual $subscriptionKeyQueryStringParamName $newApi.SubscriptionKeyQueryParamName
208+
Assert-AreEqual $newApiType $newApi.ApiType
209+
Assert-AreEqual $newApiTermsOfServiceUrl $newApi.TermsOfServiceUrl
210+
Assert-AreEqual $newApiContactName $newApi.Contact.Name
211+
Assert-AreEqual $newApiContactUrl $newApi.Contact.Url
212+
Assert-AreEqual $newApiContactEmail $newApi.Contact.Email
213+
Assert-AreEqual $newApiLicenseName $newApi.Nicense.Name
214+
Assert-AreEqual $newApiLicenseUrl $newApi.Nicense.Url
215+
216+
# set api
217+
$newApiName = getAssetName
218+
$newApiDescription = getAssetName
219+
$newApiPath = getAssetName
220+
$newApiServiceUrl = "http://newechoapi.cloudapp.net/newapinew"
221+
$subscriptionKeyParametersHeader = getAssetName
222+
$subscriptionKeyQueryStringParamName = getAssetName
223+
$newApiType = "graphql"
224+
$newApiTermsOfServiceUrl = "changed.microsoft.com"
225+
$newApiContactName = getAssetName
226+
$newApiContactUrl = "changed.microsoft.com"
227+
$newApiContactEmail = "[email protected]"
228+
$newApiLicenseName = getAssetName
229+
$newApiLicenseUrl = "changed.microsoft.com"
230+
231+
$newApi = Set-AzApiManagementApi -Context $context -ApiId $newApiId -Name $newApiName -Description $newApiDescription `
232+
-Protocols @("https") -Path $newApiPath -ServiceUrl $newApiServiceUrl `
233+
-SubscriptionKeyHeaderName $subscriptionKeyParametersHeader -SubscriptionKeyQueryParamName $subscriptionKeyQueryStringParamName `
234+
-PassThru `
235+
-ApiType $newApiType -TermsOfServiceUrl $newApiTermsOfServiceUrl -ContactName $newApiContactName -ContactUrl $newApiContactUrl `
236+
-ContactEmail $newApiContactEmail -LicenseName $newApiLicenseName -LicenseUrl $newApiLicenseUrl
237+
238+
Assert-AreEqual $newApiId $newApi.ApiId
239+
Assert-AreEqual $newApiName $newApi.Name
240+
Assert-AreEqual $newApiDescription $newApi.Description
241+
Assert-AreEqual $newApiServiceUrl $newApi.ServiceUrl
242+
Assert-AreEqual $newApiPath $newApi.Path
243+
Assert-AreEqual 1 $newApi.Protocols.Length
244+
Assert-AreEqual https $newApi.Protocols[0]
245+
Assert-Null $newApi.AuthorizationServerId
246+
Assert-Null $newApi.AuthorizationScope
247+
Assert-AreEqual $subscriptionKeyParametersHeader $newApi.SubscriptionKeyHeaderName
248+
Assert-AreEqual $subscriptionKeyQueryStringParamName $newApi.SubscriptionKeyQueryParamName
249+
Assert-AreEqual $newApiType $newApi.ApiType
250+
Assert-AreEqual $newApiTermsOfServiceUrl $newApi.TermsOfServiceUrl
251+
Assert-AreEqual $newApiContactName $newApi.Contact.Name
252+
Assert-AreEqual $newApiContactUrl $newApi.Contact.Url
253+
Assert-AreEqual $newApiContactEmail $newApi.Contact.Email
254+
Assert-AreEqual $newApiLicenseName $newApi.Nicense.Name
255+
Assert-AreEqual $newApiLicenseUrl $newApi.Nicense.Url
256+
257+
258+
$product = Get-AzApiManagementProduct -Context $context | Select-Object -First 1
259+
Add-AzApiManagementApiToProduct -Context $context -ApiId $newApiId -ProductId $product.ProductId
260+
261+
#get by product id
262+
$found = 0
263+
$apis = Get-AzApiManagementApi -Context $context -ProductId $product.ProductId
264+
for ($i = 0; $i -lt $apis.Count; $i++) {
265+
if ($apis[$i].ApiId -eq $newApiId) {
266+
$found = 1
267+
}
268+
}
269+
Assert-AreEqual 1 $found
270+
271+
Remove-AzApiManagementApiFromProduct -Context $context -ApiId $newApiId -ProductId $product.ProductId
272+
$found = 0
273+
$apis = Get-AzApiManagementApi -Context $context -ProductId $product.ProductId
274+
for ($i = 0; $i -lt $apis.Count; $i++) {
275+
if ($apis[$i].ApiId -eq $newApiId) {
276+
$found = 1
277+
}
278+
}
279+
Assert-AreEqual 0 $found
280+
}
281+
finally {
282+
# remove created api
283+
$removed = Remove-AzApiManagementApi -Context $context -ApiId $newApiId -PassThru
284+
Assert-True { $removed }
285+
}
286+
}
287+
288+
function Api-CrudWebsocketTest {
289+
Param($resourceGroupName, $serviceName)
290+
291+
$context = New-AzApiManagementContext -ResourceGroupName $resourceGroupName -ServiceName $serviceName
292+
293+
# create new api
294+
$newApiId = getAssetName
295+
try {
296+
$newApiName = getAssetName
297+
$newApiDescription = getAssetName
298+
$newApiPath = getAssetName
299+
$newApiServiceUrl = "http://newechoapi.cloudapp.net/newapi"
300+
$subscriptionKeyParametersHeader = getAssetName
301+
$subscriptionKeyQueryStringParamName = getAssetName
302+
$newApiType = "websocket"
303+
$newApiTermsOfServiceUrl = "microsoft.com"
304+
$newApiContactName = getAssetName
305+
$newApiContactUrl = "microsoft.com"
306+
$newApiContactEmail = "[email protected]"
307+
$newApiLicenseName = getAssetName
308+
$newApiLicenseUrl = "microsoft.com"
309+
310+
$newApi = New-AzApiManagementApi -Context $context -ApiId $newApiId -Name $newApiName -Description $newApiDescription `
311+
-Protocols @("ws", "wss") -Path $newApiPath -ServiceUrl $newApiServiceUrl `
312+
-SubscriptionKeyHeaderName $subscriptionKeyParametersHeader -SubscriptionKeyQueryParamName $subscriptionKeyQueryStringParamName `
313+
-ApiType $newApiType -TermsOfServiceUrl $newApiTermsOfServiceUrl -ContactName $newApiContactName -ContactUrl $newApiContactUrl `
314+
-ContactEmail $newApiContactEmail -LicenseName $newApiLicenseName -LicenseUrl $newApiLicenseUrl
315+
316+
Assert-AreEqual $newApiId $newApi.ApiId
317+
Assert-AreEqual $newApiName $newApi.Name
318+
Assert-AreEqual $newApiDescription.Description
319+
Assert-AreEqual $newApiServiceUrl $newApi.ServiceUrl
320+
Assert-AreEqual $newApiPath $newApi.Path
321+
Assert-AreEqual 2 $newApi.Protocols.Length
322+
Assert-AreEqual http $newApi.Protocols[0]
323+
Assert-AreEqual https $newApi.Protocols[1]
324+
Assert-Null $newApi.AuthorizationServerId
325+
Assert-Null $newApi.AuthorizationScope
326+
Assert-AreEqual $subscriptionKeyParametersHeader $newApi.SubscriptionKeyHeaderName
327+
Assert-AreEqual $subscriptionKeyQueryStringParamName $newApi.SubscriptionKeyQueryParamName
328+
Assert-AreEqual $newApiType $newApi.ApiType
329+
Assert-AreEqual $newApiTermsOfServiceUrl $newApi.TermsOfServiceUrl
330+
Assert-AreEqual $newApiContactName $newApi.Contact.Name
331+
Assert-AreEqual $newApiContactUrl $newApi.Contact.Url
332+
Assert-AreEqual $newApiContactEmail $newApi.Contact.Email
333+
Assert-AreEqual $newApiLicenseName $newApi.Nicense.Name
334+
Assert-AreEqual $newApiLicenseUrl $newApi.Nicense.Url
335+
336+
# set api
337+
$newApiName = getAssetName
338+
$newApiDescription = getAssetName
339+
$newApiPath = getAssetName
340+
$newApiServiceUrl = "http://newechoapi.cloudapp.net/newapinew"
341+
$subscriptionKeyParametersHeader = getAssetName
342+
$subscriptionKeyQueryStringParamName = getAssetName
343+
$newApiType = "websocket"
344+
$newApiTermsOfServiceUrl = "changed.microsoft.com"
345+
$newApiContactName = getAssetName
346+
$newApiContactUrl = "changed.microsoft.com"
347+
$newApiContactEmail = "[email protected]"
348+
$newApiLicenseName = getAssetName
349+
$newApiLicenseUrl = "changed.microsoft.com"
350+
351+
$newApi = Set-AzApiManagementApi -Context $context -ApiId $newApiId -Name $newApiName -Description $newApiDescription `
352+
-Protocols @("ws") -Path $newApiPath -ServiceUrl $newApiServiceUrl `
353+
-SubscriptionKeyHeaderName $subscriptionKeyParametersHeader -SubscriptionKeyQueryParamName $subscriptionKeyQueryStringParamName `
354+
-PassThru `
355+
-ApiType $newApiType -TermsOfServiceUrl $newApiTermsOfServiceUrl -ContactName $newApiContactName -ContactUrl $newApiContactUrl `
356+
-ContactEmail $newApiContactEmail -LicenseName $newApiLicenseName -LicenseUrl $newApiLicenseUrl
357+
358+
Assert-AreEqual $newApiId $newApi.ApiId
359+
Assert-AreEqual $newApiName $newApi.Name
360+
Assert-AreEqual $newApiDescription $newApi.Description
361+
Assert-AreEqual $newApiServiceUrl $newApi.ServiceUrl
362+
Assert-AreEqual $newApiPath $newApi.Path
363+
Assert-AreEqual 1 $newApi.Protocols.Length
364+
Assert-AreEqual https $newApi.Protocols[0]
365+
Assert-Null $newApi.AuthorizationServerId
366+
Assert-Null $newApi.AuthorizationScope
367+
Assert-AreEqual $subscriptionKeyParametersHeader $newApi.SubscriptionKeyHeaderName
368+
Assert-AreEqual $subscriptionKeyQueryStringParamName $newApi.SubscriptionKeyQueryParamName
369+
Assert-AreEqual $newApiType $newApi.ApiType
370+
Assert-AreEqual $newApiTermsOfServiceUrl $newApi.TermsOfServiceUrl
371+
Assert-AreEqual $newApiContactName $newApi.Contact.Name
372+
Assert-AreEqual $newApiContactUrl $newApi.Contact.Url
373+
Assert-AreEqual $newApiContactEmail $newApi.Contact.Email
374+
Assert-AreEqual $newApiLicenseName $newApi.Nicense.Name
375+
Assert-AreEqual $newApiLicenseUrl $newApi.Nicense.Url
376+
377+
378+
$product = Get-AzApiManagementProduct -Context $context | Select-Object -First 1
379+
Add-AzApiManagementApiToProduct -Context $context -ApiId $newApiId -ProductId $product.ProductId
380+
381+
#get by product id
382+
$found = 0
383+
$apis = Get-AzApiManagementApi -Context $context -ProductId $product.ProductId
384+
for ($i = 0; $i -lt $apis.Count; $i++) {
385+
if ($apis[$i].ApiId -eq $newApiId) {
386+
$found = 1
387+
}
388+
}
389+
Assert-AreEqual 1 $found
390+
391+
Remove-AzApiManagementApiFromProduct -Context $context -ApiId $newApiId -ProductId $product.ProductId
392+
$found = 0
393+
$apis = Get-AzApiManagementApi -Context $context -ProductId $product.ProductId
394+
for ($i = 0; $i -lt $apis.Count; $i++) {
395+
if ($apis[$i].ApiId -eq $newApiId) {
396+
$found = 1
397+
}
398+
}
399+
Assert-AreEqual 0 $found
400+
}
401+
finally {
402+
# remove created api
403+
$removed = Remove-AzApiManagementApi -Context $context -ApiId $newApiId -PassThru
404+
Assert-True { $removed }
405+
}
406+
}
407+
168408
<#
169409
.SYNOPSIS
170410
Tests CRUD operations for Cloning an API into a ApiVersionSet.

0 commit comments

Comments
 (0)