Skip to content

Commit a4a4404

Browse files
committed
Add mock support and fix source formatting
1 parent 774b71c commit a4a4404

File tree

4 files changed

+35
-37
lines changed

4 files changed

+35
-37
lines changed

src/Common/Commands.Common/AzurePSCmdlet.cs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,17 @@ static AzurePSCmdlet()
4747
}
4848

4949
AzureSession.ClientFactory.UserAgents.Add(AzurePowerShell.UserAgentValue);
50-
InitializeTokenCaches();
51-
DefaultProfile = InitializeDefaultProfile();
52-
CurrentProfile = DefaultProfile;
53-
UpdateSessionStateForProfile(CurrentProfile);
54-
AzureSession.DataStore = new DiskDataStore();
50+
if (!TestMockSupport.RunningMocked)
51+
{
52+
InitializeTokenCaches();
53+
DefaultProfile = InitializeDefaultProfile();
54+
CurrentProfile = DefaultProfile;
55+
UpdateSessionStateForProfile(CurrentProfile);
56+
AzureSession.DataStore = new DiskDataStore();
57+
}
5558
}
5659

57-
/// <summary>
60+
/// <summary>
5861
/// Create the default profile, based on the default profile path
5962
/// </summary>
6063
/// <returns>The default prpofile, serialized from the default location on disk</returns>
@@ -68,7 +71,7 @@ protected static AzureProfile InitializeDefaultProfile()
6871
}
6972
catch
7073
{
71-
// swallow exceptions in creating the profile from disk
74+
// swallow exceptions in creating the profile from disk
7275
}
7376
}
7477

@@ -138,9 +141,9 @@ private void InitializeProfile()
138141
{
139142
if (Profile == null)
140143
{
141-
Profile = AzurePSCmdlet.CurrentProfile;
144+
Profile = AzurePSCmdlet.CurrentProfile;
142145
}
143-
146+
144147
UpdateSessionStateForProfile(Profile);
145148
}
146149

src/Common/Commands.Profile/Models/AzureProfileSettings.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public class AzureProfileSettings
2828
public string SubscriptionId { get; set; }
2929

3030
public string StorageAccount { get; set; }
31-
31+
3232
public X509Certificate2 Certificate { get; set; }
3333

3434
public PSCredential Credential { get; set; }
@@ -44,7 +44,7 @@ public static AzureProfileSettings Create(NewAzureProfileCommand command)
4444
return new AzureProfileSettings
4545
{
4646
Environment = command.Environment,
47-
SubscriptionId = command.SubscriptionId,
47+
SubscriptionId = command.SubscriptionId,
4848
StorageAccount = command.StorageAccount,
4949
Certificate = command.Certificate,
5050
Credential = command.Credential,
@@ -53,6 +53,5 @@ public static AzureProfileSettings Create(NewAzureProfileCommand command)
5353
AccountId = command.AccountId
5454
};
5555
}
56-
5756
}
5857
}

src/ServiceManagement/Services/Commands.Test/Profile/NewAzureProfileTests.ps1

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,11 @@ function Test-NewAzureProfileInRDFEMode
8383
{
8484
param([string] $token, [string] $user, [string] $sub)
8585
$profile = $(Create-Profile $token $user $sub)
86-
Assert-AreEqual "AzureCloud" $profile.Context.Environment.Name
87-
Clear-AzureProfile -Force
88-
$locations = Get-AzureLocation -Profile $profile
89-
Assert-NotNull $locations
90-
Assert-True {$locations.Count -gt 1}
91-
86+
Assert-AreEqual "AzureCloud" $profile.Context.Environment.Name
87+
Clear-AzureProfile -Force
88+
$locations = Get-AzureLocation -Profile $profile
89+
Assert-NotNull $locations
90+
Assert-True {$locations.Count -gt 1}
9291
}
9392

9493
<#

src/ServiceManagement/Services/Commands.Test/Profile/ProfileClientHelper.cs

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ public class MockRdfeSubscriptionOperations : Microsoft.Azure.Subscriptions.Rdfe
4343

4444
private MockRdfeSubscriptionOperations()
4545
{
46-
4746
}
4847

4948
/// <summary>
@@ -74,7 +73,6 @@ private Azure.Subscriptions.Rdfe.Models.Subscription CreateSubscription(string s
7473
};
7574
}
7675

