Skip to content

Commit 87985a2

Browse files
author
Hovsep
committed
Merge pull request Azure#2142 from TianoMS/dev
Create Get-AzureRmLocation Cmdlet
2 parents 3315ae0 + 5d49ccb commit 87985a2

File tree

18 files changed

+489
-191
lines changed

18 files changed

+489
-191
lines changed

src/ResourceManager/Resources/Commands.ResourceManager/Cmdlets/Implementation/Policy/NewAzurePolicyDefinition.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,10 @@ private JToken GetResource()
126126
/// </summary>
127127
private JToken GetPolicyRuleObject()
128128
{
129-
return File.Exists(this.Policy)
130-
? JToken.FromObject(FileUtilities.DataStore.ReadFileAsText(this.TryResolvePath(this.Policy)))
129+
string policyFilePath = this.TryResolvePath(this.Policy);
130+
131+
return File.Exists(policyFilePath)
132+
? JToken.FromObject(FileUtilities.DataStore.ReadFileAsText(policyFilePath))
131133
: JToken.FromObject(this.Policy);
132134
}
133135
}

src/ResourceManager/Resources/Commands.ResourceManager/Cmdlets/Implementation/Policy/SetAzurePolicyDefinition.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,10 @@ protected string GetResourceId()
171171
/// </summary>
172172
protected JToken GetPolicyRuleObject()
173173
{
174-
return File.Exists(this.Policy)
175-
? JToken.FromObject(FileUtilities.DataStore.ReadFileAsText(this.TryResolvePath(this.Policy)))
174+
string policyFilePath = this.TryResolvePath(this.Policy);
175+
176+
return File.Exists(policyFilePath)
177+
? JToken.FromObject(FileUtilities.DataStore.ReadFileAsText(policyFilePath))
176178
: JToken.FromObject(this.Policy);
177179
}
178180
}

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>
@@ -348,6 +352,9 @@
348352
<None Include="SessionRecords\Microsoft.Azure.Commands.Resources.Test.ScenarioTests.DeploymentTests\TestSaveDeploymentTemplateFile.json">
349353
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
350354
</None>
355+
<None Include="SessionRecords\Microsoft.Azure.Commands.Resources.Test.ScenarioTests.LocationTests\TestAzureLocation.json">
356+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
357+
</None>
351358
<None Include="SessionRecords\Microsoft.Azure.Commands.Resources.Test.ScenarioTests.MoveResourceTest\TestMoveAzureResource.json">
352359
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
353360
</None>

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

Lines changed: 0 additions & 114 deletions
Original file line numberDiff line numberDiff line change
@@ -1948,120 +1948,6 @@ public void CancelsActiveDeployment()
19481948
deploymentsMock.Verify(f => f.CancelAsync(resourceGroupName, deploymentName + 3, new CancellationToken()), Times.Once());
19491949
}
19501950

