@@ -12,6 +12,7 @@ namespace Azure.Functions.PowerShell.Tests.E2E
1212
1313 using System . Net . Http ;
1414 using Newtonsoft . Json ;
15+ using System . Text ;
1516
1617 [ Collection ( Constants . FunctionAppCollectionName ) ]
1718 public class DurableEndToEndTests
@@ -201,6 +202,66 @@ public async Task OrchestratationContextHasAllExpectedProperties()
201202 }
202203 }
203204
205+ [ Fact ]
206+ public async Task ExternalEventReturnsData ( )
207+ {
208+ var initialResponse = await Utilities . GetHttpTriggerResponse ( "DurableClient" , queryString : "?FunctionName=DurableOrchestratorRaiseEvent" ) ;
209+ Assert . Equal ( HttpStatusCode . Accepted , initialResponse . StatusCode ) ;
210+
211+ var initialResponseBody = await initialResponse . Content . ReadAsStringAsync ( ) ;
212+ dynamic initialResponseBodyObject = JsonConvert . DeserializeObject ( initialResponseBody ) ;
213+ var statusQueryGetUri = ( string ) initialResponseBodyObject . statusQueryGetUri ;
214+ var raiseEventUri = ( string ) initialResponseBodyObject . sendEventPostUri ;
215+
216+ raiseEventUri = raiseEventUri . Replace ( "{eventName}" , "TESTEVENTNAME" ) ;
217+
218+ var startTime = DateTime . UtcNow ;
219+
220+ using ( var httpClient = new HttpClient ( ) )
221+ {
222+ while ( true )
223+ {
224+ // Send external event payload
225+ var json = JsonConvert . SerializeObject ( "helloWorld!" ) ;
226+ var httpContent = new StringContent ( json , Encoding . UTF8 , "application/json" ) ;
227+ await httpClient . PostAsync ( raiseEventUri , httpContent ) ;
228+
229+ var statusResponse = await httpClient . GetAsync ( statusQueryGetUri ) ;
230+ switch ( statusResponse . StatusCode )
231+ {
232+ case HttpStatusCode . Accepted :
233+ {
234+ var statusResponseBody = await GetResponseBodyAsync ( statusResponse ) ;
235+ var runtimeStatus = ( string ) statusResponseBody . runtimeStatus ;
236+ Assert . True (
237+ runtimeStatus == "Running" || runtimeStatus == "Pending" ,
238+ $ "Unexpected runtime status: { runtimeStatus } ") ;
239+
240+ if ( DateTime . UtcNow > startTime + _orchestrationCompletionTimeout )
241+ {
242+ Assert . True ( false , $ "The orchestration has not completed after { _orchestrationCompletionTimeout } ") ;
243+ }
244+
245+ await Task . Delay ( TimeSpan . FromSeconds ( 2 ) ) ;
246+ break ;
247+ }
248+
249+ case HttpStatusCode . OK :
250+ {
251+ var statusResponseBody = await GetResponseBodyAsync ( statusResponse ) ;
252+ Assert . Equal ( "Completed" , ( string ) statusResponseBody . runtimeStatus ) ;
253+ Assert . Equal ( "helloWorld!" , statusResponseBody . output . ToString ( ) ) ;
254+ return ;
255+ }
256+
257+ default :
258+ Assert . True ( false , $ "Unexpected orchestration status code: { statusResponse . StatusCode } ") ;
259+ break ;
260+ }
261+ }
262+ }
263+ }
264+
204265 [ Fact ]
205266 public async Task ActivityCanHaveQueueBinding ( )
206267 {
0 commit comments