@@ -23,6 +23,7 @@ namespace Microsoft.Azure.Commands.Resources.Test
23
23
using Rest . Azure ;
24
24
using ScenarioTest ;
25
25
using System ;
26
+ using System . Collections . Generic ;
26
27
using System . Linq ;
27
28
using System . Management . Automation ;
28
29
using System . Net ;
@@ -72,7 +73,8 @@ public GetAzureProviderFeatureCmdletTests()
72
73
FeaturesManagementClient = featureClient . Object
73
74
}
74
75
} ;
75
- System . Reflection . TypeExtensions . GetProperty ( cmdlet . GetType ( ) , "CommandRuntime" ) . SetValue ( cmdlet , commandRuntimeMock . Object ) ;
76
+ //System.Reflection.TypeExtensions.GetProperty(cmdlet.GetType(), "CommandRuntime").SetValue(cmdlet, commandRuntimeMock.Object);
77
+ PSCmdletExtensions . SetCommandRuntimeMock ( cmdlet , commandRuntimeMock . Object ) ;
76
78
}
77
79
78
80
/// <summary>
@@ -122,13 +124,18 @@ public void GetProviderFeatureTests()
122
124
Type = "Microsoft.Features/feature"
123
125
} ;
124
126
125
- var listResult = new Page < FeatureResult > ( ) ;
126
- var pagableResult = new [ ] { provider1RegisteredFeature , provider1UnregisteredFeature , provider2UnregisteredFeature } ;
127
- System . Reflection . TypeExtensions . GetProperty ( listResult . GetType ( ) , "Items" ) . SetValue ( listResult , pagableResult ) ;
127
+ var pagableResult = new Page < FeatureResult > ( ) ;
128
+ //var listResult = new[] { provider1RegisteredFeature, provider1UnregisteredFeature, provider2UnregisteredFeature };
129
+ var listResult = new List < FeatureResult > ( ) { provider1RegisteredFeature , provider1UnregisteredFeature , provider2UnregisteredFeature } ;
130
+ pagableResult . SetItemValue < FeatureResult > ( listResult ) ;
131
+ var result = new AzureOperationResponse < IPage < FeatureResult > > ( )
132
+ {
133
+ Body = pagableResult
134
+ } ;
128
135
129
136
this . featureOperationsMock
130
- . Setup ( f => f . ListAllAsync ( It . IsAny < CancellationToken > ( ) ) )
131
- . Returns ( ( ) => Task . FromResult ( ( IPage < FeatureResult > ) listResult ) ) ;
137
+ . Setup ( f => f . ListAllWithHttpMessagesAsync ( null , It . IsAny < CancellationToken > ( ) ) )
138
+ . Returns ( ( ) => Task . FromResult ( result ) ) ;
132
139
133
140
// 1. List only registered features of providers
134
141
this . commandRuntimeMock
@@ -172,14 +179,16 @@ public void GetProviderFeatureTests()
172
179
string providerOfChoice = Provider1Namespace ;
173
180
this . cmdlet . ListAvailable = false ;
174
181
this . cmdlet . ProviderNamespace = providerOfChoice ;
175
- System . Reflection . TypeExtensions
176
- . GetProperty ( listResult . GetType ( ) , "Items" )
177
- . SetValue ( listResult , new [ ] { provider1RegisteredFeature , provider1UnregisteredFeature } ) ;
182
+ pagableResult . SetItemValue < FeatureResult > ( new List < FeatureResult > ( ) { provider1RegisteredFeature , provider1UnregisteredFeature } ) ;
178
183
179
184
this . featureOperationsMock
180
- . Setup ( f => f . ListAsync ( It . IsAny < string > ( ) , It . IsAny < CancellationToken > ( ) ) )
181
- . Callback ( ( string providerName , CancellationToken ignored ) => Assert . Equal ( providerOfChoice , providerName , StringComparer . OrdinalIgnoreCase ) )
182
- . Returns ( ( ) => Task . FromResult ( ( IPage < FeatureResult > ) listResult ) ) ;
185
+ . Setup ( f => f . ListWithHttpMessagesAsync ( It . IsAny < string > ( ) , null , It . IsAny < CancellationToken > ( ) ) )
186
+ . Callback ( ( string providerName , Dictionary < string , List < string > > customHeaders , CancellationToken ignored ) => Assert . Equal ( providerOfChoice , providerName , StringComparer . OrdinalIgnoreCase ) )
187
+ . Returns ( ( ) => Task . FromResult (
188
+ new AzureOperationResponse < IPage < FeatureResult > > ( )
189
+ {
190
+ Body = pagableResult
191
+ } ) ) ;
183
192
184
193
this . commandRuntimeMock
185
194
. Setup ( m => m . WriteObject ( It . IsAny < object > ( ) ) )
@@ -206,9 +215,7 @@ public void GetProviderFeatureTests()
206
215
providerOfChoice = Provider2Namespace ;
207
216
this . cmdlet . ListAvailable = false ;
208
217
this . cmdlet . ProviderNamespace = providerOfChoice ;
209
- System . Reflection . TypeExtensions
210
- . GetProperty ( listResult . GetType ( ) , "Items" )
211
- . SetValue ( listResult , new [ ] { provider2UnregisteredFeature } ) ;
218
+ pagableResult . SetItemValue < FeatureResult > ( new List < FeatureResult > ( ) { provider2UnregisteredFeature } ) ;
212
219
213
220
this . commandRuntimeMock
214
221
. Setup ( m => m . WriteObject ( It . IsAny < object > ( ) ) )
@@ -228,9 +235,7 @@ public void GetProviderFeatureTests()
228
235
providerOfChoice = Provider1Namespace ;
229
236
this . cmdlet . ProviderNamespace = providerOfChoice ;
230
237
this . cmdlet . ListAvailable = true ;
231
- System . Reflection . TypeExtensions
232
- . GetProperty ( listResult . GetType ( ) , "Items" )
233
- . SetValue ( listResult , new [ ] { provider1RegisteredFeature , provider1UnregisteredFeature } ) ;
238
+ pagableResult . SetItemValue < FeatureResult > ( new List < FeatureResult > ( ) { provider1RegisteredFeature , provider1UnregisteredFeature } ) ;
234
239
235
240
this . commandRuntimeMock
236
241
. Setup ( m => m . WriteObject ( It . IsAny < object > ( ) ) )
@@ -256,13 +261,16 @@ public void GetProviderFeatureTests()
256
261
this . cmdlet . ListAvailable = false ;
257
262
258
263
this . featureOperationsMock
259
- . Setup ( f => f . GetAsync ( It . IsAny < string > ( ) , It . IsAny < string > ( ) , It . IsAny < CancellationToken > ( ) ) )
260
- . Callback ( ( string providerName , string featureName , CancellationToken ignored ) =>
264
+ . Setup ( f => f . GetWithHttpMessagesAsync ( It . IsAny < string > ( ) , It . IsAny < string > ( ) , null , It . IsAny < CancellationToken > ( ) ) )
265
+ . Callback ( ( string providerName , string featureName , Dictionary < string , List < string > > customHeaders , CancellationToken ignored ) =>
261
266
{
262
267
Assert . Equal ( Provider2Namespace , providerName , StringComparer . OrdinalIgnoreCase ) ;
263
268
Assert . Equal ( Feature1Name , featureName , StringComparer . OrdinalIgnoreCase ) ;
264
269
} )
265
- . Returns ( ( ) => Task . FromResult ( provider2UnregisteredFeature ) ) ;
270
+ . Returns ( ( ) => Task . FromResult ( new AzureOperationResponse < FeatureResult > ( )
271
+ {
272
+ Body = provider2UnregisteredFeature
273
+ } ) ) ;
266
274
267
275
this . commandRuntimeMock
268
276
. Setup ( m => m . WriteObject ( It . IsAny < object > ( ) ) )
@@ -298,11 +306,11 @@ private void ResetCalls()
298
306
/// </summary>
299
307
private void VerifyGetCallPatternAndReset ( )
300
308
{
301
- this . featureOperationsMock . Verify ( f => f . GetAsync ( It . IsAny < string > ( ) , It . IsAny < string > ( ) , It . IsAny < CancellationToken > ( ) ) , Times . Once ( ) ) ;
302
- this . featureOperationsMock . Verify ( f => f . ListAsync ( It . IsAny < string > ( ) , It . IsAny < CancellationToken > ( ) ) , Times . Never ) ;
303
- this . featureOperationsMock . Verify ( f => f . ListAllAsync ( It . IsAny < CancellationToken > ( ) ) , Times . Never ) ;
304
- this . featureOperationsMock . Verify ( f => f . ListNextAsync ( It . IsAny < string > ( ) , It . IsAny < CancellationToken > ( ) ) , Times . Never ) ;
305
- this . featureOperationsMock . Verify ( f => f . ListAllNextAsync ( It . IsAny < string > ( ) , It . IsAny < CancellationToken > ( ) ) , Times . Never ) ;
309
+ this . featureOperationsMock . Verify ( f => f . GetWithHttpMessagesAsync ( It . IsAny < string > ( ) , It . IsAny < string > ( ) , null , It . IsAny < CancellationToken > ( ) ) , Times . Once ( ) ) ;
310
+ this . featureOperationsMock . Verify ( f => f . ListWithHttpMessagesAsync ( It . IsAny < string > ( ) , null , It . IsAny < CancellationToken > ( ) ) , Times . Never ) ;
311
+ this . featureOperationsMock . Verify ( f => f . ListAllWithHttpMessagesAsync ( null , It . IsAny < CancellationToken > ( ) ) , Times . Never ) ;
312
+ this . featureOperationsMock . Verify ( f => f . ListNextWithHttpMessagesAsync ( It . IsAny < string > ( ) , null , It . IsAny < CancellationToken > ( ) ) , Times . Never ) ;
313
+ this . featureOperationsMock . Verify ( f => f . ListAllNextWithHttpMessagesAsync ( It . IsAny < string > ( ) , null , It . IsAny < CancellationToken > ( ) ) , Times . Never ) ;
306
314
this . commandRuntimeMock . Verify ( f => f . WriteObject ( It . IsAny < object > ( ) , It . IsAny < bool > ( ) ) , Times . Once ( ) ) ;
307
315
308
316
this . ResetCalls ( ) ;
@@ -313,8 +321,8 @@ private void VerifyGetCallPatternAndReset()
313
321
/// </summary>
314
322
private void VerifyListAllCallPatternAndReset ( )
315
323
{
316
- this . featureOperationsMock . Verify ( f => f . ListAllAsync ( It . IsAny < CancellationToken > ( ) ) , Times . Once ( ) ) ;
317
- this . featureOperationsMock . Verify ( f => f . ListAllNextAsync ( It . IsAny < string > ( ) , It . IsAny < CancellationToken > ( ) ) , Times . Never ) ;
324
+ this . featureOperationsMock . Verify ( f => f . ListAllWithHttpMessagesAsync ( null , It . IsAny < CancellationToken > ( ) ) , Times . Once ( ) ) ;
325
+ this . featureOperationsMock . Verify ( f => f . ListAllNextWithHttpMessagesAsync ( It . IsAny < string > ( ) , null , It . IsAny < CancellationToken > ( ) ) , Times . Never ) ;
318
326
this . commandRuntimeMock . Verify ( f => f . WriteObject ( It . IsAny < object > ( ) , It . IsAny < bool > ( ) ) , Times . Once ( ) ) ;
319
327
320
328
this . ResetCalls ( ) ;
@@ -325,8 +333,8 @@ private void VerifyListAllCallPatternAndReset()
325
333
/// </summary>
326
334
private void VerifyListProviderFeaturesCallPatternAndReset ( )
327
335
{
328
- this . featureOperationsMock . Verify ( f => f . ListAsync ( It . IsAny < string > ( ) , It . IsAny < CancellationToken > ( ) ) , Times . Once ( ) ) ;
329
- this . featureOperationsMock . Verify ( f => f . ListNextAsync ( It . IsAny < string > ( ) , It . IsAny < CancellationToken > ( ) ) , Times . Never ) ;
336
+ this . featureOperationsMock . Verify ( f => f . ListWithHttpMessagesAsync ( It . IsAny < string > ( ) , null , It . IsAny < CancellationToken > ( ) ) , Times . Once ( ) ) ;
337
+ this . featureOperationsMock . Verify ( f => f . ListNextWithHttpMessagesAsync ( It . IsAny < string > ( ) , null , It . IsAny < CancellationToken > ( ) ) , Times . Never ) ;
330
338
this . commandRuntimeMock . Verify ( f => f . WriteObject ( It . IsAny < object > ( ) , It . IsAny < bool > ( ) ) , Times . Once ( ) ) ;
331
339
332
340
this . ResetCalls ( ) ;
0 commit comments