Skip to content

Commit 2d14285

Browse files
author
unknown
committed
Resolve test case failures with ResourcesClient
1 parent 3f8e6e4 commit 2d14285

File tree

6 files changed

+84
-23
lines changed

6 files changed

+84
-23
lines changed

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
using Microsoft.Azure.Management.Authorization;
3030
using Microsoft.Azure.Management.Resources;
3131
using Microsoft.Azure.Management.Resources.Models;
32-
using Microsoft.Azure.Subscriptions;
3332
using Microsoft.WindowsAzure.Commands.ScenarioTest;
3433
using Microsoft.WindowsAzure.Commands.Test.Utilities.Common;
3534
using Moq;
@@ -46,8 +45,6 @@ public class ResourceClientTests : RMTestBase
4645

4746
private Mock<IAuthorizationManagementClient> authorizationManagementClientMock;
4847

49-
private Mock<ISubscriptionClient> subscriptionClientMock;
50-
5148
private Mock<IDeploymentOperations> deploymentsMock;
5249

5350
private Mock<IResourceGroupOperations> resourceGroupMock;
@@ -155,8 +152,7 @@ public ResourceClientTests()
155152
galleryTemplatesClientMock.Object,
156153
// TODO: http://vstfrd:8080/Azure/RD/_workitems#_a=edit&id=3247094
157154
//eventsClientMock.Object,
158-
authorizationManagementClientMock.Object,
159-
subscriptionClientMock.Object)
155+
authorizationManagementClientMock.Object)
160156
{
161157
VerboseLogger = progressLoggerMock.Object,
162158
ErrorLogger = errorLoggerMock.Object

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

Lines changed: 1 addition & 0 deletions
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>

src/ResourceManager/Resources/Commands.Resources/Models.ResourceGroups/ResourceClient.cs

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,6 @@ public partial class ResourcesClient
6363

6464
public IAuthorizationManagementClient AuthorizationManagementClient { get; set; }
6565

66-
public ISubscriptionClient SubscriptionClient { get; set; }
67-
6866
public GalleryTemplatesClient GalleryTemplatesClient { get; set; }
6967

7068
public Action<string> VerboseLogger { get; set; }
@@ -81,8 +79,7 @@ public ResourcesClient(AzureContext context)
8179
: this(
8280
AzureSession.ClientFactory.CreateClient<ResourceManagementClient>(context, AzureEnvironment.Endpoint.ResourceManager),
8381
new GalleryTemplatesClient(context),
84-
AzureSession.ClientFactory.CreateClient<AuthorizationManagementClient>(context, AzureEnvironment.Endpoint.ResourceManager),
85-
AzureSession.ClientFactory.CreateClient<SubscriptionClient>(context, AzureEnvironment.Endpoint.ResourceManager))
82+
AzureSession.ClientFactory.CreateClient<AuthorizationManagementClient>(context, AzureEnvironment.Endpoint.ResourceManager))
8683
{
8784

8885
}
@@ -96,13 +93,11 @@ public ResourcesClient(AzureContext context)
9693
public ResourcesClient(
9794
IResourceManagementClient resourceManagementClient,
9895
GalleryTemplatesClient galleryTemplatesClient,
99-
IAuthorizationManagementClient authorizationManagementClient,
100-
ISubscriptionClient subscriptionClient)
96+
IAuthorizationManagementClient authorizationManagementClient)
10197
{
10298
GalleryTemplatesClient = galleryTemplatesClient;
10399
AuthorizationManagementClient = authorizationManagementClient;
104100
this.ResourceManagementClient = resourceManagementClient;
105-
this.SubscriptionClient = subscriptionClient;
106101
}
107102

108103
/// <summary>
@@ -513,16 +508,6 @@ public virtual List<Provider> ListResourceProviders(string providerName = null,
513508
}
514509
}
515510

