Skip to content
This repository was archived by the owner on Dec 19, 2018. It is now read-only.

Commit 0bd4d0b

Browse files
committed
Making application available from TestServer #519
1 parent 2c7f0ff commit 0bd4d0b

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

src/Microsoft.AspNet.TestHost/TestServer.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,14 @@ public TestServer(IWebApplicationBuilder builder)
2929

3030
public Uri BaseAddress { get; set; } = new Uri("http://localhost/");
3131

32+
public IWebApplication Application
33+
{
34+
get
35+
{
36+
return _appInstance;
37+
}
38+
}
39+
3240
IFeatureCollection IServer.Features { get; }
3341

3442
public HttpMessageHandler CreateHandler()

test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,21 @@ public void CreateWithDelegate()
3131
new TestServer(new WebApplicationBuilder().Configure(app => { }));
3232
}
3333

34+
[Fact]
35+
public void ApplicationServicesAvailableFromTestServer()
36+
{
37+
var testService = new TestService();
38+
var builder = new WebApplicationBuilder()
39+
.Configure(app => { })
40+
.ConfigureServices(services =>
41+
{
42+
services.AddSingleton(testService);
43+
});
44+
var server = new TestServer(builder);
45+
46+
Assert.Equal(testService, server.Application.Services.GetRequiredService<TestService>());
47+
}
48+
3449
[ConditionalFact]
3550
[FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Hangs randomly (issue #507)")]
3651
public async Task RequestServicesAutoCreated()

0 commit comments

Comments
 (0)