1
- //
1
+ //
2
2
// Copyright (c) Microsoft. All rights reserved.
3
- //
3
+ //
4
4
// Licensed under the Apache License, Version 2.0 (the "License");
5
5
// you may not use this file except in compliance with the License.
6
6
// You may obtain a copy of the License at
7
7
// http://www.apache.org/licenses/LICENSE-2.0
8
- //
8
+ //
9
9
// Unless required by applicable law or agreed to in writing, software
10
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22
22
using Microsoft . WindowsAzure . Commands . ScenarioTest ;
23
23
using Microsoft . WindowsAzure . Commands . Test . Utilities . Common ;
24
24
using Xunit ;
25
+ using Microsoft . Azure . Commands . TestFx ;
26
+ using Xunit . Abstractions ;
25
27
26
28
namespace Microsoft . Azure . Commands . ApiManagement . ServiceManagement . Test . ScenarioTests
27
29
{
28
30
using Microsoft . Azure . ServiceManagement . Common . Models ;
29
31
using ApiManagementClient = Management . ApiManagement . ApiManagementClient ;
30
32
31
- public class ApiManagementTests : RMTestBase
33
+ public class ApiManagementTestRunner
34
+ {
35
+ protected readonly ITestRunner TestRunner ;
36
+
37
+ protected ApiManagementTestRunner ( ITestOutputHelper output )
38
+ {
39
+ TestRunner = TestManager . CreateInstance ( output )
40
+ . WithNewPsScriptFilename ( $ "{ GetType ( ) . Name } .ps1")
41
+ . WithProjectSubfolderForTests ( "ScenarioTests" )
42
+ . WithCommonPsScripts ( new [ ]
43
+ {
44
+ @"Common.ps1"
45
+ } )
46
+ . WithNewRmModules ( helper => new [ ]
47
+ {
48
+ helper . RMProfileModule ,
49
+ helper . GetRMModulePath ( "Az.ApiManagement.psd1" )
50
+ } )
51
+ . WithManagementClients (
52
+ ApiManagementHelper . GetApiManagementClient ,
53
+ ApiManagementHelper . GetResourceManagementClient
54
+ )
55
+ . Build ( ) ;
56
+ }
57
+ }
58
+
59
+ public class ApiManagementTests : ApiManagementTestRunner
32
60
{
33
- private readonly EnvironmentSetupHelper _helper ;
34
61
public string Location { get ; set ; }
35
62
public string ResourceGroupName { get ; set ; }
36
63
public string ApiManagementServiceName { get ; set ; }
37
64
38
- public ApiManagementTests ( Xunit . Abstractions . ITestOutputHelper output )
65
+ public ApiManagementTests ( Xunit . Abstractions . ITestOutputHelper output ) : base ( output )
39
66
{
40
- _helper = new EnvironmentSetupHelper
41
- {
42
- TracingInterceptor = new XunitTracingInterceptor ( output )
43
- } ;
44
- XunitTracingInterceptor . AddToContext ( _helper . TracingInterceptor ) ;
45
-
46
67
using ( var context = MockContext . Start ( "ApiManagementTests" , "CreateApiManagementService" ) )
47
68
{
48
69
var resourceManagementClient = ApiManagementHelper . GetResourceManagementClient ( context ) ;
@@ -60,266 +81,247 @@ public ApiManagementTests(Xunit.Abstractions.ITestOutputHelper output)
60
81
}
61
82
}
62
83
84
+ public string [ ] ConvertScriptName ( params string [ ] scripts )
85
+ {
86
+ return scripts . Select ( s => s + $ " { ResourceGroupName } { ApiManagementServiceName } ") . ToArray ( ) ;
87
+ }
88
+
63
89
[ Fact ]
64
90
[ Trait ( Category . AcceptanceType , Category . CheckIn ) ]
65
91
public void ApiCrudTest ( )
66
92
{
67
- RunPowerShellTest ( "Api-CrudTest" ) ;
93
+ TestRunner . RunTestScript ( ConvertScriptName ( "Api-CrudTest" ) ) ;
68
94
}
69
95
70
96
[ Fact ]
71
97
[ Trait ( Category . AcceptanceType , Category . CheckIn ) ]
72
- public void ApiCloneCrudTest ( )
98
+ public void ApiCloneCrudTest ( )
73
99
{
74
- RunPowerShellTest ( "ApiClone-Test" ) ;
75
- }
100
+ TestRunner . RunTestScript ( ConvertScriptName ( "ApiClone-Test" ) ) ;
101
+ }
76
102
77
103
[ Fact ]
78
104
[ Trait ( Category . AcceptanceType , Category . CheckIn ) ]
79
105
public void ApiImportExportWadlTest ( )
80
106
{
81
- RunPowerShellTest ( "Api-ImportExportWadlTest" ) ;
107
+ TestRunner . RunTestScript ( ConvertScriptName ( "Api-ImportExportWadlTest" ) ) ;
82
108
}
83
109
84
110
[ Fact ]
85
111
[ Trait ( Category . AcceptanceType , Category . CheckIn ) ]
86
112
public void ApiImportExportSwaggerTest ( )
87
113
{
88
- RunPowerShellTest ( "Api-ImportExportSwaggerTest" ) ;
114
+ TestRunner . RunTestScript ( ConvertScriptName ( "Api-ImportExportSwaggerTest" ) ) ;
89
115
}
90
116
91
117
[ Fact ]
92
118
[ Trait ( Category . AcceptanceType , Category . CheckIn ) ]
93
119
public void ApiImportExportWsdlTest ( )
94
120
{
95
- RunPowerShellTest ( "Api-ImportExportWsdlTest" ) ;
121
+ TestRunner . RunTestScript ( ConvertScriptName ( "Api-ImportExportWsdlTest" ) ) ;
96
122
}
97
123
98
124
[ Fact ]
99
125
[ Trait ( Category . AcceptanceType , Category . CheckIn ) ]
100
126
public void ApiImportExportOpenApiTest ( )
101
127
{
102
- RunPowerShellTest ( "Api-ImportExportOpenApiTest" ) ;
128
+ TestRunner . RunTestScript ( ConvertScriptName ( "Api-ImportExportOpenApiTest" ) ) ;
103
129
}
104
130
105
131
[ Fact ]
106
132
[ Trait ( Category . AcceptanceType , Category . CheckIn ) ]
107
133
public void ApiImportExportOpenApiJsonTest ( )
108
134
{
109
- RunPowerShellTest ( "Api-ImportExportOpenApiJsonTest" ) ;
135
+ TestRunner . RunTestScript ( ConvertScriptName ( "Api-ImportExportOpenApiJsonTest" ) ) ;
110
136
}
111
-
137
+
112
138
[ Fact ]
113
139
[ Trait ( Category . AcceptanceType , Category . CheckIn ) ]
114
140
public void ApiSchemaCrudOnSwaggerApiTest ( )
115
141
{
116
- RunPowerShellTest ( "ApiSchema-SwaggerCRUDTest" ) ;
142
+ TestRunner . RunTestScript ( ConvertScriptName ( "ApiSchema-SwaggerCRUDTest" ) ) ;
117
143
}
118
144
119
145
[ Fact ]
120
146
[ Trait ( Category . AcceptanceType , Category . CheckIn ) ]
121
147
public void ApiSchemaCrudOnWsdlApiTest ( )
122
148
{
123
- RunPowerShellTest ( "ApiSchema-WsdlCRUDTest" ) ;
149
+ TestRunner . RunTestScript ( ConvertScriptName ( "ApiSchema-WsdlCRUDTest" ) ) ;
124
150
}
125
151
126
152
[ Fact ]
127
153
[ Trait ( Category . AcceptanceType , Category . CheckIn ) ]
128
154
public void OperationsCrudTest ( )
129
155
{
130
- RunPowerShellTest ( "Operations-CrudTest" ) ;
156
+ TestRunner . RunTestScript ( ConvertScriptName ( "Operations-CrudTest" ) ) ;
131
157
}
132
158
133
159
[ Fact ]
134
160
[ Trait ( Category . AcceptanceType , Category . CheckIn ) ]
135
161
public void ProductCrudTest ( )
136
162
{
137
- RunPowerShellTest ( "Product-CrudTest" ) ;
163
+ TestRunner . RunTestScript ( ConvertScriptName ( "Product-CrudTest" ) ) ;
138
164
}
139
165
140
166
[ Fact ]
141
167
[ Trait ( Category . AcceptanceType , Category . CheckIn ) ]
142
168
public void SubscriptionOldModelCrudTest ( )
143
169
{
144
- RunPowerShellTest ( "SubscriptionOldModel-CrudTest" ) ;
170
+ TestRunner . RunTestScript ( ConvertScriptName ( "SubscriptionOldModel-CrudTest" ) ) ;
145
171
}
146
172
147
173
[ Fact ]
148
174
[ Trait ( Category . AcceptanceType , Category . CheckIn ) ]
149
175
public void SubscriptionNewModelCrudTest ( )
150
176
{
151
- RunPowerShellTest ( "SubscriptionNewModel-CrudTest" ) ;
177
+ TestRunner . RunTestScript ( ConvertScriptName ( "SubscriptionNewModel-CrudTest" ) ) ;
152
178
}
153
179
154
180
[ Fact ]
155
181
[ Trait ( Category . AcceptanceType , Category . CheckIn ) ]
156
182
public void UserCrudTest ( )
157
183
{
158
- RunPowerShellTest ( "User-CrudTest" ) ;
184
+ TestRunner . RunTestScript ( ConvertScriptName ( "User-CrudTest" ) ) ;
159
185
}
160
186
161
187
[ Fact ]
162
188
[ Trait ( Category . AcceptanceType , Category . CheckIn ) ]
163
189
public void GroupCrudTest ( )
164
190
{
165
- RunPowerShellTest ( "Group-CrudTest" ) ;
191
+ TestRunner . RunTestScript ( ConvertScriptName ( "Group-CrudTest" ) ) ;
166
192
}
167
193
168
194
[ Fact ]
169
195
[ Trait ( Category . AcceptanceType , Category . CheckIn ) ]
170
196
public void PolicyCrudTest ( )
171
197
{
172
- RunPowerShellTest ( "Policy-CrudTest" ) ;
198
+ TestRunner . RunTestScript ( ConvertScriptName ( "Policy-CrudTest" ) ) ;
173
199
}
174
200
175
201
[ Fact ]
176
202
[ Trait ( Category . AcceptanceType , Category . CheckIn ) ]
177
203
public void CertificateCrudTest ( )
178
204
{
179
- RunPowerShellTest ( "Certificate-CrudTest" ) ;
205
+ TestRunner . RunTestScript ( ConvertScriptName ( "Certificate-CrudTest" ) ) ;
180
206
}
181
207
182
208
[ Fact ]
183
209
[ Trait ( Category . AcceptanceType , Category . CheckIn ) ]
184
210
public void AuthorizationServerCrudTest ( )
185
211
{
186
- RunPowerShellTest ( "AuthorizationServer-CrudTest" ) ;
212
+ TestRunner . RunTestScript ( ConvertScriptName ( "AuthorizationServer-CrudTest" ) ) ;
187
213
}
188
214
189
215
[ Fact ]
190
216
[ Trait ( Category . AcceptanceType , Category . CheckIn ) ]
191
217
public void LoggerCrudTest ( )
192
218
{
193
- RunPowerShellTest ( "Logger-CrudTest" ) ;
219
+ TestRunner . RunTestScript ( ConvertScriptName ( "Logger-CrudTest" ) ) ;
194
220
}
195
221
196
222
[ Fact ]
197
223
[ Trait ( Category . AcceptanceType , Category . CheckIn ) ]
198
224
public void GatewayCrudTest ( )
199
225
{
200
- RunPowerShellTest ( "Gateway-CrudTest" ) ;
226
+ TestRunner . RunTestScript ( ConvertScriptName ( "Gateway-CrudTest" ) ) ;
201
227
}
202
228
203
229
[ Fact ]
204
230
[ Trait ( Category . AcceptanceType , Category . CheckIn ) ]
205
231
public void PropertiesCrudTest ( )
206
232
{
207
- RunPowerShellTest ( "Properties-CrudTest" ) ;
233
+ TestRunner . RunTestScript ( ConvertScriptName ( "Properties-CrudTest" ) ) ;
208
234
}
209
235
210
236
[ Fact ]
211
237
[ Trait ( Category . AcceptanceType , Category . CheckIn ) ]
212
238
public void OpenIdConnectProviderCrudTest ( )
213
239
{
214
- RunPowerShellTest ( "OpenIdConnectProvider-CrudTest" ) ;
240
+ TestRunner . RunTestScript ( ConvertScriptName ( "OpenIdConnectProvider-CrudTest" ) ) ;
215
241
}
216
242
217
243
[ Fact ]
218
244
[ Trait ( Category . AcceptanceType , Category . CheckIn ) ]
219
245
public void IdentityProviderAadB2CCrudTest ( )
220
246
{
221
- RunPowerShellTest ( "IdentityProvider-AadB2C-CrudTest" ) ;
247
+ TestRunner . RunTestScript ( ConvertScriptName ( "IdentityProvider-AadB2C-CrudTest" ) ) ;
222
248
}
223
249
224
250
[ Fact ]
225
251
[ Trait ( Category . AcceptanceType , Category . CheckIn ) ]
226
252
public void IdentityProviderCrudTest ( )
227
253
{
228
- RunPowerShellTest ( "IdentityProvider-CrudTest" ) ;
254
+ TestRunner . RunTestScript ( ConvertScriptName ( "IdentityProvider-CrudTest" ) ) ;
229
255
}
230
256
231
257
[ Fact ]
232
258
[ Trait ( Category . AcceptanceType , Category . CheckIn ) ]
233
259
public void TenantGitConfCrudTest ( )
234
260
{
235
- RunPowerShellTest ( "TenantGitConfiguration-CrudTest" ) ;
261
+ TestRunner . RunTestScript ( ConvertScriptName ( "TenantGitConfiguration-CrudTest" ) ) ;
236
262
}
237
263
238
264
[ Fact ]
239
265
[ Trait ( Category . AcceptanceType , Category . CheckIn ) ]
240
266
public void TenantAccessConfCrudTest ( )
241
267
{
242
- RunPowerShellTest ( "TenantAccessConfiguration-CrudTest" ) ;
268
+ TestRunner . RunTestScript ( ConvertScriptName ( "TenantAccessConfiguration-CrudTest" ) ) ;
243
269
}
244
270
245
271
[ Fact ]
246
272
[ Trait ( Category . AcceptanceType , Category . CheckIn ) ]
247
273
public void BackendCrudTest ( )
248
274
{
249
- RunPowerShellTest ( "Backend-CrudTest" ) ;
275
+ TestRunner . RunTestScript ( ConvertScriptName ( "Backend-CrudTest" ) ) ;
250
276
}
251
277
252
278
[ Fact ]
253
279
[ Trait ( Category . AcceptanceType , Category . CheckIn ) ]
254
280
public void BackendServiceFabricCrudTest ( )
255
281
{
256
- RunPowerShellTest ( "BackendServiceFabric-CrudTest" ) ;
282
+ TestRunner . RunTestScript ( ConvertScriptName ( "BackendServiceFabric-CrudTest" ) ) ;
257
283
}
258
284
259
285
[ Fact ]
260
286
[ Trait ( Category . AcceptanceType , Category . CheckIn ) ]
261
287
public void ApiVersionSetImportCrudTest ( )
262
288
{
263
- RunPowerShellTest ( "ApiVersionSet-ImportCrudTest" ) ;
289
+ TestRunner . RunTestScript ( ConvertScriptName ( "ApiVersionSet-ImportCrudTest" ) ) ;
264
290
}
265
291
266
292
[ Fact ]
267
293
[ Trait ( Category . AcceptanceType , Category . CheckIn ) ]
268
294
public void ApiVersionSetCrudTest ( )
269
295
{
270
- RunPowerShellTest ( "ApiVersionSet-SetCrudTest" ) ;
296
+ TestRunner . RunTestScript ( ConvertScriptName ( "ApiVersionSet-SetCrudTest" ) ) ;
271
297
}
272
298
273
299
[ Fact ]
274
300
[ Trait ( Category . AcceptanceType , Category . CheckIn ) ]
275
301
public void ApiRevisionCrudTest ( )
276
302
{
277
- RunPowerShellTest ( "ApiRevision-CrudTest" ) ;
303
+ TestRunner . RunTestScript ( ConvertScriptName ( "ApiRevision-CrudTest" ) ) ;
278
304
}
279
305
280
306
[ Fact ]
281
307
[ Trait ( Category . AcceptanceType , Category . CheckIn ) ]
282
308
public void CacheCrudTest ( )
283
309
{
284
- RunPowerShellTest ( "Cache-CrudTest" ) ;
310
+ TestRunner . RunTestScript ( ConvertScriptName ( "Cache-CrudTest" ) ) ;
285
311
}
286
312
287
313
[ Fact ]
288
314
[ Trait ( Category . AcceptanceType , Category . CheckIn ) ]
289
315
public void DiagnosticCrudTest ( )
290
316
{
291
- RunPowerShellTest ( "Diagnostic-CrudTest" ) ;
317
+ TestRunner . RunTestScript ( ConvertScriptName ( "Diagnostic-CrudTest" ) ) ;
292
318
}
293
319
294
320
[ Fact ]
295
321
[ Trait ( Category . AcceptanceType , Category . CheckIn ) ]
296
322
public void ApiDiagnosticCrudTest ( )
297
323
{
298
- RunPowerShellTest ( "ApiDiagnostic-CrudTest" ) ;
299
- }
300
-
301
- private void RunPowerShellTest ( params string [ ] scripts )
302
- {
303
- var sf = new StackTrace ( ) . GetFrame ( 1 ) ;
304
- var callingClassType = sf . GetMethod ( ) . ReflectedType ? . ToString ( ) ;
305
- var mockName = sf . GetMethod ( ) . Name ;
306
-
307
- HttpMockServer . RecordsDirectory = Path . Combine ( AppDomain . CurrentDomain . BaseDirectory , "SessionRecords" ) ;
308
-
309
- using ( var context = MockContext . Start ( callingClassType , mockName ) )
310
- {
311
- _helper . SetupSomeOfManagementClients ( context . GetServiceClient < ApiManagementClient > ( TestEnvironmentFactory . GetTestEnvironment ( ) ) ) ;
312
-
313
- _helper . SetupEnvironment ( AzureModule . AzureResourceManager ) ;
314
- _helper . SetupModules ( AzureModule . AzureResourceManager ,
315
- "ScenarioTests\\ Common.ps1" ,
316
- "ScenarioTests\\ " + GetType ( ) . Name + ".ps1" ,
317
- _helper . RMProfileModule ,
318
- _helper . GetRMModulePath ( @"AzureRM.ApiManagement.psd1" ) ) ;
319
-
320
- scripts = scripts . Select ( s => s + $ " { ResourceGroupName } { ApiManagementServiceName } ") . ToArray ( ) ;
321
- _helper . RunPowerShellTest ( scripts ) ;
322
- }
324
+ TestRunner . RunTestScript ( ConvertScriptName ( "ApiDiagnostic-CrudTest" ) ) ;
323
325
}
324
326
}
325
327
}
0 commit comments