Skip to content

Commit 75c1733

Browse files
author
unknown
committed
Create Get-AzureRmLocation Cmdlet
1 parent 874c8c2 commit 75c1733

File tree

13 files changed

+426
-189
lines changed

13 files changed

+426
-189
lines changed

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@
201201
<Content Include="ScenarioTests\ProviderTests.ps1">
202202
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
203203
</Content>
204+
<Compile Include="ScenarioTests\LocationTests.cs" />
204205
<Compile Include="ScenarioTests\MoveResourceTest.cs" />
205206
<Compile Include="ScenarioTests\ProviderFeatureTests.cs" />
206207
<Compile Include="ScenarioTests\ProviderTests.cs" />
@@ -306,6 +307,9 @@
306307
<None Include="ScenarioTests\DeploymentTests.ps1">
307308
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
308309
</None>
310+
<None Include="ScenarioTests\LocationTests.ps1">
311+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
312+
</None>
309313
<None Include="ScenarioTests\MoveResourceTest.ps1">
310314
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
311315
</None>
@@ -345,6 +349,9 @@
345349
<None Include="SessionRecords\Microsoft.Azure.Commands.Resources.Test.ScenarioTests.DeploymentTests\TestSaveDeploymentTemplateFile.json">
346350
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
347351
</None>
352+
<None Include="SessionRecords\Microsoft.Azure.Commands.Resources.Test.ScenarioTests.LocationTests\TestAzureLocation.json">
353+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
354+
</None>
348355
<None Include="SessionRecords\Microsoft.Azure.Commands.Resources.Test.ScenarioTests.MoveResourceTest\TestMoveAzureResource.json">
349356
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
350357
</None>

src/ResourceManager/Resources/Commands.Resources.Test/Models.ResourceGroups/ResourceClientTests.cs

Lines changed: 5 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
using Microsoft.Azure.Management.Authorization;
3030
using Microsoft.Azure.Management.Resources;
3131
using Microsoft.Azure.Management.Resources.Models;
32+
using Microsoft.Azure.Subscriptions;
3233
using Microsoft.WindowsAzure.Commands.ScenarioTest;
3334
using Microsoft.WindowsAzure.Commands.Test.Utilities.Common;
3435
using Moq;
@@ -45,6 +46,8 @@ public class ResourceClientTests : RMTestBase
4546

4647
private Mock<IAuthorizationManagementClient> authorizationManagementClientMock;
4748

49+
private Mock<ISubscriptionClient> subscriptionClientMock;
50+
4851
private Mock<IDeploymentOperations> deploymentsMock;
4952

5053
private Mock<IResourceGroupOperations> resourceGroupMock;
@@ -152,7 +155,8 @@ public ResourceClientTests()
152155
galleryTemplatesClientMock.Object,
153156
// TODO: http://vstfrd:8080/Azure/RD/_workitems#_a=edit&id=3247094
154157
//eventsClientMock.Object,
155-
authorizationManagementClientMock.Object)
158+
authorizationManagementClientMock.Object,
159+
subscriptionClientMock.Object)
156160
{
157161
VerboseLogger = progressLoggerMock.Object,
158162
ErrorLogger = errorLoggerMock.Object
@@ -1958,120 +1962,6 @@ public void CancelsActiveDeployment()
19581962
deploymentsMock.Verify(f => f.CancelAsync(resourceGroupName, deploymentName + 3, new CancellationToken()), Times.Once());
19591963
}
19601964

