/**
  * @covers MicrosoftAzure\Storage\Table\Internal\AtomReaderWriter::getEntity
  * @covers MicrosoftAzure\Storage\Table\Internal\AtomReaderWriter::__construct
  * @covers MicrosoftAzure\Storage\Table\Internal\AtomReaderWriter::_serializeAtom
  * @covers MicrosoftAzure\Storage\Table\Internal\AtomReaderWriter::_generateProperties
  */
 public function testGetEntity()
 {
     // Setup
     $atomSerializer = new AtomReaderWriter();
     $entity = TestResources::getTestEntity('123', '456');
     $entity->addProperty('Cost', EdmType::DOUBLE, 12.45);
     $expected = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>' . "\n" . '<entry xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns="http://www.w3.org/2005/Atom">' . "\n" . ' <title/>' . "\n" . ' <updated>' . Utilities::isoDate() . '</updated>' . "\n" . ' <author>' . "\n" . '  <name/>' . "\n" . ' </author>' . "\n" . ' <id/>' . "\n" . ' <content type="application/xml">' . "\n" . '  <m:properties>' . "\n" . '   <d:PartitionKey>123</d:PartitionKey>' . "\n" . '   <d:RowKey>456</d:RowKey>' . "\n" . '   <d:CustomerId m:type="Edm.Int32">890</d:CustomerId>' . "\n" . '   <d:CustomerName>John</d:CustomerName>' . "\n" . '   <d:IsNew m:type="Edm.Boolean">1</d:IsNew>' . "\n" . '   <d:JoinDate m:type="Edm.DateTime">2012-01-26T18:26:19.0000470Z</d:JoinDate>' . "\n" . '   <d:Cost m:type="Edm.Double">12.45</d:Cost>' . "\n" . '  </m:properties>' . "\n" . ' </content>' . "\n" . '</entry>' . "\n";
     // Test
     $actual = $atomSerializer->getEntity($entity);
     // Assert
     $this->assertEquals($expected, $actual);
     return $actual;
 }
Example #2
0
 /**
  * @covers MicrosoftAzure\Storage\Table\Models\Entity::setTimestamp
  * @covers MicrosoftAzure\Storage\Table\Models\Entity::getTimestamp
  */
 public function testSetTimestamp()
 {
     // Setup
     $entity = new Entity();
     $expected = Utilities::convertToDateTime(Utilities::isoDate());
     // Test
     $entity->setTimestamp($expected);
     // Assert
     $this->assertEquals($expected, $entity->getTimestamp());
 }
 /**
  * @covers MicrosoftAzure\Storage\Common\Internal\Utilities::isoDate
  */
 public function testIsoDate()
 {
     // Test
     $date = Utilities::isoDate();
     // Assert
     $this->assertNotNull($date);
 }
 /**
  * Serializes the atom into XML representation.
  * 
  * @param array $properties The atom properties.
  * 
  * @return string
  */
 private function _serializeAtom($properties)
 {
     $xmlw = new \XmlWriter();
     $xmlw->openMemory();
     $xmlw->setIndent(true);
     $xmlw->startDocument(strtoupper($this->_xmlVersion), $this->_xmlEncoding, 'yes');
     $xmlw->startElementNS(null, 'entry', $this->_atomNamespaceName);
     $xmlw->writeAttribute("xmlns:{$this->_dataServicesPrefix}", $this->_dataServicesNamespaceName);
     $xmlw->writeAttribute("xmlns:{$this->_dataServicesMetadataPrefix}", $this->_dataServicesMetadataNamespaceName);
     $xmlw->writeElement('title');
     $xmlw->writeElement('updated', Utilities::isoDate());
     $xmlw->startElement('author');
     $xmlw->writeElement('name');
     $xmlw->endElement();
     $xmlw->writeElement('id');
     $xmlw->startElement('content');
     $xmlw->writeAttribute('type', Resources::XML_CONTENT_TYPE);
     $xmlw->startElementNS($this->_dataServicesMetadataPrefix, 'properties', null);
     $this->_generateProperties($xmlw, $properties);
     $xmlw->endElement();
     $xmlw->endElement();
     $xmlw->endElement();
     return $xmlw->outputMemory(true);
 }