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 testGetResourceAssociationSet1()
 {
     try {
         //Get the association set where resource set in both ends are visible
         $configuration = null;
         $metadataProvider = $this->_createMetadataAndConfiguration1($configuration);
         $metaQueryProverWrapper = new MetadataQueryProviderWrapper($metadataProvider, null, $configuration, false);
         $configuration->setEntitySetAccessRule('Customers', EntitySetRights::ALL);
         $configuration->setEntitySetAccessRule('Orders', EntitySetRights::ALL);
         $customersEntitySetWrapper = $metaQueryProverWrapper->resolveResourceSet('Customers');
         $this->assertNotNull($customersEntitySetWrapper);
         $customerEntityType = $metaQueryProverWrapper->resolveResourceType('Customer');
         $this->assertNotNull($customerEntityType);
         $ordersProperty = $customerEntityType->tryResolvePropertyTypeByName('Orders');
         $this->assertNotNull($ordersProperty);
         $associationSet = $metaQueryProverWrapper->getResourceAssociationSet($customersEntitySetWrapper, $customerEntityType, $ordersProperty);
         $this->assertNotNull($associationSet);
         $associationSetEnd1 = $associationSet->getEnd1();
         $this->assertNotNull($associationSetEnd1);
         $associationSetEnd2 = $associationSet->getEnd2();
         $this->assertNotNull($associationSetEnd2);
         $this->assertEquals($associationSetEnd1->getResourceSet()->getName(), 'Customers');
         $this->assertEquals($associationSetEnd2->getResourceSet()->getName(), 'Orders');
         $this->assertEquals($associationSetEnd1->getResourceType()->getName(), 'Customer');
         $this->assertEquals($associationSetEnd2->getResourceType()->getName(), 'Order');
         //Try to get the association set where resource set in one end is invisible
         $configuration = null;
         $metadataProvider = $this->_createMetadataAndConfiguration1($configuration);
         $metaQueryProverWrapper = new MetadataQueryProviderWrapper($metadataProvider, null, $configuration, false);
         $configuration->setEntitySetAccessRule('Customers', EntitySetRights::ALL);
         //Set orders entity set as invisible
         $configuration->setEntitySetAccessRule('Orders', EntitySetRights::NONE);
         $customersEntitySetWrapper = $metaQueryProverWrapper->resolveResourceSet('Customers');
         $this->assertNotNull($customersEntitySetWrapper);
         $customerEntityType = $metaQueryProverWrapper->resolveResourceType('Customer');
         $this->assertNotNull($customerEntityType);
         $ordersProperty = $customerEntityType->tryResolvePropertyTypeByName('Orders');
         $this->assertNotNull($ordersProperty);
         $associationSet = $metaQueryProverWrapper->getResourceAssociationSet($customersEntitySetWrapper, $customerEntityType, $ordersProperty);
         $this->assertNull($associationSet);
     } catch (\Exception $exception) {
         $this->fail('An unexpected Exception has been raised' . $exception->getMessage());
     }
 }