Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions tools/Common.Netcore.Dependencies.Test.targets
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

<ItemGroup>
<PackageReference Include="Microsoft.Azure.Management.ResourceManager" Version="3.17.3-preview" />
<PackageReference Include="Microsoft.Rest.ClientRuntime.Azure.Authentication" Version="2.3.7" />
<PackageReference Include="xunit" Version="2.4.2" />
</ItemGroup>

Expand Down Expand Up @@ -40,7 +39,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.IdentityModel.Clients.ActiveDirectory" Version="3.19.2" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.5.0" />
<PackageReference Include="Microsoft.Identity.Client" Version="4.49.1" />
</ItemGroup>
</Project>
6 changes: 3 additions & 3 deletions tools/Gen2Master/MoveFromGeneration2Master.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,9 @@ Function Move-Generation2Master {
dotnet sln $slnFilePath add $_.FullName --solution-folder Accounts
}
}
Get-ChildItem -Filter *.csproj -File -Path $DestPath -Recurse | ForEach-Object {
dotnet sln $slnFilePath add $_.FullName
}
}
Get-ChildItem -Filter *.csproj -File -Path $DestPath -Recurse | ForEach-Object {
dotnet sln $slnFilePath add $_.FullName
}

$Psd1Metadata.RequiredAssemblies = Unique-PathList $Psd1Metadata.RequiredAssemblies
Expand Down
1 change: 1 addition & 0 deletions tools/TestFx/EnvironmentSetupHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,7 @@ public void SetupAzureEnvironmentFromEnvironmentVariables(AzureModule mode)
environment.StorageEndpointSuffix = AzureEnvironmentConstants.AzureStorageEndpointSuffix;
environment.AzureKeyVaultDnsSuffix = AzureEnvironmentConstants.AzureKeyVaultDnsSuffix;
environment.AzureKeyVaultServiceEndpointResourceId = AzureEnvironmentConstants.AzureKeyVaultServiceEndpointResourceId;
environment.ExtendedProperties.SetProperty(AzureEnvironment.ExtendedEndpoint.MicrosoftGraphUrl, currentEnvironment.Endpoints.GraphUri.AbsoluteUri);
environment.ExtendedProperties.SetProperty(AzureEnvironment.ExtendedEndpoint.OperationalInsightsEndpoint, "https://api.loganalytics.io/v1");
environment.ExtendedProperties.SetProperty(AzureEnvironment.ExtendedEndpoint.OperationalInsightsEndpointResourceId, "https://api.loganalytics.io");
if (!AzureRmProfileProvider.Instance.GetProfile<AzureRmProfile>().EnvironmentTable.ContainsKey(TestEnvironmentName))
Expand Down
13 changes: 11 additions & 2 deletions tools/TestFx/Mocks/MockClientFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
using Microsoft.Azure.Commands.TestFx.DelegatingHandlers;
using Microsoft.Rest.ClientRuntime.Azure.TestFramework;
using Microsoft.Azure.Test.HttpRecorder;
using Microsoft.Azure.Commands.Common.MSGraph.Version1_0;

#if NETSTANDARD
using Microsoft.Azure.Commands.Common.Authentication.Abstractions.Core;
#endif
Expand Down Expand Up @@ -81,9 +83,16 @@ public TClient CreateArmClient<TClient>(IAzureContext context, string endpoint)

