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