8
8
using System . Linq ;
9
9
using System . Runtime . CompilerServices ;
10
10
using Microsoft . AspNetCore . Routing ;
11
+ using Microsoft . Extensions . DependencyInjection ;
11
12
using Moq ;
12
13
using Xunit ;
13
14
@@ -28,7 +29,7 @@ private RouteEndpointBuilder GetRouteEndpointBuilder(IEndpointRouteBuilder endpo
28
29
[ Fact ]
29
30
public void MapEndpoint_PrecedenceOfMetadata_BuilderMetadataReturned ( )
30
31
{
31
- var builder = new DefaultEndpointRouteBuilder ( Mock . Of < IApplicationBuilder > ( ) ) ;
32
+ var builder = new DefaultEndpointRouteBuilder ( new ApplicationBuilder ( new EmptyServiceProvdier ( ) ) ) ;
32
33
33
34
[ HttpMethod ( "ATTRIBUTE" ) ]
34
35
void TestAction ( )
@@ -60,7 +61,7 @@ string GetMethod(object metadata)
60
61
[ Fact ]
61
62
public void MapGet_BuildsEndpointWithCorrectMethod ( )
62
63
{
63
- var builder = new DefaultEndpointRouteBuilder ( Mock . Of < IApplicationBuilder > ( ) ) ;
64
+ var builder = new DefaultEndpointRouteBuilder ( new ApplicationBuilder ( new EmptyServiceProvdier ( ) ) ) ;
64
65
_ = builder . MapGet ( "/" , ( Action ) ( ( ) => { } ) ) ;
65
66
66
67
var dataSource = GetBuilderEndpointDataSource ( builder ) ;
@@ -80,7 +81,7 @@ public void MapGet_BuildsEndpointWithCorrectMethod()
80
81
[ Fact ]
81
82
public void MapPost_BuildsEndpointWithCorrectMethod ( )
82
83
{
83
- var builder = new DefaultEndpointRouteBuilder ( Mock . Of < IApplicationBuilder > ( ) ) ;
84
+ var builder = new DefaultEndpointRouteBuilder ( new ApplicationBuilder ( new EmptyServiceProvdier ( ) ) ) ;
84
85
_ = builder . MapPost ( "/" , ( Action ) ( ( ) => { } ) ) ;
85
86
86
87
var dataSource = GetBuilderEndpointDataSource ( builder ) ;
@@ -100,7 +101,7 @@ public void MapPost_BuildsEndpointWithCorrectMethod()
100
101
[ Fact ]
101
102
public void MapPut_BuildsEndpointWithCorrectMethod ( )
102
103
{
103
- var builder = new DefaultEndpointRouteBuilder ( Mock . Of < IApplicationBuilder > ( ) ) ;
104
+ var builder = new DefaultEndpointRouteBuilder ( new ApplicationBuilder ( new EmptyServiceProvdier ( ) ) ) ;
104
105
_ = builder . MapPut ( "/" , ( Action ) ( ( ) => { } ) ) ;
105
106
106
107
var dataSource = GetBuilderEndpointDataSource ( builder ) ;
@@ -120,7 +121,7 @@ public void MapPut_BuildsEndpointWithCorrectMethod()
120
121
[ Fact ]
121
122
public void MapDelete_BuildsEndpointWithCorrectMethod ( )
122
123
{
123
- var builder = new DefaultEndpointRouteBuilder ( Mock . Of < IApplicationBuilder > ( ) ) ;
124
+ var builder = new DefaultEndpointRouteBuilder ( new ApplicationBuilder ( new EmptyServiceProvdier ( ) ) ) ;
124
125
_ = builder . MapDelete ( "/" , ( Action ) ( ( ) => { } ) ) ;
125
126
126
127
var dataSource = GetBuilderEndpointDataSource ( builder ) ;
@@ -148,5 +149,29 @@ public HttpMethodAttribute(params string[] httpMethods)
148
149
HttpMethods = httpMethods ;
149
150
}
150
151
}
152
+
153
+ private class EmptyServiceProvdier : IServiceScope , IServiceProvider , IServiceScopeFactory
154
+ {
155
+ public IServiceProvider ServiceProvider => this ;
156
+
157
+ public IServiceScope CreateScope ( )
158
+ {
159
+ return new EmptyServiceProvdier ( ) ;
160
+ }
161
+
162
+ public void Dispose ( )
163
+ {
164
+
165
+ }
166
+
167
+ public object ? GetService ( Type serviceType )
168
+ {
169
+ if ( serviceType == typeof ( IServiceScopeFactory ) )
170
+ {
171
+ return this ;
172
+ }
173
+ return null ;
174
+ }
175
+ }
151
176
}
152
177
}
0 commit comments