public TClient CreateCustomArmClient<TClient>(params object[] parameters) where TClient : Microsoft.Rest.ServiceClient<TClient>
{
if (!(_serviceClients.FirstOrDefault(o => o is TClient) is TClient client))
if (_serviceClients.FirstOrDefault(o => o is TClient) is not TClient client)
{
client = _mockContext?.GetServiceClient<TClient>();
if (typeof(TClient) == typeof(MicrosoftGraphClient))
{
client = _mockContext?.GetGraphServiceClient<TClient>();
}
else
{
client = _mockContext?.GetServiceClient<TClient>();
}
}

if (client == null)
Expand Down
80 changes: 18 additions & 62 deletions tools/TestFx/Mocks/MockContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,13 @@ public T GetServiceClient<T>(bool internalBaseUri = false, params DelegatingHand
/// <returns></returns>
public T GetServiceClient<T>(TestEnvironment currentEnvironment, bool internalBaseUri = false, params DelegatingHandler[] handlers) where T : class
{
if (!currentEnvironment.TokenInfo.ContainsKey(TokenAudience.Management))
{
throw new ArgumentNullException(
"currentEnvironment.TokenInfo[TokenAudience.Management]",
$"Unable to create Service Client because {nameof(T)} authentication token was not acquired during Login.");
}

return GetServiceClientWithCredentials<T>(currentEnvironment, currentEnvironment.TokenInfo[TokenAudience.Management], internalBaseUri, handlers);
}

Expand All @@ -108,9 +115,7 @@ public T GetServiceClient<T>(TestEnvironment currentEnvironment, bool internalBa
/// <typeparam name="T"></typeparam>
/// <param name="handlers">Delegating existingHandlers</param>
/// <returns></returns>
public T GetGraphServiceClient<T>(
bool internalBaseUri = false,
params DelegatingHandler[] handlers) where T : class
public T GetGraphServiceClient<T>(bool internalBaseUri = false, params DelegatingHandler[] handlers) where T : class
{
return GetGraphServiceClient<T>(TestFxEnvironment, internalBaseUri, handlers);
}
Expand All @@ -121,52 +126,16 @@ public T GetGraphServiceClient<T>(
/// <typeparam name="T"></typeparam>
/// <param name="handlers">Delegating existingHandlers</param>
/// <returns></returns>
public T GetGraphServiceClient<T>(
TestEnvironment currentEnvironment,
bool internalBaseUri = false,
params DelegatingHandler[] handlers) where T : class
public T GetGraphServiceClient<T>(TestEnvironment currentEnvironment, bool internalBaseUri = false, params DelegatingHandler[] handlers) where T : class
{
if (!currentEnvironment.TokenInfo.ContainsKey(TokenAudience.Graph))
{
throw new ArgumentNullException(
"currentEnvironment.TokenInfo[TokenAudience.Graph]",
"Unable to create Graph Management client because Graph authentication token was not acquired during Login.");
"Unable to create Graph Client because Graph authentication token was not acquired during Login.");
}

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

/// <summary>
/// Get a test environment using default options
/// </summary>
/// <typeparam name="T">The type of the service client to return</typeparam>
/// <param name="credentials">Credentials</param>
/// <param name="handlers">Delegating existingHandlers</param>
/// <returns>A Service client using credentials and base uri from the current environment</returns>
public T GetServiceClientWithCredentials<T>(object credentials, params DelegatingHandler[] handlers) where T : class
{
return GetServiceClientWithCredentials<T>(TestFxEnvironment, credentials, handlers: handlers);
}

/// <summary>
/// Get a test environment, allowing the test to customize the creation options
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="credentials">Credentials</param>
/// <param name="handlers">Delegating existingHandlers</param>
/// <returns></returns>
public T GetServiceClientWithCredentials<T>(
TestEnvironment currentEnvironment,
object credentials,
bool internalBaseUri = false,
params DelegatingHandler[] handlers) where T : class
{
return GetServiceClientWithCredentials<T>(currentEnvironment, credentials, currentEnvironment.BaseUri, internalBaseUri, handlers);
return GetServiceClientWithCredentials<T>(currentEnvironment, currentEnvironment.TokenInfo[TokenAudience.Graph], internalBaseUri, handlers);
}

/// <summary>
Expand All @@ -177,21 +146,14 @@ public T GetServiceClientWithCredentials<T>(
/// <param name="baseUri">Base Uri</param>
/// <param name="handlers">Delegating existingHandlers</param>
/// <returns></returns>
public T GetServiceClientWithCredentials<T>(
TestEnvironment currentEnvironment,
object credentials,
Uri baseUri,
bool internalBaseUri = false,
params DelegatingHandler[] handlers) where T : class
public T GetServiceClientWithCredentials<T>(TestEnvironment currentEnvironment, object credentials, bool internalBaseUri = false, params DelegatingHandler[] handlers) where T : class
{
T client;
handlers = AddHandlers(currentEnvironment, handlers);
var constructors = typeof(T).GetConstructors(BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance | BindingFlags.NonPublic);

ConstructorInfo constructor = null;
//We no longer use UseCustomUri function, rather check if BaseUri is notNull
//UseCustomeUri use to return true when BaseUri was set to some value
if ((currentEnvironment.BaseUri != null) && !internalBaseUri)
if (!internalBaseUri && currentEnvironment.BaseUri != null)
{
foreach (var c in constructors)
{
Expand All @@ -207,12 +169,11 @@ public T GetServiceClientWithCredentials<T>(
}
if (constructor == null)
{
throw new InvalidOperationException(
"can't find constructor (uri, ServiceClientCredentials, DelegatingHandler[]) to create client");
throw new InvalidOperationException("Cannot find constructor (uri, ServiceClientCredentials, DelegatingHandler[]) to create service client");
}
client = constructor.Invoke(new object[]
{
baseUri,
currentEnvironment.BaseUri,
credentials,
handlers
}) as T;
Expand All @@ -232,8 +193,7 @@ public T GetServiceClientWithCredentials<T>(
}
if (constructor == null)
{
throw new InvalidOperationException(
"can't find constructor (ServiceClientCredentials, DelegatingHandler[]) to create client");
throw new InvalidOperationException("Cannot find constructor (ServiceClientCredentials, DelegatingHandler[]) to create service client");
}
client = constructor.Invoke(new object[]
{
Expand Down Expand Up @@ -262,15 +222,11 @@ private void SetLongRunningOperationTimeouts<T>(T client) where T : class
if (HttpMockServer.Mode == HttpRecorderMode.Playback)
{
PropertyInfo retryTimeout = typeof(T).GetProperty("LongRunningOperationRetryTimeout");
if (retryTimeout != null)
{
retryTimeout.SetValue(client, 0);
}
retryTimeout?.SetValue(client, 0);
}
}

public DelegatingHandler[] AddHandlers(TestEnvironment currentEnvironment,
params DelegatingHandler[] existingHandlers)
public DelegatingHandler[] AddHandlers(TestEnvironment currentEnvironment, params DelegatingHandler[] existingHandlers)
{
HttpMockServer server;

Expand Down
2 changes: 1 addition & 1 deletion tools/TestFx/TestEndpoints.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ internal TestEndpoints(TestEnvironmentName testEnvNames)
{
case TestEnvironmentName.Prod:
Name = TestEnvironmentName.Prod;
GraphUri = new Uri("https://graph.windows.net/");
GraphUri = new Uri("https://graph.microsoft.com/");
AADAuthUri = new Uri("https://login.microsoftonline.com/");
IbizaPortalUri = new Uri("https://portal.azure.com/");
RdfePortalUri = new Uri("https://manage.windowsazure.com/");
Expand Down
Loading