Skip to content

Commit e6571ca

Browse files
committed
Add script-based test for SM
1 parent 6c8c917 commit e6571ca

File tree

6 files changed

+2570
-40
lines changed

6 files changed

+2570
-40
lines changed

src/Common/Commands.ScenarioTest/Commands.ScenarioTest.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,9 @@
203203
<None Include="SessionRecords\Microsoft.WindowsAzure.Commands.ScenarioTest.AutomationTests\TestAutomationSuspendAndResumeJob.json">
204204
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
205205
</None>
206+
<None Include="SessionRecords\Microsoft.WindowsAzure.Commands.ScenarioTest.AzureVMTests\TestGetAzureLocation.json">
207+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
208+
</None>
206209
<None Include="SessionRecords\Microsoft.WindowsAzure.Commands.ScenarioTest.AzureVMTests\TestGetAzureVM.json">
207210
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
208211
</None>
@@ -287,6 +290,7 @@
287290
<Compile Include="Resources\ResourceLocator.cs" />
288291
<Compile Include="Scheduler\SchedulerTests.cs" />
289292
<Compile Include="ServiceBusTests\ServiceBusAuthorizationRuleTests.cs" />
293+
<Compile Include="ServiceManagement\GetLocationTests.cs" />
290294
<Compile Include="ServiceManagement\GetVMTests.cs" />
291295
<Compile Include="StorageTests\StorageContainerTest.cs" />
292296
<Compile Include="StorageTests\StorageContextTest.cs" />

src/Common/Commands.ScenarioTest/Resources/ServiceManagement/AzureVMTests.ps1

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,36 +12,52 @@
1212
# limitations under the License.
1313
# ----------------------------------------------------------------------------------
1414

15-
########################################################################### Create-AzureVM Scenario Tests ###########################################################################
16-
1715
<#
1816
.SYNOPSIS
1917
Tests Create-AzureVM with valid information.
2018
#>
2119
function Test-GetAzureVM
2220
{
23-
# Setup
21+
# Setup
2422

25-
$location = Get-DefaultLocation
26-
$imgName = Get-DefaultImage $location
23+
$location = Get-DefaultLocation
24+
$imgName = Get-DefaultImage $location
2725

2826

29-
$storageName = getAssetName
30-
New-AzureStorageAccount -StorageAccountName $storageName -Location $location
27+
$storageName = getAssetName
28+
New-AzureStorageAccount -StorageAccountName $storageName -Location $location
3129

32-
Set-CurrentStorageAccountName $storageName
30+
Set-CurrentStorageAccountName $storageName
3331

34-
$vmName = "vm1"
35-
$svcName = Get-CloudServiceName
32+
$vmName = "vm1"
33+
$svcName = Get-CloudServiceName
3634

37-
# Test
38-
New-AzureService -ServiceName $svcName -Location $location
39-
New-AzureQuickVM -Windows -ImageName $imgName -Name $vmName -ServiceName $svcName -AdminUsername "pstestuser" -Password "p@ssw0rd"
35+
# Test
36+
New-AzureService -ServiceName $svcName -Location $location
37+
New-AzureQuickVM -Windows -ImageName $imgName -Name $vmName -ServiceName $svcName -AdminUsername "pstestuser" -Password "p@ssw0rd"
4038

41-
Get-AzureVM -ServiceName $svcName -Name $vmName
39+
Get-AzureVM -ServiceName $svcName -Name $vmName
4240

4341

44-
# Cleanup
45-
Cleanup-CloudService $svcName
42+
# Cleanup
43+
Cleanup-CloudService $svcName
4644
}
4745

46+
47+
<#
48+
.SYNOPSIS
49+
Test Get-AzureLocation
50+
#>
51+
function Test-GetAzureLocation
52+
{
53+
$locations = Get-AzureLocation;
54+
55+
foreach ($loc in $locations)
56+
{
57+
$svcName = getAssetName;
58+
$st = New-AzureService -ServiceName $svcName -Location $loc.Name;
59+
60+
# Cleanup
61+
Cleanup-CloudService $svcName
62+
}
63+
}

src/Common/Commands.ScenarioTest/Resources/ServiceManagement/Common.ps1

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ Sets the default storage account
2020
function Set-CurrentStorageAccountName
2121
{
2222
param([string] $storageAccountName)
23-
$currentSubscription = Get-AzureSubscription -Current
23+
$currentSubscription = Get-AzureSubscription -Current
2424

25-
Set-AzureSubscription -SubscriptionId $currentSubscription.SubscriptionId -CurrentStorageAccountName $storageAccountName
25+
Set-AzureSubscription -SubscriptionId $currentSubscription.SubscriptionId -CurrentStorageAccountName $storageAccountName
2626
}
2727

