@@ -129,4 +129,217 @@ function Run-StartAndStopMultipleVirtualMachinesTest
129
129
# Cleanup
130
130
Cleanup- CloudService $svcName ;
131
131
}
132
+ }
133
+
134
+ # Run Auto-Generated Hosted Service Cmdlet Tests
135
+ function Run-AutoGeneratedHostedServiceCmdletTests
136
+ {
137
+ # Setup
138
+ $location = Get-DefaultLocation ;
139
+ $imgName = Get-DefaultImage $location ;
140
+
141
+ $storageName = ' pstest' + (getAssetName);
142
+ New-AzureStorageAccount - StorageAccountName $storageName - Location $location ;
143
+
144
+ # Associate the new storage account with the current subscription
145
+ Set-CurrentStorageAccountName $storageName ;
146
+
147
+ $vmNameList = @ (" vm01" , " vm02" , " test04" );
148
+ $svcName = ' pstest' + (Get-CloudServiceName );
149
+ $userName = " pstestuser" ;
150
+ $password = " p@ssw0rd" ;
151
+
152
+ try
153
+ {
154
+ # Create Parameters
155
+ $svcCreateParams = New-AzureComputeParameterObject - FriendlyName ' HostedServiceCreateParameters' ;
156
+ $svcCreateParams.ServiceName = $svcName ;
157
+ $svcCreateParams.Location = $location ;
158
+ $svcCreateParams.Description = $svcName ;
159
+ $svcCreateParams.Label = $svcName ;
160
+
161
+ # Invoke Create
162
+ $st = Invoke-AzureComputeMethod - MethodName ' HostedServiceCreate' - HostedServiceCreateParameters $svcCreateParams ;
163
+
164
+ Assert-AreEqual $st.StatusCode ' Created' ;
165
+ Assert-NotNull $st.RequestId ;
166
+
167
+ # Invoke Get
168
+ $svcGetResult = Invoke-AzureComputeMethod - MethodName ' HostedServiceGet' - ServiceName $svcName ;
169
+ Assert-AreEqual $svcGetResult.ServiceName $svcName ;
170
+ Assert-AreEqual $svcGetResult.Properties.Description $svcName ;
171
+ Assert-AreEqual $svcGetResult.Properties.Label $svcName ;
172
+
173
+ # Update Parameters
174
+ $svcUpdateParams = New-AzureComputeParameterObject - FriendlyName ' HostedServiceUpdateParameters' ;
175
+ $svcUpdateParams.Description = ' update1' ;
176
+ $svcUpdateParams.Label = ' update2' ;
177
+
178
+ # Invoke Update
179
+ $svcGetResult2 = Invoke-AzureComputeMethod - MethodName ' HostedServiceUpdate' - ServiceName $svcName - HostedServiceUpdateParameters $svcUpdateParams ;
180
+
181
+ # Invoke Get
182
+ $svcGetResult2 = Invoke-AzureComputeMethod - MethodName ' HostedServiceGet' - ServiceName $svcName ;
183
+ Assert-AreEqual $svcGetResult2.ServiceName $svcName ;
184
+ Assert-AreEqual $svcGetResult2.Properties.Description $svcUpdateParams.Description ;
185
+ Assert-AreEqual $svcGetResult2.Properties.Label $svcUpdateParams.Label ;
186
+
187
+ # Invoke List
188
+ $svcListResult = Invoke-AzureComputeMethod - MethodName ' HostedServiceList' ;
189
+ Assert-True { ($svcListResult | where { $_.ServiceName -eq $svcName }).Count -gt 0 };
190
+
191
+ # Invoke Delete
192
+ $st = Invoke-AzureComputeMethod - MethodName ' HostedServiceDelete' - ServiceName $svcName ;
193
+ Assert-AreEqual $st.StatusCode ' OK' ;
194
+ Assert-NotNull $st.RequestId ;
195
+ }
196
+ finally
197
+ {
198
+ # Cleanup
199
+ Cleanup- CloudService $svcName ;
200
+ }
201
+ }
202
+
203
+ # Run Auto-Generated Virtual Machine Cmdlet Tests
204
+ function Run-AutoGeneratedVirtualMachineCmdletTests
205
+ {
206
+ # Setup
207
+ $location = Get-DefaultLocation ;
208
+
209
+ $storageName = ' pstest' + (getAssetName);
210
+ New-AzureStorageAccount - StorageAccountName $storageName - Location $location ;
211
+
212
+ # Associate the new storage account with the current subscription
213
+ Set-CurrentStorageAccountName $storageName ;
214
+
215
+ $svcName = ' pstest' + (Get-CloudServiceName );
216
+ $userName = " pstestuser" ;
217
+ $password = " p@ssw0rd" ;
218
+
219
+ try
220
+ {
221
+ # Create Hosted Service Parameters
222
+ $svcCreateParams = New-AzureComputeParameterObject - FriendlyName ' HostedServiceCreateParameters' ;
223
+ $svcCreateParams.ServiceName = $svcName ;
224
+ $svcCreateParams.Location = $location ;
225
+ $svcCreateParams.Description = $svcName ;
226
+ $svcCreateParams.Label = $svcName ;
227
+
228
+ # Invoke Hosted Service Create
229
+ $st = Invoke-AzureComputeMethod - MethodName ' HostedServiceCreate' - ArgumentList $svcCreateParams ;
230
+ Assert-AreEqual $st.StatusCode ' Created' ;
231
+ Assert-NotNull $st.RequestId ;
232
+
233
+ # Invoke Hosted Service Get
234
+ $svcGetResult = Invoke-AzureComputeMethod - MethodName ' HostedServiceGet' - ArgumentList $svcName ;
235
+ Assert-AreEqual $svcGetResult.ServiceName $svcName ;
236
+ Assert-AreEqual $svcGetResult.Properties.Description $svcName ;
237
+ Assert-AreEqual $svcGetResult.Properties.Label $svcName ;
238
+
239
+ # Invoke Virtual Machine OS Image List
240
+ $images = (Invoke-AzureComputeMethod - MethodName ' VirtualMachineOSImageList' ).Images;
241
+ $image = $images | where { $_.OperatingSystemType -eq ' Windows' -and $_.LogicalSizeInGB -le 100 } | select - First 1 ;
242
+
243
+ # Create Virtual Machine Deployment Create Parameters
244
+ $vmDeployment = New-AzureComputeParameterObject - FriendlyName ' VirtualMachineCreateDeploymentParameters' ;
245
+ $vmDeployment.Name = $svcName ;
246
+ $vmDeployment.Label = $svcName ;
247
+ $vmDeployment.DeploymentSlot = ' Production' ;
248
+ $vmDeployment.Roles = New-AzureComputeParameterObject - FriendlyName ' VirtualMachineRoleList' ;
249
+ $vmDeployment.Roles.Add ((New-AzureComputeParameterObject - FriendlyName ' VirtualMachineRole' ));
250
+ $vmDeployment.Roles [0 ].RoleName = $svcName ;
251
+ $vmDeployment.Roles [0 ].RoleSize = ' Large' ;
252
+ $vmDeployment.Roles [0 ].RoleType = ' PersistentVMRole' ;
253
+ $vmDeployment.Roles [0 ].ProvisionGuestAgent = $false ;
254
+ $vmDeployment.Roles [0 ].ResourceExtensionReferences = $null ;
255
+ $vmDeployment.Roles [0 ].DataVirtualHardDisks = $null ;
256
+ $vmDeployment.Roles [0 ].OSVirtualHardDisk = New-AzureComputeParameterObject - FriendlyName ' VirtualMachineOSVirtualHardDisk' ;
257
+ $vmDeployment.Roles [0 ].OSVirtualHardDisk.SourceImageName = $image.Name ;
258
+ $vmDeployment.Roles [0 ].OSVirtualHardDisk.MediaLink = " http://${storageName} .blob.core.windows.net/myvhds/${svcName} .vhd" ;
259
+ $vmDeployment.Roles [0 ].OSVirtualHardDisk.ResizedSizeInGB = 128 ;
260
+ $vmDeployment.Roles [0 ].OSVirtualHardDisk.HostCaching = ' ReadWrite' ;
261
+ $vmDeployment.Roles [0 ].ConfigurationSets = New-AzureComputeParameterObject - FriendlyName ' VirtualMachineConfigurationSetList' ;
262
+ $vmDeployment.Roles [0 ].ConfigurationSets.Add((New-AzureComputeParameterObject - FriendlyName ' VirtualMachineConfigurationSet' ));
263
+ $vmDeployment.Roles [0 ].ConfigurationSets[0 ].ConfigurationSetType = " WindowsProvisioningConfiguration" ;
264
+ $vmDeployment.Roles [0 ].ConfigurationSets[0 ].AdminUserName = $userName ;
265
+ $vmDeployment.Roles [0 ].ConfigurationSets[0 ].AdminPassword = $password ;
266
+ $vmDeployment.Roles [0 ].ConfigurationSets[0 ].ComputerName = ' test' ;
267
+ $vmDeployment.Roles [0 ].ConfigurationSets[0 ].HostName = " ${svcName} .cloudapp.net" ;
268
+ $vmDeployment.Roles [0 ].ConfigurationSets[0 ].EnableAutomaticUpdates = $false ;
269
+ $vmDeployment.Roles [0 ].ConfigurationSets[0 ].TimeZone = " Pacific Standard Time" ;
270
+
271
+ # Invoke Virtual Machine Create Deployment
272
+ $st = Invoke-AzureComputeMethod - MethodName ' VirtualMachineCreateDeployment' - ArgumentList $svcName , $vmDeployment ;
273
+ Assert-AreEqual $st.StatusCode ' OK' ;
274
+ Assert-NotNull $st.RequestId ;
275
+
276
+ # Invoke Virtual Machine Get
277
+ $st = Invoke-AzureComputeMethod - MethodName ' VirtualMachineGet' - ArgumentList $svcName , $svcName , $svcName ;
278
+ Assert-AreEqual $st.RoleName $svcName ;
279
+
280
+ # Invoke Hosted Service Delete
281
+ $st = Invoke-AzureComputeMethod - MethodName ' HostedServiceDeleteAll' - ArgumentList $svcName ;
282
+ Assert-AreEqual $st.StatusCode ' OK' ;
283
+ Assert-NotNull $st.RequestId ;
284
+ }
285
+ finally
286
+ {
287
+ # Cleanup
288
+ Cleanup- CloudService $svcName ;
289
+ }
290
+ }
291
+
292
+
293
+ # Run New-AzureComputeArgumentList Cmdlet Tests Using Method Names
294
+ function Run-NewAzureComputeArgumentListTests
295
+ {
296
+ $command = Get-Command - Name ' New-AzureComputeArgumentList' ;
297
+ $all_methods = $command.Parameters [' MethodName' ].Attributes.ValidValues;
298
+
299
+ foreach ($method in $all_methods )
300
+ {
301
+ $args = New-AzureComputeArgumentList - MethodName $method ;
302
+ foreach ($arg in $args )
303
+ {
304
+ Assert-NotNull $arg ;
305
+ }
306
+
307
+ Write-Verbose " Invoke-AzureComputeMethod -MethodName $method -ArgumentList $args ;" ;
308
+
309
+ if ($args.Count -gt 0 )
310
+ {
311
+ # If the method requires any inputs, empty/null input call would fail
312
+ Assert-Throws { Invoke-AzureComputeMethod - MethodName $method - ArgumentList $args ; }
313
+ }
314
+ else
315
+ {
316
+ # If the method doesn't requires any inputs, it shall succeed.
317
+ $st = Invoke-AzureComputeMethod - MethodName $method ;
318
+ }
319
+ }
320
+ }
321
+
322
+
323
+ # Run New-AzureComputeParameterObject Cmdlet Tests
324
+ function Run-NewAzureComputeParameterObjectTests
325
+ {
326
+ $command = Get-Command - Name ' New-AzureComputeParameterObject' ;
327
+
328
+ $all_friendly_names = $command.Parameters [' FriendlyName' ].Attributes.ValidValues;
329
+ foreach ($friendly_name in $all_friendly_names )
330
+ {
331
+ $param = New-AzureComputeParameterObject - FriendlyName $friendly_name ;
332
+ Assert-NotNull $param ;
333
+ }
334
+
335
+ $all_full_names = $command.Parameters [' FullName' ].Attributes.ValidValues;
336
+ foreach ($full_name in $all_full_names )
337
+ {
338
+ $param = New-AzureComputeParameterObject - FullName $full_name ;
339
+ Assert-NotNull $param ;
340
+
341
+ $param_type_name = $param.GetType ().ToString().Replace(' +' , ' .' );
342
+ $full_name_query = $full_name.Replace (' +' , ' .' ).Replace(' <' , ' *' ).Replace(' >' , ' *' );
343
+ Assert-True { $param_type_name -like $full_name_query } " `' $param_type_name `' & `' $full_name `' " ;
344
+ }
132
345
}
0 commit comments