10
10
using System . Net . Http ;
11
11
using System . Net . Http . Headers ;
12
12
using System . Threading . Tasks ;
13
+ using System . Web . Http ;
13
14
using Microsoft . Azure . WebJobs . Host ;
14
15
using Microsoft . Azure . WebJobs . Script . Tests . ApiHub ;
15
16
using Microsoft . WindowsAzure . Storage . Blob ;
@@ -97,6 +98,7 @@ public async Task HttpTrigger_Post_ByteArray()
97
98
Method = HttpMethod . Post ,
98
99
Content = new ByteArrayContent ( inputBytes )
99
100
} ;
101
+ request . SetConfiguration ( new HttpConfiguration ( ) ) ;
100
102
request . Content . Headers . ContentType = new MediaTypeHeaderValue ( "application/octet-stream" ) ;
101
103
102
104
Dictionary < string , object > arguments = new Dictionary < string , object >
@@ -105,7 +107,7 @@ public async Task HttpTrigger_Post_ByteArray()
105
107
} ;
106
108
await Fixture . Host . CallAsync ( "HttpTriggerByteArray" , arguments ) ;
107
109
108
- HttpResponseMessage response = ( HttpResponseMessage ) request . Properties [ "MS_AzureFunctionsHttpResponse" ] ;
110
+ HttpResponseMessage response = ( HttpResponseMessage ) request . Properties [ ScriptConstants . AzureFunctionsHttpResponseKey ] ;
109
111
Assert . Equal ( HttpStatusCode . OK , response . StatusCode ) ;
110
112
111
113
JObject testResult = await GetFunctionTestResult ( "HttpTriggerByteArray" ) ;
@@ -345,15 +347,16 @@ public async Task HttpTrigger_Get()
345
347
RequestUri = new Uri ( string . Format ( "http://localhost/api/httptrigger?name=Mathew%20Charles&location=Seattle" ) ) ,
346
348
Method = HttpMethod . Get ,
347
349
} ;
350
+ request . SetConfiguration ( new HttpConfiguration ( ) ) ;
348
351
request . Headers . Add ( "test-header" , "Test Request Header" ) ;
349
352
350
353
Dictionary < string , object > arguments = new Dictionary < string , object >
351
354
{
352
- { "req " , request }
355
+ { "request " , request }
353
356
} ;
354
357
await Fixture . Host . CallAsync ( "HttpTrigger" , arguments ) ;
355
358
356
- HttpResponseMessage response = ( HttpResponseMessage ) request . Properties [ "MS_AzureFunctionsHttpResponse" ] ;
359
+ HttpResponseMessage response = ( HttpResponseMessage ) request . Properties [ ScriptConstants . AzureFunctionsHttpResponseKey ] ;
357
360
Assert . Equal ( HttpStatusCode . OK , response . StatusCode ) ;
358
361
359
362
Assert . Equal ( "Test Response Header" , response . Headers . GetValues ( "test-header" ) . SingleOrDefault ( ) ) ;
@@ -374,6 +377,71 @@ public async Task HttpTrigger_Get()
374
377
Assert . Equal ( "Test Request Header" , reqHeaders [ "test-header" ] ) ;
375
378
}
376
379
380
+ [ Fact ]
381
+ public async Task HttpTrigger_Scenarios_ScalarReturn_InBody ( )
382
+ {
383
+ HttpRequestMessage request = new HttpRequestMessage
384
+ {
385
+ RequestUri = new Uri ( string . Format ( "http://localhost/api/httptrigger-scenarios" ) ) ,
386
+ Method = HttpMethod . Post ,
387
+ } ;
388
+ request . SetConfiguration ( new HttpConfiguration ( ) ) ;
389
+
390
+ JObject value = new JObject ( )
391
+ {
392
+ { "status" , "200" } ,
393
+ { "body" , 123 }
394
+ } ;
395
+ JObject input = new JObject ( )
396
+ {
397
+ { "scenario" , "echo" } ,
398
+ { "value" , value }
399
+ } ;
400
+ request . Content = new StringContent ( input . ToString ( ) ) ;
401
+ request . Content . Headers . ContentType = new MediaTypeHeaderValue ( "application/json" ) ;
402
+
403
+ Dictionary < string , object > arguments = new Dictionary < string , object >
404
+ {
405
+ { "req" , request }
406
+ } ;
407
+ await Fixture . Host . CallAsync ( "HttpTrigger-Scenarios" , arguments ) ;
408
+
409
+ HttpResponseMessage response = ( HttpResponseMessage ) request . Properties [ ScriptConstants . AzureFunctionsHttpResponseKey ] ;
410
+ Assert . Equal ( HttpStatusCode . OK , response . StatusCode ) ;
411
+ Assert . Equal ( "application/json" , response . Content . Headers . ContentType . MediaType ) ;
412
+ Assert . Equal ( 123 , await response . Content . ReadAsAsync < int > ( ) ) ;
413
+ }
414
+
415
+ [ Fact ]
416
+ public async Task HttpTrigger_Scenarios_ScalarReturn ( )
417
+ {
418
+ HttpRequestMessage request = new HttpRequestMessage
419
+ {
420
+ RequestUri = new Uri ( string . Format ( "http://localhost/api/httptrigger-scenarios" ) ) ,
421
+ Method = HttpMethod . Post ,
422
+ } ;
423
+ request . SetConfiguration ( new HttpConfiguration ( ) ) ;
424
+
425
+ JObject input = new JObject ( )
426
+ {
427
+ { "scenario" , "echo" } ,
428
+ { "value" , 123 }
429
+ } ;
430
+ request . Content = new StringContent ( input . ToString ( ) ) ;
431
+ request . Content . Headers . ContentType = new MediaTypeHeaderValue ( "application/json" ) ;
432
+
433
+ Dictionary < string , object > arguments = new Dictionary < string , object >
434
+ {
435
+ { "req" , request }
436
+ } ;
437
+ await Fixture . Host . CallAsync ( "HttpTrigger-Scenarios" , arguments ) ;
438
+
439
+ HttpResponseMessage response = ( HttpResponseMessage ) request . Properties [ ScriptConstants . AzureFunctionsHttpResponseKey ] ;
440
+ Assert . Equal ( HttpStatusCode . OK , response . StatusCode ) ;
441
+ Assert . Equal ( "application/json" , response . Content . Headers . ContentType . MediaType ) ;
442
+ Assert . Equal ( 123 , await response . Content . ReadAsAsync < int > ( ) ) ;
443
+ }
444
+
377
445
[ Fact ]
378
446
public async Task HttpTrigger_Post_PlainText ( )
379
447
{
@@ -384,14 +452,15 @@ public async Task HttpTrigger_Post_PlainText()
384
452
Method = HttpMethod . Post ,
385
453
Content = new StringContent ( testData )
386
454
} ;
455
+ request . SetConfiguration ( new HttpConfiguration ( ) ) ;
387
456
388
457
Dictionary < string , object > arguments = new Dictionary < string , object >
389
458
{
390
- { "req " , request }
459
+ { "request " , request }
391
460
} ;
392
461
await Fixture . Host . CallAsync ( "HttpTrigger" , arguments ) ;
393
462
394
- HttpResponseMessage response = ( HttpResponseMessage ) request . Properties [ "MS_AzureFunctionsHttpResponse" ] ;
463
+ HttpResponseMessage response = ( HttpResponseMessage ) request . Properties [ ScriptConstants . AzureFunctionsHttpResponseKey ] ;
395
464
Assert . Equal ( HttpStatusCode . OK , response . StatusCode ) ;
396
465
397
466
string body = await response . Content . ReadAsStringAsync ( ) ;
@@ -417,15 +486,16 @@ public async Task HttpTrigger_Post_JsonObject()
417
486
Method = HttpMethod . Post ,
418
487
Content = new StringContent ( rawBody )
419
488
} ;
489
+ request . SetConfiguration ( new HttpConfiguration ( ) ) ;
420
490
request . Content . Headers . ContentType = new MediaTypeHeaderValue ( "application/json" ) ;
421
491
422
492
Dictionary < string , object > arguments = new Dictionary < string , object >
423
493
{
424
- { "req " , request }
494
+ { "request " , request }
425
495
} ;
426
496
await Fixture . Host . CallAsync ( "HttpTrigger" , arguments ) ;
427
497
428
- HttpResponseMessage response = ( HttpResponseMessage ) request . Properties [ "MS_AzureFunctionsHttpResponse" ] ;
498
+ HttpResponseMessage response = ( HttpResponseMessage ) request . Properties [ ScriptConstants . AzureFunctionsHttpResponseKey ] ;
429
499
Assert . Equal ( HttpStatusCode . OK , response . StatusCode ) ;
430
500
431
501
string body = await response . Content . ReadAsStringAsync ( ) ;
@@ -487,15 +557,16 @@ public async Task HttpTrigger_Post_JsonArray()
487
557
Method = HttpMethod . Post ,
488
558
Content = new StringContent ( rawBody )
489
559
} ;
560
+ request . SetConfiguration ( new HttpConfiguration ( ) ) ;
490
561
request . Content . Headers . ContentType = new MediaTypeHeaderValue ( "application/json" ) ;
491
562
492
563
Dictionary < string , object > arguments = new Dictionary < string , object >
493
564
{
494
- { "req " , request }
565
+ { "request " , request }
495
566
} ;
496
567
await Fixture . Host . CallAsync ( "HttpTrigger" , arguments ) ;
497
568
498
- HttpResponseMessage response = ( HttpResponseMessage ) request . Properties [ "MS_AzureFunctionsHttpResponse" ] ;
569
+ HttpResponseMessage response = ( HttpResponseMessage ) request . Properties [ ScriptConstants . AzureFunctionsHttpResponseKey ] ;
499
570
Assert . Equal ( HttpStatusCode . OK , response . StatusCode ) ;
500
571
501
572
string body = await response . Content . ReadAsStringAsync ( ) ;
@@ -528,6 +599,7 @@ public async Task WebHookTrigger_GenericJson()
528
599
Method = HttpMethod . Post ,
529
600
Content = new StringContent ( testObject . ToString ( ) )
530
601
} ;
602
+ request . SetConfiguration ( new HttpConfiguration ( ) ) ;
531
603
request . Content . Headers . ContentType = new MediaTypeHeaderValue ( "application/json" ) ;
532
604
533
605
Dictionary < string , object > arguments = new Dictionary < string , object >
@@ -536,7 +608,7 @@ public async Task WebHookTrigger_GenericJson()
536
608
} ;
537
609
await Fixture . Host . CallAsync ( "WebHookTrigger" , arguments ) ;
538
610
539
- HttpResponseMessage response = ( HttpResponseMessage ) request . Properties [ "MS_AzureFunctionsHttpResponse" ] ;
611
+ HttpResponseMessage response = ( HttpResponseMessage ) request . Properties [ ScriptConstants . AzureFunctionsHttpResponseKey ] ;
540
612
Assert . Equal ( HttpStatusCode . OK , response . StatusCode ) ;
541
613
542
614
string body = await response . Content . ReadAsStringAsync ( ) ;
0 commit comments