Skip to content

Commit 06925b7

Browse files
cormacpayneMaddie Clayton
authored andcommitted
Fix issue with Properties property of PSResource (#6218)
* Fix issue with Properties property of PSResource * Add test coverage for Properties property
1 parent de13e78 commit 06925b7

File tree

9 files changed

+2193
-5
lines changed

9 files changed

+2193
-5
lines changed

src/ResourceManager/Resources/ChangeLog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
- Additional information about change #1
1919
-->
2020
## Current Release
21+
* Fix issue with `Properties` property of `PSResource` object(s) returned from `Get-AzureRmResource`
2122

2223
## Version 6.0.0
2324
* Set minimum dependency of module to PowerShell 5.0

src/ResourceManager/Resources/Commands.ResourceManager/Cmdlets/SdkModels/Resources/PSResource.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,13 @@
1313
// ----------------------------------------------------------------------------------
1414

1515
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.Components;
16+
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.Extensions;
1617
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.SdkExtensions;
1718
using Microsoft.Azure.Management.ResourceManager.Models;
19+
using Newtonsoft.Json.Linq;
1820
using System.Collections;
1921
using System.Collections.Generic;
22+
using System.Management.Automation;
2023

2124
namespace Microsoft.Azure.Commands.ResourceManager.Cmdlets.SdkModels
2225
{
@@ -40,7 +43,7 @@ public class PSResource
4043

4144
public Plan Plan { get; set; }
4245

43-
public object Properties { get; set; }
46+
public PSObject Properties { get; set; }
4447

4548
public string ResourceGroupName { get; set; }
4649

@@ -62,7 +65,7 @@ public PSResource(GenericResource resource)
6265
this.ManagedBy = resource.ManagedBy;
6366
this.Name = resource.Name;
6467
this.Plan = resource.Plan;
65-
this.Properties = resource.Properties;
68+
this.Properties = ((JToken)resource.Properties).ToPsObject();
6669
this.ResourceType = resource.Type;
6770
this.Sku = resource.Sku;
6871
this.Tags = resource.Tags;

src/ResourceManager/Resources/Commands.Resources.Test/Commands.Resources.Test.csproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,12 @@
494494
<None Include="SessionRecords\Microsoft.Azure.Commands.Resources.Test.ScenarioTests.ResourceTests\TestFindAResourceTest.json">
495495
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
496496
</None>
497+
<None Include="SessionRecords\Microsoft.Azure.Commands.Resources.Test.ScenarioTests.ResourceTests\TestGetResourceByComponentsAndProperties.json">
498+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
499+
</None>
500+
<None Include="SessionRecords\Microsoft.Azure.Commands.Resources.Test.ScenarioTests.ResourceTests\TestGetResourceByIdAndProperties.json">
501+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
502+
</None>
497503
<None Include="SessionRecords\Microsoft.Azure.Commands.Resources.Test.ScenarioTests.ResourceTests\TestGetResourceForNonExisingResource.json">
498504
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
499505
</None>

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.

tools/StaticAnalysis/Exceptions/BreakingChangeIssues.csv

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"AssemblyFileName","ClassName","Target","Severity","ProblemId","Description","Remediation"
2+
"Microsoft.Azure.Commands.ResourceManager.Cmdlets.dll","Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation.GetAzureResourceCmdlet","Get-AzureRmResource","0","3000","The type of property 'Properties' of type 'Microsoft.Azure.Commands.ResourceManager.Cmdlets.SdkModels.PSResource' has changed from 'System.Object' to 'System.Management.Automation.PSObject'.","Change the type of property 'Properties' back to 'System.Object'."
23
"Microsoft.Azure.Commands.ServiceFabric.dll","Microsoft.Azure.Commands.ServiceFabric.Commands.NewAzureRmServiceFabricCluster","New-AzureRmServiceFabricCluster","0","3000","The type of property 'Properties' of type 'Microsoft.Azure.Commands.ServiceFabric.Models.PSDeploymentExtended' has changed from 'Microsoft.Azure.Management.ResourceManager.Models.DeploymentPropertiesExtended' to 'Microsoft.Azure.Management.Internal.Resources.Models.DeploymentPropertiesExtended'.","Change the type of property 'Properties' back to 'Microsoft.Azure.Management.ResourceManager.Models.DeploymentPropertiesExtended'."
34
"Microsoft.Azure.Commands.Sql.dll","Microsoft.Azure.Commands.Sql.FailoverGroup.Cmdlet.AddAzureSqlDatabaseToFailoverGroup","Add-AzureRmSqlDatabaseToFailoverGroup","0","3000","The type of property 'Edition' of type 'Microsoft.Azure.Commands.Sql.Database.Model.AzureSqlDatabaseModel' has changed from 'Microsoft.Azure.Commands.Sql.Database.Model.DatabaseEdition' to 'System.String'.","Change the type of property 'Edition' back to 'Microsoft.Azure.Commands.Sql.Database.Model.DatabaseEdition'."
45
"Microsoft.Azure.Commands.Sql.dll","Microsoft.Azure.Commands.Sql.ElasticPool.Cmdlet.NewAzureSqlElasticPool","New-AzureRmSqlElasticPool","0","2020","The cmdlet 'New-AzureRmSqlElasticPool' no longer supports the type 'Microsoft.Azure.Commands.Sql.Database.Model.DatabaseEdition' for parameter 'Edition'.","Change the type for parameter 'Edition' back to 'Microsoft.Azure.Commands.Sql.Database.Model.DatabaseEdition'."

0 commit comments

Comments
 (0)