From 55e57af8156eab2c28c62b5c6c5473405cb1c411 Mon Sep 17 00:00:00 2001 From: "Chris Ross (ASP.NET)" Date: Wed, 2 May 2018 11:35:48 -0700 Subject: [PATCH] Adding additional tests for AddHostedService --- .../HostTests.cs | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/test/Microsoft.Extensions.Hosting.Tests/HostTests.cs b/test/Microsoft.Extensions.Hosting.Tests/HostTests.cs index 31a38b81c5..eaca45f5e8 100644 --- a/test/Microsoft.Extensions.Hosting.Tests/HostTests.cs +++ b/test/Microsoft.Extensions.Hosting.Tests/HostTests.cs @@ -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(); + services.AddHostedService(); + }) + .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() {