1- //    
1+ // 
22// Copyright (c) Microsoft.  All rights reserved. 
3- //   
3+ // 
44//  Licensed under the Apache License, Version 2.0 (the "License"); 
55//  you may not use this file except in compliance with the License. 
66//  You may obtain a copy of the License at 
77//    http://www.apache.org/licenses/LICENSE-2.0 
8- //   
8+ // 
99//  Unless required by applicable law or agreed to in writing, software 
1010//  distributed under the License is distributed on an "AS IS" BASIS, 
1111//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
2222using  Microsoft . WindowsAzure . Commands . ScenarioTest ; 
2323using  Microsoft . WindowsAzure . Commands . Test . Utilities . Common ; 
2424using  Xunit ; 
25+ using  Microsoft . Azure . Commands . TestFx ; 
26+ using  Xunit . Abstractions ; 
2527
2628namespace  Microsoft . Azure . Commands . ApiManagement . ServiceManagement . Test . ScenarioTests 
2729{ 
2830    using  Microsoft . Azure . ServiceManagement . Common . Models ; 
2931    using  ApiManagementClient  =  Management . ApiManagement . ApiManagementClient ; 
3032
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 
3260    { 
33-         private  readonly  EnvironmentSetupHelper  _helper ; 
3461        public  string  Location  {  get ;  set ;  } 
3562        public  string  ResourceGroupName  {  get ;  set ;  } 
3663        public  string  ApiManagementServiceName  {  get ;  set ;  } 
3764
38-         public  ApiManagementTests ( Xunit . Abstractions . ITestOutputHelper  output ) 
65+         public  ApiManagementTests ( Xunit . Abstractions . ITestOutputHelper  output )   :   base ( output ) 
3966        { 
40-             _helper  =  new  EnvironmentSetupHelper 
41-             { 
42-                 TracingInterceptor  =  new  XunitTracingInterceptor ( output ) 
43-             } ; 
44-             XunitTracingInterceptor . AddToContext ( _helper . TracingInterceptor ) ; 
45- 
4667            using  ( var  context  =  MockContext . Start ( "ApiManagementTests" ,  "CreateApiManagementService" ) ) 
4768            { 
4869                var  resourceManagementClient  =  ApiManagementHelper . GetResourceManagementClient ( context ) ; 
@@ -60,266 +81,247 @@ public ApiManagementTests(Xunit.Abstractions.ITestOutputHelper output)
6081            } 
6182        } 
6283
84+         public  string [ ]  ConvertScriptName ( params  string [ ]  scripts ) 
85+         { 
86+             return  scripts . Select ( s =>  s  +  $ " { ResourceGroupName }  { ApiManagementServiceName } ") . ToArray ( ) ; 
87+         } 
88+ 
6389        [ Fact ] 
6490        [ Trait ( Category . AcceptanceType ,  Category . CheckIn ) ] 
6591        public  void  ApiCrudTest ( ) 
6692        { 
67-             RunPowerShellTest ( "Api-CrudTest" ) ; 
93+             TestRunner . RunTestScript ( ConvertScriptName ( "Api-CrudTest" ) ) ; 
6894        } 
6995
7096        [ Fact ] 
7197        [ Trait ( Category . AcceptanceType ,  Category . CheckIn ) ] 
72-           public  void  ApiCloneCrudTest ( ) 
98+         public  void  ApiCloneCrudTest ( ) 
7399        { 
74-             RunPowerShellTest ( "ApiClone-Test" ) ; 
75-         }          
100+             TestRunner . RunTestScript ( ConvertScriptName ( "ApiClone-Test" ) ) ; 
101+         } 
76102
77103        [ Fact ] 
78104        [ Trait ( Category . AcceptanceType ,  Category . CheckIn ) ] 
79105        public  void  ApiImportExportWadlTest ( ) 
80106        { 
81-             RunPowerShellTest ( "Api-ImportExportWadlTest" ) ; 
107+             TestRunner . RunTestScript ( ConvertScriptName ( "Api-ImportExportWadlTest" ) ) ; 
82108        } 
83109
84110        [ Fact ] 
85111        [ Trait ( Category . AcceptanceType ,  Category . CheckIn ) ] 
86112        public  void  ApiImportExportSwaggerTest ( ) 
87113        { 
88-             RunPowerShellTest ( "Api-ImportExportSwaggerTest" ) ; 
114+             TestRunner . RunTestScript ( ConvertScriptName ( "Api-ImportExportSwaggerTest" ) ) ; 
89115        } 
90116
91117        [ Fact ] 
92118        [ Trait ( Category . AcceptanceType ,  Category . CheckIn ) ] 
93119        public  void  ApiImportExportWsdlTest ( ) 
94120        { 
95-             RunPowerShellTest ( "Api-ImportExportWsdlTest" ) ; 
121+             TestRunner . RunTestScript ( ConvertScriptName ( "Api-ImportExportWsdlTest" ) ) ; 
96122        } 
97123
98124        [ Fact ] 
99125        [ Trait ( Category . AcceptanceType ,  Category . CheckIn ) ] 
100126        public  void  ApiImportExportOpenApiTest ( ) 
101127        { 
102-             RunPowerShellTest ( "Api-ImportExportOpenApiTest" ) ; 
128+             TestRunner . RunTestScript ( ConvertScriptName ( "Api-ImportExportOpenApiTest" ) ) ; 
103129        } 
104130
105131        [ Fact ] 
106132        [ Trait ( Category . AcceptanceType ,  Category . CheckIn ) ] 
107133        public  void  ApiImportExportOpenApiJsonTest ( ) 
108134        { 
109-             RunPowerShellTest ( "Api-ImportExportOpenApiJsonTest" ) ; 
135+             TestRunner . RunTestScript ( ConvertScriptName ( "Api-ImportExportOpenApiJsonTest" ) ) ; 
110136        } 
111-          
137+ 
112138        [ Fact ] 
113139        [ Trait ( Category . AcceptanceType ,  Category . CheckIn ) ] 
114140        public  void  ApiSchemaCrudOnSwaggerApiTest ( ) 
115141        { 
116-             RunPowerShellTest ( "ApiSchema-SwaggerCRUDTest" ) ; 
142+             TestRunner . RunTestScript ( ConvertScriptName ( "ApiSchema-SwaggerCRUDTest" ) ) ; 
117143        } 
118144
119145        [ Fact ] 
120146        [ Trait ( Category . AcceptanceType ,  Category . CheckIn ) ] 
121147        public  void  ApiSchemaCrudOnWsdlApiTest ( ) 
122148        { 
123-             RunPowerShellTest ( "ApiSchema-WsdlCRUDTest" ) ; 
149+             TestRunner . RunTestScript ( ConvertScriptName ( "ApiSchema-WsdlCRUDTest" ) ) ; 
124150        } 
125151
126152        [ Fact ] 
127153        [ Trait ( Category . AcceptanceType ,  Category . CheckIn ) ] 
128154        public  void  OperationsCrudTest ( ) 
129155        { 
130-             RunPowerShellTest ( "Operations-CrudTest" ) ; 
156+             TestRunner . RunTestScript ( ConvertScriptName ( "Operations-CrudTest" ) ) ; 
131157        } 
132158
133159        [ Fact ] 
134160        [ Trait ( Category . AcceptanceType ,  Category . CheckIn ) ] 
135161        public  void  ProductCrudTest ( ) 
136162        { 
137-             RunPowerShellTest ( "Product-CrudTest" ) ; 
163+             TestRunner . RunTestScript ( ConvertScriptName ( "Product-CrudTest" ) ) ; 
138164        } 
139165
140166        [ Fact ] 
141167        [ Trait ( Category . AcceptanceType ,  Category . CheckIn ) ] 
142168        public  void  SubscriptionOldModelCrudTest ( ) 
143169        { 
144-             RunPowerShellTest ( "SubscriptionOldModel-CrudTest" ) ; 
170+             TestRunner . RunTestScript ( ConvertScriptName ( "SubscriptionOldModel-CrudTest" ) ) ; 
145171        } 
146172
147173        [ Fact ] 
148174        [ Trait ( Category . AcceptanceType ,  Category . CheckIn ) ] 
149175        public  void  SubscriptionNewModelCrudTest ( ) 
150176        { 
151-             RunPowerShellTest ( "SubscriptionNewModel-CrudTest" ) ; 
177+             TestRunner . RunTestScript ( ConvertScriptName ( "SubscriptionNewModel-CrudTest" ) ) ; 
152178        } 
153179
154180        [ Fact ] 
155181        [ Trait ( Category . AcceptanceType ,  Category . CheckIn ) ] 
156182        public  void  UserCrudTest ( ) 
157183        { 
158-             RunPowerShellTest ( "User-CrudTest" ) ; 
184+             TestRunner . RunTestScript ( ConvertScriptName ( "User-CrudTest" ) ) ; 
159185        } 
160186
161187        [ Fact ] 
162188        [ Trait ( Category . AcceptanceType ,  Category . CheckIn ) ] 
163189        public  void  GroupCrudTest ( ) 
164190        { 
165-             RunPowerShellTest ( "Group-CrudTest" ) ; 
191+             TestRunner . RunTestScript ( ConvertScriptName ( "Group-CrudTest" ) ) ; 
166192        } 
167193
168194        [ Fact ] 
169195        [ Trait ( Category . AcceptanceType ,  Category . CheckIn ) ] 
170196        public  void  PolicyCrudTest ( ) 
171197        { 
172-             RunPowerShellTest ( "Policy-CrudTest" ) ; 
198+             TestRunner . RunTestScript ( ConvertScriptName ( "Policy-CrudTest" ) ) ; 
173199        } 
174200
175201        [ Fact ] 
176202        [ Trait ( Category . AcceptanceType ,  Category . CheckIn ) ] 
177203        public  void  CertificateCrudTest ( ) 
178204        { 
179-             RunPowerShellTest ( "Certificate-CrudTest" ) ; 
205+             TestRunner . RunTestScript ( ConvertScriptName ( "Certificate-CrudTest" ) ) ; 
180206        } 
181207
182208        [ Fact ] 
183209        [ Trait ( Category . AcceptanceType ,  Category . CheckIn ) ] 
184210        public  void  AuthorizationServerCrudTest ( ) 
185211        { 
186-             RunPowerShellTest ( "AuthorizationServer-CrudTest" ) ; 
212+             TestRunner . RunTestScript ( ConvertScriptName ( "AuthorizationServer-CrudTest" ) ) ; 
187213        } 
188214
189215        [ Fact ] 
190216        [ Trait ( Category . AcceptanceType ,  Category . CheckIn ) ] 
191217        public  void  LoggerCrudTest ( ) 
192218        { 
193-             RunPowerShellTest ( "Logger-CrudTest" ) ; 
219+             TestRunner . RunTestScript ( ConvertScriptName ( "Logger-CrudTest" ) ) ; 
194220        } 
195221
196222        [ Fact ] 
197223        [ Trait ( Category . AcceptanceType ,  Category . CheckIn ) ] 
198224        public  void  GatewayCrudTest ( ) 
199225        { 
200-             RunPowerShellTest ( "Gateway-CrudTest" ) ; 
226+             TestRunner . RunTestScript ( ConvertScriptName ( "Gateway-CrudTest" ) ) ; 
201227        } 
202228
203229        [ Fact ] 
204230        [ Trait ( Category . AcceptanceType ,  Category . CheckIn ) ] 
205231        public  void  PropertiesCrudTest ( ) 
206232        { 
207-             RunPowerShellTest ( "Properties-CrudTest" ) ; 
233+             TestRunner . RunTestScript ( ConvertScriptName ( "Properties-CrudTest" ) ) ; 
208234        } 
209235
210236        [ Fact ] 
211237        [ Trait ( Category . AcceptanceType ,  Category . CheckIn ) ] 
212238        public  void  OpenIdConnectProviderCrudTest ( ) 
213239        { 
214-             RunPowerShellTest ( "OpenIdConnectProvider-CrudTest" ) ; 
240+             TestRunner . RunTestScript ( ConvertScriptName ( "OpenIdConnectProvider-CrudTest" ) ) ; 
215241        } 
216242
217243        [ Fact ] 
218244        [ Trait ( Category . AcceptanceType ,  Category . CheckIn ) ] 
219245        public  void  IdentityProviderAadB2CCrudTest ( ) 
220246        { 
221-             RunPowerShellTest ( "IdentityProvider-AadB2C-CrudTest" ) ; 
247+             TestRunner . RunTestScript ( ConvertScriptName ( "IdentityProvider-AadB2C-CrudTest" ) ) ; 
222248        } 
223249
224250        [ Fact ] 
225251        [ Trait ( Category . AcceptanceType ,  Category . CheckIn ) ] 
226252        public  void  IdentityProviderCrudTest ( ) 
227253        { 
228-             RunPowerShellTest ( "IdentityProvider-CrudTest" ) ; 
254+             TestRunner . RunTestScript ( ConvertScriptName ( "IdentityProvider-CrudTest" ) ) ; 
229255        } 
230256
231257        [ Fact ] 
232258        [ Trait ( Category . AcceptanceType ,  Category . CheckIn ) ] 
233259        public  void  TenantGitConfCrudTest ( ) 
234260        { 
235-             RunPowerShellTest ( "TenantGitConfiguration-CrudTest" ) ; 
261+             TestRunner . RunTestScript ( ConvertScriptName ( "TenantGitConfiguration-CrudTest" ) ) ; 
236262        } 
237263
238264        [ Fact ] 
239265        [ Trait ( Category . AcceptanceType ,  Category . CheckIn ) ] 
240266        public  void  TenantAccessConfCrudTest ( ) 
241267        { 
242-             RunPowerShellTest ( "TenantAccessConfiguration-CrudTest" ) ; 
268+             TestRunner . RunTestScript ( ConvertScriptName ( "TenantAccessConfiguration-CrudTest" ) ) ; 
243269        } 
244270
245271        [ Fact ] 
246272        [ Trait ( Category . AcceptanceType ,  Category . CheckIn ) ] 
247273        public  void  BackendCrudTest ( ) 
248274        { 
249-             RunPowerShellTest ( "Backend-CrudTest" ) ; 
275+             TestRunner . RunTestScript ( ConvertScriptName ( "Backend-CrudTest" ) ) ; 
250276        } 
251277
252278        [ Fact ] 
253279        [ Trait ( Category . AcceptanceType ,  Category . CheckIn ) ] 
254280        public  void  BackendServiceFabricCrudTest ( ) 
255281        { 
256-             RunPowerShellTest ( "BackendServiceFabric-CrudTest" ) ; 
282+             TestRunner . RunTestScript ( ConvertScriptName ( "BackendServiceFabric-CrudTest" ) ) ; 
257283        } 
258284
259285        [ Fact ] 
260286        [ Trait ( Category . AcceptanceType ,  Category . CheckIn ) ] 
261287        public  void  ApiVersionSetImportCrudTest ( ) 
262288        { 
263-             RunPowerShellTest ( "ApiVersionSet-ImportCrudTest" ) ; 
289+             TestRunner . RunTestScript ( ConvertScriptName ( "ApiVersionSet-ImportCrudTest" ) ) ; 
264290        } 
265291
266292        [ Fact ] 
267293        [ Trait ( Category . AcceptanceType ,  Category . CheckIn ) ] 
268294        public  void  ApiVersionSetCrudTest ( ) 
269295        { 
270-             RunPowerShellTest ( "ApiVersionSet-SetCrudTest" ) ; 
296+             TestRunner . RunTestScript ( ConvertScriptName ( "ApiVersionSet-SetCrudTest" ) ) ; 
271297        } 
272298
273299        [ Fact ] 
274300        [ Trait ( Category . AcceptanceType ,  Category . CheckIn ) ] 
275301        public  void  ApiRevisionCrudTest ( ) 
276302        { 
277-             RunPowerShellTest ( "ApiRevision-CrudTest" ) ; 
303+             TestRunner . RunTestScript ( ConvertScriptName ( "ApiRevision-CrudTest" ) ) ; 
278304        } 
279305
280306        [ Fact ] 
281307        [ Trait ( Category . AcceptanceType ,  Category . CheckIn ) ] 
282308        public  void  CacheCrudTest ( ) 
283309        { 
284-             RunPowerShellTest ( "Cache-CrudTest" ) ; 
310+             TestRunner . RunTestScript ( ConvertScriptName ( "Cache-CrudTest" ) ) ; 
285311        } 
286312
287313        [ Fact ] 
288314        [ Trait ( Category . AcceptanceType ,  Category . CheckIn ) ] 
289315        public  void  DiagnosticCrudTest ( ) 
290316        { 
291-             RunPowerShellTest ( "Diagnostic-CrudTest" ) ; 
317+             TestRunner . RunTestScript ( ConvertScriptName ( "Diagnostic-CrudTest" ) ) ; 
292318        } 
293319
294320        [ Fact ] 
295321        [ Trait ( Category . AcceptanceType ,  Category . CheckIn ) ] 
296322        public  void  ApiDiagnosticCrudTest ( ) 
297323        { 
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" ) ) ; 
323325        } 
324326    } 
325327} 
0 commit comments