public async Task OneTimeTearDown() { // Once all tests have completed, delete all queues that were created. // Use the QueueNamePrefix to determine which queues to delete. var transport = new TransportExtensions <SqsTransport>(new SettingsHolder()); transport = transport.ConfigureSqsTransport(SqsQueueNamePrefix); var transportConfiguration = new TransportConfiguration(transport.GetSettings()); using (var sqsClient = SqsTransportExtensions.CreateSQSClient()) { var listQueuesResult = await sqsClient.ListQueuesAsync(transportConfiguration.QueueNamePrefix).ConfigureAwait(false); foreach (var queueUrl in listQueuesResult.QueueUrls) { try { await sqsClient.DeleteQueueAsync(queueUrl).ConfigureAwait(false); } catch (Exception ex) { Console.WriteLine($"Exception when deleting queue: {ex}"); } } } }
public TransportConfigurationResult Configure(SettingsHolder settings, TransportTransactionMode transactionMode) { var sqsTransport = new SqsTransport(); var sqsConfig = new TransportExtensions <SqsTransport>(settings); sqsConfig.ConfigureSqsTransport(SetupFixture.SqsQueueNamePrefix); return(new TransportConfigurationResult { TransportInfrastructure = sqsTransport.Initialize(settings, ""), PurgeInputQueueOnStartup = false }); }
async Task SendPoisonMessage(string inputQueueName) { var transport = new TransportExtensions <SqsTransport>(new SettingsHolder()); transport = transport.ConfigureSqsTransport(SetupFixture.SqsQueueNamePrefix); var transportConfiguration = new TransportConfiguration(transport.GetSettings()); using (var sqsClient = SqsTransportExtensions.CreateSQSClient()) { var getQueueUrlResponse = await sqsClient.GetQueueUrlAsync(new GetQueueUrlRequest { QueueName = QueueNameHelper.GetSqsQueueName(inputQueueName, transportConfiguration) }).ConfigureAwait(false); await sqsClient.SendMessageAsync(new SendMessageRequest { QueueUrl = getQueueUrlResponse.QueueUrl, MessageBody = PoisonMessageBody }).ConfigureAwait(false); } }
async Task CheckErrorQueue(string errorQueueName, CancellationToken cancellationToken) { var transport = new TransportExtensions <SqsTransport>(new SettingsHolder()); transport = transport.ConfigureSqsTransport(SetupFixture.SqsQueueNamePrefix); var transportConfiguration = new TransportConfiguration(transport.GetSettings()); using (var sqsClient = SqsTransportExtensions.CreateSQSClient()) { var getQueueUrlResponse = await sqsClient.GetQueueUrlAsync(new GetQueueUrlRequest { QueueName = QueueNameHelper.GetSqsQueueName(errorQueueName, transportConfiguration) }, cancellationToken).ConfigureAwait(false); var messageReceived = false; ReceiveMessageResponse receiveMessageResponse = null; while (messageReceived == false && !cancellationToken.IsCancellationRequested) { receiveMessageResponse = await sqsClient.ReceiveMessageAsync(new ReceiveMessageRequest { QueueUrl = getQueueUrlResponse.QueueUrl, WaitTimeSeconds = 20 }, cancellationToken).ConfigureAwait(false); if (receiveMessageResponse.Messages.Any()) { messageReceived = true; } } Assert.NotNull(receiveMessageResponse); Assert.AreEqual(1, receiveMessageResponse.Messages.Count); Assert.AreEqual(PoisonMessageBody, receiveMessageResponse.Messages.Single().Body); } }