Skip to content

Commit ef35853

Browse files
author
Samuel Anudeep
committed
Merge pull request #47 from MabOneSdk/anudeeb
PS Tests
2 parents da3d809 + 959950b commit ef35853

File tree

14 files changed

+611
-52
lines changed

14 files changed

+611
-52
lines changed

src/ResourceManager/AzureBackup/Commands.AzureBackup.Test/Commands.AzureBackup.Test.csproj

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,6 @@
3939
<SpecificVersion>False</SpecificVersion>
4040
<HintPath>..\..\..\packages\Microsoft.Azure.Common.Authentication.1.0.25-preview\lib\net45\Microsoft.Azure.Common.Authentication.dll</HintPath>
4141
</Reference>
42-
<Reference Include="Microsoft.Azure.Management.BackupServicesManagment">
43-
<HintPath>..\..\..\..\..\azure-sdk-for-net\src\ResourceManagement\AzureBackup\BackupServicesManagment\bin\Net45-Debug\Microsoft.Azure.Management.BackupServicesManagment.dll</HintPath>
44-
</Reference>
4542
<Reference Include="Microsoft.Azure.ResourceManager, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
4643
<SpecificVersion>False</SpecificVersion>
4744
<HintPath>..\..\..\packages\Microsoft.Azure.Management.Resources.2.18.0-preview\lib\net40\Microsoft.Azure.ResourceManager.dll</HintPath>
@@ -129,10 +126,15 @@
129126
<Compile Include="Properties\AssemblyInfo.cs" />
130127
<Compile Include="ScenarioTests\BackupItemTests.cs" />
131128
<Compile Include="ScenarioTests\AzureBackupJobTests.cs" />
132-
<Compile Include="ScenarioTests\ContainerTest\AzureBackupContainerTest.cs" />
133129
<Compile Include="ScenarioTests\RecoveryPointTests.cs" />
130+
<Compile Include="ScenarioTests\AzureBackupContainerTests.cs" />
131+
<Compile Include="ScenarioTests\AzureBackupVaultTests.cs" />
134132
</ItemGroup>
135133
<ItemGroup>
134+
<ProjectReference Include="..\..\..\..\..\azure-sdk-for-net\src\ResourceManagement\AzureBackup\BackupServicesManagment\BackupServicesManagment.csproj">
135+
<Project>{38a6741c-77a3-42a8-a846-83373be57c7f}</Project>
136+
<Name>BackupServicesManagment</Name>
137+
</ProjectReference>
136138
<ProjectReference Include="..\..\..\Common\Commands.Common\Commands.Common.csproj">
137139
<Project>{5ee72c53-1720-4309-b54b-5fb79703195f}</Project>
138140
<Name>Commands.Common</Name>
@@ -168,17 +170,26 @@
168170
<None Include="ScenarioTests\AzureBackupJobTests.ps1">
169171
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
170172
</None>
171-
<None Include="ScenarioTests\ContainerTest\AzureBackupContainerTest.ps1" />
172173
<None Include="ScenarioTests\RecoveryPointTests.ps1">
173174
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
174175
</None>
176+
<None Include="SessionRecords\Microsoft.Azure.Commands.AzureBackup.Test.ScenarioTests.AzureBackupContainerTests\GetAzureBackupContainerTests.json" />
177+
<None Include="SessionRecords\Microsoft.Azure.Commands.AzureBackup.Test.ScenarioTests.AzureBackupContainerTests\RegisterAzureBackupContainerTest.json" />
178+
<None Include="SessionRecords\Microsoft.Azure.Commands.AzureBackup.Test.ScenarioTests.AzureBackupContainerTests\UnregisterAzureBackupContainerTest.json" />
175179
<None Include="SessionRecords\Microsoft.Azure.Commands.AzureBackup.Test.ScenarioTests.AzureBackupItemTestCases\DisableAzureBackupProtectionTest.json" />
176180
<None Include="SessionRecords\Microsoft.Azure.Commands.AzureBackup.Test.ScenarioTests.AzureBackupItemTestCases\EnableAzureBackupProtectionTest.json" />
177181
<None Include="SessionRecords\Microsoft.Azure.Commands.AzureBackup.Test.ScenarioTests.AzureBackupItemTestCases\ListAzureBackupItemTests.json" />
178182
<None Include="SessionRecords\Microsoft.Azure.Commands.AzureBackup.Test.ScenarioTests.AzureBackupJobTests\GetAzureBackupJobTests.json" />
183+
<None Include="ScenarioTests\AzureBackupContainerTests.ps1">
184+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
185+
</None>
186+
<None Include="ScenarioTests\AzureBackupVaultTests.ps1">
187+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
188+
</None>
179189
<None Include="SessionRecords\Microsoft.Azure.Commands.AzureBackup.Test.ScenarioTests.AzureBackupTests\ListProtectionPolicyTests.json">
180190
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
181191
</None>
192+
<None Include="SessionRecords\Microsoft.Azure.Commands.AzureBackup.Test.ScenarioTests.AzureBackupVaultTests\GetAzureBackupVaultCredentialsTests.json" />
182193
<None Include="SessionRecords\Microsoft.Azure.Commands.AzureBackup.Test.ScenarioTests.BackupItemTests\BackUpAzureBackUpItem.json" />
183194
<None Include="SessionRecords\Microsoft.Azure.Commands.AzureBackup.Test.ScenarioTests.RecoveryPointTests\GetRecoveryPointTests.json" />
184195
</ItemGroup>
Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,25 @@
1212
// limitations under the License.
1313
// ----------------------------------------------------------------------------------
1414

