Skip to content

Commit 0939e23

Browse files
azure-powershell-botazurepowershell
andauthored
Sync tools folder from main branch to generation branch (#23735)
Co-authored-by: azurepowershell <[email protected]>
1 parent cc3cffb commit 0939e23

File tree

7 files changed

+101
-162
lines changed

7 files changed

+101
-162
lines changed

tools/Common.Netcore.Dependencies.Test.targets

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
<ItemGroup>
1212
<PackageReference Include="Microsoft.Azure.Management.ResourceManager" Version="3.17.3-preview" />
13-
<PackageReference Include="Microsoft.Rest.ClientRuntime.Azure.Authentication" Version="2.3.7" />
1413
<PackageReference Include="xunit" Version="2.4.2" />
1514
</ItemGroup>
1615

@@ -40,7 +39,7 @@
4039
</ItemGroup>
4140

4241
<ItemGroup>
43-
<PackageReference Include="Microsoft.IdentityModel.Clients.ActiveDirectory" Version="3.19.2" />
4442
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.5.0" />
43+
<PackageReference Include="Microsoft.Identity.Client" Version="4.49.1" />
4544
</ItemGroup>
4645
</Project>

tools/Gen2Master/MoveFromGeneration2Master.ps1

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,9 @@ Function Move-Generation2Master {
142142
dotnet sln $slnFilePath add $_.FullName --solution-folder Accounts
143143
}
144144
}
145-
Get-ChildItem -Filter *.csproj -File -Path $DestPath -Recurse | ForEach-Object {
146-
dotnet sln $slnFilePath add $_.FullName
147-
}
145+
}
146+
Get-ChildItem -Filter *.csproj -File -Path $DestPath -Recurse | ForEach-Object {
147+
dotnet sln $slnFilePath add $_.FullName
148148
}
149149

150150
$Psd1Metadata.RequiredAssemblies = Unique-PathList $Psd1Metadata.RequiredAssemblies

tools/TestFx/EnvironmentSetupHelper.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,7 @@ public void SetupAzureEnvironmentFromEnvironmentVariables(AzureModule mode)
406406
environment.StorageEndpointSuffix = AzureEnvironmentConstants.AzureStorageEndpointSuffix;
407407
environment.AzureKeyVaultDnsSuffix = AzureEnvironmentConstants.AzureKeyVaultDnsSuffix;
408408
environment.AzureKeyVaultServiceEndpointResourceId = AzureEnvironmentConstants.AzureKeyVaultServiceEndpointResourceId;
409+
environment.ExtendedProperties.SetProperty(AzureEnvironment.ExtendedEndpoint.MicrosoftGraphUrl, currentEnvironment.Endpoints.GraphUri.AbsoluteUri);
409410
environment.ExtendedProperties.SetProperty(AzureEnvironment.ExtendedEndpoint.OperationalInsightsEndpoint, "https://api.loganalytics.io/v1");
410411
environment.ExtendedProperties.SetProperty(AzureEnvironment.ExtendedEndpoint.OperationalInsightsEndpointResourceId, "https://api.loganalytics.io");
411412
if (!AzureRmProfileProvider.Instance.GetProfile<AzureRmProfile>().EnvironmentTable.ContainsKey(TestEnvironmentName))

tools/TestFx/Mocks/MockClientFactory.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
using Microsoft.Azure.Commands.TestFx.DelegatingHandlers;
3232
using Microsoft.Rest.ClientRuntime.Azure.TestFramework;
3333
using Microsoft.Azure.Test.HttpRecorder;
34+
using Microsoft.Azure.Commands.Common.MSGraph.Version1_0;
35+
3436
#if NETSTANDARD
3537
using Microsoft.Azure.Commands.Common.Authentication.Abstractions.Core;
3638
#endif
@@ -81,9 +83,16 @@ public TClient CreateArmClient<TClient>(IAzureContext context, string endpoint)
8183

