public void SynchronousTestListAllQueueMessagesWithUpdates() { IQueueingService provider = CreateProvider(); QueueName queueName = CreateRandomQueueName(); provider.CreateQueue(queueName); for (int i = 0; i < 28; i++) { provider.PostMessages(queueName, new Message <SampleMetadata>(TimeSpan.FromSeconds(120), new SampleMetadata(i, "Some Message " + i))); } HashSet <int> locatedMessages = new HashSet <int>(); QueuedMessageList messages = provider.ListMessages(queueName, null, null, true, false); foreach (QueuedMessage message in messages) { Assert.IsTrue(locatedMessages.Add(message.Body.ToObject <SampleMetadata>().ValueA), "Received the same message more than once."); } int deletedMessage = messages[0].Body.ToObject <SampleMetadata>().ValueA; provider.DeleteMessage(queueName, messages[0].Id, null); while (messages.Count > 0) { QueuedMessageList tempList = provider.ListMessages(queueName, messages.NextPageId, null, true, false); if (tempList.Count > 0) { Assert.IsTrue(locatedMessages.Add(tempList[0].Body.ToObject <SampleMetadata>().ValueA), "Received the same message more than once."); provider.DeleteMessage(queueName, tempList[0].Id, null); } messages = provider.ListMessages(queueName, messages.NextPageId, null, true, false); foreach (QueuedMessage message in messages) { Assert.IsTrue(locatedMessages.Add(message.Body.ToObject <SampleMetadata>().ValueA), "Received the same message more than once."); } } Assert.AreEqual(28, locatedMessages.Count); for (int i = 0; i < 28; i++) { Assert.IsTrue(locatedMessages.Contains(i), "The message listing did not include message '{0}', which was in the queue when the listing started and still in it afterwards.", i); } provider.DeleteQueue(queueName); }
/// <summary> /// Gets all existing messages in a queue through a series of synchronous operations, /// each of which requests a subset of the available messages. /// </summary> /// <param name="provider">The queueing service.</param> /// <param name="queueName">The queue name.</param> /// <param name="limit">The maximum number of <see cref="QueuedMessage"/> objects to return from a single task. If this value is <see langword="null"/>, a provider-specific default is used.</param> /// <param name="echo"><see langword="true"/> to include messages created by the current client; otherwise, <see langword="false"/>.</param> /// <param name="includeClaimed"><see langword="true"/> to include claimed messages; otherwise <see langword="false"/> to return only unclaimed messages.</param> /// <param name="progress">An optional callback object to receive progress notifications. If this is <see langword="null"/>, no progress notifications are sent.</param> /// <returns>A collection of <see cref="CloudQueue"/> objects describing the available queues.</returns> /// <exception cref="ArgumentNullException"> /// If <paramref name="provider"/> is <see langword="null"/>. /// <para>-or-</para> /// <para>If <paramref name="queueName"/> is <see langword="null"/>.</para> /// </exception> /// <exception cref="ArgumentOutOfRangeException">If <paramref name="limit"/> is less than or equal to 0.</exception> /// <exception cref="WebException">If the REST request does not return successfully.</exception> private static ReadOnlyCollection <QueuedMessage> ListAllMessages(IQueueingService provider, QueueName queueName, int?limit, bool echo, bool includeClaimed) { if (provider == null) { throw new ArgumentNullException("provider"); } if (queueName == null) { throw new ArgumentNullException("queueName"); } if (limit <= 0) { throw new ArgumentOutOfRangeException("limit"); } return(provider.ListMessages(queueName, null, limit, echo, includeClaimed).GetAllPages()); }
/// <summary> /// Gets all existing messages in a queue through a series of synchronous operations, /// each of which requests a subset of the available messages. /// </summary> /// <param name="provider">The queueing service.</param> /// <param name="queueName">The queue name.</param> /// <param name="limit">The maximum number of <see cref="QueuedMessage"/> objects to return from a single task. If this value is <see langword="null"/>, a provider-specific default is used.</param> /// <param name="echo"><see langword="true"/> to include messages created by the current client; otherwise, <see langword="false"/>.</param> /// <param name="includeClaimed"><see langword="true"/> to include claimed messages; otherwise <see langword="false"/> to return only unclaimed messages.</param> /// <param name="progress">An optional callback object to receive progress notifications. If this is <see langword="null"/>, no progress notifications are sent.</param> /// <returns>A collection of <see cref="CloudQueue"/> objects describing the available queues.</returns> /// <exception cref="ArgumentNullException"> /// If <paramref name="provider"/> is <see langword="null"/>. /// <para>-or-</para> /// <para>If <paramref name="queueName"/> is <see langword="null"/>.</para> /// </exception> /// <exception cref="ArgumentOutOfRangeException">If <paramref name="limit"/> is less than or equal to 0.</exception> /// <exception cref="WebException">If the REST request does not return successfully.</exception> private static ReadOnlyCollection<QueuedMessage> ListAllMessages(IQueueingService provider, QueueName queueName, int? limit, bool echo, bool includeClaimed) { if (provider == null) throw new ArgumentNullException("provider"); if (queueName == null) throw new ArgumentNullException("queueName"); if (limit <= 0) throw new ArgumentOutOfRangeException("limit"); return provider.ListMessages(queueName, null, limit, echo, includeClaimed).GetAllPages(); }