Skip to content

Commit 7633e04

Browse files
Merge pull request Azure#8456 from cormacpayne/graph-client-test-fix
Fix bug when instantiating Graph SDK client during test
2 parents fa04eb5 + 869516c commit 7633e04

File tree

1 file changed

+4
-12
lines changed

1 file changed

+4
-12
lines changed

tools/TestFx/TestClientFactory.cs

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,9 @@
1818
using System.Net;
1919
using System.Net.Http;
2020
using System.Net.Http.Headers;
21-
using Hyak.Common;
2221
using Microsoft.Azure.Commands.Common.Authentication;
2322
using Microsoft.Azure.Commands.Common.Authentication.Abstractions;
2423
using Microsoft.Azure.Commands.Common.Authentication.Models;
25-
using Microsoft.Azure.Graph.RBAC.Version1_6;
26-
using Microsoft.Rest;
2724
using Microsoft.Rest.ClientRuntime.Azure.TestFramework;
2825
#if NETSTANDARD
2926
using Microsoft.Azure.Commands.Common.Authentication.Abstractions.Core;
@@ -42,14 +39,9 @@ public TestClientFactory(MockContext mockContext)
4239

4340
public TClient CreateArmClient<TClient>(IAzureContext context, string endpoint) where TClient : Rest.ServiceClient<TClient>
4441
{
45-
if (typeof(TClient) != typeof(GraphRbacManagementClient))
46-
{
47-
return _mockContext.GetServiceClient<TClient>();
48-
}
49-
50-
var graphClient = _mockContext.GetGraphServiceClient<GraphRbacManagementClient>();
51-
graphClient.TenantID = context.Tenant.Id;
52-
return graphClient as TClient;
42+
return string.Equals(endpoint, AzureEnvironment.Endpoint.Graph, StringComparison.OrdinalIgnoreCase) ?
43+
_mockContext.GetGraphServiceClient<TClient>() :
44+
_mockContext.GetServiceClient<TClient>();
5345
}
5446

5547
public TClient CreateCustomArmClient<TClient>(params object[] parameters) where TClient : Rest.ServiceClient<TClient>
@@ -99,7 +91,7 @@ public DelegatingHandler[] GetCustomHandlers()
9991
#region UserAgent
10092

10193
public HashSet<ProductInfoHeaderValue> UniqueUserAgents { get; set; } = new HashSet<ProductInfoHeaderValue>();
102-
94+
10395
public void AddUserAgent(string productName, string productVersion)
10496
{
10597
UniqueUserAgents.Add(new ProductInfoHeaderValue(productName, productVersion));

0 commit comments

Comments
 (0)