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

Making application services available from TestServer #519 #561

Merged
merged 1 commit into from
Jan 12, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/Microsoft.AspNet.TestHost/TestServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ public TestServer(IWebApplicationBuilder builder)

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

public IWebApplication Application
{
get
{
return _appInstance;
}
}

IFeatureCollection IServer.Features { get; }

public HttpMessageHandler CreateHandler()
Expand Down
15 changes: 15 additions & 0 deletions test/Microsoft.AspNet.TestHost.Tests/TestServerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,21 @@ public void CreateWithDelegate()
new TestServer(new WebApplicationBuilder().Configure(app => { }));
}

[Fact]
public void ApplicationServicesAvailableFromTestServer()
{
var testService = new TestService();
var builder = new WebApplicationBuilder()
.Configure(app => { })
.ConfigureServices(services =>
{
services.AddSingleton(testService);
});
var server = new TestServer(builder);

Assert.Equal(testService, server.Application.Services.GetRequiredService<TestService>());
}

[ConditionalFact]
[FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Hangs randomly (issue #507)")]
public async Task RequestServicesAutoCreated()
Expand Down