13
13
// ----------------------------------------------------------------------------------
14
14
15
15
using Microsoft . Azure . Commands . Common . Authentication ;
16
- using Microsoft . Azure . Commands . Common . Authentication . Abstractions ;
17
- using Microsoft . Azure . Graph . RBAC ;
18
- using Microsoft . Azure . Management . Authorization ;
19
- using Microsoft . Azure . Management . ResourceManager ;
20
- using Microsoft . Azure . Management . Storage ;
21
- using Microsoft . Azure . Management . StorageSync ;
22
- using Microsoft . Azure . ServiceManagement . Common . Models ;
23
16
using Microsoft . Azure . Test . HttpRecorder ;
24
17
using Microsoft . Rest . ClientRuntime . Azure . TestFramework ;
25
18
using Microsoft . WindowsAzure . Commands . ScenarioTest ;
28
21
using System . Diagnostics ;
29
22
using System . IO ;
30
23
using System . Linq ;
24
+ using Microsoft . Azure . Management . Internal . Resources ;
25
+ using Microsoft . Azure . ServiceManagement . Common . Models ;
26
+ using Microsoft . WindowsAzure . Commands . Test . Utilities . Common ;
31
27
32
28
namespace Microsoft . Azure . Commands . StorageSync . Test . ScenarioTests
33
29
{
34
- public class TestController : IDisposable
30
+ public class TestController : RMTestBase
35
31
{
36
- private const string TenantIdKey = "TenantId" ;
37
- private const string DomainKey = "Domain" ;
38
- private const string SubscriptionIdKey = "SubscriptionId" ;
39
-
40
32
private readonly EnvironmentSetupHelper _helper ;
41
33
42
34
public ResourceManagementClient ResourceManagementClient { get ; private set ; }
43
35
44
- public Microsoft . Azure . Management . Internal . Resources . ResourceManagementClient InternalResourceManagementClient { get ; private set ; }
45
-
46
- public GraphRbacManagementClient GraphRbacManagementClient { get ; private set ; }
47
- //public ActiveDirectoryClient ActiveDirectoryClient { get; private set; }
48
-
49
- public StorageManagementClient StorageClient { get ; private set ; }
50
-
51
- public StorageSyncManagementClient StorageSyncClient { get ; private set ; }
52
-
53
- public Internal . Subscriptions . SubscriptionClient SubscriptionClient { get ; private set ; }
54
-
55
- public AuthorizationManagementClient AuthorizationManagementClient { get ; private set ; }
56
-
57
- public string UserDomain { get ; private set ; }
58
-
59
36
public static TestController NewInstance => new TestController ( ) ;
60
37
61
- public TestEnvironment TestEnvironment { get ; set ; }
62
-
63
38
public TestController ( )
64
39
{
65
40
_helper = new EnvironmentSetupHelper ( ) ;
66
- TestEnvironment = TestEnvironmentFactory . GetTestEnvironment ( ) ;
67
41
}
68
42
69
43
public void RunPsTest ( XunitTracingInterceptor logger , params string [ ] scripts )
70
44
{
71
- _helper . TracingInterceptor = logger ;
72
-
73
45
var sf = new StackTrace ( ) . GetFrame ( 1 ) ;
74
46
var callingClassType = sf . GetMethod ( ) . ReflectedType ? . ToString ( ) ;
75
47
var mockName = sf . GetMethod ( ) . Name ;
76
48
49
+ _helper . TracingInterceptor = logger ;
50
+
77
51
RunPsTestWorkflow (
78
52
( ) => scripts ,
79
53
// no custom cleanup
@@ -113,11 +87,7 @@ public void RunPsTestWorkflow(
113
87
var callingClassName = callingClassType . Split ( new [ ] { "." } , StringSplitOptions . RemoveEmptyEntries ) . Last ( ) ;
114
88
_helper . SetupModules ( AzureModule . AzureResourceManager ,
115
89
_helper . RMProfileModule ,
116
- #if ! NETSTANDARD
117
- _helper . RMStorageDataPlaneModule ,
118
- #endif
119
- _helper. RMStorageModule ,
120
- _helper . GetRMModulePath ( "Az.StorageSync.psd1" ) ,
90
+ _helper . GetRMModulePath ( "AzureRM.StorageSync.psd1" ) ,
121
91
"ScenarioTests\\ Common.ps1" ,
122
92
"ScenarioTests\\ " + callingClassName + ".ps1" ,
123
93
"AzureRM.Resources.ps1" ) ;
@@ -142,107 +112,13 @@ public void RunPsTestWorkflow(
142
112
private void SetupManagementClients ( MockContext context )
143
113
{
144
114
ResourceManagementClient = GetResourceManagementClient ( context ) ;
145
- InternalResourceManagementClient = GetInternalResourceManagementClient ( context ) ;
146
- SubscriptionClient = GetSubscriptionClient ( context ) ;
147
- AuthorizationManagementClient = GetAuthorizationManagementClient ( context ) ;
148
- StorageClient = GetStorageManagementClient ( context ) ;
149
- StorageSyncClient = GetStorageSyncManagementClient ( context ) ;
150
- GraphRbacManagementClient = GetGraphRbacManagementClient ( context ) ;
151
-
152
- _helper . SetupManagementClients (
153
- ResourceManagementClient ,
154
- InternalResourceManagementClient ,
155
- SubscriptionClient ,
156
- AuthorizationManagementClient ,
157
- StorageClient ,
158
- StorageSyncClient ,
159
- GraphRbacManagementClient
160
- ) ;
161
- }
162
-
163
- private ResourceManagementClient GetResourceManagementClient ( MockContext context ) => context . GetServiceClient < ResourceManagementClient > ( TestEnvironment ) /*(TestEnvironmentFactory.GetTestEnvironment())*/ ;
164
115
165
- private Internal . Subscriptions . SubscriptionClient GetSubscriptionClient ( MockContext context )
166
- {
167
- return context . GetServiceClient < Internal . Subscriptions . SubscriptionClient > ( TestEnvironment ) /*(TestEnvironmentFactory.GetTestEnvironment())*/ ;
116
+ _helper . SetupManagementClients ( ResourceManagementClient ) ;
168
117
}
169
118
170
- private GraphRbacManagementClient GetGraphRbacManagementClient ( MockContext context )
171
- {
172
- var environment = TestEnvironmentFactory . GetTestEnvironment ( ) ;
173
- string tenantId = null ;
174
-
175
- if ( HttpMockServer . Mode == HttpRecorderMode . Record )
176
- {
177
- tenantId = environment . Tenant ;
178
- UserDomain = String . IsNullOrEmpty ( environment . UserName ) ? String . Empty : environment . UserName . Split ( new [ ] { "@" } , StringSplitOptions . RemoveEmptyEntries ) . Last ( ) ;
179
-
180
- HttpMockServer . Variables [ TenantIdKey ] = tenantId ;
181
- HttpMockServer . Variables [ DomainKey ] = UserDomain ;
182
- }
183
- else if ( HttpMockServer . Mode == HttpRecorderMode . Playback )
184
- {
185
- if ( HttpMockServer . Variables . ContainsKey ( TenantIdKey ) )
186
- {
187
- tenantId = HttpMockServer . Variables [ TenantIdKey ] ;
188
- }
189
- if ( HttpMockServer . Variables . ContainsKey ( DomainKey ) )
190
- {
191
- UserDomain = HttpMockServer . Variables [ DomainKey ] ;
192
- }
193
- if ( HttpMockServer . Variables . ContainsKey ( SubscriptionIdKey ) )
194
- {
195
- AzureRmProfileProvider . Instance . Profile . DefaultContext . Subscription . Id = HttpMockServer . Variables [ SubscriptionIdKey ] ;
196
- }
197
- }
198
-
199
- var client = context . GetGraphServiceClient < GraphRbacManagementClient > ( environment ) ;
200
- client . TenantID = tenantId ;
201
- if ( AzureRmProfileProvider . Instance != null &&
202
- AzureRmProfileProvider . Instance . Profile != null &&
203
- AzureRmProfileProvider . Instance . Profile . DefaultContext != null &&
204
- AzureRmProfileProvider . Instance . Profile . DefaultContext . Tenant != null )
205
- {
206
- AzureRmProfileProvider . Instance . Profile . DefaultContext . Tenant . Id = client . TenantID ;
207
- }
208
-
209
- #region Test Code starts
210
-
211
- try
212
- {
213
-
214
- var value = client . ServicePrincipals . List ( ) ;
215
- value . Count ( ) ;
216
- }
217
-
218
- catch ( Exception e )
219
- {
220
- Console . Write ( e ) ;
221
- }
222
-
223
- #endregion Test Code ends
224
-
225
- return client ;
226
- }
227
-
228
- private AuthorizationManagementClient GetAuthorizationManagementClient ( MockContext context )
229
- {
230
- return context . GetServiceClient < AuthorizationManagementClient > ( TestEnvironment ) /*(TestEnvironmentFactory.GetTestEnvironment())*/ ;
231
- }
232
-
233
- private StorageManagementClient GetStorageManagementClient ( MockContext context ) => context . GetServiceClient < StorageManagementClient > ( TestEnvironment ) /*(TestEnvironmentFactory.GetTestEnvironment())*/ ;
234
-
235
- private StorageSyncManagementClient GetStorageSyncManagementClient ( MockContext context ) => context . GetServiceClient < StorageSyncManagementClient > ( TestEnvironment ) /*(TestEnvironmentFactory.GetTestEnvironment())*/ ;
236
-
237
- private Microsoft . Azure . Management . Internal . Resources . ResourceManagementClient GetInternalResourceManagementClient ( MockContext context ) => context . GetServiceClient < Microsoft . Azure . Management . Internal . Resources . ResourceManagementClient > ( ) ;
238
-
239
- public void Dispose ( )
119
+ private static ResourceManagementClient GetResourceManagementClient ( MockContext context )
240
120
{
241
- ResourceManagementClient ? . Dispose ( ) ;
242
- InternalResourceManagementClient ? . Dispose ( ) ;
243
- SubscriptionClient ? . Dispose ( ) ;
244
- AuthorizationManagementClient ? . Dispose ( ) ;
245
- StorageSyncClient ? . Dispose ( ) ;
121
+ return context . GetServiceClient < ResourceManagementClient > ( TestEnvironmentFactory . GetTestEnvironment ( ) ) ;
246
122
}
247
123
}
248
124
}
0 commit comments