@@ -581,24 +581,47 @@ public async Task RequestDelegateWritesComplexReturnValueAsJsonResponseBody(Dele
581581 Assert . Equal ( "Write even more tests!" , deserializedResponseBody ! . Name ) ;
582582 }
583583
584- [ Fact ]
585- public async Task RequestDelegateUsesCustomIResult ( )
584+ public static IEnumerable < object [ ] > CustomResults
586585 {
587- var resultString = "Still not enough tests!" ;
586+ get
587+ {
588+ var resultString = "Still not enough tests!" ;
589+
590+ CustomResult TestAction ( ) => new CustomResult ( resultString ) ;
591+ Task < CustomResult > TaskTestAction ( ) => Task . FromResult ( new CustomResult ( resultString ) ) ;
592+ ValueTask < CustomResult > ValueTaskTestAction ( ) => ValueTask . FromResult ( new CustomResult ( resultString ) ) ;
588593
589- CustomResult TestAction ( ) => new ( resultString ! ) ;
594+ static CustomResult StaticTestAction ( ) => new CustomResult ( "Still not enough tests!" ) ;
595+ static Task < CustomResult > StaticTaskTestAction ( ) => Task . FromResult ( new CustomResult ( "Still not enough tests!" ) ) ;
596+ static ValueTask < CustomResult > StaticValueTaskTestAction ( ) => ValueTask . FromResult ( new CustomResult ( "Still not enough tests!" ) ) ;
590597
598+ return new List < object [ ] >
599+ {
600+ new object [ ] { ( Func < CustomResult > ) TestAction } ,
601+ new object [ ] { ( Func < Task < CustomResult > > ) TaskTestAction } ,
602+ new object [ ] { ( Func < ValueTask < CustomResult > > ) ValueTaskTestAction } ,
603+ new object [ ] { ( Func < CustomResult > ) StaticTestAction } ,
604+ new object [ ] { ( Func < Task < CustomResult > > ) StaticTaskTestAction } ,
605+ new object [ ] { ( Func < ValueTask < CustomResult > > ) StaticValueTaskTestAction } ,
606+ } ;
607+ }
608+ }
609+
610+ [ Theory ]
611+ [ MemberData ( nameof ( CustomResults ) ) ]
612+ public async Task RequestDelegateUsesCustomIResult ( Delegate @delegate )
613+ {
591614 var httpContext = new DefaultHttpContext ( ) ;
592615 var responseBodyStream = new MemoryStream ( ) ;
593616 httpContext . Response . Body = responseBodyStream ;
594617
595- var requestDelegate = MapActionExpressionTreeBuilder . BuildRequestDelegate ( ( Func < CustomResult > ) TestAction ) ;
618+ var requestDelegate = MapActionExpressionTreeBuilder . BuildRequestDelegate ( @delegate ) ;
596619
597620 await requestDelegate ( httpContext ) ;
598621
599622 var decodedResponseBody = Encoding . UTF8 . GetString ( responseBodyStream . ToArray ( ) ) ;
600623
601- Assert . Equal ( resultString , decodedResponseBody ) ;
624+ Assert . Equal ( "Still not enough tests!" , decodedResponseBody ) ;
602625 }
603626
604627 private class Todo
0 commit comments