Skip to content

Commit b7d3a4d

Browse files
author
Hovsep
committed
Merge pull request #1734 from vivsriaus/CollectionGet
Support collection query in resource get
2 parents f7e4cbe + 4597b0f commit b7d3a4d

File tree

5 files changed

+1195
-3
lines changed

5 files changed

+1195
-3
lines changed

src/ResourceManager/Resources/Commands.ResourceManager/Cmdlets/Implementation/Resource/GetAzureResourceCmdlet.cs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,16 @@ public sealed class GetAzureResourceCmdlet : ResourceManagerCmdletBase
6767
/// </summary>
6868
internal const string GetResourceByNameGroupParameterSet = "Get resource by name and group";
6969

70-
/// <summary>
71-
/// The list resources by name and resource group set.
70+
/// <summary>
71+
/// The list resources by name, type and resource group set.
7272
/// </summary>
7373
internal const string GetResourceByNameGroupTypeParameterSet = "Get resource by name, group and type";
7474

75+
/// <summary>
76+
/// The list resources set.
77+
/// </summary>
78+
internal const string ListResourceCollection = "Get resource collection";
79+
7580
/// <summary>
7681
/// Caches the current subscription ids to get all subscription ids in the pipeline.
7782
/// </summary>
@@ -100,6 +105,7 @@ public sealed class GetAzureResourceCmdlet : ResourceManagerCmdletBase
100105
/// <summary>
101106
/// Gets or sets the resource type parameter.
102107
/// </summary>
108+
[Parameter(ParameterSetName = GetAzureResourceCmdlet.ListResourceCollection, Mandatory = true, HelpMessage = "When specified, ensures that the query is run against a collection instead of a resource.")]
103109
[Parameter(ParameterSetName = GetAzureResourceCmdlet.GetTenantResourceParameterSet, Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "The resource type. e.g. Microsoft.Sql/Servers/Databases.")]
104110
[Parameter(ParameterSetName = GetAzureResourceCmdlet.ListTenantResourcesParameterSet, Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "The resource type. e.g. Microsoft.Sql/Servers/Databases.")]
105111
[Parameter(ParameterSetName = GetAzureResourceCmdlet.GetResourceByNameTypeParameterSet, Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "The resource type. e.g. Microsoft.Sql/Servers/Databases.")]
@@ -121,6 +127,7 @@ public sealed class GetAzureResourceCmdlet : ResourceManagerCmdletBase
121127
/// <summary>
122128
/// Gets or sets the extension resource type.
123129
/// </summary>
130+
[Parameter(ParameterSetName = GetAzureResourceCmdlet.ListResourceCollection, Mandatory = false, HelpMessage = "When specified, ensures that the query is run against a collection instead of a resource.")]
124131
[Parameter(ParameterSetName = GetAzureResourceCmdlet.GetTenantResourceParameterSet, Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "The extension resource type. e.g. Microsoft.Sql/Servers/Databases.")]
125132
[Parameter(ParameterSetName = GetAzureResourceCmdlet.ListTenantResourcesParameterSet, Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "The extension resource type. e.g. Microsoft.Sql/Servers/Databases.")]
126133
[Parameter(ParameterSetName = GetAzureResourceCmdlet.GetResourceByNameGroupParameterSet, Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "The extension resource type. e.g. Microsoft.Sql/Servers/Databases.")]
@@ -138,11 +145,11 @@ public sealed class GetAzureResourceCmdlet : ResourceManagerCmdletBase
138145
/// <summary>
139146
/// Gets or sets the is collection.
140147
/// </summary>
148+
[Parameter(ParameterSetName = GetAzureResourceCmdlet.ListResourceCollection, Mandatory = true, HelpMessage = "When specified, ensures that the query is run against a collection instead of a resource.")]
141149
[Parameter(ParameterSetName = GetAzureResourceCmdlet.GetTenantResourceParameterSet, Mandatory = false, HelpMessage = "When specified, ensures that the query is run against a collection instead of a resource.")]
142150
[Parameter(ParameterSetName = GetAzureResourceCmdlet.ListTenantResourcesParameterSet, Mandatory = false, HelpMessage = "When specified, ensures that the query is run against a collection instead of a resource.")]
143151
[Parameter(ParameterSetName = GetAzureResourceCmdlet.GetResourceByNameTypeParameterSet, Mandatory = false, HelpMessage = "When specified, ensures that the query is run against a collection instead of a resource.")]
144152
[Parameter(ParameterSetName = GetAzureResourceCmdlet.GetResourceByNameGroupParameterSet, Mandatory = false, HelpMessage = "When specified, ensures that the query is run against a collection instead of a resource.")]
145-
[Parameter(ParameterSetName = GetAzureResourceCmdlet.GetResourceByNameGroupTypeParameterSet, Mandatory = false, HelpMessage = "When specified, ensures that the query is run against a collection instead of a resource.")]
146153
public SwitchParameter IsCollection { get; set; }
147154