77-
7876
public Task<Azure.Subscriptions.Rdfe.Models.SubscriptionListOperationResponse> ListAsync(System.Threading.CancellationToken cancellationToken)
7977
{
8078
var response = new Azure.Subscriptions.Rdfe.Models.SubscriptionListOperationResponse
@@ -100,7 +98,7 @@ private Azure.Subscriptions.Rdfe.Models.Subscription CreateSubscription(string s
10098
public class MockCsmSubscriptionClient : Microsoft.Azure.Subscriptions.Csm.SubscriptionClient
10199
{
102100
private IList<string> _subscriptions = new List<string>();
103-
private IList<string> _tenants = new List<string>();
101+
private IList<string> _tenants = new List<string>();
104102
public IList<String> ReturnedSubscriptions
105103
{
106104
get { return this._subscriptions; }
@@ -134,8 +132,8 @@ public override Azure.Subscriptions.Csm.ITenantOperations Tenants
134132

135133
public class MockCsmTenantOperations : Microsoft.Azure.Subscriptions.Csm.ITenantOperations
136134
{
137-
private IList<string> _tenants = new List<string> ();
138-
135+
private IList<string> _tenants = new List<string>();
136+
139137
/// <summary>
140138
/// Create a tenant mock using the given set of tenants
141139
/// </summary>
@@ -152,16 +150,16 @@ public static MockCsmTenantOperations Create(IList<string> knownTenants)
152150
return operations;
153151
}
154152

155-
public Task<Azure.Subscriptions.Csm.Models.TenantListResult> ListAsync(System.Threading.CancellationToken cancellationToken)
156-
{
157-
var result = new Azure.Subscriptions.Csm.Models.TenantListResult
158-
{
159-
StatusCode = HttpStatusCode.OK,
160-
TenantIds = CreateTenantList()
161-
};
153+
public Task<Azure.Subscriptions.Csm.Models.TenantListResult> ListAsync(System.Threading.CancellationToken cancellationToken)
154+
{
155+
var result = new Azure.Subscriptions.Csm.Models.TenantListResult
156+
{
157+
StatusCode = HttpStatusCode.OK,
158+
TenantIds = CreateTenantList()
159+
};
162160

163-
return Task.FromResult(result);
164-
}
161+
return Task.FromResult(result);
162+
}
165163

166164
private static Azure.Subscriptions.Csm.Models.TenantIdDescription CreateTenant(string tenantId)
167165
{
@@ -172,7 +170,6 @@ private static Azure.Subscriptions.Csm.Models.TenantIdDescription CreateTenant(s
172170
};
173171
}
174172

175-
176173
private IList<Azure.Subscriptions.Csm.Models.TenantIdDescription> CreateTenantList()
177174
{
178175
var result = new List<Azure.Subscriptions.Csm.Models.TenantIdDescription>();
@@ -183,12 +180,11 @@ private static Azure.Subscriptions.Csm.Models.TenantIdDescription CreateTenant(s
183180

184181
return result;
185182
}
186-
187-
}
183+
}
188184

189185
public class MockCsmSubscriptionOperations : Microsoft.Azure.Subscriptions.Csm.ISubscriptionOperations
190186
{
191-
private IList<string> _subscriptions = new List<string> ();
187+
private IList<string> _subscriptions = new List<string>();
192188

193189
/// <summary>
194190
/// Create a subscription mock using the given set of subscriptions
@@ -236,6 +232,7 @@ public static MockCsmSubscriptionOperations Create(IList<string> knownSubscripti
236232

237233
return Task.FromResult(result);
238234
}
235+
239236
private static Azure.Subscriptions.Csm.Models.Subscription CreateSubscription(string subscriptionId)
240237
{
241238
return new Azure.Subscriptions.Csm.Models.Subscription
@@ -247,7 +244,6 @@ private static Azure.Subscriptions.Csm.Models.Subscription CreateSubscription(st
247244
};
248245
}
249246

250-
251247
private IList<Azure.Subscriptions.Csm.Models.Subscription> CreateSubscriptionList()
252248
{
253249
var result = new List<Azure.Subscriptions.Csm.Models.Subscription>();
@@ -259,6 +255,7 @@ private static Azure.Subscriptions.Csm.Models.Subscription CreateSubscription(st
259255
return result;
260256
}
261257
}
258+
262259
public static class ProfileClientHelper
263260
{
264261
public static Microsoft.Azure.Subscriptions.Rdfe.SubscriptionClient CreateRdfeSubscriptionClient(

0 commit comments

Comments
 (0)