Adding additional tests for AddHostedService

This commit is contained in:
Chris Ross (ASP.NET) 2018-05-02 11:35:48 -07:00
parent 982508e863
commit 55e57af815
1 changed files with 32 additions and 0 deletions

View File

@ -104,6 +104,38 @@ namespace Microsoft.Extensions.Hosting
Assert.Equal(1, service.DisposeCount);
}
[Fact]
public void HostedServiceCanAcceptSingletonDependencies()
{
using (var host = CreateBuilder()
.ConfigureServices((hostContext, services) =>
{
services.AddSingleton<IFakeService, FakeService>();
services.AddHostedService<FakeHostedServiceWithDependency>();
})
.Start())
{
}
}
private class FakeHostedServiceWithDependency : IHostedService
{
public FakeHostedServiceWithDependency(IFakeService fakeService)
{
Assert.NotNull(fakeService);
}
public Task StartAsync(CancellationToken cancellationToken)
{
return Task.CompletedTask;
}
public Task StopAsync(CancellationToken cancellationToken)
{
return Task.CompletedTask;
}
}
[Fact]
public async Task HostedServiceStartNotCalledIfHostNotStarted()
{