Skip to content

Commit 7523322

Browse files
authored
Fix graph client url issue in testfx (#23740)
1 parent 711e53a commit 7523322

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

src/Resources/Resources.Test/ScenarioTests/ResourcesTestRunner.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ protected ResourcesTestRunner(ITestOutputHelper output)
6262
? new Func<ServiceClientCredentials>(() =>
6363
{
6464
var testEnvironment = TestEnvironmentFactory.GetTestEnvironment();
65-
return testEnvironment.TokenInfo[TokenAudience.Graph];
65+
return testEnvironment.TokenInfo[TokenAudience.Management];
6666
})()
6767
: new TokenCredentials("foo");
6868

tools/TestFx/Mocks/MockContext.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ public T GetServiceClient<T>(TestEnvironment currentEnvironment, bool internalBa
106106
$"Unable to create Service Client because {nameof(T)} authentication token was not acquired during Login.");
107107
}
108108

109-
return GetServiceClientWithCredentials<T>(currentEnvironment, currentEnvironment.TokenInfo[TokenAudience.Management], internalBaseUri, handlers);
109+
return GetServiceClientWithCredentials<T>(currentEnvironment, currentEnvironment.BaseUri, currentEnvironment.TokenInfo[TokenAudience.Management], internalBaseUri, handlers);
110110
}
111111

112112
/// <summary>
@@ -135,7 +135,7 @@ public T GetGraphServiceClient<T>(TestEnvironment currentEnvironment, bool inter
135135
"Unable to create Graph Client because Graph authentication token was not acquired during Login.");
136136
}
137137

138-
return GetServiceClientWithCredentials<T>(currentEnvironment, currentEnvironment.TokenInfo[TokenAudience.Graph], internalBaseUri, handlers);
138+
return GetServiceClientWithCredentials<T>(currentEnvironment, currentEnvironment.Endpoints.GraphUri, currentEnvironment.TokenInfo[TokenAudience.Graph], internalBaseUri, handlers);
139139
}
140140

141141
/// <summary>
@@ -146,14 +146,15 @@ public T GetGraphServiceClient<T>(TestEnvironment currentEnvironment, bool inter
146146
/// <param name="baseUri">Base Uri</param>
147147
/// <param name="handlers">Delegating existingHandlers</param>
148148
/// <returns></returns>
149-
public T GetServiceClientWithCredentials<T>(TestEnvironment currentEnvironment, object credentials, bool internalBaseUri = false, params DelegatingHandler[] handlers) where T : class
149+
public T GetServiceClientWithCredentials<T>(TestEnvironment currentEnvironment, Uri baseUri, object credentials, bool internalBaseUri, params DelegatingHandler[] handlers) where T : class
150150
{
151151
T client;
152152
handlers = AddHandlers(currentEnvironment, handlers);
153153
var constructors = typeof(T).GetConstructors(BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance | BindingFlags.NonPublic);
154154

155+
Uri uri = baseUri ?? currentEnvironment.BaseUri;
155156
ConstructorInfo constructor = null;
156-
if (!internalBaseUri && currentEnvironment.BaseUri != null)
157+
if (!internalBaseUri && uri != null)
157158
{
158159
foreach (var c in constructors)
159160
{
@@ -173,7 +174,7 @@ public T GetServiceClientWithCredentials<T>(TestEnvironment currentEnvironment,
173174
}
174175
client = constructor.Invoke(new object[]
175176
{
176-
currentEnvironment.BaseUri,
177+
uri,
177178
credentials,
178179
handlers
179180
}) as T;

0 commit comments

Comments
 (0)