1951-
[Fact]
1952-
[Trait(Category.AcceptanceType, Category.CheckIn)]
1953-
public void GetsLocations()
1954-
{
1955-
providersMock.Setup(f => f.ListAsync(null, new CancellationToken()))
1956-
.Returns(Task.Factory.StartNew(() => new ProviderListResult()
1957-
{
1958-
Providers = new List<Provider>()
1959-
{
1960-
new Provider()
1961-
{
1962-
Namespace = "Microsoft.Web",
1963-
RegistrationState = "Registered",
1964-
ResourceTypes = new List<ProviderResourceType>()
1965-
{
1966-
new ProviderResourceType()
1967-
{
1968-
Locations = new List<string>() {"West US", "East US"},
1969-
Name = "database"
1970-
},
1971-
new ProviderResourceType()
1972-
{
1973-
Locations = new List<string>() {"West US", "South Central US"},
1974-
Name = "servers"
1975-
}
1976-
}
1977-
},
1978-
new Provider()
1979-
{
1980-
Namespace = "Microsoft.HDInsight",
1981-
RegistrationState = "UnRegistered",
1982-
ResourceTypes = new List<ProviderResourceType>()
1983-
{
1984-
new ProviderResourceType()
1985-
{
1986-
Locations = new List<string>() {"West US", "East US"},
1987-
Name = "hadoop"
1988-
},
1989-
new ProviderResourceType()
1990-
{
1991-
Locations = new List<string>() {"West US", "South Central US"},
1992-
Name = "websites"
1993-
}
1994-
}
1995-
}
1996-
}
1997-
}));
1998-
List<PSResourceProviderLocationInfo> resourceTypes = resourcesClient.GetLocations(
1999-
ResourcesClient.ResourceGroupTypeName,
2000-
"Microsoft.HDInsight");
2001-
2002-
Assert.Equal(3, resourceTypes.Count);
2003-
Assert.Equal(ResourcesClient.ResourceGroupTypeName, resourceTypes[0].Name);
2004-
Assert.Equal(ResourcesClient.KnownLocations.Count, resourceTypes[0].Locations.Count);
2005-
Assert.Equal("East Asia", resourceTypes[0].Locations[0]);
2006-
Assert.Equal("Microsoft.HDInsight/hadoop", resourceTypes[1].Name);
2007-
}
2008-
2009-
[Fact]
2010-
[Trait(Category.AcceptanceType, Category.CheckIn)]
2011-
public void IgnoresResourceTypesWithEmptyLocations()
2012-
{
2013-
providersMock.Setup(f => f.ListAsync(null, new CancellationToken()))
2014-
.Returns(Task.Factory.StartNew(() => new ProviderListResult()
2015-
{
2016-
Providers = new List<Provider>()
2017-
{
2018-
new Provider()
2019-
{
2020-
Namespace = "Microsoft.Web",
2021-
RegistrationState = "Registered",
2022-
ResourceTypes = new List<ProviderResourceType>()
2023-
{
2024-
new ProviderResourceType()
2025-
{
2026-
Name = "database"
2027-
},
2028-
new ProviderResourceType()
2029-
{
2030-
Locations = new List<string>(),
2031-
Name = "servers"
2032-
}
2033-
}
2034-
},
2035-
new Provider()
2036-
{
2037-
Namespace = "Microsoft.HDInsight",
2038-
RegistrationState = "UnRegistered",
2039-
ResourceTypes = new List<ProviderResourceType>()
2040-
{
2041-
new ProviderResourceType()
2042-
{
2043-
Locations = new List<string>() {"West US", "East US"},
2044-
Name = "hadoop"
2045-
},
2046-
new ProviderResourceType()
2047-
{
2048-
Locations = new List<string>() {"West US", "South Central US"},
2049-
Name = "websites"
2050-
}
2051-
}
2052-
}
2053-
}
2054-
}));
2055-
List<PSResourceProviderLocationInfo> resourceTypes = resourcesClient.GetLocations(
2056-
ResourcesClient.ResourceGroupTypeName,
2057-
"Microsoft.Web");
2058-
2059-
Assert.Equal(1, resourceTypes.Count);
2060-
Assert.Equal(ResourcesClient.ResourceGroupTypeName, resourceTypes[0].Name);
2061-
Assert.Equal(ResourcesClient.KnownLocations.Count, resourceTypes[0].Locations.Count);
2062-
Assert.Equal("East Asia", resourceTypes[0].Locations[0]);
2063-
}
2064-
20651951
[Fact]
20661952
[Trait(Category.AcceptanceType, Category.CheckIn)]
20671953
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: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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-True { $providerLocations.Count -gt 0 }
24+
foreach ($location in $providerLocations)
25+
{
26+
Assert-True { $location.Providers.Count -gt 0 }
27+
}
28+
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ function Test-PolicyDefinitionCRUD
2828
Assert-AreEqual $expected.PolicyDefinitionId $actual.PolicyDefinitionId
2929
Assert-NotNull($actual.Properties.PolicyRule)
3030

