3
3
4
4
using System ;
5
5
using System . Collections . Generic ;
6
+ using System . Linq ;
6
7
using System . Threading . Tasks ;
7
8
using Microsoft . AspNet . Builder ;
8
9
using Microsoft . Extensions . DependencyInjection ;
11
12
12
13
namespace Microsoft . AspNet . Owin
13
14
{
15
+ using AppFunc = Func < IDictionary < string , object > , Task > ;
14
16
using CreateMiddleware = Func <
15
17
Func < IDictionary < string , object > , Task > ,
16
18
Func < IDictionary < string , object > , Task >
@@ -22,22 +24,32 @@ namespace Microsoft.AspNet.Owin
22
24
23
25
public class OwinExtensionTests
24
26
{
27
+ static AppFunc notFound = async env => env [ "owin.ResponseStatusCode" ] = 404 ;
28
+
25
29
[ Fact ]
26
30
public void OwinConfigureServicesAddsServices ( )
27
31
{
28
- AddMiddleware build = new List < CreateMiddleware > ( ) . Add ;
32
+ IList < CreateMiddleware > list = new List < CreateMiddleware > ( ) ;
33
+ AddMiddleware build = list . Add ;
29
34
IServiceProvider serviceProvider = null ;
35
+ FakeService fakeService = null ;
30
36
31
37
var builder = build . UseBuilder ( applicationBuilder =>
32
38
{
33
39
serviceProvider = applicationBuilder . ApplicationServices ;
34
- }
35
- , serviceCollection =>
40
+ applicationBuilder . Run ( async context =>
41
+ {
42
+ fakeService = context . ApplicationServices . GetService < FakeService > ( ) ;
43
+ } ) ;
44
+ } , serviceCollection =>
36
45
{
37
46
serviceCollection . AddInstance ( new FakeService ( ) ) ;
38
47
} ) ;
39
48
40
- Assert . NotNull ( serviceProvider ) ;
49
+ list . Reverse ( ) . Aggregate ( notFound , ( next , middleware ) => middleware ( next ) ) . Invoke ( new Dictionary < string , object > ( ) ) ;
50
+
51
+ Assert . NotNull ( fakeService ) ;
52
+ Assert . NotNull ( serviceProvider ? . GetService < FakeService > ( ) ) ;
41
53
}
42
54
43
55
public class FakeService
0 commit comments