148155
/// <summary>
@@ -162,6 +169,7 @@ public sealed class GetAzureResourceCmdlet : ResourceManagerCmdletBase
162169
/// <summary>
163170
/// Gets or sets the resource group name.
164171
/// </summary>
172+
[Parameter(ParameterSetName = GetAzureResourceCmdlet.ListResourceCollection, Mandatory = true, HelpMessage = "When specified, ensures that the query is run against a collection instead of a resource.")]
165173
[Parameter(ParameterSetName = GetAzureResourceCmdlet.GetResourceByNameGroupParameterSet, Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "The resource group name.")]
166174
[Parameter(ParameterSetName = GetAzureResourceCmdlet.GetResourceByNameGroupTypeParameterSet, Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "The resource group name.")]
167175
[ValidateNotNullOrEmpty]

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -501,6 +501,9 @@
501501
<None Include="SessionRecords\Microsoft.Azure.Commands.Resources.Test.ScenarioTests.ActiveDirectoryTests\TestNewADServicePrincipal.json">
502502
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
503503
</None>
504+
<None Include="SessionRecords\Microsoft.Azure.Commands.Resources.Test.ScenarioTests.ResourceTests\TestGetResourceWithCollection.json">
505+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
506+
</None>
504507
<None Include="SessionRecords\Microsoft.Azure.Commands.Resources.Test.ScenarioTests.ResourceTests\TestGetResourceWithExpandProperties.json">
505508
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
506509
</None>

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,5 +111,12 @@ public void TestGetResourceWithExpandProperties()
111111
{
112112
ResourcesController.NewInstance.RunPsTest("Test-GetResourceExpandProperties");
113113
}
114+
115+
[Fact]
116+
[Trait(Category.AcceptanceType, Category.CheckIn)]
117+
public void TestGetResourceWithCollection()
118+
{
119+
ResourcesController.NewInstance.RunPsTest("Test-GetResourceWithCollection");
120+
}
114121
}
115122
}

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,4 +347,26 @@ function Test-GetResourceExpandProperties
347347

348348
# Assert
349349
Assert-AreEqual $resourceGet.Properties.key "value"
350+
}
351+
352+
<#
353+
.SYNOPSIS
354+
Tests getting a resource with IsCollection
355+
#>
356+
function Test-GetResourceWithCollection
357+
{
358+
# Setup
359+
$rgname = Get-ResourceGroupName
360+
$rname = Get-ResourceName
361+
$rglocation = Get-ProviderLocation ResourceManagement
362+
$apiversion = "2015-08-01"
363+
$resourceType = "Providers.Test/statefulResources"
364+
365+
# Test
366+
New-AzureRmResourceGroup -Name $rgname -Location $rglocation
367+
New-AzureRmResourceGroupDeployment -Name $rname -ResourceGroupName $rgname -TemplateFile sampleTemplate.json -TemplateParameterFile sampleTemplateParams.json
368+
$resourceGet = Get-AzureRmResource -ResourceGroupName $rgname -ResourceType Microsoft.Web/serverFarms -IsCollection -ApiVersion 2015-08-01
369+
370+
# Assert
371+
Assert-AreEqual $resourceGet.ResourceType "Microsoft.Web/serverFarms"
350372
}

0 commit comments

Comments
 (0)