Skip to content

Commit 51bea0b

Browse files
committed
Add test coverage for Properties property
1 parent 197d347 commit 51bea0b

File tree

5 files changed

+2180
-3
lines changed

5 files changed

+2180
-3
lines changed

src/ResourceManager/Resources/Commands.Resources.Test/ScenarioTests/ResourceTests.cs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,14 +98,14 @@ public void TestMoveResourceFailed()
9898
ResourcesController.NewInstance.RunPsTest("Test-MoveResourceFailed");
9999
}
100100

101-
[Fact(Skip = "Successfully re-recorded, but still failing in playback")]
101+
[Fact]
102102
[Trait(Category.AcceptanceType, Category.CheckIn)]
103103
public void TestSetAResourceTest()
104104
{
105105
ResourcesController.NewInstance.RunPsTest("Test-SetAResource");
106106
}
107107

108-
[Fact(Skip = "Successfully re-recorded, but still failing in playback")]
108+
[Fact]
109109
[Trait(Category.AcceptanceType, Category.CheckIn)]
110110
public void TestSetAResourceWithPatchTest()
111111
{
@@ -133,6 +133,20 @@ public void TestGetResourceWithExpandProperties()
133133
ResourcesController.NewInstance.RunPsTest("Test-GetResourceExpandProperties");
134134
}
135135

136+
[Fact]
137+
[Trait(Category.AcceptanceType, Category.CheckIn)]
138+
public void TestGetResourceByIdAndProperties()
139+
{
140+
ResourcesController.NewInstance.RunPsTest("Test-GetResourceByIdAndProperties");
141+
}
142+
143+
[Fact]
144+
[Trait(Category.AcceptanceType, Category.CheckIn)]
145+
public void TestGetResourceByComponentsAndProperties()
146+
{
147+
ResourcesController.NewInstance.RunPsTest("Test-GetResourceByComponentsAndProperties");
148+
}
149+
136150
[Fact(Skip = "Zones are disabled for now.")]
137151
[Trait(Category.AcceptanceType, Category.CheckIn)]
138152
public void TestManageResourceWithZones()

src/ResourceManager/Resources/Commands.Resources.Test/ScenarioTests/ResourceTests.ps1

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,78 @@ function Test-GetResourceExpandProperties
471471
}
472472
}
473473

474+
<#
475+
.SYNOPSIS
476+
Tests getting a resource by id and its properties
477+
#>
478+
function Test-GetResourceByIdAndProperties
479+
{
480+
# Setup
481+
$rgname = Get-ResourceGroupName
482+
$rname = Get-ResourceName
483+
$rglocation = Get-Location "Microsoft.Resources" "resourceGroups" "West US"
484+
$apiversion = "2014-04-01"
485+
$resourceType = "Providers.Test/statefulResources"
486+
487+
try
488+
{
489+
# Test
490+
New-AzureRmResourceGroup -Name $rgname -Location $rglocation
491+
$resource = New-AzureRmResource -Name $rname -Location $rglocation -Tags @{testtag = "testval"} -ResourceGroupName $rgname -ResourceType $resourceType -PropertyObject @{"key" = "value"} -SkuObject @{ Name = "A0" } -ApiVersion $apiversion -Force
492+
$resourceGet = Get-AzureRmResource -ResourceId $resource.ResourceId
493+
494+
# Assert
495+
Assert-NotNull $resourceGet
496+
Assert-AreEqual $resourceGet.Name $rname
497+
Assert-AreEqual $resourceGet.ResourceGroupName $rgname
498+
Assert-AreEqual $resourceGet.ResourceType $resourceType
499+
$properties = $resourceGet.Properties
500+
Assert-NotNull $properties
501+
Assert-NotNull $properties.key
502+
Assert-AreEqual $properties.key "value"
503+
}
504+
finally
505+
{
506+
Clean-ResourceGroup $rgname
507+
}
508+
}
509+
510+
<#
511+
.SYNOPSIS
512+
Tests getting a resource by its components and its properties
513+
#>
514+
function Test-GetResourceByComponentsAndProperties
515+
{
516+
# Setup
517+
$rgname = Get-ResourceGroupName
518+
$rname = Get-ResourceName
519+
$rglocation = Get-Location "Microsoft.Resources" "resourceGroups" "West US"
520+
$apiversion = "2014-04-01"
521+
$resourceType = "Providers.Test/statefulResources"
522+
523+
try
524+
{
525+
# Test
526+
New-AzureRmResourceGroup -Name $rgname -Location $rglocation
527+
$resource = New-AzureRmResource -Name $rname -Location $rglocation -Tags @{testtag = "testval"} -ResourceGroupName $rgname -ResourceType $resourceType -PropertyObject @{"key" = "value"} -SkuObject @{ Name = "A0" } -ApiVersion $apiversion -Force
528+
$resourceGet = Get-AzureRmResource -Name $rname -ResourceGroupName $rgname -ResourceType $resourceType
529+
530+
# Assert
531+
Assert-NotNull $resourceGet
532+
Assert-AreEqual $resourceGet.Name $rname
533+
Assert-AreEqual $resourceGet.ResourceGroupName $rgname
534+
Assert-AreEqual $resourceGet.ResourceType $resourceType
535+
$properties = $resourceGet.Properties
536+
Assert-NotNull $properties
537+
Assert-NotNull $properties.key
538+
Assert-AreEqual $properties.key "value"
539+
}
540+
finally
541+
{
542+
Clean-ResourceGroup $rgname
543+
}
544+
}
545+
474546
<#
475547
.SYNOPSIS
476548
Tests managing resource with zones.

src/ResourceManager/Resources/Commands.Resources.Test/ScenarioTests/ResourcesController.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public void RunPsTest(params string[] scripts)
9292
() => scripts,
9393
// no custom initializer
9494
null,
95-
// no custom cleanup
95+
// no custom cleanup
9696
null,
9797
callingClassType,
9898
mockName);
@@ -121,6 +121,7 @@ public void RunPsTestWorkflow(
121121
d.Add("Microsoft.Resources", null);
122122
d.Add("Microsoft.Features", null);
123123
d.Add("Microsoft.Authorization", null);
124+
d.Add("Providers.Test", null);
124125
var providersToIgnore = new Dictionary<string, string>();
125126
providersToIgnore.Add("Microsoft.Azure.Management.ResourceManager.ResourceManagementClient", "2016-07-01");
126127
providersToIgnore.Add("Microsoft.Azure.Management.Resources.ResourceManagementClient", "2016-02-01");

src/ResourceManager/Resources/Commands.Resources.Test/SessionRecords/Microsoft.Azure.Commands.Resources.Test.ScenarioTests.ResourceTests/TestGetResourceByComponentsAndProperties.json

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

src/ResourceManager/Resources/Commands.Resources.Test/SessionRecords/Microsoft.Azure.Commands.Resources.Test.ScenarioTests.ResourceTests/TestGetResourceByIdAndProperties.json

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

0 commit comments

Comments
 (0)