516-
public List<Location> ListLocations(string subscriptionId)
517-
{
518-
var locationList = new List<Location>();
519-
520-
var tempResult = this.SubscriptionClient.Subscriptions.ListLocations(subscriptionId);
521-
locationList.AddRange(tempResult.Locations);
522-
523-
return locationList;
524-
}
525-
526511
private bool ContainsNormalizedLocation(string[] locations, string location)
527512
{
528513
return locations.Any(existingLocation => this.NormalizeLetterOrDigitToUpperInvariant(existingLocation).Equals(this.NormalizeLetterOrDigitToUpperInvariant(location)));

src/ResourceManager/Resources/Commands.Resources/Models.ResourceGroups/ResourcesBaseCmdlet.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
using System.IO;
1616
using Microsoft.Azure.ServiceManagemenet.Common;
1717
using Microsoft.Azure.ServiceManagemenet.Common.Models;
18+
using Microsoft.Azure.Subscriptions;
1819

1920
namespace Microsoft.Azure.Commands.Resources.Models
2021
{
@@ -42,6 +43,11 @@ public abstract class ResourcesBaseCmdlet : AzureRMCmdlet
4243
/// </summary>
4344
private AuthorizationClient policiesClient;
4445

46+
/// <summary>
47+
/// Field that holds the subscripotions client instance
48+
/// </summary>
49+
private SubscriptionsClient subscriptionsClient;
50+
4551
/// <summary>
4652
/// Gets or sets the resources client
4753
/// </summary>
@@ -101,6 +107,23 @@ public AuthorizationClient PoliciesClient
101107
set { this.policiesClient = value; }
102108
}
103109

110+
/// <summary>
111+
/// Gets or sets the subscriptions client
112+
/// </summary>
113+
public SubscriptionsClient SubscriptionsClient
114+
{
115+
get
116+
{
117+
if (this.subscriptionsClient == null)
118+
{
119+
this.subscriptionsClient = new SubscriptionsClient(DefaultContext);
120+
}
121+
return this.subscriptionsClient;
122+
}
123+
124+
set { this.subscriptionsClient = value; }
125+
}
126+
104127
/// <summary>
105128
/// Determines the parameter set name.
106129
/// </summary>
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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+
using System.Collections.Generic;
16+
using Microsoft.Azure.Commands.Common.Authentication;
17+
using Microsoft.Azure.Commands.Common.Authentication.Models;
18+
using Microsoft.Azure.Subscriptions;
19+
using Microsoft.Azure.Subscriptions.Models;
20+
21+
namespace Microsoft.Azure.Commands.Resources.Models
22+
{
23+
public class SubscriptionsClient
24+
{
25+
public ISubscriptionClient SubscriptionClient { get; set; }
26+
27+
/// <summary>
28+
/// Creates new SubscriptionsClient
29+
/// </summary>
30+
/// <param name="context">Profile containing resources to manipulate</param>
31+
public SubscriptionsClient(AzureContext context)
32+
: this(AzureSession.ClientFactory.CreateClient<SubscriptionClient>(context, AzureEnvironment.Endpoint.ResourceManager))
33+
{
34+
35+
}
36+
37+
/// <summary>
38+
/// Creates new SubscriptionsClient instance
39+
/// </summary>
40+
/// <param name="subscriptionClient">The subscription client instance</param>
41+
public SubscriptionsClient(ISubscriptionClient subscriptionClient)
42+
{
43+
this.SubscriptionClient = subscriptionClient;
44+
}
45+
46+
public List<Location> ListLocations(string subscriptionId)
47+
{
48+
var locationList = new List<Location>();
49+
50+
var tempResult = this.SubscriptionClient.Subscriptions.ListLocations(subscriptionId);
51+
locationList.AddRange(tempResult.Locations);
52+
53+
return locationList;
54+
}
55+
}
56+
}

src/ResourceManager/Resources/Commands.Resources/Providers/GetAzureLocationCmdlet.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public override void ExecuteCmdlet()
3737
{
3838
WriteWarning("The output object type of this cmdlet will be modified in a future release.");
3939

40-
var allLocations = this.ResourcesClient.ListLocations(DefaultContext.Subscription.Id.ToString());
40+
var allLocations = this.SubscriptionsClient.ListLocations(DefaultContext.Subscription.Id.ToString());
4141
var providers = this.ResourcesClient.ListResourceProviders(providerName: null, listAvailable: true);
4242
var providerLocations = ConstructResourceProviderLocations(allLocations, providers);
4343

0 commit comments

Comments
 (0)