public static async Task AddMessageAndCreateIfNotExistsAsync(this IStorageQueue queue,
                                                                     IStorageQueueMessage message, CancellationToken cancellationToken)
        {
            if (queue == null)
            {
                throw new ArgumentNullException("queue");
            }

            bool isQueueNotFoundException = false;

            try
            {
                await queue.AddMessageAsync(message, cancellationToken);

                return;
            }
            catch (StorageException exception)
            {
                if (!exception.IsNotFoundQueueNotFound())
                {
                    throw;
                }

                isQueueNotFoundException = true;
            }

            Debug.Assert(isQueueNotFoundException);
            await queue.CreateIfNotExistsAsync(cancellationToken);

            await queue.AddMessageAsync(message, cancellationToken);
        }
        public static void AddMessage(this IStorageQueue queue, IStorageQueueMessage message)
        {
            if (queue == null)
            {
                throw new ArgumentNullException("queue");
            }

            queue.AddMessageAsync(message, CancellationToken.None).GetAwaiter().GetResult();
        }
Example #3
0
            protected override async Task CopyMessageToPoisonQueueAsync(CloudQueueMessage message, CloudQueue poisonQueue, CancellationToken cancellationToken)
            {
                FakeStorageQueueMessage fakeMessage = new FakeStorageQueueMessage(message);

                await _poisonQueue.CreateIfNotExistsAsync(cancellationToken);

                await _poisonQueue.AddMessageAsync(fakeMessage, cancellationToken);

                OnMessageAddedToPoisonQueue(new PoisonMessageEventArgs(message, poisonQueue));
            }
Example #4
0
        public async Task CloudQueueAddMessage_AddsMessage()
        {
            // Arrange
            CloudStorageAccount sdkAccount = CreateSdkAccount();
            string queueName = GetQueueName("add-message");

            CloudQueue sdkQueue = CreateSdkQueue(sdkAccount, queueName);
            await sdkQueue.CreateIfNotExistsAsync();

            try
            {
                string expectedContent = "hello";

                IStorageAccount     product = CreateProductUnderTest(sdkAccount);
                IStorageQueueClient client  = product.CreateQueueClient();
                Assert.NotNull(client); // Guard
                IStorageQueue queue = client.GetQueueReference(queueName);
                Assert.NotNull(queue);  // Guard

                IStorageQueueMessage message = queue.CreateMessage(expectedContent);
                Assert.NotNull(message); // Guard

                // Act
                queue.AddMessageAsync(message, CancellationToken.None).GetAwaiter().GetResult();

                // Assert
                CloudQueueMessage sdkMessage = await sdkQueue.GetMessageAsync();

                Assert.NotNull(sdkMessage);
                Assert.Equal(expectedContent, sdkMessage.AsString);
            }
            finally
            {
                await sdkQueue.DeleteAsync();
            }
        }