1010using System . Net . Http ;
1111using System . Net . Http . Headers ;
1212using System . Threading . Tasks ;
13+ using System . Web . Http ;
1314using Microsoft . Azure . WebJobs . Host ;
1415using Microsoft . Azure . WebJobs . Script . Tests . ApiHub ;
1516using Microsoft . WindowsAzure . Storage . Blob ;
@@ -97,6 +98,7 @@ public async Task HttpTrigger_Post_ByteArray()
9798 Method = HttpMethod . Post ,
9899 Content = new ByteArrayContent ( inputBytes )
99100 } ;
101+ request . SetConfiguration ( new HttpConfiguration ( ) ) ;
100102 request . Content . Headers . ContentType = new MediaTypeHeaderValue ( "application/octet-stream" ) ;
101103
102104 Dictionary < string , object > arguments = new Dictionary < string , object >
@@ -105,7 +107,7 @@ public async Task HttpTrigger_Post_ByteArray()
105107 } ;
106108 await Fixture . Host . CallAsync ( "HttpTriggerByteArray" , arguments ) ;
107109
108- HttpResponseMessage response = ( HttpResponseMessage ) request . Properties [ "MS_AzureFunctionsHttpResponse" ] ;
110+ HttpResponseMessage response = ( HttpResponseMessage ) request . Properties [ ScriptConstants . AzureFunctionsHttpResponseKey ] ;
109111 Assert . Equal ( HttpStatusCode . OK , response . StatusCode ) ;
110112
111113 JObject testResult = await GetFunctionTestResult ( "HttpTriggerByteArray" ) ;
@@ -345,15 +347,16 @@ public async Task HttpTrigger_Get()
345347 RequestUri = new Uri ( string . Format ( "http://localhost/api/httptrigger?name=Mathew%20Charles&location=Seattle" ) ) ,
346348 Method = HttpMethod . Get ,
347349 } ;
350+ request . SetConfiguration ( new HttpConfiguration ( ) ) ;
348351 request . Headers . Add ( "test-header" , "Test Request Header" ) ;
349352
350353 Dictionary < string , object > arguments = new Dictionary < string , object >
351354 {
352- { "req " , request }
355+ { "request " , request }
353356 } ;
354357 await Fixture . Host . CallAsync ( "HttpTrigger" , arguments ) ;
355358
356- HttpResponseMessage response = ( HttpResponseMessage ) request . Properties [ "MS_AzureFunctionsHttpResponse" ] ;
359+ HttpResponseMessage response = ( HttpResponseMessage ) request . Properties [ ScriptConstants . AzureFunctionsHttpResponseKey ] ;
357360 Assert . Equal ( HttpStatusCode . OK , response . StatusCode ) ;
358361
359362 Assert . Equal ( "Test Response Header" , response . Headers . GetValues ( "test-header" ) . SingleOrDefault ( ) ) ;
@@ -374,6 +377,71 @@ public async Task HttpTrigger_Get()
374377 Assert . Equal ( "Test Request Header" , reqHeaders [ "test-header" ] ) ;
375378 }
376379
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+
377445 [ Fact ]
378446 public async Task HttpTrigger_Post_PlainText ( )
379447 {
@@ -384,14 +452,15 @@ public async Task HttpTrigger_Post_PlainText()
384452 Method = HttpMethod . Post ,
385453 Content = new StringContent ( testData )
386454 } ;
455+ request . SetConfiguration ( new HttpConfiguration ( ) ) ;
387456
388457 Dictionary < string , object > arguments = new Dictionary < string , object >
389458 {
390- { "req " , request }
459+ { "request " , request }
391460 } ;
392461 await Fixture . Host . CallAsync ( "HttpTrigger" , arguments ) ;
393462
394- HttpResponseMessage response = ( HttpResponseMessage ) request . Properties [ "MS_AzureFunctionsHttpResponse" ] ;
463+ HttpResponseMessage response = ( HttpResponseMessage ) request . Properties [ ScriptConstants . AzureFunctionsHttpResponseKey ] ;
395464 Assert . Equal ( HttpStatusCode . OK , response . StatusCode ) ;
396465
397466 string body = await response . Content . ReadAsStringAsync ( ) ;
@@ -417,15 +486,16 @@ public async Task HttpTrigger_Post_JsonObject()
417486 Method = HttpMethod . Post ,
418487 Content = new StringContent ( rawBody )
419488 } ;
489+ request . SetConfiguration ( new HttpConfiguration ( ) ) ;
420490 request . Content . Headers . ContentType = new MediaTypeHeaderValue ( "application/json" ) ;
421491
422492 Dictionary < string , object > arguments = new Dictionary < string , object >
423493 {
424- { "req " , request }
494+ { "request " , request }
425495 } ;
426496 await Fixture . Host . CallAsync ( "HttpTrigger" , arguments ) ;
427497
428- HttpResponseMessage response = ( HttpResponseMessage ) request . Properties [ "MS_AzureFunctionsHttpResponse" ] ;
498+ HttpResponseMessage response = ( HttpResponseMessage ) request . Properties [ ScriptConstants . AzureFunctionsHttpResponseKey ] ;
429499 Assert . Equal ( HttpStatusCode . OK , response . StatusCode ) ;
430500
431501 string body = await response . Content . ReadAsStringAsync ( ) ;
@@ -487,15 +557,16 @@ public async Task HttpTrigger_Post_JsonArray()
487557 Method = HttpMethod . Post ,
488558 Content = new StringContent ( rawBody )
489559 } ;
560+ request . SetConfiguration ( new HttpConfiguration ( ) ) ;
490561 request . Content . Headers . ContentType = new MediaTypeHeaderValue ( "application/json" ) ;
491562
492563 Dictionary < string , object > arguments = new Dictionary < string , object >
493564 {
494- { "req " , request }
565+ { "request " , request }
495566 } ;
496567 await Fixture . Host . CallAsync ( "HttpTrigger" , arguments ) ;
497568
498- HttpResponseMessage response = ( HttpResponseMessage ) request . Properties [ "MS_AzureFunctionsHttpResponse" ] ;
569+ HttpResponseMessage response = ( HttpResponseMessage ) request . Properties [ ScriptConstants . AzureFunctionsHttpResponseKey ] ;
499570 Assert . Equal ( HttpStatusCode . OK , response . StatusCode ) ;
500571
501572 string body = await response . Content . ReadAsStringAsync ( ) ;
@@ -528,6 +599,7 @@ public async Task WebHookTrigger_GenericJson()
528599 Method = HttpMethod . Post ,
529600 Content = new StringContent ( testObject . ToString ( ) )
530601 } ;
602+ request . SetConfiguration ( new HttpConfiguration ( ) ) ;
531603 request . Content . Headers . ContentType = new MediaTypeHeaderValue ( "application/json" ) ;
532604
533605 Dictionary < string , object > arguments = new Dictionary < string , object >
@@ -536,7 +608,7 @@ public async Task WebHookTrigger_GenericJson()
536608 } ;
537609 await Fixture . Host . CallAsync ( "WebHookTrigger" , arguments ) ;
538610
539- HttpResponseMessage response = ( HttpResponseMessage ) request . Properties [ "MS_AzureFunctionsHttpResponse" ] ;
611+ HttpResponseMessage response = ( HttpResponseMessage ) request . Properties [ ScriptConstants . AzureFunctionsHttpResponseKey ] ;
540612 Assert . Equal ( HttpStatusCode . OK , response . StatusCode ) ;
541613
542614 string body = await response . Content . ReadAsStringAsync ( ) ;
0 commit comments