/**
  * Receives a message. 
  * 
  * Queues:
  *
  * @link http://msdn.microsoft.com/en-us/library/windowsazure/hh780735
  * @link http://msdn.microsoft.com/en-us/library/windowsazure/hh780756 
  *
  * Topic Subscriptions:
  * @link http://msdn.microsoft.com/en-us/library/windowsazure/hh780722
  * @link http://msdn.microsoft.com/en-us/library/windowsazure/hh780770
  *
  * @param string                 $path                  The path of the 
  *                                                      message. 
  * @param ReceivedMessageOptions $receiveMessageOptions The options to 
  *                                                      receive the message. 
  * 
  * @return BrokeredMessage
  */
 public function receiveMessage($path, $receiveMessageOptions = null)
 {
     if (is_null($receiveMessageOptions)) {
         $receiveMessageOptions = new ReceiveMessageOptions();
     }
     $httpCallContext = new HttpCallContext();
     $httpCallContext->setPath($path);
     $httpCallContext->addStatusCode(Resources::STATUS_CREATED);
     $httpCallContext->addStatusCode(Resources::STATUS_NO_CONTENT);
     $httpCallContext->addStatusCode(Resources::STATUS_OK);
     $timeout = $receiveMessageOptions->getTimeout();
     if (!is_null($timeout)) {
         $httpCallContext->addQueryParameter('timeout', $timeout);
     }
     if ($receiveMessageOptions->getIsReceiveAndDelete()) {
         $httpCallContext->setMethod(Resources::HTTP_DELETE);
     } elseif ($receiveMessageOptions->getIsPeekLock()) {
         $httpCallContext->setMethod(Resources::HTTP_POST);
     } else {
         throw new \InvalidArgumentException(Resources::INVALID_RECEIVE_MODE_MSG);
     }
     $response = $this->sendContext($httpCallContext);
     if ($response->getStatus() === Resources::STATUS_NO_CONTENT) {
         $brokeredMessage = null;
     } else {
         $responseHeaders = $response->getHeader();
         $brokerProperties = new BrokerProperties();
         if (array_key_exists('brokerproperties', $responseHeaders)) {
             $brokerProperties = BrokerProperties::create($responseHeaders['brokerproperties']);
         }
         if (array_key_exists('location', $responseHeaders)) {
             $brokerProperties->setLockLocation($responseHeaders['location']);
         }
         $brokeredMessage = new BrokeredMessage();
         $brokeredMessage->setBrokerProperties($brokerProperties);
         if (array_key_exists(Resources::CONTENT_TYPE, $responseHeaders)) {
             $brokeredMessage->setContentType($responseHeaders[Resources::CONTENT_TYPE]);
         }
         if (array_key_exists('Date', $responseHeaders)) {
             $brokeredMessage->setDate($responseHeaders['Date']);
         }
         $brokeredMessage->setBody($response->getBody());
         foreach (array_keys($responseHeaders) as $headerKey) {
             $value = $responseHeaders[$headerKey];
             $decodedValue = json_decode($value);
             if (is_scalar($decodedValue)) {
                 $brokeredMessage->setProperty($headerKey, $decodedValue);
             }
         }
     }
     return $brokeredMessage;
 }
 /** 
  * @covers WindowsAzure\ServiceBus\Models\BrokeredMessage::getDate
  * @covers WindowsAzure\ServiceBus\Models\BrokeredMessage::setDate
  */
 public function testGetSetDate()
 {
     // Setup
     $expected = 'testDate';
     $brokeredMessage = new BrokeredMessage();
     // Test
     $brokeredMessage->setDate($expected);
     $actual = $brokeredMessage->getDate();
     // Assert
     $this->assertEquals($expected, $actual);
 }