Skip to content

Create Get-AzureRmLocation Cmdlet #2142

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 5 commits into from
Apr 26, 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 @@ -126,8 +126,10 @@ private JToken GetResource()
/// </summary>
private JToken GetPolicyRuleObject()
{
return File.Exists(this.Policy)
? JToken.FromObject(FileUtilities.DataStore.ReadFileAsText(this.TryResolvePath(this.Policy)))
string policyFilePath = this.TryResolvePath(this.Policy);

return File.Exists(policyFilePath)
? JToken.FromObject(FileUtilities.DataStore.ReadFileAsText(policyFilePath))
: JToken.FromObject(this.Policy);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,10 @@ protected string GetResourceId()
/// </summary>
protected JToken GetPolicyRuleObject()
{
return File.Exists(this.Policy)
? JToken.FromObject(FileUtilities.DataStore.ReadFileAsText(this.TryResolvePath(this.Policy)))
string policyFilePath = this.TryResolvePath(this.Policy);

return File.Exists(policyFilePath)
? JToken.FromObject(FileUtilities.DataStore.ReadFileAsText(policyFilePath))
: JToken.FromObject(this.Policy);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@
<Content Include="ScenarioTests\ProviderTests.ps1">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Compile Include="ScenarioTests\LocationTests.cs" />
<Compile Include="ScenarioTests\MoveResourceTest.cs" />
<Compile Include="ScenarioTests\ProviderFeatureTests.cs" />
<Compile Include="ScenarioTests\ProviderTests.cs" />
Expand Down Expand Up @@ -306,6 +307,9 @@
<None Include="ScenarioTests\DeploymentTests.ps1">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="ScenarioTests\LocationTests.ps1">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="ScenarioTests\MoveResourceTest.ps1">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
Expand Down Expand Up @@ -345,6 +349,9 @@
<None Include="SessionRecords\Microsoft.Azure.Commands.Resources.Test.ScenarioTests.DeploymentTests\TestSaveDeploymentTemplateFile.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="SessionRecords\Microsoft.Azure.Commands.Resources.Test.ScenarioTests.LocationTests\TestAzureLocation.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="SessionRecords\Microsoft.Azure.Commands.Resources.Test.ScenarioTests.MoveResourceTest\TestMoveAzureResource.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1958,120 +1958,6 @@ public void CancelsActiveDeployment()
deploymentsMock.Verify(f => f.CancelAsync(resourceGroupName, deploymentName + 3, new CancellationToken()), Times.Once());
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void GetsLocations()
{
providersMock.Setup(f => f.ListAsync(null, new CancellationToken()))
.Returns(Task.Factory.StartNew(() => new ProviderListResult()
{
Providers = new List<Provider>()
{
new Provider()
{
Namespace = "Microsoft.Web",
RegistrationState = "Registered",
ResourceTypes = new List<ProviderResourceType>()
{
new ProviderResourceType()
{
Locations = new List<string>() {"West US", "East US"},
Name = "database"
},
new ProviderResourceType()
{
Locations = new List<string>() {"West US", "South Central US"},
Name = "servers"
}
}
},
new Provider()
{
Namespace = "Microsoft.HDInsight",
RegistrationState = "UnRegistered",
ResourceTypes = new List<ProviderResourceType>()
{
new ProviderResourceType()
{
Locations = new List<string>() {"West US", "East US"},
Name = "hadoop"
},
new ProviderResourceType()
{
Locations = new List<string>() {"West US", "South Central US"},
Name = "websites"
}
}
}
}
}));
List<PSResourceProviderLocationInfo> resourceTypes = resourcesClient.GetLocations(
ResourcesClient.ResourceGroupTypeName,
"Microsoft.HDInsight");

Assert.Equal(3, resourceTypes.Count);
Assert.Equal(ResourcesClient.ResourceGroupTypeName, resourceTypes[0].Name);
Assert.Equal(ResourcesClient.KnownLocations.Count, resourceTypes[0].Locations.Count);
Assert.Equal("East Asia", resourceTypes[0].Locations[0]);
Assert.Equal("Microsoft.HDInsight/hadoop", resourceTypes[1].Name);
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void IgnoresResourceTypesWithEmptyLocations()
{
providersMock.Setup(f => f.ListAsync(null, new CancellationToken()))
.Returns(Task.Factory.StartNew(() => new ProviderListResult()
{
Providers = new List<Provider>()
{
new Provider()
{
Namespace = "Microsoft.Web",
RegistrationState = "Registered",
ResourceTypes = new List<ProviderResourceType>()
{
new ProviderResourceType()
{
Name = "database"
},
new ProviderResourceType()
{
Locations = new List<string>(),
Name = "servers"
}
}
},
new Provider()
{
Namespace = "Microsoft.HDInsight",
RegistrationState = "UnRegistered",
ResourceTypes = new List<ProviderResourceType>()
{
new ProviderResourceType()
{
Locations = new List<string>() {"West US", "East US"},
Name = "hadoop"
},
new ProviderResourceType()
{
Locations = new List<string>() {"West US", "South Central US"},
Name = "websites"
}
}
}
}
}));
List<PSResourceProviderLocationInfo> resourceTypes = resourcesClient.GetLocations(
ResourcesClient.ResourceGroupTypeName,
"Microsoft.Web");

Assert.Equal(1, resourceTypes.Count);
Assert.Equal(ResourcesClient.ResourceGroupTypeName, resourceTypes[0].Name);
Assert.Equal(ResourcesClient.KnownLocations.Count, resourceTypes[0].Locations.Count);
Assert.Equal("East Asia", resourceTypes[0].Locations[0]);
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void ParseErrorMessageSupportsFlatErrors()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// ----------------------------------------------------------------------------------
//
// Copyright Microsoft Corporation
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ----------------------------------------------------------------------------------

namespace Microsoft.Azure.Commands.Resources.Test.ScenarioTests
{
using Microsoft.WindowsAzure.Commands.ScenarioTest;
using Xunit;

public class LocationTests
{
[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestAzureLocation()
{
ResourcesController.NewInstance.RunPsTest("Test-AzureLocation");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# ----------------------------------------------------------------------------------
#
# Copyright Microsoft Corporation
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ----------------------------------------------------------------------------------

<#
.SYNOPSIS
Tests getting azure locations.
#>
function Test-AzureLocation
{
$providerLocations = Get-AzureRmLocation
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@TianoMS This test can only be executed against the production AzureCloud endpoint. It will fail if executed against a test endpoint or the AzureChinaCloud, AzureUSGovernment, or AzureGermanCloud endpoints. Please simply test that there is a non-empty list of locations and that each of the properties for each location have the appropriate properties.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will fix it.


Assert-True { $providerLocations.Count -gt 0 }
foreach ($location in $providerLocations)
{
Assert-True { $location.Providers.Count -gt 0 }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ function Test-PolicyDefinitionCRUD
Assert-AreEqual $expected.PolicyDefinitionId $actual.PolicyDefinitionId
Assert-NotNull($actual.Properties.PolicyRule)

$actual = Set-AzureRMPolicyDefinition -Name $policyName -DisplayName testDisplay -Description testDescription
$actual = Set-AzureRMPolicyDefinition -Name $policyName -DisplayName testDisplay -Description testDescription -Policy ".\SamplePolicyDefinition.json"
$expected = Get-AzureRMPolicyDefinition -Name $policyName
Assert-AreEqual $expected.Properties.DisplayName $actual.Properties.DisplayName
Assert-AreEqual $expected.Properties.Description $actual.Properties.Description
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@
<Compile Include="Models.Authorization\AuthorizationHelper.cs" />
<Compile Include="Models.Authorization\FilterRoleDefinitionOptions.cs" />
<Compile Include="Models.ResourceGroups\PSResourceProviderOperation.cs" />
<Compile Include="Models.ResourceGroups\SubscriptionsClient.cs" />
<Compile Include="Properties\Resources.Designer.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
Expand Down Expand Up @@ -186,14 +187,15 @@
<Compile Include="Models.ResourceGroups\PSDeploymentEventData.cs" />
<Compile Include="Models.ResourceGroups\ResourceClient.Events.cs" />
<Compile Include="Models.ResourceGroups\FilterResourceGroupDeploymentOptions.cs" />
<Compile Include="Models.ResourceGroups\PSResourceProviderLocationInfo.cs" />
<Compile Include="Models.ResourceGroups\PSResourceProviderLocation.cs" />
<Compile Include="Models.ResourceGroups\BasePSResourceParameters.cs" />
<Compile Include="Models.ResourceGroups\UpdatePSResourceGroupParameters.cs" />
<Compile Include="Models.ResourceGroups\UpdatePSResourceParameters.cs" />
<Compile Include="Models.ResourceGroups\TemplateFileResource.cs" />
<Compile Include="Models.ResourceGroups\ValidatePSResourceGroupDeploymentParameters.cs" />
<Compile Include="Models.Authorization\AuthorizationClient.cs" />
<Compile Include="ProviderFeatures\RegisterAzureProviderFeatureCmdlet.cs" />
<Compile Include="Providers\GetAzureLocationCmdlet.cs" />
<Compile Include="Providers\GetAzureProviderCmdlet.cs" />
<Compile Include="Providers\GetAzureProviderOperationCmdlet.cs" />
<Compile Include="Providers\RegisterAzureProviderCmdlet.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1098,6 +1098,92 @@
<maml:relatedLinks>
</maml:relatedLinks>
</command:command>
<command:command xmlns:maml="http://schemas.microsoft.com/maml/2004/10" xmlns:command="http://schemas.microsoft.com/maml/dev/command/2004/10" xmlns:dev="http://schemas.microsoft.com/maml/dev/2004/10" xmlns:MSHelp="http://msdn.microsoft.com/mshelp">
<!--Generated by PS Cmdlet Help Editor-->
<command:details>
<command:name>Get-AzureRmLocation</command:name>
<maml:description>
<maml:para />
</maml:description>
<maml:copyright>
<maml:para />
</maml:copyright>
<command:verb>Get</command:verb>
<command:noun>AzureRmLocation</command:noun>
<dev:version />
</command:details>
<maml:description>
<maml:para>Get all locations and the supported resource providers.</maml:para>
</maml:description>
<command:syntax>
<command:syntaxItem>
<maml:name>Get-AzureRmLocation</maml:name>
</command:syntaxItem>
</command:syntax>
<command:parameters>
</command:parameters>
<command:inputTypes>
<command:inputType>
<dev:type>
<maml:name></maml:name>
<maml:uri></maml:uri>
<maml:description/>
</dev:type>
<maml:description>
<maml:para>
</maml:para>
</maml:description>
</command:inputType>
</command:inputTypes>
<command:returnValues>
<command:returnValue>
<dev:type>
<maml:name></maml:name>
<maml:uri></maml:uri>
<maml:description/>
</dev:type>
<maml:description>
<maml:para>
</maml:para>
</maml:description>
</command:returnValue>
</command:returnValues>
<command:terminatingErrors></command:terminatingErrors>
<command:nonTerminatingErrors></command:nonTerminatingErrors>
<maml:alertSet>
<maml:title></maml:title>
<maml:alert>
<maml:para />
</maml:alert>
</maml:alertSet>
<command:examples>
<command:example>
<maml:title>-------------------------- Example 1: Get all locations and the supported resource providers --------------------------</maml:title>
<maml:introduction>
<maml:paragraph>PS C:\&gt;</maml:paragraph>
</maml:introduction>
<dev:code>
PS C:\&gt;Get-AzureRmLocation
</dev:code>
<dev:remarks>
<maml:para>This command gets all locations and the supported resource providers.</maml:para>
<maml:para />
<maml:para />
<maml:para>
</maml:para>
</dev:remarks>
<command:commandLines>
<command:commandLine>
<command:commandText>
<maml:para />
</command:commandText>
</command:commandLine>
</command:commandLines>
</command:example>
</command:examples>
<maml:relatedLinks>
</maml:relatedLinks>
</command:command>
<command:command xmlns:maml="http://schemas.microsoft.com/maml/2004/10" xmlns:command="http://schemas.microsoft.com/maml/dev/command/2004/10" xmlns:dev="http://schemas.microsoft.com/maml/dev/2004/10" xmlns:MSHelp="http://msdn.microsoft.com/mshelp">
<!--Generated by PS Cmdlet Help Editor-->
<command:details>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,32 @@
</ListEntries>
</ListControl>
</View>
<View>
<Name>Microsoft.Azure.Commands.Resources.Models.PSResourceProviderLocation</Name>
<ViewSelectedBy>
<TypeName>Microsoft.Azure.Commands.Resources.Models.PSResourceProviderLocation</TypeName>
</ViewSelectedBy>
<ListControl>
<ListEntries>
<ListEntry>
<ListItems>
<ListItem>
<Label>Location</Label>
<PropertyName>Location</PropertyName>
</ListItem>
<ListItem>
<Label>DisplayName</Label>
<PropertyName>DisplayName</PropertyName>
</ListItem>
<ListItem>
<Label>Providers</Label>
<PropertyName>Providers</PropertyName>
</ListItem>
</ListItems>
</ListEntry>
</ListEntries>
</ListControl>
</View>
<View>
<Name>Microsoft.Azure.Commands.Resources.Models.PSResource</Name>
<ViewSelectedBy>
Expand Down
Loading