8284
public TClient CreateCustomArmClient<TClient>(params object[] parameters) where TClient : Microsoft.Rest.ServiceClient<TClient>
8385
{
84-
if (!(_serviceClients.FirstOrDefault(o => o is TClient) is TClient client))
86+
if (_serviceClients.FirstOrDefault(o => o is TClient) is not TClient client)
8587
{
86-
client = _mockContext?.GetServiceClient<TClient>();
88+
if (typeof(TClient) == typeof(MicrosoftGraphClient))
89+
{
90+
client = _mockContext?.GetGraphServiceClient<TClient>();
91+
}
92+
else
93+
{
94+
client = _mockContext?.GetServiceClient<TClient>();
95+
}
8796
}
8897

8998
if (client == null)

tools/TestFx/Mocks/MockContext.cs

Lines changed: 18 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,13 @@ public T GetServiceClient<T>(bool internalBaseUri = false, params DelegatingHand
9999
/// <returns></returns>
100100
public T GetServiceClient<T>(TestEnvironment currentEnvironment, bool internalBaseUri = false, params DelegatingHandler[] handlers) where T : class
101101
{
102+
if (!currentEnvironment.TokenInfo.ContainsKey(TokenAudience.Management))
103+
{
104+
throw new ArgumentNullException(
105+
"currentEnvironment.TokenInfo[TokenAudience.Management]",
106+
$"Unable to create Service Client because {nameof(T)} authentication token was not acquired during Login.");
107+
}
108+
102109
return GetServiceClientWithCredentials<T>(currentEnvironment, currentEnvironment.TokenInfo[TokenAudience.Management], internalBaseUri, handlers);
103110
}
104111

@@ -108,9 +115,7 @@ public T GetServiceClient<T>(TestEnvironment currentEnvironment, bool internalBa
108115
/// <typeparam name="T"></typeparam>
109116
/// <param name="handlers">Delegating existingHandlers</param>
110117
/// <returns></returns>
111-
public T GetGraphServiceClient<T>(
112-
bool internalBaseUri = false,
113-
params DelegatingHandler[] handlers) where T : class
118+
public T GetGraphServiceClient<T>(bool internalBaseUri = false, params DelegatingHandler[] handlers) where T : class
114119
{
115120
return GetGraphServiceClient<T>(TestFxEnvironment, internalBaseUri, handlers);
116121
}
@@ -121,52 +126,16 @@ public T GetGraphServiceClient<T>(
121126
/// <typeparam name="T"></typeparam>
122127
/// <param name="handlers">Delegating existingHandlers</param>
123128
/// <returns></returns>
124-
public T GetGraphServiceClient<T>(
125-
TestEnvironment currentEnvironment,
126-
bool internalBaseUri = false,
127-
params DelegatingHandler[] handlers) where T : class
129+
public T GetGraphServiceClient<T>(TestEnvironment currentEnvironment, bool internalBaseUri = false, params DelegatingHandler[] handlers) where T : class
128130
{
129131
if (!currentEnvironment.TokenInfo.ContainsKey(TokenAudience.Graph))
130132
{
131133
throw new ArgumentNullException(
132134
"currentEnvironment.TokenInfo[TokenAudience.Graph]",
133-
"Unable to create Graph Management client because Graph authentication token was not acquired during Login.");
135+
"Unable to create Graph Client because Graph authentication token was not acquired during Login.");
134136
}
135137

136-
return GetServiceClientWithCredentials<T>(
137-
currentEnvironment,
138-
currentEnvironment.TokenInfo[TokenAudience.Graph],
139-
currentEnvironment.Endpoints.GraphUri,
140-
internalBaseUri,
141-
handlers);
142-
}
143-
144-
/// <summary>
145-
/// Get a test environment using default options
146-
/// </summary>
147-
/// <typeparam name="T">The type of the service client to return</typeparam>
148-
/// <param name="credentials">Credentials</param>
149-
/// <param name="handlers">Delegating existingHandlers</param>
150-
/// <returns>A Service client using credentials and base uri from the current environment</returns>
151-
public T GetServiceClientWithCredentials<T>(object credentials, params DelegatingHandler[] handlers) where T : class
152-
{
153-
return GetServiceClientWithCredentials<T>(TestFxEnvironment, credentials, handlers: handlers);
154-
}
155-
156-
/// <summary>
157-
/// Get a test environment, allowing the test to customize the creation options
158-
/// </summary>
159-
/// <typeparam name="T"></typeparam>
160-
/// <param name="credentials">Credentials</param>
161-
/// <param name="handlers">Delegating existingHandlers</param>
162-
/// <returns></returns>
163-
public T GetServiceClientWithCredentials<T>(
164-
TestEnvironment currentEnvironment,
165-
object credentials,
166-
bool internalBaseUri = false,
167-
params DelegatingHandler[] handlers) where T : class
168-
{
169-
return GetServiceClientWithCredentials<T>(currentEnvironment, credentials, currentEnvironment.BaseUri, internalBaseUri, handlers);
138+
return GetServiceClientWithCredentials<T>(currentEnvironment, currentEnvironment.TokenInfo[TokenAudience.Graph], internalBaseUri, handlers);
170139
}
171140

172141
/// <summary>
@@ -177,21 +146,14 @@ public T GetServiceClientWithCredentials<T>(
177146
/// <param name="baseUri">Base Uri</param>
178147
/// <param name="handlers">Delegating existingHandlers</param>
179148
/// <returns></returns>
180-
public T GetServiceClientWithCredentials<T>(
181-
TestEnvironment currentEnvironment,
182-
object credentials,
183-
Uri baseUri,
184-
bool internalBaseUri = false,
185-
params DelegatingHandler[] handlers) where T : class
149+
public T GetServiceClientWithCredentials<T>(TestEnvironment currentEnvironment, object credentials, bool internalBaseUri = false, params DelegatingHandler[] handlers) where T : class
186150
{
187151
T client;
188152
handlers = AddHandlers(currentEnvironment, handlers);
189153
var constructors = typeof(T).GetConstructors(BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance | BindingFlags.NonPublic);
190154

191155
ConstructorInfo constructor = null;
192-
//We no longer use UseCustomUri function, rather check if BaseUri is notNull
193-
//UseCustomeUri use to return true when BaseUri was set to some value
194-
if ((currentEnvironment.BaseUri != null) && !internalBaseUri)
156+
if (!internalBaseUri && currentEnvironment.BaseUri != null)
195157
{
196158
foreach (var c in constructors)
197159
{
@@ -207,12 +169,11 @@ public T GetServiceClientWithCredentials<T>(
207169
}
208170
if (constructor == null)
209171
{
210-
throw new InvalidOperationException(
211-
"can't find constructor (uri, ServiceClientCredentials, DelegatingHandler[]) to create client");
172+
throw new InvalidOperationException("Cannot find constructor (uri, ServiceClientCredentials, DelegatingHandler[]) to create service client");
212173
}
213174
client = constructor.Invoke(new object[]
214175
{
215-
baseUri,
176+
currentEnvironment.BaseUri,
216177
credentials,
217178
handlers
218179
}) as T;
@@ -232,8 +193,7 @@ public T GetServiceClientWithCredentials<T>(
232193
}
233194
if (constructor == null)
234195
{
235-
throw new InvalidOperationException(
236-
"can't find constructor (ServiceClientCredentials, DelegatingHandler[]) to create client");
196+
throw new InvalidOperationException("Cannot find constructor (ServiceClientCredentials, DelegatingHandler[]) to create service client");
237197
}
238198
client = constructor.Invoke(new object[]
239199
{
@@ -262,15 +222,11 @@ private void SetLongRunningOperationTimeouts<T>(T client) where T : class
262222
if (HttpMockServer.Mode == HttpRecorderMode.Playback)
263223
{
264224
PropertyInfo retryTimeout = typeof(T).GetProperty("LongRunningOperationRetryTimeout");
265-
if (retryTimeout != null)
266-
{
267-
retryTimeout.SetValue(client, 0);
268-
}
225+
retryTimeout?.SetValue(client, 0);
269226
}
270227
}
271228

272-
public DelegatingHandler[] AddHandlers(TestEnvironment currentEnvironment,
273-
params DelegatingHandler[] existingHandlers)
229+
public DelegatingHandler[] AddHandlers(TestEnvironment currentEnvironment, params DelegatingHandler[] existingHandlers)
274230
{
275231
HttpMockServer server;
276232

tools/TestFx/TestEndpoints.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ internal TestEndpoints(TestEnvironmentName testEnvNames)
127127
{
128128
case TestEnvironmentName.Prod:
129129
Name = TestEnvironmentName.Prod;
130-
GraphUri = new Uri("https://graph.windows.net/");
130+
GraphUri = new Uri("https://graph.microsoft.com/");
131131
AADAuthUri = new Uri("https://login.microsoftonline.com/");
132132
IbizaPortalUri = new Uri("https://portal.azure.com/");
133133
RdfePortalUri = new Uri("https://manage.windowsazure.com/");

0 commit comments

Comments
 (0)