1
1
// Copyright (c) .NET Foundation. All rights reserved.
2
2
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3
3
4
+ using System . Threading . Tasks ;
4
5
using Microsoft . AspNetCore . Http ;
6
+ using Microsoft . AspNetCore . Http . Features ;
5
7
using Xunit ;
6
8
7
9
namespace Microsoft . AspNetCore . Builder . Internal
@@ -20,6 +22,59 @@ public void BuildReturnsCallableDelegate()
20
22
Assert . Equal ( 404 , httpContext . Response . StatusCode ) ;
21
23
}
22
24
25
+ [ Fact ]
26
+ public void BuildImplicitlyCallsMatchedEndpointAsLastStep ( )
27
+ {
28
+ var builder = new ApplicationBuilder ( null ) ;
29
+ var app = builder . Build ( ) ;
30
+
31
+ var endpointCalled = false ;
32
+ var endpoint = new Endpoint (
33
+ context =>
34
+ {
35
+ endpointCalled = true ;
36
+ return Task . CompletedTask ;
37
+ } ,
38
+ EndpointMetadataCollection . Empty ,
39
+ "Test endpoint" ) ;
40
+
41
+ var httpContext = new DefaultHttpContext ( ) ;
42
+ httpContext . SetEndpoint ( endpoint ) ;
43
+
44
+ app . Invoke ( httpContext ) ;
45
+
46
+ Assert . True ( endpointCalled ) ;
47
+ }
48
+
49
+ [ Fact ]
50
+ public void BuildDoesNotCallMatchedEndpointWhenTerminated ( )
51
+ {
52
+ var builder = new ApplicationBuilder ( null ) ;
53
+ builder . Use ( ( context , next ) =>
54
+ {
55
+ // Do not call next
56
+ return Task . CompletedTask ;
57
+ } ) ;
58
+ var app = builder . Build ( ) ;
59
+
60
+ var endpointCalled = false ;
61
+ var endpoint = new Endpoint (
62
+ context =>
63
+ {
64
+ endpointCalled = true ;
65
+ return Task . CompletedTask ;
66
+ } ,
67
+ EndpointMetadataCollection . Empty ,
68
+ "Test endpoint" ) ;
69
+
70
+ var httpContext = new DefaultHttpContext ( ) ;
71
+ httpContext . SetEndpoint ( endpoint ) ;
72
+
73
+ app . Invoke ( httpContext ) ;
74
+
75
+ Assert . False ( endpointCalled ) ;
76
+ }
77
+
23
78
[ Fact ]
24
79
public void PropertiesDictionaryIsDistinctAfterNew ( )
25
80
{
0 commit comments