|
1 | 1 | // Licensed to the .NET Foundation under one or more agreements.
|
2 | 2 | // The .NET Foundation licenses this file to you under the MIT license.
|
3 | 3 |
|
| 4 | +using System.IO.Pipelines; |
4 | 5 | using System.Linq.Expressions;
|
| 6 | +using System.Text; |
5 | 7 | using Microsoft.AspNetCore.Http;
|
| 8 | +using Microsoft.AspNetCore.Http.Features; |
6 | 9 | using Microsoft.AspNetCore.Routing;
|
7 | 10 | using Microsoft.AspNetCore.Routing.Patterns;
|
| 11 | +using Microsoft.Extensions.DependencyInjection; |
| 12 | +using Microsoft.Extensions.Logging; |
8 | 13 | using Moq;
|
9 | 14 |
|
10 | 15 | namespace Microsoft.AspNetCore.Builder;
|
@@ -69,6 +74,30 @@ public void MapEndpoint_StringPattern_BuildsEndpoint()
|
69 | 74 | Assert.Equal("/", endpointBuilder1.RoutePattern.RawText);
|
70 | 75 | }
|
71 | 76 |
|
| 77 | + [Fact] |
| 78 | + public async Task MapEndpoint_ReturnGenericTypeTask_GeneratedDelegate() |
| 79 | + { |
| 80 | + var httpContext = new DefaultHttpContext(); |
| 81 | + var responseBodyStream = new MemoryStream(); |
| 82 | + httpContext.Response.Body = responseBodyStream; |
| 83 | + |
| 84 | + // Arrange |
| 85 | + var builder = new DefaultEndpointRouteBuilder(Mock.Of<IApplicationBuilder>()); |
| 86 | + static async Task<string> GenericTypeTaskDelegate(HttpContext context) => await Task.FromResult("String Test"); |
| 87 | + |
| 88 | + // Act |
| 89 | + var endpointBuilder = builder.MapGet("/", GenericTypeTaskDelegate); |
| 90 | + |
| 91 | + // Assert |
| 92 | + var endpointBuilder1 = GetRouteEndpointBuilder(builder); |
| 93 | + var requestDelegate = endpointBuilder1.RequestDelegate; |
| 94 | + await requestDelegate(httpContext); |
| 95 | + |
| 96 | + var responseBody = Encoding.UTF8.GetString(responseBodyStream.ToArray()); |
| 97 | + |
| 98 | + Assert.Equal("String Test", responseBody); |
| 99 | + } |
| 100 | + |
72 | 101 | [Fact]
|
73 | 102 | public void MapEndpoint_TypedPattern_BuildsEndpoint()
|
74 | 103 | {
|
|
0 commit comments