コード例 #1
0
        public void WaitForMessage_WithMessageInQueue_ShouldSucceed()
        {
            // Setup
            // TODO: Replace this with a mocked factory.
            IAwsClientFactory awsClientFactory = new AwsClientFactory();
            ITaskLogger       logger           = new NullLogger();

            var sendMessageTask = new SendSQSMessageTask(awsClientFactory, logger)
            {
                QueueUrl                = _queueUrl,
                MessageBody             = "Test Wait for Mesage",
                EncryptionContainerName = TestHelper.EncryptionContainerName,
            };

            Assert.IsTrue(sendMessageTask.Execute(), "Failed to send setup message");

            // Message should have appeared in the 60 seconds timeout
            var task = new WaitForSQSMessageTask(awsClientFactory, logger)
            {
                QueueUrl                = _queueUrl,
                TimeOutSeconds          = 60,
                PollIntervalSeconds     = 1,
                EncryptionContainerName = TestHelper.EncryptionContainerName,
            };

            // Execute
            bool suceeded = task.Execute();

            // Test
            Assert.IsTrue(suceeded, "Did not suceeded");
            Assert.IsNotNullOrEmpty(task.MessageBody, "MessageBody");
            Assert.IsNotNullOrEmpty(task.MessageId, "MessageId");
            Assert.IsNotNullOrEmpty(task.ReceiptHandle, "ReceiptHandle");
        }
コード例 #2
0
        public void SendMessage_Should_ReturnMessageId()
        {
            // Setup
            // TODO: Replace this with a mocked factory.
            IAwsClientFactory awsClientFactory = new AwsClientFactory();
            ITaskLogger       logger           = new NullLogger();

            const string messageBody = "TestMessageBody";

            var task = new SendSQSMessageTask(awsClientFactory, logger)
            {
                QueueUrl                = _queueUrl,
                MessageBody             = messageBody,
                EncryptionContainerName = TestHelper.EncryptionContainerName
            };

            // Execute
            bool suceeded = task.Execute();

            // Test
            Assert.IsTrue(suceeded, "Did not suceed");
            Assert.IsNotNullOrEmpty(task.MessageId, "MessageId");
        }
コード例 #3
0
        public void ReceiveMessage_Should_ReceiveMessage()
        {
            // Setup
            // TODO: Replace this with a mocked factory.
            IAwsClientFactory awsClientFactory = new AwsClientFactory();
            ITaskLogger       logger           = new NullLogger();

            // Add a message to the queue to ensure that their is one and wait for 2 seconds to allow
            // the message to propogate.
            // Add the time on to ensure the correct message is received.
            string expectedMessage    = "Sample test message " + DateTime.Now.ToLongTimeString();
            var    sendSqsMessageTask = new SendSQSMessageTask(awsClientFactory, logger)
            {
                QueueUrl                = _queueUrl,
                MessageBody             = expectedMessage,
                EncryptionContainerName = TestHelper.EncryptionContainerName,
            };

            sendSqsMessageTask.Execute();

            // Messages can be very slow to appear on the queue.
            Thread.Sleep(60000);

            var task = new ReceiveSQSMessageTask(awsClientFactory, logger)
            {
                QueueUrl = _queueUrl,
                EncryptionContainerName = TestHelper.EncryptionContainerName,
            };

            // Execute
            bool suceeded = task.Execute();

            // Test
            Assert.IsTrue(suceeded, "Did not suceed");
            Assert.IsTrue(task.HasMessage, "No message");
            Assert.IsNotNullOrEmpty(expectedMessage, task.MessageBody, "MessageId");
        }