15-
using Microsoft.WindowsAzure.Commands.ScenarioTest;
15+
using System;
16+
using System.Collections.Generic;
17+
using System.Linq;
18+
using System.Text;
19+
using System.Threading.Tasks;
1620
using Xunit;
1721

1822
namespace Microsoft.Azure.Commands.AzureBackup.Test.ScenarioTests
1923
{
20-
public class AzureBackupContainerTest : AzureBackupTestsBase
24+
public class AzureBackupContainerTests : AzureBackupTestsBase
2125
{
26+
[Fact]
27+
public void GetAzureBackupContainerTests()
28+
{
29+
this.RunPowerShellTest("Test-GetAzureBackupContainerWithoutFilterReturnsNonZeroContainers");
30+
31+
this.RunPowerShellTest("Test-GetAzureBackupContainerWithUniqueFilterReturnsOneContainer");
32+
}
33+
2234
[Fact]
2335
public void RegisterAzureBackupContainerTest()
2436
{
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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+
$ResourceGroupName = "backuprg"
16+
$ResourceName = "backuprn"
17+
$Location = "SouthEast Asia"
18+
$ContainerResourceGroupName = "dev01Testing"
19+
$ContainerResourceName = "dev01Testing"
20+
21+
<#
22+
.SYNOPSIS
23+
Tests to test list containers
24+
#>
25+
function Test-GetAzureBackupContainerWithoutFilterReturnsNonZeroContainers
26+
{
27+
$containers = Get-AzureBackupContainer -ResourceGroupName $ResourceGroupName -ResourceName $ResourceName -Location $Location
28+
Assert-NotNull $containers 'Container list should not be null';
29+
}
30+
31+
function Test-GetAzureBackupContainerWithUniqueFilterReturnsOneContainer
32+
{
33+
$container = Get-AzureBackupContainer -ResourceGroupName $ResourceGroupName -ResourceName $ResourceName -Location $Location -ContainerResourceGroupName $ContainerResourceGroupName -ContainerResourceName $ContainerResourceName
34+
Assert-NotNull $container 'Container should not be null';
35+
Assert-AreEqual $container.ResourceName $ContainerResourceName -CaseSensitive 'Returned container resource name (a.k.a friendly name) does not match the test VM resource name';
36+
Assert-AreEqual $container.ResourceGroupName $ContainerResourceGroupName -CaseSensitive 'Returned container resource group name (a.k.a parent friendly name) does not match the test VM resource group name';
37+
}
38+
39+
<#
40+
.SYNOPSIS
41+
Tests to register the container
42+
#>
43+
function Test-RegisterAzureBackupContainer
44+
{
45+
$jobId = Register-AzureBackupContainer -ResourceGroupName $ResourceGroupName -ResourceName $ResourceName -location $Location -Name $ContainerResourceName -ServiceName $ContainerResourceGroupName
46+
47+
Assert-NotNull $jobId 'JobID should not be null';
48+
}
49+
50+
function Test-UnregisterAzureBackupContainer
51+
{
52+
$container = Get-AzureBackupContainer -ResourceGroupName $ResourceGroupName -ResourceName $ResourceName -location $Location -ContainerResourceName $ContainerResourceName -ContainerResourceGroupName $ContainerResourceGroupName
53+
$jobId = Unregister-AzureBackupContainer -ResourceGroupName $ResourceGroupName -ResourceName $ResourceName -location $Location -AzureBackupContainer $container
54+
55+
Assert-NotNull $jobId 'JobID should not be null';
56+
}

src/ResourceManager/AzureBackup/Commands.AzureBackup.Test/ScenarioTests/AzureBackupTests.ps1

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
$ResourceGroupName = "backuprg"
1616
$ResourceName = "backuprn"
1717
$ContainerName = "iaasvmcontainer;dev01testing;dev01testing"
18+
$ContainerResourceGroupName = "dev01Testing"
19+
$ContainerResourceName = "dev01Testing"
1820
$ContainerType = "IaasVMContainer"
1921
$DataSourceType = "VM"
2022
$DataSourceId = "17593283453810"
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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 System;
16+
using System.Collections.Generic;
17+
using System.Linq;
18+
using System.Text;
19+
using System.Threading.Tasks;
20+
using Xunit;
21+
22+
namespace Microsoft.Azure.Commands.AzureBackup.Test.ScenarioTests
23+
{
24+
public class AzureBackupVaultTests : AzureBackupTestsBase
25+
{
26+
[Fact]
27+
public void GetAzureBackupVaultCredentialsTests()
28+
{
29+
this.RunPowerShellTest("Test-GetAzureBackupVaultCredentialsReturnsFileNameAndDownloadsCert");
30+
}
31+
32+
[Fact]
33+
public void SetAzureBackupVaultStorageTypeTests()
34+
{
35+
this.RunPowerShellTest("Test-SetAzureBackupVaultStorageTypeWithFreshResourceDoesNotThrowException");
36+
37+
this.RunPowerShellTest("Test-SetAzureBackupVaultStorageTypeWithLockedResourceThrowsException");
38+
}
39+
}
40+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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+
$ResourceGroupName = "backuprg"
16+
$ResourceName = "backuprn"
17+
$Location = "SouthEast Asia"
18+
$CertTargetLocation = (Get-Item -Path ".\" -Verbose).FullName;
19+
20+
function Test-GetAzureBackupVaultCredentialsReturnsFileNameAndDownloadsCert
21+
{
22+
$fileName = Get-AzureBackupVaultCredentials -ResourceGroupName $ResourceGroupName -ResourceName $ResourceName -Location $Location -TargetLocation $CertTargetLocation
23+
Assert-NotNull $fileName 'File name should not be null';
24+
$certFileFullPath = [io.path]::combine($CertTargetLocation, $fileName);
25+
Assert-True {{ Test-Path $certFileFullPath }}
26+
}
27+
28+
function Test-SetAzureBackupVaultStorageTypeWithFreshResourceDoesNotThrowException
29+
{
30+
# TODO: Create a new resource and use it for these calls. At the end, delete it.
31+
32+
Set-AzureBackupVaultStorageType -ResourceGroupName $ResourceGroupName -ResourceName $ResourceName -Location $Location -Type GeoRedundant
33+
34+
Set-AzureBackupVaultStorageType -ResourceGroupName $ResourceGroupName -ResourceName $ResourceName -Location $Location -Type LocallyRedundant
35+
36+
Set-AzureBackupVaultStorageType -ResourceGroupName $ResourceGroupName -ResourceName $ResourceName -Location $Location -Type GeoRedundant
37+
38+
Set-AzureBackupVaultStorageType -ResourceGroupName $ResourceGroupName -ResourceName $ResourceName -Location $Location -Type LocallyRedundant
39+
}
40+
41+
function Test-SetAzureBackupVaultStorageTypeWithLockedResourceThrowsException
42+
{
43+
# One of them is bound to fail
44+
45+
Assert-Throws { Set-AzureBackupVaultStorageType -ResourceGroupName $ResourceGroupName -ResourceName $ResourceName -Location $Location -Type GeoRedundant }
46+
47+
Assert-Throws { Set-AzureBackupVaultStorageType -ResourceGroupName $ResourceGroupName -ResourceName $ResourceName -Location $Location -Type LocallyRedundant }
48+
}

src/ResourceManager/AzureBackup/Commands.AzureBackup.Test/ScenarioTests/ContainerTest/AzureBackupContainerTest.ps1

Lines changed: 0 additions & 39 deletions
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
{
2+
"Entries": [
3+
{
4+
"RequestUri": "/Subscriptions/f5303a0b-fae4-4cdb-b44d-0e4c032dde26/resourceGroups/backuprg/providers/Microsoft.Backupseadev01/BackupVault/backuprn/containers?api-version=2014-09-01&dummy=%26FriendlyName%3Ddev01Testing",
5+
"EncodedRequestUri": "L1N1YnNjcmlwdGlvbnMvZjUzMDNhMGItZmFlNC00Y2RiLWI0NGQtMGU0YzAzMmRkZTI2L3Jlc291cmNlR3JvdXBzL2JhY2t1cHJnL3Byb3ZpZGVycy9NaWNyb3NvZnQuQmFja3Vwc2VhZGV2MDEvQmFja3VwVmF1bHQvYmFja3Vwcm4vY29udGFpbmVycz9hcGktdmVyc2lvbj0yMDE0LTA5LTAxJmR1bW15PSUyNkZyaWVuZGx5TmFtZSUzRGRldjAxVGVzdGluZw==",
6+
"RequestMethod": "GET",
7+
"RequestBody": "",
8+
"RequestHeaders": {
9+
"Accept-Language": [
10+
"en-us"
11+
],
12+
"x-ms-version": [
13+
"2013-03-01"
14+
],
15+
"User-Agent": [
16+
"Microsoft.Azure.Management.BackupServices.BackupServicesManagementClient/0.0.0.0"
17+
]
18+
},
19+
"ResponseBody": "{\r\n \"Objects\": [\r\n {\r\n \"FriendlyName\": \"dev01Testing\",\r\n \"SubscriptionId\": \"f5303a0b-fae4-4cdb-b44d-0e4c032dde26\",\r\n \"ContainerType\": \"IaasVMContainer\",\r\n \"ParentContainerName\": \"dev01Testing\",\r\n \"ParentContainerFriendlyName\": \"dev01Testing\",\r\n \"RegistrationStatus\": \"Registered\",\r\n \"HealthStatus\": \"Healthy\",\r\n \"PropertyBag\": null,\r\n \"InstanceId\": null,\r\n \"Name\": \"iaasvmcontainer;dev01testing;dev01testing\",\r\n \"OperationInProgress\": false\r\n },\r\n {\r\n \"FriendlyName\": \"dev01Testing\",\r\n \"SubscriptionId\": \"f5303a0b-fae4-4cdb-b44d-0e4c032dde26\",\r\n \"ContainerType\": \"IaasVMServiceContainer\",\r\n \"ParentContainerName\": null,\r\n \"ParentContainerFriendlyName\": null,\r\n \"RegistrationStatus\": \"NotRegistered\",\r\n \"HealthStatus\": \"Healthy\",\r\n \"PropertyBag\": \"\",\r\n \"InstanceId\": null,\r\n \"Name\": \"dev01testing\",\r\n \"OperationInProgress\": false\r\n }\r\n ],\r\n \"ResultCount\": 2,\r\n \"Skiptoken\": null\r\n}",
20+
"ResponseHeaders": {
21+
"Content-Length": [
22+
"763"
23+
],
24+
"Content-Type": [
25+
"application/json"
26+
],
27+
"Expires": [
28+
"-1"
29+
],
30+
"Pragma": [
31+
"no-cache"
32+
],
33+
"x-ms-request-id": [
34+
"ce4dfbf6-9708-49f2-9532-0dbc9e912bf7"
35+
],
36+
"x-ms-client-request-id": [
37+
"0482c73c-7196-49f8-96a0-3dcd0ccdaa90",
38+
"0482c73c-7196-49f8-96a0-3dcd0ccdaa90"
39+
],
40+
"Strict-Transport-Security": [
41+
"max-age=31536000; includeSubDomains"
42+
],
43+
"x-ms-ratelimit-remaining-subscription-reads": [
44+
"14997"
45+
],
46+
"x-ms-correlation-request-id": [
47+
"ce4dfbf6-9708-49f2-9532-0dbc9e912bf7"
48+
],
49+
"x-ms-routing-request-id": [
50+
"CENTRALUS:20150617T170930Z:ce4dfbf6-9708-49f2-9532-0dbc9e912bf7"
51+
],
52+
"Cache-Control": [
53+
"no-cache"
54+
],
55+
"Date": [
56+
"Wed, 17 Jun 2015 17:09:30 GMT"
57+
],
58+
"Server": [
59+
"Microsoft-IIS/8.0"
60+
],
61+
"X-Powered-By": [
62+
"ASP.NET"
63+
]
64+
},
65+
"StatusCode": 200
66+
}
67+
],
68+
"Names": {},
69+
"Variables": {
70+
"SubscriptionId": "f5303a0b-fae4-4cdb-b44d-0e4c032dde26"
71+
}
72+
}

0 commit comments

Comments
 (0)