31-
$actual = Set-AzureRMPolicyDefinition -Name $policyName -DisplayName testDisplay -Description testDescription
31+
$actual = Set-AzureRMPolicyDefinition -Name $policyName -DisplayName testDisplay -Description testDescription -Policy ".\SamplePolicyDefinition.json"
3232
$expected = Get-AzureRMPolicyDefinition -Name $policyName
3333
Assert-AreEqual $expected.Properties.DisplayName $actual.Properties.DisplayName
3434
Assert-AreEqual $expected.Properties.Description $actual.Properties.Description

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: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@
141141
<Compile Include="Models.Authorization\AuthorizationHelper.cs" />
142142
<Compile Include="Models.Authorization\FilterRoleDefinitionOptions.cs" />
143143
<Compile Include="Models.ResourceGroups\PSResourceProviderOperation.cs" />
144+
<Compile Include="Models.ResourceGroups\SubscriptionsClient.cs" />
144145
<Compile Include="Properties\Resources.Designer.cs">
145146
<AutoGen>True</AutoGen>
146147
<DesignTime>True</DesignTime>
@@ -186,14 +187,15 @@
186187
<Compile Include="Models.ResourceGroups\PSDeploymentEventData.cs" />
187188
<Compile Include="Models.ResourceGroups\ResourceClient.Events.cs" />
188189
<Compile Include="Models.ResourceGroups\FilterResourceGroupDeploymentOptions.cs" />
189-
<Compile Include="Models.ResourceGroups\PSResourceProviderLocationInfo.cs" />
190+
<Compile Include="Models.ResourceGroups\PSResourceProviderLocation.cs" />
190191
<Compile Include="Models.ResourceGroups\BasePSResourceParameters.cs" />
191192
<Compile Include="Models.ResourceGroups\UpdatePSResourceGroupParameters.cs" />
192193
<Compile Include="Models.ResourceGroups\UpdatePSResourceParameters.cs" />
193194
<Compile Include="Models.ResourceGroups\TemplateFileResource.cs" />
194195
<Compile Include="Models.ResourceGroups\ValidatePSResourceGroupDeploymentParameters.cs" />
195196
<Compile Include="Models.Authorization\AuthorizationClient.cs" />
196197
<Compile Include="ProviderFeatures\RegisterAzureProviderFeatureCmdlet.cs" />
198+
<Compile Include="Providers\GetAzureLocationCmdlet.cs" />
197199
<Compile Include="Providers\GetAzureProviderCmdlet.cs" />
198200
<Compile Include="Providers\GetAzureProviderOperationCmdlet.cs" />
199201
<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
@@ -27,6 +27,32 @@
2727
</ListEntries>
2828
</ListControl>
2929
</View>
30+
<View>
31+
<Name>Microsoft.Azure.Commands.Resources.Models.PSResourceProviderLocation</Name>
32+
<ViewSelectedBy>
33+
<TypeName>Microsoft.Azure.Commands.Resources.Models.PSResourceProviderLocation</TypeName>
34+
</ViewSelectedBy>
35+
<ListControl>
36+
<ListEntries>
37+
<ListEntry>
38+
<ListItems>
39+
<ListItem>
40+
<Label>Location</Label>
41+
<PropertyName>Location</PropertyName>
42+
</ListItem>
43+
<ListItem>
44+
<Label>DisplayName</Label>
45+
<PropertyName>DisplayName</PropertyName>
46+
</ListItem>
47+
<ListItem>
48+
<Label>Providers</Label>
49+
<PropertyName>Providers</PropertyName>
50+
</ListItem>
51+
</ListItems>
52+
</ListEntry>
53+
</ListEntries>
54+
</ListControl>
55+
</View>
3056
<View>
3157
<Name>Microsoft.Azure.Commands.Resources.Models.PSResource</Name>
3258
<ViewSelectedBy>

0 commit comments

Comments
 (0)