public function testCheckListMessagesOptions()
 {
     $options = new ListMessagesOptions();
     $this->assertNull($options->getTimeout(), 'Default ListMessagesOptions->getTimeout');
     $this->assertNull($options->getNumberOfMessages(), 'Default ListMessagesOptions->getNumberOfMessages');
     $this->assertNull($options->getVisibilityTimeoutInSeconds(), 'Default ListMessagesOptions->getVisibilityTimeoutInSeconds');
     $options->setTimeout(self::INT_MAX_VALUE);
     $options->setNumberOfMessages(0);
     $options->setVisibilityTimeoutInSeconds(self::INT_MIN_VALUE);
     $this->assertEquals(self::INT_MAX_VALUE, $options->getTimeout(), 'Set ListMessagesOptions->getTimeout');
     $this->assertEquals(0, $options->getNumberOfMessages(), 'Set ListMessagesOptions->getNumberOfMessages');
     $this->assertEquals(self::INT_MIN_VALUE, $options->getVisibilityTimeoutInSeconds(), 'Set ListMessagesOptions->getVisibilityTimeoutInSeconds');
 }
 /**
  * @covers MicrosoftAzure\Storage\ServiceBus\ServiceBusRestProxy::clearMessages
  * @covers MicrosoftAzure\Storage\ServiceBus\ServiceBusRestProxy::createMessage
  * @covers MicrosoftAzure\Storage\ServiceBus\ServiceBusRestProxy::listMessages
  */
 private function clearMessagesWorker($options)
 {
     self::println('Trying $options: ' . self::tmptostring($options));
     $queue = QueueServiceFunctionalTestData::$testQueueNames;
     $queue = $queue[0];
     $this->restProxy->clearMessages($queue);
     // Put three messages into the queue.
     $this->restProxy->createMessage($queue, QueueServiceFunctionalTestData::getSimpleMessageText());
     $this->restProxy->createMessage($queue, QueueServiceFunctionalTestData::getSimpleMessageText());
     $this->restProxy->createMessage($queue, QueueServiceFunctionalTestData::getSimpleMessageText());
     // Wait a bit to make sure the messages are there.
     sleep(1);
     // Make sure the messages are there, and use a short visibility timeout to make sure the are visible again later.
     $opts = new ListMessagesOptions();
     $opts->setVisibilityTimeoutInSeconds(1);
     $opts->setNumberOfMessages(32);
     $lmr = $this->restProxy->listMessages($queue, $opts);
     $this->assertEquals(3, count($lmr->getQueueMessages()), 'getQueueMessages() count');
     sleep(2);
     try {
         if (is_null($options)) {
             $this->restProxy->clearMessages($queue);
         } else {
             $this->restProxy->clearMessages($queue, $options);
         }
         if (is_null($options)) {
             $options = new CreateMessageOptions();
         } else {
             if (!is_null($options->getTimeout()) && $options->getTimeout() < 1) {
                 $this->assertTrue(false, 'Expect negative timeouts in $options to throw');
             }
         }
         // Wait 2 seconds to make sure the messages would be visible again.
         $opts = new ListMessagesOptions();
         $opts->setVisibilityTimeoutInSeconds(1);
         $opts->setNumberOfMessages(32);
         $lmr = $this->restProxy->listMessages($queue, $opts);
         $this->assertEquals(0, count($lmr->getQueueMessages()), 'getQueueMessages() count');
     } catch (ServiceException $e) {
         if (is_null($options)) {
             $options = new CreateMessageOptions();
         }
         if (!is_null($options->getTimeout()) && $options->getTimeout() < 1) {
             $this->assertEquals(TestResources::STATUS_INTERNAL_SERVER_ERROR, $e->getCode(), 'getCode');
         } else {
             throw $e;
         }
     }
     $this->restProxy->clearMessages($queue);
 }
 /**
  * @covers MicrosoftAzure\Storage\Queue\QueueRestProxy::createMessage
  * @covers MicrosoftAzure\Storage\Queue\QueueRestProxy::deleteMessage
  * @covers MicrosoftAzure\Storage\Queue\QueueRestProxy::listMessages
  */
 public function testDeleteMessageWorks()
 {
     // Arrange
     // Act
     $this->restProxy->createMessage(self::$testQueueForMessages7, 'message1');
     $this->restProxy->createMessage(self::$testQueueForMessages7, 'message2');
     $this->restProxy->createMessage(self::$testQueueForMessages7, 'message3');
     $this->restProxy->createMessage(self::$testQueueForMessages7, 'message4');
     $result = $this->restProxy->listMessages(self::$testQueueForMessages7);
     $message0 = $result->getQueueMessages();
     $message0 = $message0[0];
     $this->restProxy->deleteMessage(self::$testQueueForMessages7, $message0->getMessageId(), $message0->getPopReceipt());
     $opts = new ListMessagesOptions();
     $opts->setNumberOfMessages(32);
     $result2 = $this->restProxy->listMessages(self::$testQueueForMessages7, $opts);
     // Assert
     $this->assertNotNull($result2, '$result2');
     $this->assertEquals(3, count($result2->getQueueMessages()), 'count($result2->getQueueMessages())');
 }
 /**
  * Lists all messages in the queue.
  * 
  * @param string              $queueName The queue name.
  * @param ListMessagesOptions $options   The optional parameters.
  * 
  * @return MicrosoftAzure\Storage\Common\Models\ListMessagesResult
  */
 public function listMessages($queueName, $options = null)
 {
     Validate::isString($queueName, 'queueName');
     Validate::notNullOrEmpty($queueName, 'queueName');
     $method = Resources::HTTP_GET;
     $headers = array();
     $queryParams = array();
     $postParams = array();
     $path = $queueName . '/messages';
     $statusCode = Resources::STATUS_OK;
     if (is_null($options)) {
         $options = new ListMessagesOptions();
     }
     $messagesCount = $options->getNumberOfMessages();
     $visibility = $options->getVisibilityTimeoutInSeconds();
     $timeout = $options->getTimeout();
     $this->addOptionalQueryParam($queryParams, Resources::QP_TIMEOUT, $timeout);
     $this->addOptionalQueryParam($queryParams, Resources::QP_NUM_OF_MESSAGES, $messagesCount);
     $this->addOptionalQueryParam($queryParams, Resources::QP_VISIBILITY_TIMEOUT, $visibility);
     $response = $this->send($method, $headers, $queryParams, $postParams, $path, $statusCode);
     $parsed = $this->dataSerializer->unserialize($response->getBody());
     return ListMessagesResult::create($parsed);
 }
 /**
  * @covers MicrosoftAzure\Storage\Queue\QueueRestProxy::listMessages
  */
 public function testListMessagesMultiplesMessages()
 {
     // Setup
     $name = 'listmessagesmultiplesmessages';
     $this->createQueue($name);
     $expected1 = 'Message #1 Text';
     $expected2 = 'Message #2 Text';
     $expected3 = 'Message #3 Text';
     $this->restProxy->createMessage($name, $expected1);
     $this->restProxy->createMessage($name, $expected2);
     $this->restProxy->createMessage($name, $expected3);
     $options = new ListMessagesOptions();
     $options->setNumberOfMessages(10);
     // Test
     $result = $this->restProxy->listMessages($name, $options);
     // Assert
     $actual = $result->getQueueMessages();
     $this->assertCount(3, $actual);
     $this->assertEquals($expected1, $actual[0]->getMessageText());
     $this->assertEquals($expected2, $actual[1]->getMessageText());
     $this->assertEquals($expected3, $actual[2]->getMessageText());
 }
 /**
  * @covers MicrosoftAzure\Storage\Queue\Models\ListMessagesOptions::setNumberOfMessages
  */
 public function testSetNumberOfMessages()
 {
     // Setup
     $listMessagesOptions = new ListMessagesOptions();
     $expected = 10;
     // Test
     $listMessagesOptions->setNumberOfMessages($expected);
     // Assert
     $actual = $listMessagesOptions->getNumberOfMessages();
     $this->assertEquals($expected, $actual);
 }