/**
  * Test search InternalSkipToeknInfo::GetIndexOfFirstEntryInNextPage function
  */
 public function testGetIndexOfFirstEntryInNextPage2()
 {
     try {
         $northWindMetadata = CreateNorthWindMetadata1::Create();
         $configuration = new DataServiceConfiguration($northWindMetadata);
         $configuration->setEntitySetAccessRule('*', EntitySetRights::ALL);
         $metaQueryProverWrapper = new MetadataQueryProviderWrapper($northWindMetadata, null, $configuration, false);
         $resourceSetWrapper = $metaQueryProverWrapper->resolveResourceSet('Orders');
         $resourceType = $resourceSetWrapper->getResourceType();
         $orderBy = 'ShipName asc, Freight';
         //Note: library will add prim key as last sort key
         $orderBy .= ', OrderID';
         $qp = new NorthWindQueryProvider1();
         $orders = $qp->getResourceSet($resourceSetWrapper->getResourceSet());
         $internalOrderByInfo = OrderByParser::parseOrderByClause($resourceSetWrapper, $resourceType, $orderBy, $metaQueryProverWrapper);
         $compFun = $internalOrderByInfo->getSorterFunction();
         $fun = $compFun->getReference();
         usort($orders, $fun);
         $numRecords = count($orders);
         //-----------------------------------------------------------------
         //Search with a key that exactly matches
         $skipToken = utf8_decode(urldecode("'Antonio%20Moreno%20Taquer%C3%ADa',22.0000M,10365"));
         $skipToken = urldecode($skipToken);
         $internalSkipTokenInfo = SkipTokenParser::parseSkipTokenClause($resourceType, $internalOrderByInfo, $skipToken);
         $nextIndex = $internalSkipTokenInfo->getIndexOfFirstEntryInTheNextPage($orders);
         $this->assertTrue($nextIndex > 1);
         $this->assertTrue($nextIndex < $numRecords);
         //$nextIndex is the index of order record next to the searched record
         $this->assertEquals($orders[$nextIndex - 1]->OrderID, 10365);
         $this->assertEquals($orders[$nextIndex - 1]->Freight, 22.0);
         //-----------------------------------------------------------------
         //Search with a key that partially matches, in the DB there is no
         //order with ShipName 'An', but there are records start with
         //'An', so partial match, since its a parial match other two
         //key wont be used for comparsion
         $skipToken = "'An',22.0000M,10365";
         $internalSkipTokenInfo = SkipTokenParser::parseSkipTokenClause($resourceType, $internalOrderByInfo, $skipToken);
         $nextIndex = $internalSkipTokenInfo->getIndexOfFirstEntryInTheNextPage($orders);
         $this->assertTrue($nextIndex > 1);
         $this->assertTrue($nextIndex < $numRecords);
         //Make sure this is the most matching record by comparing with previous record
         $prevOrder = $orders[$nextIndex - 1];
         $r = strcmp($prevOrder->ShipName, $orders[$nextIndex]->ShipName);
         $this->assertTrue($r < 0);
         //Make sure this is the most matching record by comparing with next record
         $nextOrder = $orders[$nextIndex + 1];
         $r = strcmp($nextOrder->ShipName, $orders[$nextIndex]->ShipName);
         $this->assertTrue($r >= 0);
         //-----------------------------------------------------------------
         //Search with a key that does not exists
         $skipToken = "'XXX',11,10365";
         $internalSkipTokenInfo = SkipTokenParser::parseSkipTokenClause($resourceType, $internalOrderByInfo, $skipToken);
         $nextIndex = $internalSkipTokenInfo->getIndexOfFirstEntryInTheNextPage($orders);
         $this->assertTrue($nextIndex == -1);
         //-----------------------------------------------------------------
     } catch (\Exception $exception) {
         $this->fail('An unexpected Exception has been raised.' . $exception->getMessage());
     }
 }
 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);
 }
 /**
  * 
  * @see library/ODataProducer/ODataProducer.IServiceProvider::getService()
  * 
  * @return object
  */
 public function getService($serviceType)
 {
     if ($serviceType === 'IDataServiceMetadataProvider') {
         if (is_null($this->_northWindMetadata)) {
             $this->_northWindMetadata = CreateNorthWindMetadata1::Create();
         }
         return $this->_northWindMetadata;
     } else {
         if ($serviceType === 'IDataServiceQueryProvider') {
             if (is_null($this->_northWindQueryProvider)) {
                 $this->_northWindQueryProvider = new NorthWindQueryProvider1();
             }
             return $this->_northWindQueryProvider;
         } else {
             if ($serviceType === 'IDataServiceStreamProvider') {
                 return new NorthWindStreamProvider2();
             }
         }
     }
     return null;
 }