Unit testing ILogger with NSubstitute and time information
There are several problems when testing a method like protected override async Task ExecuteAsync(CancellationToken stoppingToken) { logger.LogInformation("QueueProcessorService started at: {time:g}", timeProvider.GetUtcNow()); while (!stoppingToken.IsCancellationRequested) { await processor.TryProcessingAsync(stoppingToken).ConfigureAwait(false); await Task.Delay(Constants.QUEUE_POLLING_INTERVAL).ConfigureAwait(false); } logger.LogInformation("QueueProcessorService stopped at: {time:g}", timeProvider.GetUtcNow()); } and more specifically the logger.LogInformation calls. For one thing, doing a simple await Task.Delay(Constants.QUEUE_POLLING_INTERVAL).ConfigureAwait(false); will actually slow down the test for however long the specified interval is. This is unacceptable for any significant value of QUEUE_POLLING_INTERVAL (the production code might only want to check the queue once...