Skip to content

Support collection query in resource get #1734

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 28, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,16 @@ public sealed class GetAzureResourceCmdlet : ResourceManagerCmdletBase
/// </summary>
internal const string GetResourceByNameGroupParameterSet = "Get resource by name and group";

/// <summary>
/// The list resources by name and resource group set.
/// <summary>
/// The list resources by name, type and resource group set.
/// </summary>
internal const string GetResourceByNameGroupTypeParameterSet = "Get resource by name, group and type";

/// <summary>
/// The list resources set.
/// </summary>
internal const string ListResourceCollection = "Get resource collection";

/// <summary>
/// Caches the current subscription ids to get all subscription ids in the pipeline.
/// </summary>
Expand Down Expand Up @@ -100,6 +105,7 @@ public sealed class GetAzureResourceCmdlet : ResourceManagerCmdletBase
/// <summary>
/// Gets or sets the resource type parameter.
/// </summary>
[Parameter(ParameterSetName = GetAzureResourceCmdlet.ListResourceCollection, Mandatory = true, HelpMessage = "When specified, ensures that the query is run against a collection instead of a resource.")]
[Parameter(ParameterSetName = GetAzureResourceCmdlet.GetTenantResourceParameterSet, Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "The resource type. e.g. Microsoft.Sql/Servers/Databases.")]
[Parameter(ParameterSetName = GetAzureResourceCmdlet.ListTenantResourcesParameterSet, Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "The resource type. e.g. Microsoft.Sql/Servers/Databases.")]
[Parameter(ParameterSetName = GetAzureResourceCmdlet.GetResourceByNameTypeParameterSet, Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "The resource type. e.g. Microsoft.Sql/Servers/Databases.")]
Expand All @@ -121,6 +127,7 @@ public sealed class GetAzureResourceCmdlet : ResourceManagerCmdletBase
/// <summary>
/// Gets or sets the extension resource type.
/// </summary>
[Parameter(ParameterSetName = GetAzureResourceCmdlet.ListResourceCollection, Mandatory = false, HelpMessage = "When specified, ensures that the query is run against a collection instead of a resource.")]
[Parameter(ParameterSetName = GetAzureResourceCmdlet.GetTenantResourceParameterSet, Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "The extension resource type. e.g. Microsoft.Sql/Servers/Databases.")]
[Parameter(ParameterSetName = GetAzureResourceCmdlet.ListTenantResourcesParameterSet, Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "The extension resource type. e.g. Microsoft.Sql/Servers/Databases.")]
[Parameter(ParameterSetName = GetAzureResourceCmdlet.GetResourceByNameGroupParameterSet, Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "The extension resource type. e.g. Microsoft.Sql/Servers/Databases.")]
Expand All @@ -138,11 +145,11 @@ public sealed class GetAzureResourceCmdlet : ResourceManagerCmdletBase
/// <summary>
/// Gets or sets the is collection.
/// </summary>
[Parameter(ParameterSetName = GetAzureResourceCmdlet.ListResourceCollection, Mandatory = true, HelpMessage = "When specified, ensures that the query is run against a collection instead of a resource.")]
[Parameter(ParameterSetName = GetAzureResourceCmdlet.GetTenantResourceParameterSet, Mandatory = false, HelpMessage = "When specified, ensures that the query is run against a collection instead of a resource.")]
[Parameter(ParameterSetName = GetAzureResourceCmdlet.ListTenantResourcesParameterSet, Mandatory = false, HelpMessage = "When specified, ensures that the query is run against a collection instead of a resource.")]
[Parameter(ParameterSetName = GetAzureResourceCmdlet.GetResourceByNameTypeParameterSet, Mandatory = false, HelpMessage = "When specified, ensures that the query is run against a collection instead of a resource.")]
[Parameter(ParameterSetName = GetAzureResourceCmdlet.GetResourceByNameGroupParameterSet, Mandatory = false, HelpMessage = "When specified, ensures that the query is run against a collection instead of a resource.")]
[Parameter(ParameterSetName = GetAzureResourceCmdlet.GetResourceByNameGroupTypeParameterSet, Mandatory = false, HelpMessage = "When specified, ensures that the query is run against a collection instead of a resource.")]
public SwitchParameter IsCollection { get; set; }

/// <summary>
Expand All @@ -162,6 +169,7 @@ public sealed class GetAzureResourceCmdlet : ResourceManagerCmdletBase
/// <summary>
/// Gets or sets the resource group name.
/// </summary>
[Parameter(ParameterSetName = GetAzureResourceCmdlet.ListResourceCollection, Mandatory = true, HelpMessage = "When specified, ensures that the query is run against a collection instead of a resource.")]
[Parameter(ParameterSetName = GetAzureResourceCmdlet.GetResourceByNameGroupParameterSet, Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "The resource group name.")]
[Parameter(ParameterSetName = GetAzureResourceCmdlet.GetResourceByNameGroupTypeParameterSet, Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "The resource group name.")]
[ValidateNotNullOrEmpty]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,9 @@
<None Include="SessionRecords\Microsoft.Azure.Commands.Resources.Test.ScenarioTests.ActiveDirectoryTests\TestNewADServicePrincipal.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="SessionRecords\Microsoft.Azure.Commands.Resources.Test.ScenarioTests.ResourceTests\TestGetResourceWithCollection.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="SessionRecords\Microsoft.Azure.Commands.Resources.Test.ScenarioTests.ResourceTests\TestGetResourceWithExpandProperties.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,5 +111,12 @@ public void TestGetResourceWithExpandProperties()
{
ResourcesController.NewInstance.RunPsTest("Test-GetResourceExpandProperties");
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestGetResourceWithCollection()
{
ResourcesController.NewInstance.RunPsTest("Test-GetResourceWithCollection");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -347,4 +347,26 @@ function Test-GetResourceExpandProperties

# Assert
Assert-AreEqual $resourceGet.Properties.key "value"
}

<#
.SYNOPSIS
Tests getting a resource with IsCollection
#>
function Test-GetResourceWithCollection
{
# Setup
$rgname = Get-ResourceGroupName
$rname = Get-ResourceName
$rglocation = Get-ProviderLocation ResourceManagement
$apiversion = "2015-08-01"
$resourceType = "Providers.Test/statefulResources"

# Test
New-AzureRmResourceGroup -Name $rgname -Location $rglocation
New-AzureRmResourceGroupDeployment -Name $rname -ResourceGroupName $rgname -TemplateFile sampleTemplate.json -TemplateParameterFile sampleTemplateParams.json
$resourceGet = Get-AzureRmResource -ResourceGroupName $rgname -ResourceType Microsoft.Web/serverFarms -IsCollection -ApiVersion 2015-08-01

# Assert
Assert-AreEqual $resourceGet.ResourceType "Microsoft.Web/serverFarms"
}
Loading