18
18
using Microsoft . Azure . Management . Authorization ;
19
19
using Microsoft . Azure . Management . KeyVault ;
20
20
using Microsoft . Azure . Management . Resources ;
21
+ using Microsoft . Azure . ServiceManagemenet . Common . Models ;
21
22
using Microsoft . Azure . Subscriptions ;
22
- using Microsoft . Azure . Test ;
23
23
using Microsoft . Azure . Test . HttpRecorder ;
24
+ using Microsoft . Rest . ClientRuntime . Azure . TestFramework ;
24
25
using Microsoft . WindowsAzure . Commands . Common ;
25
26
using Microsoft . WindowsAzure . Commands . ScenarioTest ;
26
27
using System ;
27
28
using System . Collections . Generic ;
28
29
using System . IO ;
29
30
using System . Linq ;
31
+ using LegacyTest = Microsoft . Azure . Test ;
30
32
31
33
namespace Microsoft . Azure . Commands . KeyVault . Test
32
34
{
@@ -38,10 +40,11 @@ namespace Microsoft.Azure.Commands.KeyVault.Test
38
40
public class KeyVaultManagementController
39
41
{
40
42
41
- private CSMTestEnvironmentFactory csmTestFactory ;
43
+ private LegacyTest . CSMTestEnvironmentFactory csmTestFactory ;
42
44
private KeyVaultEnvSetupHelper helper ;
43
45
private const string TenantIdKey = "TenantId" ;
44
46
private const string DomainKey = "Domain" ;
47
+ private const string SubscriptionIdKey = "SubscriptionId" ;
45
48
46
49
public ResourceManagementClient ResourceManagementClient { get ; private set ; }
47
50
@@ -70,11 +73,13 @@ public KeyVaultManagementController()
70
73
helper = new KeyVaultEnvSetupHelper ( ) ;
71
74
}
72
75
73
- public void RunPsTest ( params string [ ] scripts )
76
+ public void RunPsTest ( XunitTracingInterceptor logger , params string [ ] scripts )
74
77
{
75
78
var callingClassType = TestUtilities . GetCallingClass ( 2 ) ;
76
79
var mockName = TestUtilities . GetCurrentMethodName ( 2 ) ;
77
80
81
+ logger . Information ( string . Format ( "Test method entered: {0}.{1}" , callingClassType , mockName ) ) ;
82
+ helper . TracingInterceptor = logger ;
78
83
RunPsTestWorkflow (
79
84
( ) => scripts ,
80
85
// no custom initializer
@@ -83,12 +88,13 @@ public void RunPsTest(params string[] scripts)
83
88
null ,
84
89
callingClassType ,
85
90
mockName ) ;
91
+ logger . Information ( string . Format ( "Test method finished: {0}.{1}" , callingClassType , mockName ) ) ;
86
92
}
87
93
88
94
89
95
public void RunPsTestWorkflow (
90
96
Func < string [ ] > scriptBuilder ,
91
- Action < CSMTestEnvironmentFactory > initialize ,
97
+ Action < LegacyTest . CSMTestEnvironmentFactory > initialize ,
92
98
Action cleanup ,
93
99
string callingClassType ,
94
100
string mockName )
@@ -104,7 +110,7 @@ public void RunPsTestWorkflow(
104
110
HttpMockServer . RecordsDirectory = Path . Combine ( AppDomain . CurrentDomain . BaseDirectory , "SessionRecords" ) ;
105
111
using ( MockContext context = MockContext . Start ( callingClassType , mockName ) )
106
112
{
107
- this . csmTestFactory = new CSMTestEnvironmentFactory ( ) ;
113
+ this . csmTestFactory = new LegacyTest . CSMTestEnvironmentFactory ( ) ;
108
114
109
115
if ( initialize != null )
110
116
{
@@ -120,7 +126,7 @@ public void RunPsTestWorkflow(
120
126
. Last ( ) ;
121
127
helper . SetupModules ( AzureModule . AzureResourceManager ,
122
128
"ScenarioTests\\ Common.ps1" ,
123
- "ScenarioTests \\ " + callingClassName + ".ps1" ,
129
+ "Scripts \\ ControlPlane \\ " + callingClassName + ".ps1" ,
124
130
helper . RMProfileModule ,
125
131
helper . RMResourceModule ,
126
132
helper . GetRMModulePath ( "AzureRM.KeyVault.psd1" ) ) ;
@@ -154,7 +160,7 @@ private void SetupManagementClients(MockContext context)
154
160
GalleryClient = GetGalleryClient ( ) ;
155
161
AuthorizationManagementClient = GetAuthorizationManagementClient ( ) ;
156
162
GraphClient = GetGraphClient ( context ) ;
157
- KeyVaultManagementClient = GetKeyVaultManagementClient ( ) ;
163
+ KeyVaultManagementClient = GetKeyVaultManagementClient ( context ) ;
158
164
helper . SetupManagementClients ( ResourceManagementClient ,
159
165
SubscriptionClient ,
160
166
KeyVaultManagementClient ,
@@ -167,26 +173,26 @@ private void SetupManagementClients(MockContext context)
167
173
168
174
private AuthorizationManagementClient GetAuthorizationManagementClient ( )
169
175
{
170
- return TestBase . GetServiceClient < AuthorizationManagementClient > ( this . csmTestFactory ) ;
176
+ return LegacyTest . TestBase . GetServiceClient < AuthorizationManagementClient > ( this . csmTestFactory ) ;
171
177
}
172
178
173
179
private ResourceManagementClient GetResourceManagementClient ( )
174
180
{
175
- return TestBase . GetServiceClient < ResourceManagementClient > ( this . csmTestFactory ) ;
181
+ return LegacyTest . TestBase . GetServiceClient < ResourceManagementClient > ( this . csmTestFactory ) ;
176
182
}
177
183
178
- private KeyVaultManagementClient GetKeyVaultManagementClient ( )
184
+ private KeyVaultManagementClient GetKeyVaultManagementClient ( MockContext context )
179
185
{
180
- return TestBase . GetServiceClient < KeyVaultManagementClient > ( this . csmTestFactory ) ;
186
+ return context . GetServiceClient < KeyVaultManagementClient > ( TestEnvironmentFactory . GetTestEnvironment ( ) ) ;
181
187
}
182
188
private SubscriptionClient GetSubscriptionClient ( )
183
189
{
184
- return TestBase . GetServiceClient < SubscriptionClient > ( this . csmTestFactory ) ;
190
+ return LegacyTest . TestBase . GetServiceClient < SubscriptionClient > ( this . csmTestFactory ) ;
185
191
}
186
192
187
193
private GalleryClient GetGalleryClient ( )
188
194
{
189
- return TestBase . GetServiceClient < GalleryClient > ( this . csmTestFactory ) ;
195
+ return LegacyTest . TestBase . GetServiceClient < GalleryClient > ( this . csmTestFactory ) ;
190
196
}
191
197
192
198
private GraphRbacManagementClient GetGraphClient ( MockContext context )
@@ -207,19 +213,27 @@ private GraphRbacManagementClient GetGraphClient(MockContext context)
207
213
if ( HttpMockServer . Variables . ContainsKey ( TenantIdKey ) )
208
214
{
209
215
tenantId = HttpMockServer . Variables [ TenantIdKey ] ;
210
- AzureRmProfileProvider . Instance . Profile . Context . Tenant . Id = new Guid ( tenantId ) ;
211
216
}
212
217
if ( HttpMockServer . Variables . ContainsKey ( DomainKey ) )
213
218
{
214
219
UserDomain = HttpMockServer . Variables [ DomainKey ] ;
215
- AzureRmProfileProvider . Instance . Profile . Context . Tenant . Domain = UserDomain ;
216
220
}
217
-
221
+ if ( HttpMockServer . Variables . ContainsKey ( SubscriptionIdKey ) )
222
+ {
223
+ AzureRmProfileProvider . Instance . Profile . Context . Subscription . Id = new Guid ( HttpMockServer . Variables [ SubscriptionIdKey ] ) ;
224
+ }
218
225
}
219
226
220
227
var client = context . GetGraphServiceClient < GraphRbacManagementClient > ( environment ) ;
221
228
client . TenantID = tenantId ;
222
- return client ;
229
+ if ( AzureRmProfileProvider . Instance != null &&
230
+ AzureRmProfileProvider . Instance . Profile != null &&
231
+ AzureRmProfileProvider . Instance . Profile . Context != null &&
232
+ AzureRmProfileProvider . Instance . Profile . Context . Tenant != null )
233
+ {
234
+ AzureRmProfileProvider . Instance . Profile . Context . Tenant . Id = Guid . Parse ( client . TenantID ) ;
235
+ }
236
+ return client ;
223
237
}
224
238
225
239
}
0 commit comments