-
Notifications
You must be signed in to change notification settings - Fork 10k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add explicit conversion for value-type returning handlers with filters (
- Loading branch information
1 parent
7db360c
commit 53ba80b
Showing
2 changed files
with
103 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
98 changes: 98 additions & 0 deletions
98
src/Http/Http.Extensions/test/RequestDelegateFactoryTests.EndpointFilters.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using Microsoft.AspNetCore.Http; | ||
using Microsoft.AspNetCore.InternalTesting; | ||
|
||
namespace Microsoft.AspNetCore.Routing.Internal; | ||
|
||
public partial class RequestDelegateFactoryTests : LoggedTest | ||
{ | ||
public static object[][] ValueTypeReturningDelegates => | ||
[ | ||
[(Func<HttpContext, int>)((HttpContext httpContext) => 42)], | ||
[(Func<HttpContext, char>)((HttpContext httpContext) => 'b')], | ||
[(Func<HttpContext, bool>)((HttpContext httpContext) => true)], | ||
[(Func<HttpContext, float>)((HttpContext httpContext) => 4.2f)], | ||
[(Func<HttpContext, double>)((HttpContext httpContext) => 4.2)], | ||
[(Func<HttpContext, decimal>)((HttpContext httpContext) => 4.2m)], | ||
[(Func<HttpContext, long>)((HttpContext httpContext) => 42)], | ||
[(Func<HttpContext, short>)((HttpContext httpContext) => 42)], | ||
[(Func<HttpContext, byte>)((HttpContext httpContext) => 42)], | ||
[(Func<HttpContext, uint>)((HttpContext httpContext) => 42)], | ||
[(Func<HttpContext, ulong>)((HttpContext httpContext) => 42)], | ||
[(Func<HttpContext, ushort>)((HttpContext httpContext) => 42)], | ||
[(Func<HttpContext, sbyte>)((HttpContext httpContext) => 42)] | ||
]; | ||
|
||
[Theory] | ||
[MemberData(nameof(ValueTypeReturningDelegates))] | ||
public void Create_WithEndpointFilterOnBuiltInValueTypeReturningDelegate_Works(Delegate @delegate) | ||
{ | ||
var invokeCount = 0; | ||
|
||
RequestDelegateFactoryOptions options = new() | ||
{ | ||
EndpointBuilder = CreateEndpointBuilderFromFilterFactories( | ||
[ | ||
(routeHandlerContext, next) => | ||
{ | ||
invokeCount++; | ||
return next; | ||
}, | ||
(routeHandlerContext, next) => | ||
{ | ||
invokeCount++; | ||
return next; | ||
}, | ||
]), | ||
}; | ||
|
||
var result = RequestDelegateFactory.Create(@delegate, options); | ||
Assert.Equal(2, invokeCount); | ||
} | ||
|
||
public static object[][] NullableValueTypeReturningDelegates => | ||
[ | ||
[(Func<HttpContext, int?>)((HttpContext httpContext) => 42)], | ||
[(Func<HttpContext, char?>)((HttpContext httpContext) => 'b')], | ||
[(Func<HttpContext, bool?>)((HttpContext httpContext) => true)], | ||
[(Func<HttpContext, float?>)((HttpContext httpContext) => 4.2f)], | ||
[(Func<HttpContext, double?>)((HttpContext httpContext) => 4.2)], | ||
[(Func<HttpContext, decimal?>)((HttpContext httpContext) => 4.2m)], | ||
[(Func<HttpContext, long?>)((HttpContext httpContext) => 42)], | ||
[(Func<HttpContext, short?>)((HttpContext httpContext) => 42)], | ||
[(Func<HttpContext, byte?>)((HttpContext httpContext) => 42)], | ||
[(Func<HttpContext, uint?>)((HttpContext httpContext) => 42)], | ||
[(Func<HttpContext, ulong?>)((HttpContext httpContext) => 42)], | ||
[(Func<HttpContext, ushort?>)((HttpContext httpContext) => 42)], | ||
[(Func<HttpContext, sbyte?>)((HttpContext httpContext) => 42)] | ||
]; | ||
|
||
[Theory] | ||
[MemberData(nameof(NullableValueTypeReturningDelegates))] | ||
public void Create_WithEndpointFilterOnNullableBuiltInValueTypeReturningDelegate_Works(Delegate @delegate) | ||
{ | ||
var invokeCount = 0; | ||
|
||
RequestDelegateFactoryOptions options = new() | ||
{ | ||
EndpointBuilder = CreateEndpointBuilderFromFilterFactories( | ||
[ | ||
(routeHandlerContext, next) => | ||
{ | ||
invokeCount++; | ||
return next; | ||
}, | ||
(routeHandlerContext, next) => | ||
{ | ||
invokeCount++; | ||
return next; | ||
}, | ||
]), | ||
}; | ||
|
||
var result = RequestDelegateFactory.Create(@delegate, options); | ||
Assert.Equal(2, invokeCount); | ||
} | ||
} |