12
12
// limitations under the License.
13
13
// ----------------------------------------------------------------------------------
14
14
15
- using System . IO ;
16
15
using System . Linq ;
17
16
using System . Net ;
18
- using System . Net . Http ;
19
17
using System . Threading . Tasks ;
20
18
using Microsoft . Azure . Batch ;
21
- using Microsoft . Azure . Batch . Common ;
22
19
using Microsoft . Azure . Batch . Protocol ;
23
- using Microsoft . Azure . Commands . Batch . Models ;
24
- using Microsoft . Azure . Commands . Batch . Test . ScenarioTests ;
25
- using Microsoft . Azure . Management . Batch ;
26
20
using Microsoft . Azure . Management . Batch . Models ;
27
21
using System ;
28
22
using System . Collections ;
29
23
using System . Collections . Generic ;
30
24
using System . Reflection ;
31
- using Microsoft . Azure . Management . Resources ;
32
- using Microsoft . Azure . Management . Resources . Models ;
33
- using Microsoft . Azure . Test . HttpRecorder ;
34
- using Microsoft . WindowsAzure . Storage . Shared . Protocol ;
35
25
using Xunit ;
36
26
using ProxyModels = Microsoft . Azure . Batch . Protocol . Models ;
37
27
@@ -114,16 +104,21 @@ public static void AssertBatchAccountContextsAreEqual(BatchAccountContext contex
114
104
/// Creates a RequestInterceptor that does not contact the Batch Service but instead uses the supplied response body.
115
105
/// </summary>
116
106
/// <param name="responseToUse">The response the interceptor should return. If none is specified, then a new instance of the response type is instantiated.</param>
107
+ /// <param name="requestAction">An action to perform on the request.</param>
117
108
/// <typeparam name="TParameters">The type of the request parameters.</typeparam>
118
109
/// <typeparam name="TResponse">The type of the expected response.</typeparam>
119
- public static RequestInterceptor CreateNoOpInterceptor < TParameters , TResponse > ( TResponse responseToUse = null )
110
+ public static RequestInterceptor CreateNoOpInterceptor < TParameters , TResponse > ( TResponse responseToUse = null , Action < BatchRequest < TParameters , TResponse > > requestAction = null )
120
111
where TParameters : ProxyModels . BatchParameters
121
112
where TResponse : ProxyModels . BatchOperationResponse , new ( )
122
113
{
123
114
RequestInterceptor interceptor = new RequestInterceptor ( ( baseRequest ) =>
124
115
{
125
- BatchRequest < TParameters , TResponse > request =
126
- ( BatchRequest < TParameters , TResponse > ) baseRequest ;
116
+ BatchRequest < TParameters , TResponse > request = ( BatchRequest < TParameters , TResponse > ) baseRequest ;
117
+
118
+ if ( requestAction != null )
119
+ {
120
+ requestAction ( request ) ;
121
+ }
127
122
128
123
request . ServiceRequestFunc = ( cancellationToken ) =>
129
124
{
@@ -145,7 +140,7 @@ public static RequestInterceptor CreateNoOpGetFileAndPropertiesInterceptor(strin
145
140
RequestInterceptor interceptor = new RequestInterceptor ( ( baseRequest ) =>
146
141
{
147
142
BatchRequest < ProxyModels . NodeFileGetParameters , ProxyModels . NodeFileGetResponse > fileRequest = baseRequest as
148
- BatchRequest < ProxyModels . NodeFileGetParameters , ProxyModels . NodeFileGetResponse > ;
143
+ BatchRequest < ProxyModels . NodeFileGetParameters , ProxyModels . NodeFileGetResponse > ;
149
144
150
145
if ( fileRequest != null )
151
146
{
@@ -401,6 +396,106 @@ public static ProxyModels.NodeFileListResponse CreateNodeFileListResponse(IEnume
401
396
return response ;
402
397
}
403
398
399
+ /// <summary>
400
+ /// Fabricates a CloudJob that's in the bound state
401
+ /// </summary>
402
+ public static CloudJob CreateFakeBoundJob ( BatchAccountContext context )
403
+ {
404
+ string jobId = "testJob" ;
405
+
406
+ RequestInterceptor interceptor = new RequestInterceptor ( ( baseRequest ) =>
407
+ {
408
+ BatchRequest < ProxyModels . CloudJobGetParameters , ProxyModels . CloudJobGetResponse > request =
409
+ ( BatchRequest < ProxyModels . CloudJobGetParameters , ProxyModels . CloudJobGetResponse > ) baseRequest ;
410
+
411
+ request . ServiceRequestFunc = ( cancellationToken ) =>
412
+ {
413
+ ProxyModels . CloudJobGetResponse response = new ProxyModels . CloudJobGetResponse ( ) ;
414
+ response . Job = new ProxyModels . CloudJob ( jobId , new ProxyModels . PoolInformation ( ) ) ;
415
+
416
+ Task < ProxyModels . CloudJobGetResponse > task = Task . FromResult ( response ) ;
417
+ return task ;
418
+ } ;
419
+ } ) ;
420
+
421
+ return context . BatchOMClient . JobOperations . GetJob ( jobId , additionalBehaviors : new BatchClientBehavior [ ] { interceptor } ) ;
422
+ }
423
+
424
+ /// <summary>
425
+ /// Fabricates a CloudJobSchedule that's in the bound state
426
+ /// </summary>
427
+ public static CloudJobSchedule CreateFakeBoundJobSchedule ( BatchAccountContext context )
428
+ {
429
+ string jobScheduleId = "testJobSchedule" ;
430
+
431
+ RequestInterceptor interceptor = new RequestInterceptor ( ( baseRequest ) =>
432
+ {
433
+ BatchRequest < ProxyModels . CloudJobScheduleGetParameters , ProxyModels . CloudJobScheduleGetResponse > request =
434
+ ( BatchRequest < ProxyModels . CloudJobScheduleGetParameters , ProxyModels . CloudJobScheduleGetResponse > ) baseRequest ;
435
+
436
+ request . ServiceRequestFunc = ( cancellationToken ) =>
437
+ {
438
+ ProxyModels . CloudJobScheduleGetResponse response = new ProxyModels . CloudJobScheduleGetResponse ( ) ;
439
+ response . JobSchedule = new ProxyModels . CloudJobSchedule ( jobScheduleId , new ProxyModels . Schedule ( ) , new ProxyModels . JobSpecification ( ) ) ;
440
+
441
+ Task < ProxyModels . CloudJobScheduleGetResponse > task = Task . FromResult ( response ) ;
442
+ return task ;
443
+ } ;
444
+ } ) ;
445
+
446
+ return context . BatchOMClient . JobScheduleOperations . GetJobSchedule ( jobScheduleId , additionalBehaviors : new BatchClientBehavior [ ] { interceptor } ) ;
447
+ }
448
+
449
+ /// <summary>
450
+ /// Fabricates a CloudPool that's in the bound state
451
+ /// </summary>
452
+ public static CloudPool CreateFakeBoundPool ( BatchAccountContext context )
453
+ {
454
+ string poolId = "testPool" ;
455
+
456
+ RequestInterceptor interceptor = new RequestInterceptor ( ( baseRequest ) =>
457
+ {
458
+ BatchRequest < ProxyModels . CloudPoolGetParameters , ProxyModels . CloudPoolGetResponse > request =
459
+ ( BatchRequest < ProxyModels . CloudPoolGetParameters , ProxyModels . CloudPoolGetResponse > ) baseRequest ;
460
+
461
+ request . ServiceRequestFunc = ( cancellationToken ) =>
462
+ {
463
+ ProxyModels . CloudPoolGetResponse response = new ProxyModels . CloudPoolGetResponse ( ) ;
464
+ response . Pool = new ProxyModels . CloudPool ( poolId , "small" , "4" ) ;
465
+
466
+ Task < ProxyModels . CloudPoolGetResponse > task = Task . FromResult ( response ) ;
467
+ return task ;
468
+ } ;
469
+ } ) ;
470
+
471
+ return context . BatchOMClient . PoolOperations . GetPool ( poolId , additionalBehaviors : new BatchClientBehavior [ ] { interceptor } ) ;
472
+ }
473
+
474
+ /// <summary>
475
+ /// Fabricates a CloudTask that's in the bound state
476
+ /// </summary>
477
+ public static CloudTask CreateFakeBoundTask ( BatchAccountContext context )
478
+ {
479
+ string taskId = "testTask" ;
480
+
481
+ RequestInterceptor interceptor = new RequestInterceptor ( ( baseRequest ) =>
482
+ {
483
+ BatchRequest < ProxyModels . CloudTaskGetParameters , ProxyModels . CloudTaskGetResponse > request =
484
+ ( BatchRequest < ProxyModels . CloudTaskGetParameters , ProxyModels . CloudTaskGetResponse > ) baseRequest ;
485
+
486
+ request . ServiceRequestFunc = ( cancellationToken ) =>
487
+ {
488
+ ProxyModels . CloudTaskGetResponse response = new ProxyModels . CloudTaskGetResponse ( ) ;
489
+ response . Task = new ProxyModels . CloudTask ( taskId , "cmd /c dir /s" ) ;
490
+
491
+ Task < ProxyModels . CloudTaskGetResponse > task = Task . FromResult ( response ) ;
492
+ return task ;
493
+ } ;
494
+ } ) ;
495
+
496
+ return context . BatchOMClient . JobOperations . GetTask ( "jobId" , taskId , additionalBehaviors : new BatchClientBehavior [ ] { interceptor } ) ;
497
+ }
498
+
404
499
/// <summary>
405
500
/// Uses Reflection to set a property value on an object. Can be used to bypass restricted set accessors.
406
501
/// </summary>
0 commit comments