public void UnitTestConstructorWithQueueMessagesListXmlAndGetMessages() { // <QueueMessagesList> // <QueueMessage> // <MessageText>PFN0dWZmIC8+</MessageText> // </QueueMessage> // </QueueMessagesList> // "PFN0dWZmIC8+" = "<Stuff />" base 64 encoded. const string QueueMessagesListXml = "<QueueMessagesList><QueueMessage><MessageText>PFN0dWZmIC8+</MessageText></QueueMessage></QueueMessagesList>"; QueueMessagesList queueMessagesList = new QueueMessagesList(QueueMessagesListXml); QueueMessage[] queueMessages = queueMessagesList.GetMessages(); Assert.AreEqual(1, queueMessages.Length, "The number of queue messages was not as expected."); Assert.AreEqual("<Stuff />", queueMessages[0].MessageText, "The message text was not as expected."); }
public QueueMessage PeekMessage(string queueName) { if (string.IsNullOrEmpty(queueName)) { throw new ArgumentException("The Queue Name may not be null or empty.", "queueName"); } try { HttpWebRequest httpWebRequest = this.storageServiceRequest.Create(RequestMethod.Get, queueName + "/messages?peekonly=true"); HttpWebResponse httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse(); Stream responseStream = httpWebResponse.GetResponseStream(); if (responseStream == null) { throw new AzureExtensionsException("The response did not provide a stream as expected."); } string message; using (StreamReader reader = new StreamReader(responseStream)) { message = reader.ReadToEnd(); } httpWebResponse.Close(); QueueMessagesList queueMessagesList = new QueueMessagesList(message); QueueMessage[] queueMessages = queueMessagesList.GetMessages(); if (queueMessages.Length == 0) { return null; } return queueMessages[0]; } catch (WebException ex) { HttpWebResponse httpWebResponse = (HttpWebResponse)ex.Response; if (ex.Status == WebExceptionStatus.ProtocolError && ex.Response != null && httpWebResponse.StatusCode == HttpStatusCode.Conflict) { return null; } throw; } }