12
12
// limitations under the License.
13
13
// ----------------------------------------------------------------------------------
14
14
15
- using Microsoft . Azure . Commands . Common . Authentication ;
15
+ using System ;
16
+ using System . Collections . Generic ;
17
+ using System . Linq ;
16
18
using Microsoft . Azure . Gallery ;
17
19
using Microsoft . Azure . Management . Authorization ;
18
- using Microsoft . Azure . Management . Compute ;
19
- using Microsoft . Azure . Management . Insights ;
20
20
using Microsoft . Azure . Management . Network ;
21
- using Microsoft . Azure . Management . Redis ;
22
21
using Microsoft . Azure . Management . Resources ;
23
- using Microsoft . Azure . Management . Storage ;
24
22
using Microsoft . Azure . Subscriptions ;
23
+ using Microsoft . WindowsAzure . Commands . ScenarioTest ;
25
24
using Microsoft . Azure . Test ;
25
+ using Microsoft . Azure . Commands . Common . Authentication ;
26
26
using Microsoft . Azure . Test . HttpRecorder ;
27
- using Microsoft . WindowsAzure . Commands . ScenarioTest ;
28
- using System ;
29
- using System . Collections . Generic ;
30
- using System . IO ;
31
- using System . Linq ;
32
27
using RestTestFramework = Microsoft . Rest . ClientRuntime . Azure . TestFramework ;
33
28
34
29
namespace Commands . Network . Test
@@ -37,7 +32,7 @@ public sealed class NetworkResourcesController
37
32
{
38
33
private CSMTestEnvironmentFactory csmTestFactory ;
39
34
private EnvironmentSetupHelper helper ;
40
-
35
+
41
36
public ResourceManagementClient ResourceManagementClient { get ; private set ; }
42
37
43
38
public SubscriptionClient SubscriptionClient { get ; private set ; }
@@ -48,16 +43,11 @@ public sealed class NetworkResourcesController
48
43
49
44
public NetworkManagementClient NetworkManagementClient { get ; private set ; }
50
45
51
- public ComputeManagementClient ComputeManagementClient { get ; private set ; }
46
+ public Microsoft . Azure . Management . Internal . Resources . ResourceManagementClient InternalResourceManagementClient { get ; private set ; }
47
+ public Microsoft . Azure . Management . ResourceManager . ResourceManagementClient LegacyResourceManagementClient { get ; private set ; }
52
48
53
- public StorageManagementClient StorageManagementClient { get ; private set ; }
54
-
55
- public InsightsManagementClient InsightsManagementClient { get ; private set ; }
56
-
57
- public RedisManagementClient RedisManagementClient { get ; private set ; }
58
-
59
- public static NetworkResourcesController NewInstance
60
- {
49
+ public static NetworkResourcesController NewInstance
50
+ {
61
51
get
62
52
{
63
53
return new NetworkResourcesController ( ) ;
@@ -71,64 +61,60 @@ public NetworkResourcesController()
71
61
72
62
public void RunPsTest ( params string [ ] scripts )
73
63
{
74
- Dictionary < string , string > d = new Dictionary < string , string > ( ) ;
75
- d . Add ( "Microsoft.Resources" , null ) ;
76
- d . Add ( "Microsoft.Features" , null ) ;
77
- d . Add ( "Microsoft.Authorization" , null ) ;
78
- d . Add ( "Microsoft.Storage" , null ) ;
79
- var providersToIgnore = new Dictionary < string , string > ( ) ;
80
- providersToIgnore . Add ( "Microsoft.Azure.Management.Resources.ResourceManagementClient" , "2016-02-01" ) ;
81
- HttpMockServer . Matcher = new PermissiveRecordMatcherWithApiExclusion ( true , d , providersToIgnore ) ;
82
-
83
64
var callingClassType = TestUtilities . GetCallingClass ( 2 ) ;
84
65
var mockName = TestUtilities . GetCurrentMethodName ( 2 ) ;
85
66
86
67
RunPsTestWorkflow (
87
- ( ) => scripts ,
68
+ ( ) => scripts ,
88
69
// no custom initializer
89
- null ,
70
+ null ,
90
71
// no custom cleanup
91
72
null ,
92
73
callingClassType ,
93
74
mockName ) ;
94
75
}
95
76
96
77
public void RunPsTestWorkflow (
97
- Func < string [ ] > scriptBuilder ,
98
- Action < CSMTestEnvironmentFactory > initialize ,
78
+ Func < string [ ] > scriptBuilder ,
79
+ Action < CSMTestEnvironmentFactory > initialize ,
99
80
Action cleanup ,
100
81
string callingClassType ,
101
82
string mockName )
102
83
{
103
- HttpMockServer . RecordsDirectory = Path . Combine ( AppDomain . CurrentDomain . BaseDirectory , "SessionRecords" ) ;
84
+ Dictionary < string , string > d = new Dictionary < string , string > ( ) ;
85
+ d . Add ( "Microsoft.Resources" , null ) ;
86
+ d . Add ( "Microsoft.Features" , null ) ;
87
+ d . Add ( "Microsoft.Authorization" , null ) ;
88
+ d . Add ( "Microsoft.Compute" , null ) ;
89
+ var providersToIgnore = new Dictionary < string , string > ( ) ;
90
+ providersToIgnore . Add ( "Microsoft.Azure.Management.Resources.ResourceManagementClient" , "2016-02-01" ) ;
91
+ providersToIgnore . Add ( "Microsoft.Azure.Management.ResourceManager.ResourceManagementClient" , "2016-02-01" ) ;
92
+ providersToIgnore . Add ( "Microsoft.Azure.Management.Storage.StorageManagementClient" , "2015-06-15" ) ;
93
+
94
+ HttpMockServer . Matcher = new PermissiveRecordMatcherWithApiExclusion ( true , d , providersToIgnore ) ;
95
+
104
96
using ( RestTestFramework . MockContext context = RestTestFramework . MockContext . Start ( callingClassType , mockName ) )
105
97
{
106
98
this . csmTestFactory = new CSMTestEnvironmentFactory ( ) ;
107
99
108
- if ( initialize != null )
100
+ if ( initialize != null )
109
101
{
110
102
initialize ( this . csmTestFactory ) ;
111
103
}
112
104
113
105
SetupManagementClients ( context ) ;
114
106
115
107
helper . SetupEnvironment ( AzureModule . AzureResourceManager ) ;
116
-
108
+
117
109
var callingClassName = callingClassType
118
110
. Split ( new [ ] { "." } , StringSplitOptions . RemoveEmptyEntries )
119
111
. Last ( ) ;
120
- helper . SetupModules ( AzureModule . AzureResourceManager ,
121
- "ScenarioTests\\ Common.ps1" ,
122
- "ScenarioTests\\ " + callingClassName + ".ps1" ,
123
- helper . RMProfileModule ,
124
- helper . RMResourceModule ,
125
- helper . GetRMModulePath ( "AzureRM.Insights.psd1" ) ,
126
- helper . GetRMModulePath ( "AzureRM.RedisCache.psd1" ) ,
127
- helper . GetRMModulePath ( "AzureRM.Network.psd1" ) ,
128
- helper . GetRMModulePath ( "AzureRM.Compute.psd1" ) ,
129
- helper . RMStorageDataPlaneModule ,
130
- "AzureRM.Storage.ps1" ,
131
- "AzureRM.Resources.ps1" ) ;
112
+ helper . SetupModules ( AzureModule . AzureResourceManager ,
113
+ "ScenarioTests\\ Common.ps1" ,
114
+ "ScenarioTests\\ " + callingClassName + ".ps1" ,
115
+ helper . StackRMProfileModule ,
116
+ helper . StackRMResourceModule ,
117
+ helper . GetStackRMModulePath ( "AzureRM.Network.psd1" ) ) ;
132
118
133
119
try
134
120
{
@@ -144,53 +130,32 @@ public void RunPsTestWorkflow(
144
130
}
145
131
finally
146
132
{
147
- if ( cleanup != null )
133
+ if ( cleanup != null )
148
134
{
149
135
cleanup ( ) ;
150
136
}
151
137
}
152
138
}
153
139
}
154
140
155
- private Microsoft . Azure . Management . Resources . ResourceManagementClient GetLegacyResourceManagementClient ( )
156
- {
157
- return Microsoft . Azure . Test . TestBase . GetServiceClient < Microsoft . Azure . Management . Resources . ResourceManagementClient > ( this . csmTestFactory ) ;
158
- }
159
-
160
- private Microsoft . Azure . Subscriptions . SubscriptionClient GetLegacySubscriptionClient ( )
161
- {
162
- return Microsoft . Azure . Test . TestBase . GetServiceClient < Microsoft . Azure . Subscriptions . SubscriptionClient > ( this . csmTestFactory ) ;
163
- }
164
-
165
- private Microsoft . Azure . Management . ResourceManager . ResourceManagementClient GetResourceManagerResourceManagementClient ( RestTestFramework . MockContext context )
166
- {
167
- return context . GetServiceClient < Microsoft . Azure . Management . ResourceManager . ResourceManagementClient > ( RestTestFramework . TestEnvironmentFactory . GetTestEnvironment ( ) ) ;
168
- }
169
-
170
141
private void SetupManagementClients ( RestTestFramework . MockContext context )
171
142
{
172
- Microsoft . Azure . Management . ResourceManager . ResourceManagementClient ResourceManagerResourceManagementClient = GetResourceManagerResourceManagementClient ( context ) ;
173
143
this . ResourceManagementClient = this . GetResourceManagementClient ( ) ;
174
144
this . SubscriptionClient = this . GetSubscriptionClient ( ) ;
145
+ InternalResourceManagementClient = GetInternalResourceManagementClient ( context ) ;
146
+ LegacyResourceManagementClient = GetLegacyResourceManagementClient ( context ) ;
175
147
this . GalleryClient = this . GetGalleryClient ( ) ;
176
148
this . NetworkManagementClient = this . GetNetworkManagementClient ( context ) ;
177
- this . ComputeManagementClient = this . GetComputeManagementClient ( context ) ;
178
- this . StorageManagementClient = this . GetStorageManagementClient ( context ) ;
179
149
this . AuthorizationManagementClient = this . GetAuthorizationManagementClient ( ) ;
180
- this . InsightsManagementClient = this . GetInsightsManagementClient ( ) ;
181
- this . RedisManagementClient = this . GetRedisManagementClient ( context ) ;
182
150
183
151
helper . SetupManagementClients (
184
- ResourceManagerResourceManagementClient ,
185
152
ResourceManagementClient ,
153
+ InternalResourceManagementClient ,
154
+ LegacyResourceManagementClient ,
186
155
SubscriptionClient ,
187
156
GalleryClient ,
188
- this . NetworkManagementClient ,
189
- this . ComputeManagementClient ,
190
- this . StorageManagementClient ,
191
- this . AuthorizationManagementClient ,
192
- this . InsightsManagementClient ,
193
- this . RedisManagementClient ) ;
157
+ AuthorizationManagementClient ,
158
+ this . NetworkManagementClient ) ;
194
159
}
195
160
196
161
private AuthorizationManagementClient GetAuthorizationManagementClient ( )
@@ -202,6 +167,15 @@ private ResourceManagementClient GetResourceManagementClient()
202
167
{
203
168
return TestBase . GetServiceClient < ResourceManagementClient > ( this . csmTestFactory ) ;
204
169
}
170
+ private Microsoft . Azure . Management . ResourceManager . ResourceManagementClient GetLegacyResourceManagementClient ( RestTestFramework . MockContext context )
171
+ {
172
+ return context . GetServiceClient < Microsoft . Azure . Management . ResourceManager . ResourceManagementClient > ( Microsoft . Rest . ClientRuntime . Azure . TestFramework . TestEnvironmentFactory . GetTestEnvironment ( ) ) ;
173
+ }
174
+
175
+ private Microsoft . Azure . Management . Internal . Resources . ResourceManagementClient GetInternalResourceManagementClient ( RestTestFramework . MockContext context )
176
+ {
177
+ return context . GetServiceClient < Microsoft . Azure . Management . Internal . Resources . ResourceManagementClient > ( Microsoft . Rest . ClientRuntime . Azure . TestFramework . TestEnvironmentFactory . GetTestEnvironment ( ) ) ;
178
+ }
205
179
206
180
private SubscriptionClient GetSubscriptionClient ( )
207
181
{
@@ -212,30 +186,9 @@ private NetworkManagementClient GetNetworkManagementClient(RestTestFramework.Moc
212
186
{
213
187
return context . GetServiceClient < NetworkManagementClient > ( RestTestFramework . TestEnvironmentFactory . GetTestEnvironment ( ) ) ;
214
188
}
215
-
216
- private StorageManagementClient GetStorageManagementClient ( RestTestFramework . MockContext context )
217
- {
218
- return context . GetServiceClient < StorageManagementClient > ( RestTestFramework . TestEnvironmentFactory . GetTestEnvironment ( ) ) ;
219
- }
220
-
221
189
private GalleryClient GetGalleryClient ( )
222
190
{
223
191
return TestBase . GetServiceClient < GalleryClient > ( this . csmTestFactory ) ;
224
192
}
225
-
226
- private InsightsManagementClient GetInsightsManagementClient ( )
227
- {
228
- return TestBase . GetServiceClient < InsightsManagementClient > ( this . csmTestFactory ) ;
229
- }
230
-
231
- private RedisManagementClient GetRedisManagementClient ( RestTestFramework . MockContext context )
232
- {
233
- return context . GetServiceClient < RedisManagementClient > ( RestTestFramework . TestEnvironmentFactory . GetTestEnvironment ( ) ) ;
234
- }
235
-
236
- private ComputeManagementClient GetComputeManagementClient ( RestTestFramework . MockContext context )
237
- {
238
- return context . GetServiceClient < ComputeManagementClient > ( RestTestFramework . TestEnvironmentFactory . GetTestEnvironment ( ) ) ;
239
- }
240
193
}
241
194
}
0 commit comments