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,65 @@ 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 . Features . Set < IEndpointFeature > ( new EndpointFeature
43
+ {
44
+ Endpoint = endpoint
45
+ } ) ;
46
+
47
+ app . Invoke ( httpContext ) ;
48
+
49
+ Assert . True ( endpointCalled ) ;
50
+ }
51
+
52
+ [ Fact ]
53
+ public void BuildDoesNotCallMatchedEndpointWhenTerminated ( )
54
+ {
55
+ var builder = new ApplicationBuilder ( null ) ;
56
+ builder . Use ( ( context , next ) =>
57
+ {
58
+ // Do not call next
59
+ return Task . CompletedTask ;
60
+ } ) ;
61
+ var app = builder . Build ( ) ;
62
+
63
+ var endpointCalled = false ;
64
+ var endpoint = new Endpoint (
65
+ context =>
66
+ {
67
+ endpointCalled = true ;
68
+ return Task . CompletedTask ;
69
+ } ,
70
+ EndpointMetadataCollection . Empty ,
71
+ "Test endpoint" ) ;
72
+
73
+ var httpContext = new DefaultHttpContext ( ) ;
74
+ httpContext . Features . Set < IEndpointFeature > ( new EndpointFeature
75
+ {
76
+ Endpoint = endpoint
77
+ } ) ;
78
+
79
+ app . Invoke ( httpContext ) ;
80
+
81
+ Assert . False ( endpointCalled ) ;
82
+ }
83
+
23
84
[ Fact ]
24
85
public void PropertiesDictionaryIsDistinctAfterNew ( )
25
86
{
@@ -31,5 +92,10 @@ public void PropertiesDictionaryIsDistinctAfterNew()
31
92
32
93
Assert . Equal ( "value1" , builder1 . Properties [ "test" ] ) ;
33
94
}
95
+
96
+ private class EndpointFeature : IEndpointFeature
97
+ {
98
+ public Endpoint Endpoint { get ; set ; }
99
+ }
34
100
}
35
101
}
0 commit comments