21
21
using System . Collections ;
22
22
using System . Collections . Generic ;
23
23
using System . IO ;
24
+ using System . Linq ;
24
25
using System . Net ;
25
26
using System . Net . Http ;
26
27
using System . Reflection ;
@@ -157,7 +158,7 @@ public static void AssertBatchAccountContextsAreEqual(BatchAccountContext contex
157
158
public static RequestInterceptor CreateFakeServiceResponseInterceptor < TBody , TOptions , TResponse > ( TResponse responseToUse = default ( TResponse ) ,
158
159
Action < BatchRequest < TBody , TOptions , TResponse > > requestAction = null )
159
160
where TOptions : ProxyModels . IOptions , new ( )
160
- where TResponse : IAzureOperationResponse , new ( )
161
+ where TResponse : class , IAzureOperationResponse , new ( )
161
162
{
162
163
RequestInterceptor interceptor = new RequestInterceptor ( ( baseRequest ) =>
163
164
{
@@ -170,15 +171,12 @@ public static void AssertBatchAccountContextsAreEqual(BatchAccountContext contex
170
171
171
172
request . ServiceRequestFunc = ( cancellationToken ) =>
172
173
{
173
- if ( responseToUse == null )
174
+ TResponse response = responseToUse ?? new TResponse ( )
174
175
{
175
- responseToUse = new TResponse ( )
176
- {
177
- Response = new HttpResponseMessage ( )
178
- } ;
179
- }
176
+ Response = new HttpResponseMessage ( )
177
+ } ;
180
178
181
- Task < TResponse > task = Task . FromResult ( responseToUse ) ;
179
+ Task < TResponse > task = Task . FromResult ( response ) ;
182
180
return task ;
183
181
} ;
184
182
} ) ;
@@ -192,7 +190,7 @@ public static void AssertBatchAccountContextsAreEqual(BatchAccountContext contex
192
190
/// <typeparam name="THeader">The type of header for the response</typeparam>
193
191
/// <returns></returns>
194
192
public static AzureOperationResponse < TBody , THeader > CreateGenericAzureOperationResponse < TBody , THeader > ( )
195
- where TBody : class , new ( )
193
+ where TBody : class , new ( )
196
194
where THeader : class , new ( )
197
195
{
198
196
var response = new AzureOperationResponse < TBody , THeader > ( )
@@ -221,7 +219,7 @@ public static AzureOperationResponse<IPage<TBody>, THeader> CreateGenericAzureOp
221
219
} ;
222
220
223
221
return response ;
224
- }
222
+ }
225
223
226
224
/// <summary>
227
225
/// Creates a RequestInterceptor that does not contact the Batch Service on a Get NodeFile or a Get NodeFile Properties call.
@@ -319,7 +317,7 @@ public static RequestInterceptor CreateFakeGetFileAndPropertiesFromComputeNodeRe
319
317
cert . Thumbprint = thumbprint ;
320
318
321
319
response . Body = cert ;
322
-
320
+
323
321
return response ;
324
322
}
325
323
@@ -330,7 +328,7 @@ public static RequestInterceptor CreateFakeGetFileAndPropertiesFromComputeNodeRe
330
328
{
331
329
var response = new AzureOperationResponse < IPage < ProxyModels . Certificate > , ProxyModels . CertificateListHeaders > ( ) ;
332
330
response . Response = new HttpResponseMessage ( HttpStatusCode . OK ) ;
333
-
331
+
334
332
List < ProxyModels . Certificate > certs = new List < ProxyModels . Certificate > ( ) ;
335
333
336
334
foreach ( string t in certThumbprints )
@@ -383,6 +381,23 @@ public static RequestInterceptor CreateFakeGetFileAndPropertiesFromComputeNodeRe
383
381
return response ;
384
382
}
385
383
384
+ /// <summary>
385
+ /// Builds a GetRemoteLoginSettingsResponse object
386
+ /// </summary>
387
+ public static AzureOperationResponse < ProxyModels . ComputeNodeGetRemoteLoginSettingsResult , ProxyModels . ComputeNodeGetRemoteLoginSettingsHeaders > CreateRemoteLoginSettingsGetResponse ( string ipAddress )
388
+ {
389
+ var settings = new ProxyModels . ComputeNodeGetRemoteLoginSettingsResult ( ) ;
390
+ settings . RemoteLoginIPAddress = ipAddress ;
391
+
392
+ var response = new AzureOperationResponse < ProxyModels . ComputeNodeGetRemoteLoginSettingsResult , ProxyModels . ComputeNodeGetRemoteLoginSettingsHeaders > ( )
393
+ {
394
+ Response = new HttpResponseMessage ( HttpStatusCode . OK ) ,
395
+ Body = settings
396
+ } ;
397
+
398
+ return response ;
399
+ }
400
+
386
401
/// <summary>
387
402
/// Builds a ComputeNodeGetResponse object
388
403
/// </summary>
@@ -492,7 +507,7 @@ public static RequestInterceptor CreateFakeGetFileAndPropertiesFromComputeNodeRe
492
507
job . Id = id ;
493
508
jobs . Add ( job ) ;
494
509
}
495
-
510
+
496
511
response . Body = new MockPagedEnumerable < ProxyModels . CloudJob > ( jobs ) ;
497
512
498
513
return response ;
@@ -519,7 +534,7 @@ public static RequestInterceptor CreateFakeGetFileAndPropertiesFromComputeNodeRe
519
534
/// </summary>
520
535
public static AzureOperationResponse < IPage < ProxyModels . CloudTask > , ProxyModels . TaskListHeaders > CreateCloudTaskListResponse ( IEnumerable < string > taskIds )
521
536
{
522
- var response = new AzureOperationResponse < IPage < ProxyModels . CloudTask > , ProxyModels . TaskListHeaders > ( ) ;
537
+ var response = new AzureOperationResponse < IPage < ProxyModels . CloudTask > , ProxyModels . TaskListHeaders > ( ) ;
523
538
response . Response = new HttpResponseMessage ( HttpStatusCode . OK ) ;
524
539
525
540
List < ProxyModels . CloudTask > tasks = new List < ProxyModels . CloudTask > ( ) ;
@@ -563,6 +578,23 @@ public static RequestInterceptor CreateFakeGetFileAndPropertiesFromComputeNodeRe
563
578
return response ;
564
579
}
565
580
581
+ /// <summary>
582
+ /// Builds a NodeAgentSKUResponse object
583
+ /// </summary>
584
+ public static AzureOperationResponse < IPage < ProxyModels . NodeAgentSku > , ProxyModels . AccountListNodeAgentSkusHeaders > CreateNodeAgentSkuResponse ( IEnumerable < string > skuIds )
585
+ {
586
+ IEnumerable < ProxyModels . NodeAgentSku > nodeAgents =
587
+ skuIds . Select ( id => new ProxyModels . NodeAgentSku ( ) { Id = id } ) ;
588
+
589
+ var response = new AzureOperationResponse < IPage < ProxyModels . NodeAgentSku > , ProxyModels . AccountListNodeAgentSkusHeaders > ( )
590
+ {
591
+ Response = new HttpResponseMessage ( HttpStatusCode . OK ) ,
592
+ Body = new MockPagedEnumerable < ProxyModels . NodeAgentSku > ( nodeAgents )
593
+ } ;
594
+
595
+ return response ;
596
+ }
597
+
566
598
/// <summary>
567
599
/// Builds a NodeFileGetPropertiesResponse object
568
600
/// </summary>
@@ -638,7 +670,7 @@ public static RequestInterceptor CreateFakeGetFileAndPropertiesFromComputeNodeRe
638
670
response . Response = new HttpResponseMessage ( HttpStatusCode . OK ) ;
639
671
640
672
List < ProxyModels . NodeFile > files = new List < ProxyModels . NodeFile > ( ) ;
641
-
673
+
642
674
foreach ( string name in fileNames )
643
675
{
644
676
ProxyModels . NodeFile file = new ProxyModels . NodeFile ( ) ;
@@ -689,7 +721,7 @@ public static CloudJobSchedule CreateFakeBoundJobSchedule(BatchAccountContext co
689
721
request . ServiceRequestFunc = ( cancellationToken ) =>
690
722
{
691
723
var response = new AzureOperationResponse < ProxyModels . CloudJobSchedule , ProxyModels . JobScheduleGetHeaders > ( ) ;
692
-
724
+
693
725
response . Body = new ProxyModels . CloudJobSchedule ( id : jobScheduleId , schedule : new ProxyModels . Schedule ( ) , jobSpecification : new ProxyModels . JobSpecification ( ) ) ;
694
726
695
727
Task < AzureOperationResponse < ProxyModels . CloudJobSchedule , ProxyModels . JobScheduleGetHeaders > > task = Task . FromResult ( response ) ;
@@ -759,7 +791,7 @@ internal static void SetProperty(object obj, string propertyName, object propert
759
791
}
760
792
761
793
/// <summary>
762
- /// Uses Reflection to set a property value on an object.
794
+ /// Uses Reflection to set a property value on an object.
763
795
/// </summary>
764
796
internal static void SetField ( object obj , string fieldName , object fieldValue )
765
797
{
0 commit comments