-
Notifications
You must be signed in to change notification settings - Fork 10k
/
RequestDelegateEndpointRouteBuilderExtensionsTest.cs
599 lines (478 loc) · 23 KB
/
RequestDelegateEndpointRouteBuilderExtensionsTest.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
#nullable enable
using System.Linq.Expressions;
using System.Reflection;
using System.Text;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.HttpResults;
using Microsoft.AspNetCore.Http.Metadata;
using Microsoft.AspNetCore.Routing;
using Microsoft.AspNetCore.Routing.Patterns;
using Microsoft.Extensions.Primitives;
namespace Microsoft.AspNetCore.Builder;
public class RequestDelegateEndpointRouteBuilderExtensionsTest
{
private EndpointDataSource GetBuilderEndpointDataSource(IEndpointRouteBuilder endpointRouteBuilder) =>
Assert.Single(endpointRouteBuilder.DataSources);
private RouteEndpointBuilder GetRouteEndpointBuilder(IEndpointRouteBuilder endpointRouteBuilder) =>
GetBuilderEndpointDataSource(endpointRouteBuilder) switch
{
RouteEndpointDataSource routeDataSource => routeDataSource.GetSingleRouteEndpointBuilder(),
_ => throw new InvalidOperationException($"Unknown EndointDataSource type!"),
};
public static object[][] MapMethods
{
get
{
IEndpointConventionBuilder MapGet(IEndpointRouteBuilder routes, string template, RequestDelegate action) =>
routes.MapGet(template, action);
IEndpointConventionBuilder MapPost(IEndpointRouteBuilder routes, string template, RequestDelegate action) =>
routes.MapPost(template, action);
IEndpointConventionBuilder MapPut(IEndpointRouteBuilder routes, string template, RequestDelegate action) =>
routes.MapPut(template, action);
IEndpointConventionBuilder MapDelete(IEndpointRouteBuilder routes, string template, RequestDelegate action) =>
routes.MapDelete(template, action);
IEndpointConventionBuilder Map(IEndpointRouteBuilder routes, string template, RequestDelegate action) =>
routes.Map(template, action);
return new object[][]
{
new object[] { (Func<IEndpointRouteBuilder, string, RequestDelegate, IEndpointConventionBuilder>)MapGet },
new object[] { (Func<IEndpointRouteBuilder, string, RequestDelegate, IEndpointConventionBuilder>)MapPost },
new object[] { (Func<IEndpointRouteBuilder, string, RequestDelegate, IEndpointConventionBuilder>)MapPut },
new object[] { (Func<IEndpointRouteBuilder, string, RequestDelegate, IEndpointConventionBuilder>)MapDelete },
new object[] { (Func<IEndpointRouteBuilder, string, RequestDelegate, IEndpointConventionBuilder>)Map },
};
}
}
[Fact]
public void MapEndpoint_StringPattern_BuildsEndpoint()
{
// Arrange
var builder = new DefaultEndpointRouteBuilder(new ApplicationBuilder(EmptyServiceProvider.Instance));
RequestDelegate requestDelegate = (d) => Task.CompletedTask;
// Act
var endpointBuilder = builder.Map("/", requestDelegate);
// Assert
var endpointBuilder1 = GetRouteEndpointBuilder(builder);
Assert.Equal(requestDelegate, endpointBuilder1.RequestDelegate);
Assert.Equal("/", endpointBuilder1.DisplayName);
Assert.Equal("/", endpointBuilder1.RoutePattern.RawText);
}
[Theory]
[MemberData(nameof(MapMethods))]
public async Task MapEndpoint_ReturnGenericTypeTask_GeneratedDelegate(Func<IEndpointRouteBuilder, string, RequestDelegate, IEndpointConventionBuilder> map)
{
var httpContext = new DefaultHttpContext();
var responseBodyStream = new MemoryStream();
httpContext.Response.Body = responseBodyStream;
// Arrange
var builder = new DefaultEndpointRouteBuilder(new ApplicationBuilder(EmptyServiceProvider.Instance));
static async Task<string> GenericTypeTaskDelegate(HttpContext context)
{
await context.Response.WriteAsync("Response string text");
return await Task.FromResult("String Test");
}
// Act
var endpointBuilder = map(builder, "/", GenericTypeTaskDelegate);
// Assert
var dataSource = GetBuilderEndpointDataSource(builder);
var endpoint = Assert.Single(dataSource.Endpoints); // Triggers build and construction of delegate
Assert.NotNull(endpoint.RequestDelegate);
var requestDelegate = endpoint.RequestDelegate!;
await requestDelegate(httpContext);
var responseBody = Encoding.UTF8.GetString(responseBodyStream.ToArray());
Assert.Equal("Response string text", responseBody);
}
[Theory]
[MemberData(nameof(MapMethods))]
public async Task MapEndpoint_CanBeFiltered_EndpointFilterFactory(Func<IEndpointRouteBuilder, string, RequestDelegate, IEndpointConventionBuilder> map)
{
var builder = new DefaultEndpointRouteBuilder(new ApplicationBuilder(EmptyServiceProvider.Instance));
var httpContext = new DefaultHttpContext();
var responseBodyStream = new MemoryStream();
httpContext.Response.Body = responseBodyStream;
RequestDelegate initialRequestDelegate = static (context) => Task.CompletedTask;
var endpointBuilder = map(builder, "/", initialRequestDelegate).AddEndpointFilterFactory(filterFactory: (routeHandlerContext, next) =>
{
return async invocationContext =>
{
Assert.IsAssignableFrom<HttpContext>(Assert.Single(invocationContext.Arguments));
// Ignore thre result and write filtered because we can!
_ = await next(invocationContext);
return "filtered!";
};
});
var dataSource = GetBuilderEndpointDataSource(builder);
var endpoint = Assert.Single(dataSource.Endpoints);
Assert.NotSame(initialRequestDelegate, endpoint.RequestDelegate);
Assert.NotNull(endpoint.RequestDelegate);
var requestDelegate = endpoint.RequestDelegate!;
await requestDelegate(httpContext);
var responseBody = Encoding.UTF8.GetString(responseBodyStream.ToArray());
Assert.Equal("filtered!", responseBody);
}
[Fact]
public async Task MapEndpoint_CanBeFiltered_EndpointFilter()
{
var builder = new DefaultEndpointRouteBuilder(new ApplicationBuilder(EmptyServiceProvider.Instance));
var httpContext = new DefaultHttpContext();
var responseBodyStream = new MemoryStream();
httpContext.Response.Body = responseBodyStream;
RequestDelegate initialRequestDelegate = static (context) => Task.CompletedTask;
var endpointBuilder = builder.Map("/", initialRequestDelegate)
.AddEndpointFilter(new HttpContextArgFilter("First"))
.AddEndpointFilter(new HttpContextArgFilter("Second"));
var dataSource = GetBuilderEndpointDataSource(builder);
var endpoint = Assert.Single(dataSource.Endpoints);
Assert.NotSame(initialRequestDelegate, endpoint.RequestDelegate);
Assert.NotNull(endpoint.RequestDelegate);
var requestDelegate = endpoint.RequestDelegate!;
await requestDelegate(httpContext);
var responseBody = Encoding.UTF8.GetString(responseBodyStream.ToArray());
Assert.Equal("filtered!", responseBody);
Assert.Equal(1, (int)httpContext.Items["First-Order"]!);
Assert.Equal(2, (int)httpContext.Items["Second-Order"]!);
}
[Fact]
public async Task MapEndpoint_Filtered_DontExecuteEndpointWhenErrorResponseStatus()
{
var builder = new DefaultEndpointRouteBuilder(new ApplicationBuilder(EmptyServiceProvider.Instance));
var httpContext = new DefaultHttpContext();
var responseBodyStream = new MemoryStream();
httpContext.Response.Body = responseBodyStream;
RequestDelegate initialRequestDelegate = static (context) =>
{
context.Items["ExecutedEndpoint"] = true;
throw new Exception("Shouldn't reach here.");
};
var endpointBuilder = builder.Map("/", initialRequestDelegate)
.AddEndpointFilterFactory(filterFactory: (routeHandlerContext, next) =>
{
return async invocationContext =>
{
var httpContext = Assert.IsAssignableFrom<HttpContext>(Assert.Single(invocationContext.Arguments));
httpContext.Items["First"] = true;
httpContext.Response.StatusCode = 400;
return await next(invocationContext);
};
})
.AddEndpointFilterFactory(filterFactory: (routeHandlerContext, next) =>
{
return invocationContext =>
{
var httpContext = Assert.IsAssignableFrom<HttpContext>(Assert.Single(invocationContext.Arguments));
httpContext.Items["Second"] = true;
return next(invocationContext);
};
});
var dataSource = GetBuilderEndpointDataSource(builder);
var endpoint = Assert.Single(dataSource.Endpoints);
Assert.NotSame(initialRequestDelegate, endpoint.RequestDelegate);
Assert.NotNull(endpoint.RequestDelegate);
var requestDelegate = endpoint.RequestDelegate!;
await requestDelegate(httpContext);
Assert.True((bool)httpContext.Items["First"]!);
Assert.True((bool)httpContext.Items["Second"]!);
Assert.False(httpContext.Items.ContainsKey("ExecutedEndpoint"));
}
[Fact]
public async Task RequestFilters_CanAssertOnEmptyResult()
{
var builder = new DefaultEndpointRouteBuilder(new ApplicationBuilder(EmptyServiceProvider.Instance));
var httpContext = new DefaultHttpContext();
var responseBodyStream = new MemoryStream();
httpContext.Response.Body = responseBodyStream;
var @delegate = (HttpContext context) => context.Items.Add("param", "Value");
object? response = null;
var endpointBuilder = builder.Map("/", @delegate)
.AddEndpointFilterFactory(filterFactory: (routeHandlerContext, next) =>
{
return async invocationContext =>
{
response = await next(invocationContext);
return response;
};
});
var dataSource = GetBuilderEndpointDataSource(builder);
var endpoint = Assert.Single(dataSource.Endpoints);
httpContext.Request.Query = new QueryCollection(new Dictionary<string, StringValues>
{
["name"] = "Tester"
});
await endpoint.RequestDelegate!(httpContext);
Assert.IsType<EmptyHttpResult>(response);
Assert.Same(Results.Empty, response);
}
[Fact]
public async Task RequestFilters_ReturnValue_SerializeJson()
{
var builder = new DefaultEndpointRouteBuilder(new ApplicationBuilder(EmptyServiceProvider.Instance));
var httpContext = new DefaultHttpContext();
var responseBodyStream = new MemoryStream();
httpContext.Response.Body = responseBodyStream;
RequestDelegate requestDelegate = (HttpContext context) => Task.CompletedTask;
var endpointBuilder = builder.Map("/", requestDelegate)
.AddEndpointFilterFactory(filterFactory: (routeHandlerContext, next) =>
{
return async invocationContext =>
{
await next(invocationContext);
return new MyCoolType(Name: "你好"); // serialized as JSON
};
});
var dataSource = GetBuilderEndpointDataSource(builder);
var endpoint = Assert.Single(dataSource.Endpoints);
await endpoint.RequestDelegate!(httpContext);
var responseBody = Encoding.UTF8.GetString(responseBodyStream.ToArray());
Assert.Equal(@"{""name"":""你好""}", responseBody);
}
private record struct MyCoolType(string Name);
private sealed class HttpContextArgFilter : IEndpointFilter
{
private readonly string _name;
public HttpContextArgFilter(string name)
{
_name = name;
}
public async ValueTask<object?> InvokeAsync(EndpointFilterInvocationContext context, EndpointFilterDelegate next)
{
if (context.Arguments[0] is HttpContext httpContext)
{
int order;
if (httpContext.Items["CurrentOrder"] is int)
{
order = (int)httpContext.Items["CurrentOrder"]!;
order++;
httpContext.Items["CurrentOrder"] = order;
}
else
{
order = 1;
httpContext.Items["CurrentOrder"] = order;
}
httpContext.Items[$"{_name}-Order"] = order;
}
// Ignore thre result and write filtered because we can!
_ = await next(context);
return "filtered!";
}
}
[Theory]
[MemberData(nameof(MapMethods))]
public void MapEndpoint_UsesOriginalRequestDelegateInstance_IfFilterDoesNotChangePerRequestBehavior(Func<IEndpointRouteBuilder, string, RequestDelegate, IEndpointConventionBuilder> map)
{
var builder = new DefaultEndpointRouteBuilder(new ApplicationBuilder(EmptyServiceProvider.Instance));
RequestDelegate initialRequestDelegate = static (context) => Task.CompletedTask;
var runCount = 0;
var endpointBuilder = map(builder, "/", initialRequestDelegate).AddEndpointFilterFactory((routeHandlerContext, next) =>
{
runCount++;
return next;
});
var dataSource = GetBuilderEndpointDataSource(builder);
var endpoint = Assert.Single(dataSource.Endpoints);
Assert.Same(initialRequestDelegate, endpoint.RequestDelegate);
Assert.Equal(1, runCount);
}
[Fact]
public void MapEndpoint_TypedPattern_BuildsEndpoint()
{
// Arrange
var builder = new DefaultEndpointRouteBuilder(new ApplicationBuilder(EmptyServiceProvider.Instance));
RequestDelegate requestDelegate = (d) => Task.CompletedTask;
// Act
var endpointBuilder = builder.Map(RoutePatternFactory.Parse("/"), requestDelegate);
// Assert
var endpointBuilder1 = GetRouteEndpointBuilder(builder);
Assert.Equal(requestDelegate, endpointBuilder1.RequestDelegate);
Assert.Equal("/", endpointBuilder1.DisplayName);
Assert.Equal("/", endpointBuilder1.RoutePattern.RawText);
}
[Fact]
public void MapEndpoint_AttributesCollectedAsMetadata()
{
// Arrange
var builder = new DefaultEndpointRouteBuilder(new ApplicationBuilder(EmptyServiceProvider.Instance));
// Act
var endpointBuilder = builder.Map(RoutePatternFactory.Parse("/"), Handle);
// Assert
var endpointBuilder1 = GetRouteEndpointBuilder(builder);
Assert.Equal("/", endpointBuilder1.RoutePattern.RawText);
Assert.Equal(2, endpointBuilder1.Metadata.Count);
Assert.IsType<Attribute1>(endpointBuilder1.Metadata[0]);
Assert.IsType<Attribute2>(endpointBuilder1.Metadata[1]);
}
[Fact]
public void MapEndpoint_GeneratedDelegateWorks()
{
// Arrange
var builder = new DefaultEndpointRouteBuilder(new ApplicationBuilder(EmptyServiceProvider.Instance));
Expression<RequestDelegate> handler = context => Task.CompletedTask;
// Act
var endpointBuilder = builder.Map(RoutePatternFactory.Parse("/"), handler.Compile());
// Assert
var endpointBuilder1 = GetRouteEndpointBuilder(builder);
Assert.Equal("/", endpointBuilder1.RoutePattern.RawText);
}
[Fact]
public void MapEndpoint_PrecedenceOfMetadata_BuilderMetadataReturned()
{
// Arrange
var builder = new DefaultEndpointRouteBuilder(new ApplicationBuilder(EmptyServiceProvider.Instance));
// Act
var endpointBuilder = builder.MapMethods("/", new[] { "METHOD" }, HandleHttpMetdata);
endpointBuilder.WithMetadata(new HttpMethodMetadata(new[] { "BUILDER" }));
// Assert
var dataSource = Assert.Single(builder.DataSources);
var endpoint = Assert.Single(dataSource.Endpoints);
// As with the Delegate Map method overloads for route handlers, the attributes on the RequestDelegate
// can override the HttpMethodMetadata. Extension methods could already do this.
Assert.Equal(4, endpoint.Metadata.Count);
Assert.Equal("METHOD", GetMethod(endpoint.Metadata[0]));
Assert.Equal("ATTRIBUTE", GetMethod(endpoint.Metadata[1]));
Assert.Equal("BUILDER", GetMethod(endpoint.Metadata[2]));
Assert.IsAssignableFrom<IRouteDiagnosticsMetadata>(endpoint.Metadata[3]);
Assert.Equal("BUILDER", endpoint.Metadata.GetMetadata<IHttpMethodMetadata>()?.HttpMethods.Single());
string GetMethod(object metadata)
{
var httpMethodMetadata = Assert.IsAssignableFrom<IHttpMethodMetadata>(metadata);
return Assert.Single(httpMethodMetadata.HttpMethods);
}
}
[Theory]
[MemberData(nameof(MapMethods))]
public void Map_EndpointMetadataNotDuplicated(Func<IEndpointRouteBuilder, string, RequestDelegate, IEndpointConventionBuilder> map)
{
// Arrange
var builder = new DefaultEndpointRouteBuilder(new ApplicationBuilder(EmptyServiceProvider.Instance));
// Act
var endpointBuilder = map(builder, "/", context => Task.CompletedTask).WithMetadata(new EndpointNameMetadata("MapMe"));
// Assert
var ds = GetBuilderEndpointDataSource(builder);
_ = ds.Endpoints;
_ = ds.Endpoints;
_ = ds.Endpoints;
Assert.Single(ds.Endpoints);
var endpoint = ds.Endpoints.Single();
Assert.Single(endpoint.Metadata.GetOrderedMetadata<IEndpointNameMetadata>());
}
[Theory]
[MemberData(nameof(MapMethods))]
public void AddingMetadataAfterBuildingEndpointThrows(Func<IEndpointRouteBuilder, string, RequestDelegate, IEndpointConventionBuilder> map)
{
// Arrange
var builder = new DefaultEndpointRouteBuilder(new ApplicationBuilder(EmptyServiceProvider.Instance));
// Act
var endpointBuilder = map(builder, "/", context => Task.CompletedTask).WithMetadata(new EndpointNameMetadata("MapMe"));
// Assert
var ds = GetBuilderEndpointDataSource(builder);
var endpoint = Assert.Single(ds.Endpoints);
Assert.Single(endpoint.Metadata.GetOrderedMetadata<IEndpointNameMetadata>());
Assert.Throws<InvalidOperationException>(() => endpointBuilder.WithMetadata(new RouteNameMetadata("Foo")));
Assert.Throws<InvalidOperationException>(() => endpointBuilder.Finally(b => b.Metadata.Add(new RouteNameMetadata("Foo"))));
}
[Fact]
public void Map_AddsMetadata_InCorrectOrder()
{
// Arrange
var builder = new DefaultEndpointRouteBuilder(new ApplicationBuilder(EmptyServiceProvider.Instance));
var @delegate = [Attribute1, Attribute2] (AddsCustomParameterMetadata param1) => new AddsCustomEndpointMetadataResult();
// Act
builder.Map("/test", @delegate);
// Assert
var ds = GetBuilderEndpointDataSource(builder);
var endpoint = Assert.Single(ds.Endpoints);
var metadata = endpoint.Metadata;
Assert.Collection(metadata,
m => Assert.IsAssignableFrom<MethodInfo>(m),
m => Assert.IsAssignableFrom<IParameterBindingMetadata>(m),
m => Assert.IsAssignableFrom<ParameterNameMetadata>(m),
m =>
{
Assert.IsAssignableFrom<CustomEndpointMetadata>(m);
Assert.Equal(MetadataSource.Parameter, ((CustomEndpointMetadata)m).Source);
},
m =>
{
Assert.IsAssignableFrom<CustomEndpointMetadata>(m);
Assert.Equal(MetadataSource.ReturnType, ((CustomEndpointMetadata)m).Source);
},
m => Assert.Equal("System.Runtime.CompilerServices.NullableContextAttribute", m.ToString()),
m => Assert.IsAssignableFrom<Attribute1>(m),
m => Assert.IsAssignableFrom<Attribute2>(m),
m => Assert.IsAssignableFrom<IRouteDiagnosticsMetadata>(m));
}
[Fact]
public void MapEndpoint_Filter()
{
// Arrange
var builder = new DefaultEndpointRouteBuilder(new ApplicationBuilder(EmptyServiceProvider.Instance));
// Act
var endpointBuilder = builder
.Map(RoutePatternFactory.Parse("/"), context => Task.CompletedTask)
.AddEndpointFilter(new HttpContextArgFilter(""));
// Assert
var endpointBuilder1 = GetRouteEndpointBuilder(builder);
Assert.Equal("/", endpointBuilder1.RoutePattern.RawText);
}
[Attribute1]
[Attribute2]
private static Task Handle(HttpContext context) => Task.CompletedTask;
[HttpMethod("ATTRIBUTE")]
private static Task HandleHttpMetdata(HttpContext context) => Task.CompletedTask;
private class HttpMethodAttribute : Attribute, IHttpMethodMetadata
{
public bool AcceptCorsPreflight => false;
public IReadOnlyList<string> HttpMethods { get; }
public HttpMethodAttribute(params string[] httpMethods)
{
HttpMethods = httpMethods;
}
}
private class Attribute1 : Attribute
{
}
private class Attribute2 : Attribute
{
}
private class AddsCustomEndpointMetadataResult : IEndpointMetadataProvider, IResult
{
public static void PopulateMetadata(MethodInfo method, EndpointBuilder builder)
{
builder.Metadata.Add(new CustomEndpointMetadata { Source = MetadataSource.ReturnType });
}
public Task ExecuteAsync(HttpContext httpContext) => throw new NotImplementedException();
}
private class AddsCustomParameterMetadata : IEndpointParameterMetadataProvider, IEndpointMetadataProvider
{
public static ValueTask<AddsCustomParameterMetadata?> BindAsync(HttpContext context, ParameterInfo parameter) => default;
public static void PopulateMetadata(ParameterInfo parameter, EndpointBuilder builder)
{
builder.Metadata.Add(new ParameterNameMetadata { Name = parameter.Name ?? string.Empty });
}
public static void PopulateMetadata(MethodInfo method, EndpointBuilder builder)
{
builder.Metadata.Add(new CustomEndpointMetadata { Source = MetadataSource.Parameter });
}
}
private class ParameterNameMetadata
{
public string Name { get; init; } = string.Empty;
}
private class CustomEndpointMetadata
{
public string Data { get; init; } = string.Empty;
public MetadataSource Source { get; init; }
}
private enum MetadataSource
{
Parameter,
ReturnType
}
private sealed class EmptyServiceProvider : IServiceProvider
{
public static EmptyServiceProvider Instance { get; } = new EmptyServiceProvider();
public object? GetService(Type serviceType) => null;
}
}