title: .NET Core stop HostedService in the Integration test
body: <p>I have .NET Core web API project, for some reasons, we created a background service in this project and start running the background service while the application is started.
  So, we created a <code>BackgroundWorkderService</code>, which inherited from BackgroundService (Microsoft.Extensions.Hosting) like below:</p>
  <pre><code>public class BackgroundWorkerService : BackgroundService
  {
      protected override async Task ExecuteAsync(CancellationToken stoppingToken)
      {
          await DoWork(stoppingToken);
      }
  
      public override async Task StartAsync(CancellationToken cancellationToken)
      {
          await ExecuteAsync(cancellationToken);
      }
  
      public override Task StopAsync(CancellationToken cancellationToken)
      {
          return Task.CompletedTask;
      }
  }
  </code></pre>
  <p>To run it while the application starts, I added the background service to the hosted service in Program.cs as below:</p>
  <pre><code>.ConfigureServices(services =&gt;
                  services.AddHostedService&lt;BackgroundWorkerService&gt;());
  </code></pre>
  <p>Now, we need to create an integration test, and we want to stop the background service while we are running the integration test.</p>
  <p>Does anyone know how to stop it in the integration test? I have tried to remove the service from ConfigureTestServices, but no luck with it, the background service still runs when the integration test starts.</p>