2828
<#
@@ -31,7 +31,7 @@ Gets the default location
3131
#>
3232
function Get-DefaultLocation
3333
{
34-
return (Get-AzureLocation)[0].Name
34+
return (Get-AzureLocation)[0].Name
3535
}
3636

3737
<#
@@ -41,7 +41,7 @@ Gets the default image
4141
function Get-DefaultImage
4242
{
4343
param([string] $loc)
44-
return (Get-AzureVMImage | where {$_.OS -eq "Windows"} | where {$_.Location.Contains($loc)})[0].ImageName
44+
return (Get-AzureVMImage | where {$_.OS -eq "Windows"} | where {$_.Location.Contains($loc)})[0].ImageName
4545
}
4646

4747

@@ -51,7 +51,7 @@ Gets valid and available cloud service name.
5151
#>
5252
function Get-CloudServiceName
5353
{
54-
return getAssetName
54+
return getAssetName
5555
}
5656

5757
<#
@@ -61,14 +61,14 @@ Cleanup cloud service
6161
function Cleanup-CloudService
6262
{
6363
param([string] $name)
64-
try
65-
{
66-
Remove-AzureService -ServiceName $name -Force
67-
}
68-
catch
69-
{
70-
Write-Warning "Cannot Remove the Cloud Service"
71-
}
64+
try
65+
{
66+
Remove-AzureService -ServiceName $name -Force
67+
}
68+
catch
69+
{
70+
Write-Warning "Cannot Remove the Cloud Service"
71+
}
7272
}
7373

7474
<#
@@ -78,13 +78,13 @@ Cleanup storage
7878
function Cleanup-Storage
7979
{
8080
param([string] $name)
81-
Remove-AzureStorageAccount -StorageAccountName $name
82-
try
83-
{
84-
Remove-AzureStorageAccount -StorageAccountName $name
85-
}
86-
catch
87-
{
88-
Write-Warning "Cannot Remove the Storage Account"
89-
}
81+
Remove-AzureStorageAccount -StorageAccountName $name
82+
try
83+
{
84+
Remove-AzureStorageAccount -StorageAccountName $name
85+
}
86+
catch
87+
{
88+
Write-Warning "Cannot Remove the Storage Account"
89+
}
9090
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
using Microsoft.WindowsAzure.Commands.ScenarioTest.Common;
16+
using Xunit;
17+
18+
namespace Microsoft.WindowsAzure.Commands.ScenarioTest
19+
{
20+
public partial class AzureVMTests
21+
{
22+
[Fact]
23+
[Trait(Category.Service, Category.ServiceManagement)]
24+
[Trait(Category.AcceptanceType, Category.CheckIn)]
25+
[Trait(Category.AcceptanceType, Category.BVT)]
26+
public void TestGetAzureLocation()
27+
{
28+
this.RunPowerShellTest("Test-GetAzureLocation");
29+
}
30+
}
31+
}

src/Common/Commands.ScenarioTest/ServiceManagement/GetVMTests.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
namespace Microsoft.WindowsAzure.Commands.ScenarioTest
2323
{
24-
public class AzureVMTests
24+
public partial class AzureVMTests
2525
{
2626
private EnvironmentSetupHelper helper = new EnvironmentSetupHelper();
2727

@@ -52,9 +52,10 @@ protected void RunPowerShellTest(params string[] scripts)
5252

5353
List<string> modules = Directory.GetFiles("Resources\\ServiceManagement", "*.ps1").ToList();
5454
modules.Add("Common.ps1");
55+
modules.Add(@"..\..\..\..\Package\Debug\ServiceManagement\Azure\Azure.psd1");
5556

5657
helper.SetupEnvironment(AzureModule.AzureServiceManagement);
57-
helper.SetupModules(AzureModule.AzureServiceManagement, modules.ToArray());
58+
helper.SetupModules(modules.ToArray());
5859

5960
helper.RunPowerShellTest(scripts);
6061
}

src/Common/Commands.ScenarioTest/SessionRecords/Microsoft.WindowsAzure.Commands.ScenarioTest.AzureVMTests/TestGetAzureLocation.json

Lines changed: 2478 additions & 0 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)