public function testMissingDatesDeserializeAsNull()
 {
     // Act
     $properties = BrokerProperties::create('{}');
     // Assert
     $this->assertNull($properties->getLockedUntilUtc(), '$properties->getLockedUntilUtc()');
     $this->assertNull($properties->getScheduledEnqueueTimeUtc(), '$properties->getScheduledEnqueueTimeUtc()');
 }
 /**
  * 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\BrokerProperties::create
  */
 public function testCreateBrokerPropertiesAllPropertiesSuccess()
 {
     // Setup
     $brokerPropertiesJsonString = '{"CorrelationId":"testCorrelationId","SessionId":"testSessionId","DeliveryCount":38,"LockedUntilUtc":"Sun, 06 Nov 2011 01:00:00 GMT","LockToken":"testLockToken","MessageId":"testMessageId","Label":"testLabel","ReplyTo":"testReplyTo","SequenceNumber":88,"TimeToLive":123.456,"To":"testTo","ScheduledEnqueueTimeUtc":"Sun, 06 Nov 2011 01:00:00 GMT","ReplyToSessionId":"testReplyToSessionId","MessageLocation":"testMessageLocation","LockLocation":"testLockLocation"}';
     $expectedCorrelationId = 'testCorrelationId';
     $expectedSessionId = 'testSessionId';
     $expectedDeliveryCount = 38;
     $expectedLockedUntilUtc = \DateTime::createFromFormat(Resources::AZURE_DATE_FORMAT, "Sun, 06 Nov 2011 01:00:00 GMT");
     $expectedLockToken = 'testLockToken';
     $expectedMessageId = 'testMessageId';
     $expectedLabel = 'testLabel';
     $expectedReplyTo = 'testReplyTo';
     $expectedSequenceNumber = 88;
     $expectedTimeToLive = '123.456';
     $expectedTo = 'testTo';
     $expectedScheduledEnqueueTimeUtc = $expectedLockedUntilUtc;
     $expectedReplyToSessionId = 'testReplyToSessionId';
     $expectedMessageLocation = 'testMessageLocation';
     $expectedLockLocation = 'testLockLocation';
     // Test
     $brokerProperties = BrokerProperties::create($brokerPropertiesJsonString);
     // Assert
     $this->assertEquals($expectedCorrelationId, $brokerProperties->getCorrelationId());
     $this->assertEquals($expectedSessionId, $brokerProperties->getSessionId());
     $this->assertEquals($expectedDeliveryCount, $brokerProperties->getDeliveryCount());
     $this->assertEquals($expectedLockedUntilUtc->format(Resources::AZURE_DATE_FORMAT), $brokerProperties->getLockedUntilUtc()->format(Resources::AZURE_DATE_FORMAT));
     $this->assertEquals($expectedLockToken, $brokerProperties->getLockToken());
     $this->assertEquals($expectedMessageId, $brokerProperties->getMessageId());
     $this->assertEquals($expectedLabel, $brokerProperties->getLabel());
     $this->assertEquals($expectedReplyTo, $brokerProperties->getReplyTo());
     $this->assertEquals($expectedSequenceNumber, $brokerProperties->getSequenceNumber());
     $this->assertEquals($expectedTimeToLive, $brokerProperties->getTimeToLive());
     $this->assertEquals($expectedTo, $brokerProperties->getTo());
     $this->assertEquals($expectedScheduledEnqueueTimeUtc, $brokerProperties->getScheduledEnqueueTimeUtc());
     $this->assertEquals($expectedReplyToSessionId, $brokerProperties->getReplyToSessionId());
     $this->assertEquals($expectedMessageLocation, $brokerProperties->getMessageLocation());
     $this->assertEquals($expectedLockLocation, $brokerProperties->getLockLocation());
 }