Skip to content

Commit fbf56ed

Browse files
committed
Fixed MockClientFactory behavior
1 parent 8dda7e1 commit fbf56ed

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

src/Common/Commands.Common.Test/Mocks/MockClientFactory.cs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,20 @@ public TClient CreateClient<TClient>(AzureProfile profile, AzureEnvironment.Endp
6060

6161
public TClient CreateClient<TClient>(AzureProfile profile, AzureSubscription subscription, AzureEnvironment.Endpoint endpoint) where TClient : ServiceClient<TClient>
6262
{
63-
SubscriptionCloudCredentials creds = new TokenCloudCredentials(subscription == null ? "fake_subscription" : subscription.Id.ToString(), "fake_token");
63+
if (subscription == null)
64+
{
65+
throw new ArgumentException(Commands.Common.Properties.Resources.InvalidDefaultSubscription);
66+
}
67+
68+
if (profile == null)
69+
{
70+
profile = new AzureProfile(Path.Combine(AzureSession.ProfileDirectory, AzureSession.ProfileFile));
71+
}
72+
73+
SubscriptionCloudCredentials creds = new TokenCloudCredentials(subscription.Id.ToString(), "fake_token");
6474
if (HttpMockServer.GetCurrentMode() != HttpRecorderMode.Playback)
6575
{
66-
ProfileClient profileClient = new ProfileClient(
67-
profile ?? new AzureProfile(Path.Combine(AzureSession.ProfileDirectory, AzureSession.ProfileFile)));
76+
ProfileClient profileClient = new ProfileClient(profile);
6877
AzureContext context = new AzureContext(
6978
subscription,
7079
profileClient.GetAccount(subscription.Account),
@@ -74,7 +83,7 @@ public TClient CreateClient<TClient>(AzureProfile profile, AzureSubscription sub
7483
creds = AzureSession.AuthenticationFactory.GetSubscriptionCloudCredentials(context);
7584
}
7685

77-
Uri endpointUri = (new ProfileClient(profile ?? new AzureProfile(Path.Combine(AzureSession.ProfileDirectory, AzureSession.ProfileFile)))).Profile.Environments[subscription.Environment].GetEndpointAsUri(endpoint);
86+
Uri endpointUri = profile.Environments[subscription.Environment].GetEndpointAsUri(endpoint);
7887
return CreateCustomClient<TClient>(creds, endpointUri);
7988
}
8089

0 commit comments

Comments
 (0)