public async Task HostsAreProcessed()
        {
            var testPending            = CreateMxHostTestPending();
            List <TlsTestPending> list = new List <TlsTestPending>
            {
                testPending
            };

            A.CallTo(() => _mxQueueProcessor.GetMxHosts())
            .Returns(Task.FromResult(list)).Once()
            .Then
            .Returns(Task.FromResult(new List <TlsTestPending>()));

            A.CallTo(() => _recentlyProcessedLedger.Contains(A <string> ._)).Returns(false);

            A.CallTo(() => _mxQueueProcessor.DeleteMessage(A <string> ._, A <string> ._)).Returns(Task.CompletedTask);

            var testResult = CreateMxHostTestResult();

            A.CallTo(() => _mxHostTester.Test(testPending)).Returns(Task.FromResult(testResult)).Once();

            A.CallTo(() => _processingFilter.Reserve(A <string> ._)).Returns(true);

            A.CallTo(() => _publisher.Publish(A <Message> ._, A <string> ._)).Returns(Task.CompletedTask);

            Task process = _mxSecurityTesterProcessor.Process(cancellationTokenSource.Token);

            await _pipelineStartBlock.SendAsync(null);

            cancellationTokenSource.Cancel();

            await process;

            A.CallTo(() => _mxQueueProcessor.GetMxHosts()).MustHaveHappenedOnceExactly();
            A.CallTo(() => _mxHostTester.Test(testPending)).MustHaveHappenedOnceExactly();
            A.CallTo(() => _publisher.Publish(testResult, A <string> ._)).MustHaveHappenedOnceExactly();
            A.CallTo(() => _mxQueueProcessor.DeleteMessage("MessageId1", "ReceiptHandle1")).MustHaveHappenedOnceExactly();
            A.CallTo(() => _processingFilter.Reserve("host.domain1.gov.uk")).MustHaveHappenedOnceExactly();
            A.CallTo(() => _processingFilter.ReleaseReservation("host.domain1.gov.uk")).MustHaveHappenedOnceExactly();
            A.CallTo(() => _recentlyProcessedLedger.Set("host.domain1.gov.uk")).MustHaveHappenedOnceExactly();
        }
        private async Task RemoveFromQueue(MxHostTestDetails[] messages)
        {
            foreach (MxHostTestDetails tlsTestResult in messages)
            {
                var test               = tlsTestResult.Test;
                var hostname           = test.Id;
                var normalizedHostname = tlsTestResult.NormalizedHostname;
                var messageId          = test.MessageId;
                var receiptHandle      = test.ReceiptHandle;

                using (_log.BeginScope(new Dictionary <string, object> {
                    [TlsHostLogPropertyName] = hostname
                }))
                {
                    try
                    {
                        if (tlsTestResult.PublishedResultsSuccessfully)
                        {
                            _recentlyProcessedLedger.Set(normalizedHostname);
                        }

                        if (tlsTestResult.PublishedResultsSuccessfully || tlsTestResult.SkipTesting)
                        {
                            _log.LogInformation($"Deleting message from sqs for host: {hostname} - Message Id: {messageId}");
                            await _mxQueueProcessor.DeleteMessage(messageId, receiptHandle);

                            _log.LogInformation($"Deleted message from sqs for host: {hostname} - Message Id: {messageId}");
                        }
                        else
                        {
                            _log.LogInformation($"Returning message to queue - failed to retrieve or publish results for host {hostname}");
                        }
                    }
                    catch (Exception ex)
                    {
                        _log.LogError(ex, $"Error occurred deleting message {test.MessageId} from queue for hostname {hostname}");
                    }
                    finally
                    {
                        _processingFilter.ReleaseReservation(hostname);
                    }
                }
            }
        }