1961-
[Fact]
1962-
[Trait(Category.AcceptanceType, Category.CheckIn)]
1963-
public void GetsLocations()
1964-
{
1965-
providersMock.Setup(f => f.ListAsync(null, new CancellationToken()))
1966-
.Returns(Task.Factory.StartNew(() => new ProviderListResult()
1967-
{
1968-
Providers = new List<Provider>()
1969-
{
1970-
new Provider()
1971-
{
1972-
Namespace = "Microsoft.Web",
1973-
RegistrationState = "Registered",
1974-
ResourceTypes = new List<ProviderResourceType>()
1975-
{
1976-
new ProviderResourceType()
1977-
{
1978-
Locations = new List<string>() {"West US", "East US"},
1979-
Name = "database"
1980-
},
1981-
new ProviderResourceType()
1982-
{
1983-
Locations = new List<string>() {"West US", "South Central US"},
1984-
Name = "servers"
1985-
}
1986-
}
1987-
},
1988-
new Provider()
1989-
{
1990-
Namespace = "Microsoft.HDInsight",
1991-
RegistrationState = "UnRegistered",
1992-
ResourceTypes = new List<ProviderResourceType>()
1993-
{
1994-
new ProviderResourceType()
1995-
{
1996-
Locations = new List<string>() {"West US", "East US"},
1997-
Name = "hadoop"
1998-
},
1999-
new ProviderResourceType()
2000-
{
2001-
Locations = new List<string>() {"West US", "South Central US"},
2002-
Name = "websites"
2003-
}
2004-
}
2005-
}
2006-
}
2007-
}));
2008-
List<PSResourceProviderLocationInfo> resourceTypes = resourcesClient.GetLocations(
2009-
ResourcesClient.ResourceGroupTypeName,
2010-
"Microsoft.HDInsight");
2011-
2012-
Assert.Equal(3, resourceTypes.Count);
2013-
Assert.Equal(ResourcesClient.ResourceGroupTypeName, resourceTypes[0].Name);
2014-
Assert.Equal(ResourcesClient.KnownLocations.Count, resourceTypes[0].Locations.Count);
2015-
Assert.Equal("East Asia", resourceTypes[0].Locations[0]);
2016-
Assert.Equal("Microsoft.HDInsight/hadoop", resourceTypes[1].Name);
2017-
}
2018-
2019-
[Fact]
2020-
[Trait(Category.AcceptanceType, Category.CheckIn)]
2021-
public void IgnoresResourceTypesWithEmptyLocations()
2022-
{
2023-
providersMock.Setup(f => f.ListAsync(null, new CancellationToken()))
2024-
.Returns(Task.Factory.StartNew(() => new ProviderListResult()
2025-
{
2026-
Providers = new List<Provider>()
2027-
{
2028-
new Provider()
2029-
{
2030-
Namespace = "Microsoft.Web",
2031-
RegistrationState = "Registered",
2032-
ResourceTypes = new List<ProviderResourceType>()
2033-
{
2034-
new ProviderResourceType()
2035-
{
2036-
Name = "database"
2037-
},
2038-
new ProviderResourceType()
2039-
{
2040-
Locations = new List<string>(),
2041-
Name = "servers"
2042-
}
2043-
}
2044-
},
2045-
new Provider()
2046-
{
2047-
Namespace = "Microsoft.HDInsight",
2048-
RegistrationState = "UnRegistered",
2049-
ResourceTypes = new List<ProviderResourceType>()
2050-
{
2051-
new ProviderResourceType()
2052-
{
2053-
Locations = new List<string>() {"West US", "East US"},
2054-
Name = "hadoop"
2055-
},
2056-
new ProviderResourceType()
2057-
{
2058-
Locations = new List<string>() {"West US", "South Central US"},
2059-
Name = "websites"
2060-
}
2061-
}
2062-
}
2063-
}
2064-
}));
2065-
List<PSResourceProviderLocationInfo> resourceTypes = resourcesClient.GetLocations(
2066-
ResourcesClient.ResourceGroupTypeName,
2067-
"Microsoft.Web");
2068-
2069-
Assert.Equal(1, resourceTypes.Count);
2070-
Assert.Equal(ResourcesClient.ResourceGroupTypeName, resourceTypes[0].Name);
2071-
Assert.Equal(ResourcesClient.KnownLocations.Count, resourceTypes[0].Locations.Count);
2072-
Assert.Equal("East Asia", resourceTypes[0].Locations[0]);
2073-
}
2074-
20751965
[Fact]
20761966
[Trait(Category.AcceptanceType, Category.CheckIn)]
20771967
public void ParseErrorMessageSupportsFlatErrors()
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
namespace Microsoft.Azure.Commands.Resources.Test.ScenarioTests
16+
{
17+
using Microsoft.WindowsAzure.Commands.ScenarioTest;
18+
using Xunit;
19+
20+
public class LocationTests
21+
{
22+
[Fact]
23+
[Trait(Category.AcceptanceType, Category.CheckIn)]
24+
public void TestAzureLocation()
25+
{
26+
ResourcesController.NewInstance.RunPsTest("Test-AzureLocation");
27+
}
28+
}
29+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# ----------------------------------------------------------------------------------
2+
#
3+
# Copyright Microsoft Corporation
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
# Unless required by applicable law or agreed to in writing, software
9+
# distributed under the License is distributed on an "AS IS" BASIS,
10+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
# See the License for the specific language governing permissions and
12+
# limitations under the License.
13+
# ----------------------------------------------------------------------------------
14+
15+
<#
16+
.SYNOPSIS
17+
Tests getting azure locations.
18+
#>
19+
function Test-AzureLocation
20+
{
21+
$providerLocations = Get-AzureRmLocation
22+
23+
Assert-AreEqual 22 $providerLocations.Count
24+
25+
$eastAsiaLocation = $providerLocations[0]
26+
27+
Assert-AreEqual "eastasia" $eastAsiaLocation.Location
28+
Assert-AreEqual "East Asia" $eastAsiaLocation.DisplayName
29+
Assert-AreEqual 36 $eastAsiaLocation.Providers.Count
30+
}

src/ResourceManager/Resources/Commands.Resources.Test/SessionRecords/Microsoft.Azure.Commands.Resources.Test.ScenarioTests.LocationTests/TestAzureLocation.json

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

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,14 +186,15 @@
186186
<Compile Include="Models.ResourceGroups\PSDeploymentEventData.cs" />
187187
<Compile Include="Models.ResourceGroups\ResourceClient.Events.cs" />
188188
<Compile Include="Models.ResourceGroups\FilterResourceGroupDeploymentOptions.cs" />
189-
<Compile Include="Models.ResourceGroups\PSResourceProviderLocationInfo.cs" />
189+
<Compile Include="Models.ResourceGroups\PSResourceProviderLocation.cs" />
190190
<Compile Include="Models.ResourceGroups\BasePSResourceParameters.cs" />
191191
<Compile Include="Models.ResourceGroups\UpdatePSResourceGroupParameters.cs" />
192192
<Compile Include="Models.ResourceGroups\UpdatePSResourceParameters.cs" />
193193
<Compile Include="Models.ResourceGroups\TemplateFileResource.cs" />
194194
<Compile Include="Models.ResourceGroups\ValidatePSResourceGroupDeploymentParameters.cs" />
195195
<Compile Include="Models.Authorization\AuthorizationClient.cs" />
196196
<Compile Include="ProviderFeatures\RegisterAzureProviderFeatureCmdlet.cs" />
197+
<Compile Include="Providers\GetAzureLocationCmdlet.cs" />
197198
<Compile Include="Providers\GetAzureProviderCmdlet.cs" />
198199
<Compile Include="Providers\GetAzureProviderOperationCmdlet.cs" />
199200
<Compile Include="Providers\RegisterAzureProviderCmdlet.cs" />

src/ResourceManager/Resources/Commands.Resources/Microsoft.Azure.Commands.Resources.dll-Help.xml

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1098,6 +1098,92 @@
10981098
<maml:relatedLinks>
10991099
</maml:relatedLinks>
11001100
</command:command>
1101+
<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">
1102+
<!--Generated by PS Cmdlet Help Editor-->
1103+
<command:details>
1104+
<command:name>Get-AzureRmLocation</command:name>
1105+
<maml:description>
1106+
<maml:para />
1107+
</maml:description>
1108+
<maml:copyright>
1109+
<maml:para />
1110+
</maml:copyright>
1111+
<command:verb>Get</command:verb>
1112+
<command:noun>AzureRmLocation</command:noun>
1113+
<dev:version />
1114+
</command:details>
1115+
<maml:description>
1116+
<maml:para>Get all locations and the supported resource providers.</maml:para>
1117+
</maml:description>
1118+
<command:syntax>
1119+
<command:syntaxItem>
1120+
<maml:name>Get-AzureRmLocation</maml:name>
1121+
</command:syntaxItem>
1122+
</command:syntax>
1123+
<command:parameters>
1124+
</command:parameters>
1125+
<command:inputTypes>
1126+
<command:inputType>
1127+
<dev:type>
1128+
<maml:name></maml:name>
1129+
<maml:uri></maml:uri>
1130+
<maml:description/>
1131+
</dev:type>
1132+
<maml:description>
1133+
<maml:para>
1134+
</maml:para>
1135+
</maml:description>
1136+
</command:inputType>
1137+
</command:inputTypes>
1138+
<command:returnValues>
1139+
<command:returnValue>
1140+
<dev:type>
1141+
<maml:name></maml:name>
1142+
<maml:uri></maml:uri>
1143+
<maml:description/>
1144+
</dev:type>
1145+
<maml:description>
1146+
<maml:para>
1147+
</maml:para>
1148+
</maml:description>
1149+
</command:returnValue>
1150+
</command:returnValues>
1151+
<command:terminatingErrors></command:terminatingErrors>
1152+
<command:nonTerminatingErrors></command:nonTerminatingErrors>
1153+
<maml:alertSet>
1154+
<maml:title></maml:title>
1155+
<maml:alert>
1156+
<maml:para />
1157+
</maml:alert>
1158+
</maml:alertSet>
1159+
<command:examples>
1160+
<command:example>
1161+
<maml:title>-------------------------- Example 1: Get all locations and the supported resource providers --------------------------</maml:title>
1162+
<maml:introduction>
1163+
<maml:paragraph>PS C:\&gt;</maml:paragraph>
1164+
</maml:introduction>
1165+
<dev:code>
1166+
PS C:\&gt;Get-AzureRmLocation
1167+
</dev:code>
1168+
<dev:remarks>
1169+
<maml:para>This command gets all locations and the supported resource providers.</maml:para>
1170+
<maml:para />
1171+
<maml:para />
1172+
<maml:para>
1173+
</maml:para>
1174+
</dev:remarks>
1175+
<command:commandLines>
1176+
<command:commandLine>
1177+
<command:commandText>
1178+
<maml:para />
1179+
</command:commandText>
1180+
</command:commandLine>
1181+
</command:commandLines>
1182+
</command:example>
1183+
</command:examples>
1184+
<maml:relatedLinks>
1185+
</maml:relatedLinks>
1186+
</command:command>
11011187
<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">
11021188
<!--Generated by PS Cmdlet Help Editor-->
11031189
<command:details>

src/ResourceManager/Resources/Commands.Resources/Microsoft.Azure.Commands.Resources.format.ps1xml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,32 @@
2323
</ListEntries>
2424
</ListControl>
2525
</View>
26+
<View>
27+
<Name>Microsoft.Azure.Commands.Resources.Models.PSResourceProviderLocation</Name>
28+
<ViewSelectedBy>
29+
<TypeName>Microsoft.Azure.Commands.Resources.Models.PSResourceProviderLocation</TypeName>
30+
</ViewSelectedBy>
31+
<ListControl>
32+
<ListEntries>
33+
<ListEntry>
34+
<ListItems>
35+
<ListItem>
36+
<Label>Location</Label>
37+
<PropertyName>Location</PropertyName>
38+
</ListItem>
39+
<ListItem>
40+
<Label>DisplayName</Label>
41+
<PropertyName>DisplayName</PropertyName>
42+
</ListItem>
43+
<ListItem>
44+
<Label>Providers</Label>
45+
<PropertyName>Providers</PropertyName>
46+
</ListItem>
47+
</ListItems>
48+
</ListEntry>
49+
</ListEntries>
50+
</ListControl>
51+
</View>
2652
<View>
2753
<Name>Microsoft.Azure.Commands.Resources.Models.PSResource</Name>
2854
<ViewSelectedBy>

0 commit comments

Comments
 (0)