1313using Microsoft . AspNet . Http ;
1414using Microsoft . AspNet . Http . Features ;
1515using Microsoft . AspNet . Http . Features . Internal ;
16+ using Microsoft . AspNet . Http . Internal ;
1617using Microsoft . AspNet . Testing . xunit ;
1718using Microsoft . Extensions . Configuration ;
1819using Microsoft . Extensions . DependencyInjection ;
@@ -289,14 +290,18 @@ public async Task CanAccessLogger()
289290 [ Fact ]
290291 public async Task CanAccessHttpContext ( )
291292 {
293+ Action < IServiceCollection > configureServices = services =>
294+ {
295+ services . AddSingleton < IHttpContextAccessor , HttpContextAccessor > ( ) ;
296+ } ;
292297 TestServer server = TestServer . Create ( app =>
293298 {
294299 app . Run ( context =>
295300 {
296301 var accessor = app . ApplicationServices . GetRequiredService < IHttpContextAccessor > ( ) ;
297302 return context . Response . WriteAsync ( "HasContext:" + ( accessor . HttpContext != null ) ) ;
298303 } ) ;
299- } ) ;
304+ } , configureServices ) ;
300305
301306 string result = await server . CreateClient ( ) . GetStringAsync ( "/path" ) ;
302307 Assert . Equal ( "HasContext:True" , result ) ;
@@ -315,15 +320,19 @@ public ContextHolder(IHttpContextAccessor accessor)
315320 [ Fact ]
316321 public async Task CanAddNewHostServices ( )
317322 {
323+ Action < IServiceCollection > configureServices = services =>
324+ {
325+ services . AddSingleton < IHttpContextAccessor , HttpContextAccessor > ( ) ;
326+ services . AddSingleton < ContextHolder > ( ) ;
327+ } ;
318328 TestServer server = TestServer . Create ( app =>
319329 {
320330 app . Run ( context =>
321331 {
322332 var accessor = app . ApplicationServices . GetRequiredService < ContextHolder > ( ) ;
323333 return context . Response . WriteAsync ( "HasContext:" + ( accessor . Accessor . HttpContext != null ) ) ;
324334 } ) ;
325- } ,
326- services => services . AddSingleton < ContextHolder > ( ) ) ;
335+ } , configureServices ) ;
327336
328337 string result = await server . CreateClient ( ) . GetStringAsync ( "/path" ) ;
329338 Assert . Equal ( "HasContext:True" , result ) ;
0 commit comments