/** * Write entity container * * @return nothing */ private function _writeEntityContainer() { $this->_iOdataWriter->startElement(ODataConstants::ENTITY_CONTAINER); $this->_iOdataWriter->writeAttribute(ODataConstants::NAME, $this->_metadataQueryproviderWrapper->getContainerName()); $this->_iOdataWriter->writeAttributeNs(ODataConstants::ODATA_METADATA_NAMESPACE_PREFIX, ODataConstants::ISDEFAULT_ENTITY_CONTAINER_ATTRIBUTE, null, "true"); foreach ($this->_metadataManager->getResourceSets() as $resourceSet) { $this->_iOdataWriter->startElement(ODataConstants::ENTITY_SET); $this->_iOdataWriter->writeAttribute(ODataConstants::NAME, $resourceSet->getName()); $this->_iOdataWriter->writeAttribute(ODataConstants::ENTITY_TYPE, $resourceSet->getResourceType()->getFullName()); $this->_iOdataWriter->endElement(); } $this->_writeAssociationSets(); $this->_iOdataWriter->endElement(); }
public function testWriteMetadata() { $northWindMetadata = CreateNorthWindMetadata1::Create(); $configuration = new DataServiceConfiguration($northWindMetadata); $configuration->setEntitySetAccessRule("*", EntitySetRights::ALL); $configuration->setMaxDataServiceVersion(DataServiceProtocolVersion::V3); $northWindQuery = new NorthWindQueryProvider1(); $metaQueryProverWrapper = new MetadataQueryProviderWrapper($northWindMetadata, $northWindQuery, $configuration, false); $metadataWriter = new MetadataWriter($metaQueryProverWrapper); $metadata = $metadataWriter->writeMetadata(); $this->assertNotNull($metadata); $this->assertEquals($metaQueryProverWrapper->getContainerName(), 'NorthWindEntities'); $this->assertEquals($metaQueryProverWrapper->getContainerNamespace(), 'NorthWind'); $this->assertStringStartsWith('<edmx:Edmx Version="1.0"', $metadata); $customerResourceSet = $metaQueryProverWrapper->resolveResourceSet('Customers'); $this->assertEquals($customerResourceSet->getName(), 'Customers'); $this->assertEquals($customerResourceSet->getResourceType()->getName(), 'Customer'); $customerEntityType = $metaQueryProverWrapper->resolveResourceType('Customer'); $this->assertEquals($customerEntityType->getResourceTypeKind(), ResourceTypeKind::ENTITY); }
public function testContainerNameAndNameSpace2() { try { $configuration = null; $metadataProvider = $this->_createMetadataAndConfiguration2($configuration); $metaQueryProverWrapper = new MetadataQueryProviderWrapper($metadataProvider, null, $configuration, false); $exceptionThrown = false; try { $metaQueryProverWrapper->getContainerName(); } catch (ODataException $exception) { $exceptionThrown = true; $this->assertEquals($exception->getMessage(), 'The value returned by IDataServiceMetadataProvider::getContainerName method must not be null or empty'); } if (!$exceptionThrown) { $this->fail('An expected ODataException null container name has not been thrown'); } $exceptionThrown = false; try { $metaQueryProverWrapper->getContainerNamespace(); } catch (ODataException $exception) { $exceptionThrown = true; $this->assertEquals($exception->getMessage(), 'The value returned by IDataServiceMetadataProvider::getContainerNamespace method must not be null or empty'); } if (!$exceptionThrown) { $this->fail('An expected ODataException null container namespace has not been thrown'); } } catch (\Exception $exception) { $this->fail('An unexpected Exception has been raised' . $exception->getMessage()); } }