PageRenderTime 79ms CodeModel.GetById 3ms app.highlight 62ms RepoModel.GetById 1ms app.codeStats 1ms

/OData Producer for PHP/Tests/UriProcessor/UriProcessorTest.php

#
PHP | 2461 lines | 1975 code | 149 blank | 337 comment | 134 complexity | 5840980579cbdb4b484766a33ca79aa8 MD5 | raw file
   1<?php
   2/**
   3 * Mainly test UriProcessor, but also do some partial test for DataService class.
   4 */
   5use ODataProducer\UriProcessor\QueryProcessor\ExpandProjectionParser\ProjectionNode;
   6use ODataProducer\UriProcessor\QueryProcessor\ExpandProjectionParser\ExpandedProjectionNode;
   7use ODataProducer\UriProcessor\QueryProcessor\ExpandProjectionParser\RootProjectionNode;
   8use ODataProducer\UriProcessor\QueryProcessor\AnonymousFunction;
   9use ODataProducer\UriProcessor\QueryProcessor\OrderByParser\OrderBySubPathSegment;
  10use ODataProducer\UriProcessor\QueryProcessor\OrderByParser\OrderByPathSegment;
  11use ODataProducer\UriProcessor\QueryProcessor\SkipTokenParser\InternalSkipTokenInfo;
  12use ODataProducer\UriProcessor\QueryProcessor\SkipTokenParser\SkipTokenInfo;
  13use ODataProducer\UriProcessor\QueryProcessor\ExpressionParser\InternalFilterInfo;
  14use ODataProducer\UriProcessor\QueryProcessor\OrderByParser\InternalOrderByInfo;
  15use ODataProducer\UriProcessor\RequestCountOption;
  16use ODataProducer\Configuration\DataServiceProtocolVersion;
  17use ODataProducer\UriProcessor\ResourcePathProcessor\SegmentParser\RequestTargetKind;
  18use ODataProducer\UriProcessor\ResourcePathProcessor\SegmentParser\RequestTargetSource;
  19use ODataProducer\Providers\Metadata\Type\Int32;
  20use ODataProducer\Providers\Metadata\Type\DateTime;
  21use ODataProducer\Common\Url;
  22use ODataProducer\Common\Version;
  23use ODataProducer\Common\ODataException;
  24require_once 'PHPUnit\Framework\Assert.php';
  25require_once 'PHPUnit\Framework\Test.php';
  26require_once 'PHPUnit\Framework\SelfDescribing.php';
  27require_once 'PHPUnit\Framework\TestCase.php';
  28require_once 'PHPUnit\Framework\TestSuite.php';
  29require_once 'ODataProducer\Common\ClassAutoLoader.php';
  30require_once (dirname(__FILE__) . "\.\..\Resources\NorthWindMetadata.php");
  31require_once (dirname(__FILE__) . "\.\..\Resources\NorthWindDataServiceV1.php");
  32require_once (dirname(__FILE__) . "\.\..\Resources\NorthWindDataService.php");
  33require_once (dirname(__FILE__) . "\.\..\Resources\NorthWindDataServiceV3.php");
  34require_once (dirname(__FILE__) . "\.\..\Resources\DataServiceHost2.php");
  35ODataProducer\Common\ClassAutoLoader::register();
  36class TestUriProcessor extends PHPUnit_Framework_TestCase
  37{
  38    protected function setUp()
  39    {
  40    }
  41
  42    /**
  43     * The request uri should be based on the service uri specified in the configuration.
  44     */
  45    /**public function testRequestUriWithInvalidBaseUri()
  46    {
  47        try {
  48            $hostInfo = array('AbsoluteRequestUri' => 
  49                                    new Url('http://localhost:8083/NorthWindDataService.svc'), 
  50				      		  'AbsoluteServiceUri' => 
  51                                    new Url('http://localhost:8083/XX/NorthWindDataService.svc'),
  52				  		      'QueryString' => 
  53                                    null);
  54            $host = new DataServiceHost2($hostInfo);
  55            $dataService = new NorthWindDataService2();
  56            $dataService->setHost($host);
  57            $exceptionThrown = false;
  58            try {
  59                $dataService->handleRequest();
  60            } catch (ODataException $odataException) {
  61                $exceptionThrown = true;
  62                $this->assertStringStartsWith("The URI 'http://localhost:8083/NorthWindDataService.svc' is not ", $odataException->getMessage());
  63            }
  64
  65            if (!$exceptionThrown) {
  66                $this->fail('An expected ODataException for invalid base uri in the request uri has not been thrown');
  67            }
  68                        
  69        } catch (\Exception $exception) {
  70            $this->fail('An unexpected Exception has been raised' . $exception->getMessage());
  71        }
  72        
  73        
  74    }**/
  75
  76    /**
  77     * Test with request uri where RequestTargetKind is NONE. RequestTargetKind will be
  78     * NONE for service directory, metadata and batch.
  79     */
  80    public function testUriProcessorWithRequestUriOfNoneTargetSourceKind()
  81    {
  82        try {
  83            //Request for service directory
  84            $hostInfo = array('AbsoluteRequestUri' => 
  85                                    new Url('http://localhost:8083/NorthWindDataService.svc'), 
  86				      		  'AbsoluteServiceUri' => 
  87                                    new Url('http://localhost:8083/NorthWindDataService.svc'),
  88				  		      'QueryString' => 
  89                                    null);
  90            $host = new DataServiceHost2($hostInfo);
  91            $dataService = new NorthWindDataService2();
  92            $dataService->setHost($host);
  93            $exceptionThrown = false;           
  94            $uriProcessor = $dataService->handleRequest();
  95            $requestDescripton = $uriProcessor->getRequestDescription();
  96            $this->assertEquals($requestDescripton->getTargetSource(), RequestTargetSource::NONE);
  97            $this->assertEquals($requestDescripton->getTargetKind(), RequestTargetKind::SERVICE_DIRECTORY);
  98            // Context is a singleton class reset it
  99            $host->getWebOperationContext()->resetWebContextInternal();
 100            
 101            //Request for metadata
 102            $hostInfo = array('AbsoluteRequestUri' => 
 103                                    new Url('http://localhost:8083/NorthWindDataService.svc/$metadata'), 
 104				      		  'AbsoluteServiceUri' => 
 105                                    new Url('http://localhost:8083/NorthWindDataService.svc'),
 106				  		      'QueryString' => 
 107                                    null);
 108                                    
 109            $host = new DataServiceHost2($hostInfo);
 110            $dataService = new NorthWindDataService2();
 111            $dataService->setHost($host);
 112            $exceptionThrown = false;   
 113            $requestDescripton = $uriProcessor = null;        
 114            $uriProcessor = $dataService->handleRequest();
 115            $requestDescripton = $uriProcessor->getRequestDescription();            
 116            $this->assertEquals($requestDescripton->getTargetSource(), RequestTargetSource::NONE);
 117            $this->assertEquals($requestDescripton->getTargetKind(), RequestTargetKind::METADATA);
 118            // Context is a singleton class reset it
 119            $host->getWebOperationContext()->resetWebContextInternal();
 120            
 121            //Request for batch
 122            $hostInfo = array('AbsoluteRequestUri' => 
 123                                    new Url('http://localhost:8083/NorthWindDataService.svc/$batch'), 
 124				      		  'AbsoluteServiceUri' => 
 125                                    new Url('http://localhost:8083/NorthWindDataService.svc'),
 126				  		      'QueryString' => 
 127                                    null);
 128            $host = new DataServiceHost2($hostInfo);
 129            $dataService = new NorthWindDataService2();
 130            $dataService->setHost($host);
 131            $exceptionThrown = false;           
 132            $uriProcessor = $dataService->handleRequest();
 133            $requestDescripton = $uriProcessor->getRequestDescription();
 134            $this->assertEquals($requestDescripton->getTargetSource(), RequestTargetSource::NONE);
 135            $this->assertEquals($requestDescripton->getTargetKind(), RequestTargetKind::BATCH);
 136            // Context is a singleton class reset it
 137            $host->getWebOperationContext()->resetWebContextInternal();
 138        } catch (\Exception $exception) {
 139            if ($host != null) {
 140                $host->getWebOperationContext()->resetWebContextInternal();
 141            }
 142            $this->fail('An unexpected Exception has been raised' . $exception->getMessage());
 143        } 
 144    }
 145
 146    /**
 147     * Test request uri for row count ($count)     
 148     * DataServiceVersion and MaxDataServiceVersion should be >= 2.0 for $count
 149     */
 150    public function testUriProcessorForCountRequest1()
 151    {
 152        try {
 153            //Test $count with DataServiceVersion < 2.0
 154            $hostInfo = array('AbsoluteRequestUri' => new Url('http://localhost:8083/NorthWindDataService.svc/Customers/$count'), 
 155			    	  'AbsoluteServiceUri' => new Url('http://localhost:8083/NorthWindDataService.svc'),
 156				      'QueryString' => null,
 157                  	  'DataServiceVersion' => new Version(1, 0),
 158                  	  'MaxDataServiceVersion' => new Version(2, 0));
 159
 160            $host = new DataServiceHost2($hostInfo);
 161            $dataService = new NorthWindDataService2();
 162            $dataService->setHost($host);
 163            $exceptionThrown = false;
 164            try {
 165                $uriProcessor = $dataService->handleRequest();                
 166            } catch (ODataException $odataException) {                
 167                $exceptionThrown = true;                
 168                $this->assertStringStartsWith("Request version '1.0' is not supported for the request payload. The only supported version is '2.0", $odataException->getMessage());
 169            }
 170
 171            if (!$exceptionThrown) {
 172                $this->fail('An expected ODataException for failure of capability negoitation over DataServiceVersion has not been thrown');
 173            }
 174
 175            // Context is a singleton class reset it
 176            $host->getWebOperationContext()->resetWebContextInternal();
 177            //Test $count with MaxDataServiceVersion < 2.0
 178            $hostInfo = array('AbsoluteRequestUri' => new Url('http://localhost:8083/NorthWindDataService.svc/Customers/$count'), 
 179			    	  'AbsoluteServiceUri' => new Url('http://localhost:8083/NorthWindDataService.svc'),
 180				      'QueryString' => null,
 181                  	  'DataServiceVersion' => new Version(2, 0),
 182                  	  'MaxDataServiceVersion' => new Version(1, 0));
 183            
 184            $host = new DataServiceHost2($hostInfo);
 185            $dataService = new NorthWindDataService2();
 186            $dataService->setHost($host);
 187            $exceptionThrown = false;
 188            try {
 189                $uriProcessor = $dataService->handleRequest();
 190            } catch (ODataException $odataException) {
 191                $exceptionThrown = true;
 192                $this->assertStringStartsWith("Request version '1.0' is not supported for the request payload. The only supported version is '2.0", $odataException->getMessage());
 193            }
 194
 195            if (!$exceptionThrown) {
 196                $this->fail('An expected ODataException for failure of capability negoitation over MaxDataServiceVersion has not been thrown');
 197            }
 198            $host->getWebOperationContext()->resetWebContextInternal();
 199        } catch (\Exception $exception) {
 200            if ($host != null) {
 201                $host->getWebOperationContext()->resetWebContextInternal();
 202            }
 203            $this->fail('An unexpected Exception has been raised' . $exception->getMessage());            
 204        }
 205    }
 206
 207    /**
 208     * Test request uri for row count ($count)     
 209     * $count is a version 2 feature so service devloper should use protocol version 2.0
 210     */
 211    public function testUriProcessorForCountRequest2()
 212    {
 213        try {            
 214            $hostInfo = array('AbsoluteRequestUri' => new Url('http://localhost:8083/NorthWindDataService.svc/Customers/$count'), 
 215			    	  'AbsoluteServiceUri' => new Url('http://localhost:8083/NorthWindDataService.svc'),
 216				      'QueryString' => null,
 217                  	  'DataServiceVersion' => new Version(2, 0),
 218                  	  'MaxDataServiceVersion' => new Version(2, 0));
 219
 220            $host = new DataServiceHost2($hostInfo);
 221            $dataService = new NorthWindDataServiceV1();                
 222            $dataService->setHost($host);
 223            $exceptionThrown = false;
 224            try {
 225                $uriProcessor = $dataService->handleRequest();
 226            } catch (ODataException $odataException) {
 227                $exceptionThrown = true;                
 228                $this->assertStringStartsWith("The response requires that version 2.0 of the protocol be used, but the MaxProtocolVersion of the data service is set to 1.0", $odataException->getMessage());
 229            }
 230
 231            if (!$exceptionThrown) {
 232                $this->fail('An expected ODataException for failure of capability negoitation due to V1 configuration has not been thrown');
 233            }
 234            $host->getWebOperationContext()->resetWebContextInternal();
 235        } catch (\Exception $exception) {
 236            if ($host != null) {
 237                $host->getWebOperationContext()->resetWebContextInternal();
 238            }
 239            $this->fail('An unexpected Exception has been raised' . $exception->getMessage());
 240        }
 241    }
 242
 243    /**
 244     * Test request uri for row count ($count)     
 245     * 
 246     * Suppose $top option is absent, still
 247     * RequestDescription::topCount will be set if the resource targetted by the
 248     * uri has paging enabled, if RequestDescription::topCount 
 249     * is set then internal orderby info will be generated. But if the request 
 250     * is for raw count for a resource collection then paging is not applicable
 251     * for that, so topCount will be null and internal orderby info will not be 
 252     * generated.
 253     */
 254    public function testUriProcessorForCountRequest3()
 255    {
 256        try {            
 257            $hostInfo = array('AbsoluteRequestUri' => new Url('http://localhost:8083/NorthWindDataService.svc/Customers/$count'), 
 258			    	  'AbsoluteServiceUri' => new Url('http://localhost:8083/NorthWindDataService.svc'),
 259				      'QueryString' => null,
 260                  	  'DataServiceVersion' => new Version(2, 0),
 261                  	  'MaxDataServiceVersion' => new Version(2, 0));
 262
 263            $host = new DataServiceHost2($hostInfo);
 264            $dataService = new NorthWindDataService2();                   
 265            $dataService->setHost($host);
 266            $exceptionThrown = false;            
 267            $uriProcessor = $dataService->handleRequest();
 268            $requestDescription = $uriProcessor->getRequestDescription();
 269            $this->assertTrue(!is_null($requestDescription));
 270            $this->assertTrue(is_null($requestDescription->getInternalOrderByInfo()));
 271            $host->getWebOperationContext()->resetWebContextInternal();
 272            
 273        } catch (\Exception $exception) {            
 274            if ($host != null) {
 275                $host->getWebOperationContext()->resetWebContextInternal();
 276            }
 277            $this->fail('An unexpected Exception has been raised' . $exception->getMessage());
 278        }
 279    }
 280
 281    /**
 282     * Test request uri for row count ($count)     
 283     * 
 284     * $orderby option can be applied to a $count request.
 285     */
 286    public function testUriProcessorForCountRequest4()
 287    {
 288        try {            
 289            $hostInfo = array('AbsoluteRequestUri' => new Url('http://localhost:8083/NorthWindDataService.svc/Customers/$count'), 
 290			    	  'AbsoluteServiceUri' => new Url('http://localhost:8083/NorthWindDataService.svc'),
 291				      'QueryString' => '$orderby=Country',
 292                  	  'DataServiceVersion' => new Version(2, 0),
 293                  	  'MaxDataServiceVersion' => new Version(2, 0));
 294
 295            $host = new DataServiceHost2($hostInfo);
 296            $dataService = new NorthWindDataService2();                   
 297            $dataService->setHost($host);
 298            $exceptionThrown = false;            
 299            $uriProcessor = $dataService->handleRequest();
 300            $requestDescription = $uriProcessor->getRequestDescription();
 301            $this->assertTrue(!is_null($requestDescription));
 302            $internalOrderByInfo = $requestDescription->getInternalOrderByInfo();
 303            $this->assertTrue(!is_null($internalOrderByInfo));
 304            $object = $internalOrderByInfo->getDummyObject();
 305            $this->assertTrue(!is_null($object));
 306            $this->assertTrue($object instanceof Customer2);
 307            $host->getWebOperationContext()->resetWebContextInternal();
 308            
 309        } catch (\Exception $exception) {
 310            if ($host != null) {
 311                $host->getWebOperationContext()->resetWebContextInternal();
 312            }
 313            $this->fail('An unexpected Exception has been raised' . $exception->getMessage());
 314        }
 315    }
 316
 317    /**
 318     * Test request uri for row count ($count)     
 319     * 
 320     * $skip and $top options can be applied to $count request, this cause
 321     * processor to generate internalorderinfo.
 322     */
 323    public function testUriProcessorForCountRequest5()
 324    {
 325        try {            
 326            $hostInfo = array('AbsoluteRequestUri' => new Url('http://localhost:8083/NorthWindDataService.svc/Customers/$count'), 
 327			    	  'AbsoluteServiceUri' => new Url('http://localhost:8083/NorthWindDataService.svc'),
 328				      'QueryString' => '$skip=2&$top=4',
 329                  	  'DataServiceVersion' => new Version(2, 0),
 330                  	  'MaxDataServiceVersion' => new Version(2, 0));
 331
 332            $host = new DataServiceHost2($hostInfo);
 333            $dataService = new NorthWindDataService2();                   
 334            $dataService->setHost($host);
 335            $exceptionThrown = false;            
 336            $uriProcessor = $dataService->handleRequest();
 337            $requestDescription = $uriProcessor->getRequestDescription();
 338            $this->assertTrue(!is_null($requestDescription));
 339            $this->assertEquals($requestDescription->getTopCount(), 4);
 340            $this->assertEquals($requestDescription->getSkipCount(), 2);
 341            $internalOrderByInfo = $requestDescription->getInternalOrderByInfo();
 342            $this->assertTrue(!is_null($internalOrderByInfo));
 343            $object = $internalOrderByInfo->getDummyObject();
 344            $this->assertTrue(!is_null($object));
 345            $this->assertTrue($object instanceof Customer2);
 346            $host->getWebOperationContext()->resetWebContextInternal();
 347        } catch (\Exception $exception) {
 348            if ($host != null) {
 349                $host->getWebOperationContext()->resetWebContextInternal();
 350            }
 351            $this->fail('An unexpected Exception has been raised' . $exception->getMessage());
 352        }
 353    }
 354
 355    /**
 356     * Test request uri for row count ($count)     
 357     * 
 358     * $skip and/or $top options along with $orderby option cause internalOrderInfo
 359     * to include sorter functions using keys + paths in the $orderby clause
 360     */
 361    public function testUriProcessorForCountRequest6()
 362    {
 363        try {            
 364            $hostInfo = array('AbsoluteRequestUri' => new Url('http://localhost:8083/NorthWindDataService.svc/Customers/$count'), 
 365			    	  'AbsoluteServiceUri' => new Url('http://localhost:8083/NorthWindDataService.svc'),
 366				      'QueryString' => '$skip=2&$top=4&$orderby=Country',
 367                  	  'DataServiceVersion' => new Version(2, 0),
 368                  	  'MaxDataServiceVersion' => new Version(2, 0));
 369
 370            $host = new DataServiceHost2($hostInfo);
 371            $dataService = new NorthWindDataService2();                   
 372            $dataService->setHost($host);
 373            $exceptionThrown = false;            
 374            $uriProcessor = $dataService->handleRequest();
 375            $requestDescription = $uriProcessor->getRequestDescription();
 376            $this->assertTrue(!is_null($requestDescription));
 377            $this->assertEquals($requestDescription->getTopCount(), 4);
 378            $this->assertEquals($requestDescription->getSkipCount(), 2);
 379            $internalOrderByInfo = $requestDescription->getInternalOrderByInfo();
 380            $this->assertTrue(!is_null($internalOrderByInfo));
 381            $object = $internalOrderByInfo->getDummyObject();
 382            $this->assertTrue(!is_null($object));
 383            $this->assertTrue($object instanceof Customer2);
 384            $pathSegments = $internalOrderByInfo->getOrderByPathSegments();
 385            $this->assertTrue(!is_null($pathSegments));
 386            $this->assertTrue(is_array($pathSegments));
 387            $this->assertEquals(count($pathSegments), 3);
 388            $this->assertTrue($pathSegments[0] instanceof OrderByPathSegment);
 389            $subPathSegments = $pathSegments[0]->getSubPathSegments();
 390            $this->assertTrue(!is_null($subPathSegments));
 391            $this->assertTrue(is_array($subPathSegments));
 392            $this->assertEquals(count($subPathSegments), 1);
 393            $this->assertTrue($subPathSegments[0] instanceof OrderBySubPathSegment);
 394            $this->assertEquals($subPathSegments[0]->getName(), 'Country');
 395            
 396            $this->assertTrue($pathSegments[1] instanceof OrderByPathSegment);
 397            $subPathSegments = $pathSegments[1]->getSubPathSegments();
 398            $this->assertTrue(!is_null($subPathSegments));
 399            $this->assertTrue(is_array($subPathSegments));
 400            $this->assertEquals(count($subPathSegments), 1);
 401            $this->assertTrue($subPathSegments[0] instanceof OrderBySubPathSegment);
 402            $this->assertEquals($subPathSegments[0]->getName(), 'CustomerID');
 403            
 404            $this->assertTrue($pathSegments[2] instanceof OrderByPathSegment);
 405            $subPathSegments = $pathSegments[2]->getSubPathSegments();
 406            $this->assertTrue(!is_null($subPathSegments));
 407            $this->assertTrue(is_array($subPathSegments));
 408            $this->assertEquals(count($subPathSegments), 1);
 409            $this->assertTrue($subPathSegments[0] instanceof OrderBySubPathSegment);
 410            $this->assertEquals($subPathSegments[0]->getName(), 'CustomerGuid');
 411            $host->getWebOperationContext()->resetWebContextInternal();
 412        } catch (\Exception $exception) {
 413            if ($host != null) {
 414                $host->getWebOperationContext()->resetWebContextInternal();
 415            }
 416            $this->fail('An unexpected Exception has been raised' . $exception->getMessage());
 417        }
 418    }
 419
 420    /**
 421     * Test request uri for row count ($count)     
 422     * $skiptoken is not applicable for $count request, as it requires
 423     * paging and paging is not applicable for $count request
 424     */
 425    public function testUriProcessorForCountRequest7()
 426    {
 427        try {            
 428            $hostInfo = array('AbsoluteRequestUri' => new Url('http://localhost:8083/NorthWindDataService.svc/Customers/$count'), 
 429			    	  'AbsoluteServiceUri' => new Url('http://localhost:8083/NorthWindDataService.svc'),
 430				      'QueryString' => '$top=1&$skiptoken=\'ALFKI\',guid\'05b242e752eb46bd8f0e6568b72cd9a5\'',
 431                  	  'DataServiceVersion' => new Version(2, 0),
 432                  	  'MaxDataServiceVersion' => new Version(2, 0));
 433
 434            $host = new DataServiceHost2($hostInfo);
 435            $dataService = new NorthWindDataService2();
 436            $dataService->setHost($host);
 437            $exceptionThrown = false;
 438            try {
 439                $uriProcessor = $dataService->handleRequest();
 440            } catch (ODataException $odataException) {
 441                $exceptionThrown = true;
 442                $this->assertStringStartsWith("Query option \$skiptoken cannot be applied to the requested resource", $odataException->getMessage());
 443            }
 444
 445            if (!$exceptionThrown) {
 446                $this->fail('An expected ODataException for applying $skiptoken on $count has not been thrown');
 447            }
 448
 449            $host->getWebOperationContext()->resetWebContextInternal();
 450        } catch (\Exception $exception) {
 451            if ($host != null) {
 452                $host->getWebOperationContext()->resetWebContextInternal();
 453            }
 454            $this->fail('An unexpected Exception has been raised' . $exception->getMessage());
 455        }
 456    }
 457
 458    /**
 459     * Test request uri for row count ($count)     
 460     * 
 461     * $filter is applicable for $count segment.
 462     */
 463    public function testUriProcessorForCountRequest8()
 464    {
 465        try {            
 466            $hostInfo = array('AbsoluteRequestUri' => new Url('http://localhost:8083/NorthWindDataService.svc/Customers/$count'), 
 467			    	  'AbsoluteServiceUri' => new Url('http://localhost:8083/NorthWindDataService.svc'),
 468				      'QueryString' => '$filter=Country eq \'USA\'',
 469                  	  'DataServiceVersion' => new Version(2, 0),
 470                  	  'MaxDataServiceVersion' => new Version(2, 0));
 471
 472            $host = new DataServiceHost2($hostInfo);
 473            $dataService = new NorthWindDataService2();                   
 474            $dataService->setHost($host);                  
 475            $uriProcessor = $dataService->handleRequest();
 476            $requestDescription = $uriProcessor->getRequestDescription();
 477            $this->assertTrue(!is_null($requestDescription));
 478            $internalFilterInfo = $requestDescription->getInternalFilterInfo();
 479            $this->assertTrue(!is_null($internalFilterInfo));
 480            $filterInfo = $internalFilterInfo->getFilterInfo();
 481            $this->assertTrue(!is_null($filterInfo));
 482            $this->assertTrue(is_null($filterInfo->getNavigationPropertiesUsed()));
 483            $filterFunction = $internalFilterInfo->getFilterFunction();
 484            $this->assertTrue(!is_null($filterFunction));
 485            $this->assertTrue($filterFunction instanceof  AnonymousFunction);
 486            $host->getWebOperationContext()->resetWebContextInternal();
 487        } catch (\Exception $exception) {
 488            if ($host != null) {
 489                $host->getWebOperationContext()->resetWebContextInternal();
 490            }
 491            $this->fail('An unexpected Exception has been raised' . $exception->getMessage());
 492        }
 493    }
 494
 495    /**
 496     * Test request uri for row count ($count)     
 497     * 
 498     * $select and $expand options are applicable for $count segment.
 499     * but when we do query execution we will ignore them.
 500     */
 501    public function testUriProcessorForCountRequest9()
 502    {
 503        try {            
 504            $hostInfo = array('AbsoluteRequestUri' => new Url('http://localhost:8083/NorthWindDataService.svc/Customers/$count'), 
 505			    	  'AbsoluteServiceUri' => new Url('http://localhost:8083/NorthWindDataService.svc'),
 506				      'QueryString' => '$select=Country&$expand=Orders',
 507                  	  'DataServiceVersion' => new Version(2, 0),
 508                  	  'MaxDataServiceVersion' => new Version(2, 0));
 509
 510            $host = new DataServiceHost2($hostInfo);
 511            $dataService = new NorthWindDataService2();                   
 512            $dataService->setHost($host);                  
 513            $uriProcessor = $dataService->handleRequest();
 514            $requestDescription = $uriProcessor->getRequestDescription();
 515            $this->assertTrue(!is_null($requestDescription));
 516            $projectionTreeRoot = $requestDescription->getRootProjectionNode();
 517            $this->assertTrue(!is_null($projectionTreeRoot));
 518            $this->assertTrue($projectionTreeRoot instanceof RootProjectionNode);
 519            //There will be one child node for 'Country', 'Orders' wont be included
 520            //as its not selected
 521            $childNodes = $projectionTreeRoot->getChildNodes();
 522            $this->assertTrue(!is_null($childNodes));
 523            $this->assertTrue(is_array($childNodes));
 524            $this->assertEquals(count($childNodes), 1);
 525            $this->assertTrue(array_key_exists('Country', $childNodes));
 526            $this->assertTrue($childNodes['Country'] instanceof ProjectionNode);
 527            $host->getWebOperationContext()->resetWebContextInternal();
 528        } catch (\Exception $exception) {
 529            if ($host != null) {
 530                $host->getWebOperationContext()->resetWebContextInternal();
 531            }
 532            $this->fail('An unexpected Exception has been raised' . $exception->getMessage());
 533        }
 534    }
 535
 536    /**
 537     * Test request uri for row count ($count)     
 538     * $count with $inlinecount not allowed
 539     */
 540    public function testUriProcessorForCountWithInline()
 541    {
 542        try {            
 543            $hostInfo = array('AbsoluteRequestUri' => new Url('http://localhost:8083/NorthWindDataService.svc/Customers/$count'), 
 544			    	  'AbsoluteServiceUri' => new Url('http://localhost:8083/NorthWindDataService.svc'),
 545				      'QueryString' => '$inlinecount=allpages',
 546                  	  'DataServiceVersion' => new Version(2, 0),
 547                  	  'MaxDataServiceVersion' => new Version(2, 0));
 548
 549            $host = new DataServiceHost2($hostInfo);
 550            $dataService = new NorthWindDataService2();
 551            $dataService->setHost($host);
 552            $exceptionThrown = false;
 553            try {
 554                $uriProcessor = $dataService->handleRequest();
 555            } catch (ODataException $odataException) {
 556                $exceptionThrown = true;
 557                $this->assertStringStartsWith("\$inlinecount cannot be applied to the resource segment \$count", $odataException->getMessage());
 558            }
 559
 560            if (!$exceptionThrown) {
 561                $this->fail('An expected ODataException for applying $skiptoken on $count has not been thrown');
 562            }
 563            $host->getWebOperationContext()->resetWebContextInternal();
 564        } catch (\Exception $exception) {
 565            if ($host != null) {
 566                $host->getWebOperationContext()->resetWebContextInternal();
 567            }
 568            $this->fail('An unexpected Exception has been raised' . $exception->getMessage());
 569        }
 570    }
 571
 572    /**
 573     * If paging is enabled for a resource set, then the uri 
 574     * processor should generate orderinfo irrespective of
 575     * whether $top or $orderby is specified or not.
 576     * 
 577     * Request DataServiceVersion => 1.0
 578     * Request MaxDataServiceVersion => 2.0
 579     */
 580    public function testUriProcessorForResourcePageInfo1()
 581    {
 582        try {
 583            //Test for generation of orderinfo for resource set
 584            //with request DataServiceVersion 1.0
 585            $hostInfo = array('AbsoluteRequestUri' => new Url('http://localhost:8083/NorthWindDataService.svc/Customers'), 
 586			    	  'AbsoluteServiceUri' => new Url('http://localhost:8083/NorthWindDataService.svc'),
 587				      'QueryString' => null,
 588                  	  'DataServiceVersion' => new Version(1, 0),
 589                  	  'MaxDataServiceVersion' => new Version(2, 0));
 590
 591            $host = new DataServiceHost2($hostInfo);
 592            $dataService = new NorthWindDataService2();
 593            $dataService->setHost($host);
 594            $uriProcessor = $dataService->handleRequest();
 595            $requestDescription = $uriProcessor->getRequestDescription();
 596            $this->assertTrue(!is_null($requestDescription));
 597            //Page size is 5, so take count is 5
 598            $this->assertEquals($requestDescription->getTopCount(), 5);
 599            
 600            //order info is required for pagination
 601            $internalOrderByInfo = $requestDescription->getInternalOrderByInfo();
 602            $this->assertTrue(!is_null($internalOrderByInfo));
 603            $pathSegments = $internalOrderByInfo->getOrderByPathSegments();
 604            $this->assertTrue(!is_null($pathSegments));
 605            $this->assertTrue(is_array($pathSegments));
 606            //Customer has two keys
 607            $this->assertEquals(count($pathSegments), 2);
 608            $this->assertTrue($pathSegments[0] instanceof OrderByPathSegment);
 609            $subPathSegments = $pathSegments[0]->getSubPathSegments();
 610            $this->assertTrue(!is_null($subPathSegments));
 611            $this->assertTrue(is_array($subPathSegments));
 612            $this->assertEquals(count($subPathSegments), 1);
 613            $this->assertTrue($subPathSegments[0] instanceof OrderBySubPathSegment);
 614            $this->assertEquals($subPathSegments[0]->getName(), 'CustomerID');
 615            
 616            $this->assertTrue($pathSegments[1] instanceof OrderByPathSegment);
 617            $subPathSegments = $pathSegments[1]->getSubPathSegments();
 618            $this->assertTrue(!is_null($subPathSegments));
 619            $this->assertTrue(is_array($subPathSegments));
 620            $this->assertEquals(count($subPathSegments), 1);
 621            $this->assertTrue($subPathSegments[0] instanceof OrderBySubPathSegment);
 622            $this->assertEquals($subPathSegments[0]->getName(), 'CustomerGuid');
 623            $host->getWebOperationContext()->resetWebContextInternal();
 624        } catch (\Exception $exception) {
 625            if ($host != null) {
 626                $host->getWebOperationContext()->resetWebContextInternal();
 627            }
 628            $this->fail('An unexpected Exception has been raised' . $exception->getMessage());
 629        }
 630    }
 631
 632    /**
 633     * If paging is enabled for a resource set, then the uri 
 634     * processor should generate orderinfo irrespective of
 635     * whether $top or $orderby is specified or not.
 636     * 
 637     * Request DataServiceVersion => 1.0
 638     * Request MaxDataServiceVersion => 1.0
 639     * 
 640     * This will fail as paging requires version 2.0 or above
 641     */
 642    public function testUriProcessorForResourcePageInfo2()
 643    {
 644        try {
 645            //Test for generation of orderinfo for resource set
 646            //with request DataServiceVersion 1.0
 647            $hostInfo = array('AbsoluteRequestUri' => new Url('http://localhost:8083/NorthWindDataService.svc/Customers'), 
 648			    	  'AbsoluteServiceUri' => new Url('http://localhost:8083/NorthWindDataService.svc'),
 649				      'QueryString' => null,
 650                  	  'DataServiceVersion' => new Version(1, 0),
 651                  	  'MaxDataServiceVersion' => new Version(1, 0));
 652
 653            $host = new DataServiceHost2($hostInfo);
 654            $dataService = new NorthWindDataService2();
 655            $dataService->setHost($host);
 656            $exceptionThrown = false;
 657            try {
 658                $uriProcessor = $dataService->handleRequest();
 659            } catch (ODataException $odataException) {
 660                $exceptionThrown = true;                
 661                $this->assertStringStartsWith("Request version '1.0' is not supported for the request payload. The only supported version is '2.0'", $odataException->getMessage());
 662            }
 663
 664            if (!$exceptionThrown) {
 665                $this->fail('An expected ODataException due to capability negotiation has not been thrown (paged result but client\'s max supportedd version is 1.0)');
 666            }
 667            $host->getWebOperationContext()->resetWebContextInternal();    
 668        } catch (\Exception $exception) {
 669            if ($host != null) {
 670                $host->getWebOperationContext()->resetWebContextInternal();
 671            }
 672            $this->fail('An unexpected Exception has been raised' . $exception->getMessage());
 673        }
 674    }
 675
 676    /**
 677     * Paging is enabled only for resource set, so with resource set
 678     * reference there will not be any paginginfo.
 679     */
 680    public function testUriProcessorForResourcePageInfo3()
 681    {
 682        try {
 683            //Test for generation of orderinfo for resource set
 684            //with request DataServiceVersion 1.0
 685            $hostInfo = array('AbsoluteRequestUri' => new Url('http://localhost:8083/NorthWindDataService.svc/Orders(123)'), 
 686			    	  'AbsoluteServiceUri' => new Url('http://localhost:8083/NorthWindDataService.svc'),
 687				      'QueryString' => null,
 688                  	  'DataServiceVersion' => new Version(1, 0),
 689                  	  'MaxDataServiceVersion' => new Version(2, 0));
 690
 691            $host = new DataServiceHost2($hostInfo);
 692            $dataService = new NorthWindDataService2();
 693            $dataService->setHost($host);
 694            $uriProcessor = $dataService->handleRequest();
 695            $requestDescription = $uriProcessor->getRequestDescription();
 696            $this->assertTrue(!is_null($requestDescription));
 697            //Page is not appliable for single resouce
 698            $this->assertEquals($requestDescription->getTopCount(), null);            
 699            //order info wont be generated as resource is not applicable for pagination
 700            $internalOrderByInfo = $requestDescription->getInternalOrderByInfo();
 701            $this->assertTrue(is_null($internalOrderByInfo));
 702            $host->getWebOperationContext()->resetWebContextInternal();
 703        } catch (\Exception $exception) {
 704            if ($host != null) {
 705                $host->getWebOperationContext()->resetWebContextInternal();
 706            }
 707            $this->fail('An unexpected Exception has been raised' . $exception->getMessage());
 708        }
 709    }
 710
 711    /**
 712     * If paging is enabled for a resource set, then $link request for that resource set
 713     * will also paged
 714     * e.g. http://host/service.svc/Customers('A')/$links/Orders
 715     * here if paging is enabled for Orders then prcoessor must generate orderbyinfo for
 716     * this.     
 717     */
 718    public function testUriProcessorForResourcePageInfo4()
 719    {
 720        try {
 721            //Test for generation of orderinfo for resource set in $links query
 722            $baseUri = 'http://localhost:8083/NorthWindDataService.svc/';
 723            $resourcePath = 'Customers(CustomerID=\'ALFKI\', CustomerGuid=guid\'05b242e752eb46bd8f0e6568b72cd9a5\')/$links/Orders';
 724            $hostInfo = array('AbsoluteRequestUri' => new Url($baseUri . $resourcePath),                                
 725			    	  			'AbsoluteServiceUri' => new Url($baseUri),
 726				      			'QueryString' => null,
 727                  	  			'DataServiceVersion' => new Version(1, 0),
 728                  	  			'MaxDataServiceVersion' => new Version(2, 0));
 729
 730            $host = new DataServiceHost2($hostInfo);
 731            $dataService = new NorthWindDataService2();
 732            $dataService->setHost($host);
 733            $uriProcessor = $dataService->handleRequest();
 734            $requestDescription = $uriProcessor->getRequestDescription();
 735            $this->assertTrue(!is_null($requestDescription));
 736            //Page size is 5, so take count is 5
 737            $this->assertEquals($requestDescription->getTopCount(), 5);            
 738            //order info is required for pagination
 739            $internalOrderByInfo = $requestDescription->getInternalOrderByInfo();
 740            $this->assertTrue(!is_null($internalOrderByInfo));
 741            $pathSegments = $internalOrderByInfo->getOrderByPathSegments();
 742            $this->assertTrue(!is_null($pathSegments));
 743            $this->assertTrue(is_array($pathSegments));
 744            //Order has one key
 745            $this->assertEquals(count($pathSegments), 1);
 746            $this->assertTrue($pathSegments[0] instanceof OrderByPathSegment);
 747            $subPathSegments = $pathSegments[0]->getSubPathSegments();
 748            $this->assertTrue(!is_null($subPathSegments));
 749            $this->assertTrue(is_array($subPathSegments));
 750            $this->assertEquals(count($subPathSegments), 1);
 751            $this->assertTrue($subPathSegments[0] instanceof OrderBySubPathSegment);
 752            $this->assertEquals($subPathSegments[0]->getName(), 'OrderID');
 753            $host->getWebOperationContext()->resetWebContextInternal();
 754        } catch (\Exception $exception) {
 755            if ($host != null) {
 756                $host->getWebOperationContext()->resetWebContextInternal();
 757            }
 758            $this->fail('An unexpected Exception has been raised' . $exception->getMessage());
 759        }
 760    }
 761
 762    /**
 763     * $orderby option can be applied to $links resource set
 764     */
 765    public function testUriProcessorForLinksResourceSet1()
 766    {
 767        try {
 768            $baseUri = 'http://localhost:8083/NorthWindDataService.svc/';
 769            $resourcePath = 'Customers(CustomerID=\'ALFKI\', CustomerGuid=guid\'05b242e752eb46bd8f0e6568b72cd9a5\')/$links/Orders';
 770            $hostInfo = array('AbsoluteRequestUri' => new Url($baseUri . $resourcePath),                                
 771			    	  			'AbsoluteServiceUri' => new Url($baseUri),
 772				      			'QueryString' => '$orderby=ShipName asc, OrderDate desc',
 773                  	  			'DataServiceVersion' => new Version(2, 0),
 774                  	  			'MaxDataServiceVersion' => new Version(2, 0));
 775
 776            $host = new DataServiceHost2($hostInfo);
 777            $dataService = new NorthWindDataService2();
 778            $dataService->setHost($host);
 779            $uriProcessor = $dataService->handleRequest();
 780            $requestDescription = $uriProcessor->getRequestDescription();
 781            $this->assertTrue(!is_null($requestDescription));
 782             $this->assertEquals($requestDescription->isSingleResult(), false); 
 783            //Page size is 5, so take count is 5 means you will get only 5 links for a request
 784            $this->assertEquals($requestDescription->getTopCount(), 5); 
 785            //Paging requires ordering, the result should be ordered like
 786            //Note: additional ordering constraint
 787            //
 788            //SELECT links(d.orderID) FROM Customers JOIN Orders WHERE CustomerID='ALFKI' AND 
 789            //CustomerGuid=guid'05b242e752eb46bd8f0e6568b72cd9a5' ORDER BY
 790            //d.ShipName ASC, d.OrderDate DESC, d.OrderID ASC
 791
 792            $internalOrderByInfo = $requestDescription->getInternalOrderByInfo();
 793            $this->assertTrue(!is_null($internalOrderByInfo));
 794            $pathSegments = $internalOrderByInfo->getOrderByPathSegments();
 795            $this->assertTrue(!is_null($pathSegments));
 796            $this->assertTrue(is_array($pathSegments));            
 797            $this->assertEquals(count($pathSegments), 3);
 798            $this->assertTrue($pathSegments[0] instanceof OrderByPathSegment);
 799            $subPathSegments = $pathSegments[0]->getSubPathSegments();
 800            $this->assertTrue($pathSegments[0]->isAscending());
 801            $this->assertTrue(!is_null($subPathSegments));
 802            $this->assertTrue(is_array($subPathSegments));
 803            $this->assertEquals(count($subPathSegments), 1);
 804            $this->assertTrue($subPathSegments[0] instanceof OrderBySubPathSegment);
 805            $this->assertEquals($subPathSegments[0]->getName(), 'ShipName');
 806            $this->assertTrue($pathSegments[1] instanceof OrderByPathSegment);
 807            $this->assertFalse($pathSegments[1]->isAscending());
 808            $subPathSegments = $pathSegments[1]->getSubPathSegments();
 809            $this->assertTrue(!is_null($subPathSegments));
 810            $this->assertTrue(is_array($subPathSegments));
 811            $this->assertEquals(count($subPathSegments), 1);
 812            $this->assertTrue($subPathSegments[0] instanceof OrderBySubPathSegment);
 813            $this->assertEquals($subPathSegments[0]->getName(), 'OrderDate');
 814            $this->assertTrue($pathSegments[2] instanceof OrderByPathSegment);
 815            $this->assertTrue($pathSegments[2]->isAscending());
 816            $subPathSegments = $pathSegments[2]->getSubPathSegments();
 817            $this->assertTrue(!is_null($subPathSegments));
 818            $this->assertTrue(is_array($subPathSegments));
 819            $this->assertEquals(count($subPathSegments), 1);
 820            $this->assertTrue($subPathSegments[0] instanceof OrderBySubPathSegment);
 821            $this->assertEquals($subPathSegments[0]->getName(), 'OrderID');
 822            $host->getWebOperationContext()->resetWebContextInternal();
 823        } catch (\Exception $exception) {
 824            if ($host != null) {
 825                $host->getWebOperationContext()->resetWebContextInternal();
 826            }
 827            $this->fail('An unexpected Exception has been raised' . $exception->getMessage());
 828        }
 829    }
 830
 831    /**
 832     * $skiptoken option can be applied to $links resource set
 833     */
 834    public function testUriProcessorForLinksResourceSet2()
 835    {
 836        try {
 837            //Test with skiptoken that corrosponds to default ordering key
 838            $baseUri = 'http://localhost:8083/NorthWindDataService.svc/';
 839            $resourcePath = 'Customers(CustomerID=\'ALFKI\', CustomerGuid=guid\'05b242e752eb46bd8f0e6568b72cd9a5\')/$links/Orders';
 840            $hostInfo = array('AbsoluteRequestUri' => new Url($baseUri . $resourcePath),                                
 841			    	  			'AbsoluteServiceUri' => new Url($baseUri),
 842				      			'QueryString' => '$skiptoken=123',
 843                  	  			'DataServiceVersion' => new Version(2, 0),
 844                  	  			'MaxDataServiceVersion' => new Version(2, 0));
 845            
 846            $host = new DataServiceHost2($hostInfo);
 847            $dataService = new NorthWindDataService2();
 848            $dataService->setHost($host);
 849            $uriProcessor = $dataService->handleRequest();
 850            $requestDescription = $uriProcessor->getRequestDescription();
 851            $this->assertTrue(!is_null($requestDescription));
 852             $this->assertEquals($requestDescription->isSingleResult(), false); 
 853            //Page size is 5, so take count is 5 means you will get only 5 links for a request
 854            $this->assertEquals($requestDescription->getTopCount(), 5); 
 855            //paging requires ordering
 856            $internalOrderByInfo = $requestDescription->getInternalOrderByInfo();
 857            $this->assertTrue(!is_null($internalOrderByInfo));
 858            $pathSegments = $internalOrderByInfo->getOrderByPathSegments();
 859            $this->assertTrue(!is_null($pathSegments));
 860            $this->assertTrue(is_array($pathSegments));            
 861            $this->assertEquals(count($pathSegments), 1);
 862            $this->assertTrue($pathSegments[0] instanceof OrderByPathSegment);
 863            $subPathSegments = $pathSegments[0]->getSubPathSegments();
 864            $this->assertTrue($pathSegments[0]->isAscending());
 865            $this->assertTrue(!is_null($subPathSegments));
 866            $this->assertTrue(is_array($subPathSegments));
 867            $this->assertEquals(count($subPathSegments), 1);
 868            $this->assertTrue($subPathSegments[0] instanceof OrderBySubPathSegment);
 869            $this->assertEquals($subPathSegments[0]->getName(), 'OrderID');
 870            //check the skiptoken details
 871            $internalSkiptokenInfo = $requestDescription->getInternalSkipTokenInfo();
 872            $this->assertTrue(!is_null($internalSkiptokenInfo));
 873            $this->assertTrue($internalSkiptokenInfo instanceof InternalSkipTokenInfo);
 874            $skipTokenInfo = $internalSkiptokenInfo->getSkipTokenInfo();
 875            $this->assertTrue(!is_null($skipTokenInfo));
 876            $this->assertTrue($skipTokenInfo instanceof SkipTokenInfo);
 877            $orderByValuesInSkipToken = $skipTokenInfo->getOrderByKeysInToken();
 878            $this->assertTrue(!is_null($orderByValuesInSkipToken));
 879            $this->assertTrue(is_array($orderByValuesInSkipToken));
 880            $this->assertEquals(count($orderByValuesInSkipToken), 1);
 881            $this->assertTrue(!is_null($orderByValuesInSkipToken[0]));
 882            $this->assertTrue(is_array($orderByValuesInSkipToken[0]));
 883            $this->assertEquals(count($orderByValuesInSkipToken[0]), 2);
 884            $this->assertEquals($orderByValuesInSkipToken[0][0], 123);
 885            $this->assertTrue(is_object($orderByValuesInSkipToken[0][1]));
 886            $this->assertTrue($orderByValuesInSkipToken[0][1] instanceof Int32);
 887            $host->getWebOperationContext()->resetWebContextInternal();
 888            
 889            //Test with skiptoken that corrosponds to explict ordering keys
 890            $baseUri = 'http://localhost:8083/NorthWindDataService.svc/';
 891            $resourcePath = 'Customers(CustomerID=\'ALFKI\', CustomerGuid=guid\'05b242e752eb46bd8f0e6568b72cd9a5\')/$links/Orders';
 892            $hostInfo = array('AbsoluteRequestUri' => new Url($baseUri . $resourcePath),                                
 893			    	  			'AbsoluteServiceUri' => new Url($baseUri),
 894				      			'QueryString' => '$orderby=OrderID asc, OrderDate desc&$skiptoken=123, datetime\'2000-11-11\'',
 895                  	  			'DataServiceVersion' => new Version(2, 0),
 896                  	  			'MaxDataServiceVersion' => new Version(2, 0));
 897            $host = new DataServiceHost2($hostInfo);
 898            $dataService = new NorthWindDataService2();
 899            $dataService->setHost($host);
 900            $uriProcessor = $dataService->handleRequest();
 901            $requestDescription = $uriProcessor->getRequestDescription();
 902            $this->assertTrue(!is_null($requestDescription));
 903             $this->assertEquals($requestDescription->isSingleResult(), false); 
 904            //Page size is 5, so take count is 5 means you will get only 5 links for a request
 905            $this->assertEquals($requestDescription->getTopCount(), 5); 
 906            //paging requires ordering
 907            $internalOrderByInfo = $requestDescription->getInternalOrderByInfo();
 908            $this->assertTrue(!is_null($internalOrderByInfo));
 909            $pathSegments = $internalOrderByInfo->getOrderByPathSegments();
 910            $this->assertTrue(!is_null($pathSegments));
 911            $this->assertTrue(is_array($pathSegments));
 912            $this->assertEquals(count($pathSegments), 2);
 913            $this->assertTrue($pathSegments[0] instanceof OrderByPathSegment);
 914            $subPathSegments = $pathSegments[0]->getSubPathSegments();
 915            $this->assertTrue($pathSegments[0]->isAscending());
 916            $this->assertTrue(!is_null($subPathSegments));
 917            $this->assertTrue(is_array($subPathSegments));
 918            $this->assertEquals(count($subPathSegments), 1);
 919            $this->assertTrue($subPathSegments[0] instanceof OrderBySubPathSegment);
 920            $this->assertEquals($subPathSegments[0]->getName(), 'OrderID');
 921            $this->assertTrue($pathSegments[1] instanceof OrderByPathSegment);            
 922            $this->assertFalse($pathSegments[1]->isAscending());
 923            $subPathSegments = $pathSegments[1]->getSubPathSegments();
 924            $this->assertTrue(!is_null($subPathSegments));
 925            $this->assertTrue(is_array($subPathSegments));
 926            $this->assertEquals(count($subPathSegments), 1);
 927            $this->assertTrue($subPathSegments[0] instanceof OrderBySubPathSegment);
 928            $this->assertEquals($subPathSegments[0]->getName(), 'OrderDate');
 929            //check the skiptoken details
 930            $internalSkiptokenInfo = $requestDescription->getInternalSkipTokenInfo();
 931            $this->assertTrue(!is_null($internalSkiptokenInfo));
 932            $this->assertTrue($internalSkiptokenInfo instanceof InternalSkipTokenInfo);
 933            $skipTokenInfo = $internalSkiptokenInfo->getSkipTokenInfo();
 934            $this->assertTrue(!is_null($skipTokenInfo));
 935            $this->assertTrue($skipTokenInfo instanceof SkipTokenInfo);
 936            $orderByValuesInSkipToken = $skipTokenInfo->getOrderByKeysInToken();
 937            $this->assertTrue(!is_null($orderByValuesInSkipToken));
 938            $this->assertTrue(is_array($orderByValuesInSkipToken));
 939            $this->assertEquals(count($orderByValuesInSkipToken), 2);
 940            $this->assertTrue(!is_null($orderByValuesInSkipToken[0]));
 941            $this->assertTrue(is_array($orderByValuesInSkipToken[0]));
 942            $this->assertEquals(count($orderByValuesInSkipToken[0]), 2);
 943            $this->assertEquals($orderByValuesInSkipToken[0][0], 123);
 944            $this->assertTrue(is_object($orderByValuesInSkipToken[0][1]));
 945            $this->assertTrue($orderByValuesInSkipToken[0][1] instanceof Int32);
 946            $this->assertTrue(!is_null($orderByValuesInSkipToken[1]));
 947            $this->assertTrue(is_array($orderByValuesInSkipToken[1]));
 948            $this->assertEquals(count($orderByValuesInSkipToken[1]), 2);
 949            $this->assertEquals($orderByValuesInSkipToken[1][0], '\'2000-11-11\'');
 950            $this->assertTrue(is_object($orderByValuesInSkipToken[1][1]));
 951            $this->assertTrue($orderByValuesInSkipToken[1][1] instanceof DateTime);
 952            $host->getWebOperationContext()->resetWebContextInternal();
 953
 954        } catch (\Exception $exception) {
 955            if ($host != null) {
 956                $host->getWebOperationContext()->resetWebContextInternal();
 957            }
 958           $this->fail('An unexpected Exception has been raised' . $exception->getMessage());
 959        }
 960    }
 961
 962    /**
 963     * $top and $skip option can be applied to $links resource set
 964     */
 965    public function testUriProcessorForLinksResourceSet3()
 966    {
 967         try {
 968            $baseUri = 'http://localhost:8083/NorthWindDataService.svc/';
 969            $resourcePath = 'Customers(CustomerID=\'ALFKI\', CustomerGuid=guid\'05b242e752eb46bd8f0e6568b72cd9a5\')/$links/Orders';
 970            $hostInfo = array('AbsoluteRequestUri' => new Url($baseUri . $resourcePath),                                
 971			    	  			'AbsoluteServiceUri' => new Url($baseUri),
 972				      			'QueryString' => '$skip=1',
 973                  	  			'DataServiceVersion' => new Version(2, 0),
 974                  	  			'MaxDataServiceVersion' => new Version(2, 0));
 975            
 976            $host = new DataServiceHost2($hostInfo);
 977            $dataService = new NorthWindDataService2();
 978            $dataService->setHost($host);
 979            $uriProcessor = $dataService->handleRequest();
 980            $requestDescription = $uriProcessor->getRequestDescription();
 981            $this->assertTrue(!is_null($requestDescription));
 982            $this->assertEquals($requestDescription->isSingleResult(), false);
 983            //$skip has been specified
 984            $this->assertEquals($requestDescription->getSkipCount(), 1);   
 985            //Page size is 5, so take count is 5 means you will get only 5 links for a request
 986            $this->assertEquals($requestDescription->getTopCount(), 5); 
 987            //paging requires ordering
 988            $internalOrderByInfo = $requestDescription->getInternalOrderByInfo();
 989            $this->assertTrue(!is_null($internalOrderByInfo));
 990            $pathSegments = $internalOrderByInfo->getOrderByPathSegments();
 991            $this->assertTrue(!is_null($pathSegments));
 992            $this->assertTrue(is_array($pathSegments));            
 993            $this->assertEquals(count($pathSegments), 1);
 994            $this->assertTrue($pathSegments[0] instanceof OrderByPathSegment);
 995            $subPathSegments = $pathSegments[0]->getSubPathSegments();
 996            $this->assertTrue($pathSegments[0]->isAscending());
 997            $this->assertTrue(!is_null($subPathSegments));
 998            $this->assertTrue(is_array($subPathSegments));
 999            $this->assertEquals(count($subPathSegments), 1);
1000            $this->assertTrue($subPathSegments[0] instanceof OrderBySubPathSegment);
1001            $this->assertEquals($subPathSegments[0]->getName(), 'OrderID');
1002            $host->getWebOperationContext()->resetWebContextInternal();
1003            //specification of a $top value less than pagesize also need sorting,
1004            //$skiptoken also applicable, only thing is nextlink will be absent
1005          
1006            $baseUri = 'http://localhost:8083/NorthWindDataService.svc/';
1007            $resourcePath = 'Customers(CustomerID=\'ALFKI\', CustomerGuid=guid\'05b242e752eb46bd8f0e6568b72cd9a5\')/$links/Orders';
1008            $hostInfo = array('AbsoluteRequestUri' => new Url($baseUri . $resourcePath),                                
1009			    	  			'AbsoluteServiceUri' => new Url($baseUri),
1010				      			'QueryString' => '$top=4&$skiptoken=1234',
1011                  	  			'DataServiceVersion' => new Version(2, 0),
1012                  	  			'MaxDataServiceVersion' => new Version(2, 0));
1013
1014            $host = new DataServiceHost2($hostInfo);
1015            $dataService = new NorthWindDataService2();
1016            $dataService->setHost($host);
1017            $uriProcessor = $dataService->handleRequest();
1018            $requestDescription = $uriProcessor->getRequestDescription();
1019            $this->assertTrue(!is_null($requestDescription));
1020            $this->assertEquals($requestDescription->isSingleResult(), false);
1021            //$skip has not been specified
1022            $this->assertEquals($requestDescription->getSkipCount(), null);   
1023            //top is specified and is less than page size
1024            $this->assertEquals($requestDescription->getTopCount(), 4); 
1025            //top requires ordering
1026            $internalOrderByInfo = $requestDescription->getInternalOrderByInfo();
1027            $this->assertTrue(!is_null($internalOrderByInfo));
1028            $pathSegments = $internalOrderByInfo->getOrderByPathSegments();
1029            $this->assertTrue(!is_null($pathSegments));
1030            $this->assertTrue(is_array($pathSegments));            
1031            $this->assertEquals(count($pathSegments), 1);
1032            $this->assertTrue($pathSegments[0] instanceof OrderByPathSegment);
1033            $subPathSegments = $pathSegments[0]->getSubPathSegments();
1034            $this->assertTrue($pathSegments[0]->isAscending());
1035            $this->assertTrue(!is_null($subPathSegments));
1036            $this->assertTrue(is_array($subPathSegments));
1037            $this->assertEquals(count($subPathSegments), 1);
1038            $this->assertTrue($subPathSegments[0] instanceof OrderBySubPathSegment);
1039            $this->assertEquals($subPathSegments[0]->getName(), 'OrderID');
1040            //$skiptoken is specified
1041            $internalSkiptokenInfo = $requestDescription->getInternalSkipTokenInfo();
1042            $this->assertTrue(!is_null($internalSkiptokenInfo));
1043            $this->assertTrue($internalSkiptokenInfo instanceof InternalSkipTokenInfo);
1044            $skipTokenInfo = $internalSkiptokenInfo->getSkipTokenInfo();
1045            $this->assertTrue($skipTokenInfo instanceof SkipTokenInfo);
1046            $orderByValuesInSkipToken = $skipTokenInfo->getOrderByKeysInToken();
1047            $this->assertTrue(!is_null($orderByValuesInSkipToken));
1048            $this->assertTrue(is_array($orderByValuesInSkipToken));
1049            $this->assertEquals(count($orderByValuesInSkipToken), 1);
1050            $this->assertTrue(!is_null($orderByValuesInSkipToken[0]));
1051            $this->assertTrue(is_array($orderByValuesInSkipToken[0]));
1052            $this->assertEquals(count($orderByValuesInSkipToken[0]), 2);
1053            $this->assertEquals($orderByValuesInSkipToken[0][0], 1234);
1054            $this->assertTrue(is_object($orderByValuesInSkipToken[0][1]));
1055            $this->assertTrue($orderByValuesInSkipToken[0][1] instanceof Int32);
1056            $host->getWebOperationContext()->resetWebContextInternal();
1057            //specification of a $top value greater than pagesize          
1058            $baseUri = 'http://localhost:8083/NorthWindDataService.svc/';
1059            $resourcePath = 'Customers(CustomerID=\'ALFKI\', CustomerGuid=guid\'05b242e752eb46bd8f0e6568b72cd9a5\')/$links/Orders';
1060            $hostInfo = array('AbsoluteRequestUri' => new Url($baseUri . $resourcePath),                                
1061			    	  			'AbsoluteServiceUri' => new Url($baseUri),
1062				      			'QueryString' => '$top=10&$skiptoken=1234',
1063                  	  			'DataServiceVersion' => new Version(2, 0),
1064                  	  			'MaxDataServiceVersion' => new Version(2, 0));
1065
1066            $host = new DataServiceHost2($hostInfo);
1067            $dataService = new NorthWindDataService2();
1068            $dataService->setHost($host);
1069            $uriProcessor = $dataService->handleRequest();
1070            $requestDescription = $uriProcessor->getRequestDescription();
1071            $this->assertTrue(!is_null($requestDescription));
1072            $this->assertEquals($requestDescription->isSingleResult(), false);
1073            //$skip has not been specified
1074            $this->assertEquals($requestDescription->getSkipCount(), null);   
1075            //top is specified and is greater than page size, so take count should be page size
1076            $this->assertEquals($requestDescription->getTopCount(), 5); 
1077            //top requires ordering
1078            $internalOrderByInfo = $requestDescription->getInternalOrderByInfo();
1079            $this->assertTrue(!is_null($internalOrderByInfo));
1080            //$skiptoken is specified
1081            $internalSkiptokenInfo = $requestDescription->getInternalSkipTokenInfo();
1082            $this->assertTrue(!is_null($internalSkiptokenInfo));
1083            $host->getWebOperationContext()->resetWebContextInternal();
1084        } catch (\Exception $exception) {
1085            if ($host != null) {
1086                $host->getWebOperationContext()->resetWebContextInternal();
1087            }
1088            $this->fail('An unexpected Exception has been raised' . $exception->getMessage());
1089        }
1090    }
1091
1092    /**
1093     * $filter option can be applied to $links resource set
1094     */
1095    public function testUriProcessorForLinksResourceSet4()
1096    {
1097       try {
1098            $baseUri = 'http://localhost:8083/NorthWindDataService.svc/';
1099            $resourcePath = 'Customers(CustomerID=\'ALFKI\', CustomerGuid=guid\'05b242e752eb46bd8f0e6568b72cd9a5\')/$links/Orders';
1100            $hostInfo = array('AbsoluteRequestUri' => new Url($baseUri . $resourcePath),                                
1101			    	  			'AbsoluteServiceUri' => new Url($baseUri),
1102				      			'QueryString' => '$filter=OrderID eq 123 and OrderDate le datetime\'2000-11-11\'',
1103                  	  			'DataServiceVersion' => new Version(2, 0),
1104                  	  			'MaxDataServiceVersion' => new Version(2, 0));
1105            
1106            $host = new DataServiceHost2($hostInfo);
1107            $dataService = new NorthWindDataService2();
1108            $dataService->setHost($host);
1109            $uriProcessor = $dataService->handleRequest();
1110            $requestDescription = $uriProcessor->getRequestDescription();
1111            $this->assertTrue(!is_null($requestDescription));
1112            $this->assertEquals($requestDescription->isSingleResult(), false);
1113            $this->assertEquals($requestDescription->getTopCount(), 5); 
1114            //paging enabled
1115            $internalOrderByInfo = $requestDescription->getInternalOrderByInfo();
1116            $this->assertTrue(!is_null($internalOrderByInfo));
1117            //$filter applied
1118            $internalFilterInfo = $requestDescription->getInternalFilterInfo();
1119            $this->assertTrue(!is_null($internalFilterInfo));
1120            $this->assertTrue($internalFilterInfo instanceof InternalFilterInfo);
1121            $filterFunction = $internalFilterInfo->getFilterFunction();
1122            $this->assertTrue(!is_null($filterFunction));
1123            $this->assertTrue($filterFunction instanceof AnonymousFunction);
1124            $code = $filterFunction->getCode();            
1125            $this->assertEquals($code, 
1126            'if(((!(is_null($lt->OrderID)) && !(is_null($lt->OrderDate))) && (($lt->OrderID == 123) && (ODataProducer\Providers\Metadata\Type\DateTime::dateTimeCmp($lt->OrderDate, \'2000-11-11\') <= 0)))) { return true; } else { return false;}');
1127            $host->getWebOperationContext()->resetWebContextInternal();
1128        } catch (\Exception $exception) {
1129            if ($host != null) {
1130                $host->getWebOperationContext()->resetWebContextInternal();
1131            }
1132            $this->fail('An unexpected Exception has been raised' . $exception->getMessage());
1133        }
1134    }
1135
1136    /**
1137     * $inlinecount can be applied to $links identifying resource set     
1138     */
1139    public function testUriProcessorForLinksResourceSet5()
1140    {
1141        try {
1142                $baseUri = 'http://localhost:8083/NorthWindDataService.svc/';
1143                $resourcePath = 'Customers(CustomerID=\'ALFKI\', CustomerGuid=guid\'05b242e752eb46bd8f0e6568b72cd9a5\')/$links/Orders';
1144                $hostInfo = array('AbsoluteRequestUri' => new Url($baseUri . $resourcePath),                                
1145	    	  	    		'AbsoluteServiceUri' => new Url($baseUri),
1146		      		    	'QueryString' => '$inlinecount=allpages',
1147          	  				'DataServiceVersion' => new Version(2, 0),
1148          	  				'MaxDataServiceVersion' => new Version(2, 0));
1149            
1150            $host = new DataServiceHost2($hostInfo);
1151            $dataService = new NorthWindDataService2();
1152            $dataService->setHost($host);
1153            $uriProcessor = $dataService->handleRequest();
1154            $requestDescription = $uriProcessor->getRequestDescription();
1155            $this->assertTrue(!is_null($requestDescription));
1156            $this->assertEquals($requestDescription->isSingleResult(), false);
1157            $this->assertEquals($requestDescription->getTopCount(), 5); 
1158            //paging enabled
1159            $internalOrderByInfo = $requestDescription->getInternalOrderByInfo();
1160            $this->assertTrue(!is_null($internalOrderByInfo));
1161            //count mode is all pages
1162            $this->assertEquals($requestDescription->getRequestCountOption(), RequestCountOption::INLINE);
1163            $host->getWebOperationContext()->resetWebContextInternal();
1164        } catch (\Exception $exception) {
1165            if ($host != null) {
1166                $host->getWebOperationContext()->resetWebContextInternal();
1167            }
1168            $this->fail('An unexpected Exception has been raised' . $exception->getMessage());
1169        }
1170    }
1171
1172    /**
1173     * $filter option can be applied to $links resource set reference
1174     */
1175    public function testUriProcessorForLinksResourceSetReference1()
1176    {
1177        try {
1178            $baseUri = 'http://localhost:8083/NorthWindDataService.svc/';
1179            $resourcePath = 'Customers(CustomerID=\'ALFKI\', CustomerGuid=guid\'05b242e752eb46bd8f0e6568b72cd9a5\')/$links/Orders(123)';
1180            $hostInfo = array('AbsoluteRequestUri' => new Url($baseUri . $resourcePath),                                
1181			    	  			'AbsoluteServiceUri' => new Url($baseUri),
1182				      			'QueryString' => '$filter=OrderID eq 123 and OrderDate le datetime\'2000-11-11\'',
1183                  	  			'DataServiceVersion' => new Version(2, 0),
1184                  	  			'MaxDataServiceVersion' => new Version(2, 0));
1185            
1186            $host = new DataServiceHost2($hostInfo);
1187            $dataService = new NorthWindDataService2();
1188            $dataService->setHost($host);
1189            $uriProcessor = $dataService->handleRequest();
1190            $requestDescription = $uriProcessor->getRequestDescription();
1191            $this->assertTrue(!is_null($requestDescription));
1192            $this->assertEquals($requestDescription->isSingleResult(), true);
1193            $this->assertEquals($requestDescription->getTopCount(), null); 
1194            $this->assertEquals($requestDescription->getSkipCount(), null); 
1195            //paging not applicable enabled
1196            $internalOrderByInfo = $requestDescription->getInternalOrderByInfo();
1197            $this->assertTrue(is_null($internalOrderByInfo));
1198            //$filter applied
1199            $internalFilterInfo = $requestDescription->getInternalFilterInfo();
1200            $this->assertTrue(!is_null($internalFilterInfo));
1201            $this->assertTrue($internalFilterInfo instanceof InternalFilterInfo);
1202            $filterFunction = $internalFilterInfo->getFilterFunction();
1203            $this->assertTrue(!is_null($filterFunction));
1204            $this->assertTrue($filterFunction instanceof AnonymousFunction);
1205            $code = $filterFunction->getCode();            
1206            $this->assertEquals($code, 
1207            'if(((!(is_null($lt->OrderID)) && !(is_null($lt->OrderDate))) && (($lt->OrderID == 123) && (ODataProducer\Providers\Metadata\Type\DateTime::dateTimeCmp($lt->OrderDate, \'2000-11-11\') <= 0)))) { return true; } else { return false;}');
1208            $host->getWebOperationContext()->resetWebContextInternal();
1209            $baseUri = 'http://localhost:8083/NorthWindDataService.svc/';
1210            $resourcePath = 'Orders(1234)/$links/Customer';
1211            $hostInfo = array('AbsoluteRequestUri' => new Url($baseUri . $resourcePath),                                
1212			    	  			'AbsoluteServiceUri' => new Url($baseUri),
1213				      			'QueryString' => '$filter=true',
1214                  	  			'DataServiceVersion' => new Version(2, 0),
1215                  	  			'MaxDataServiceVersion' => new Version(2, 0));
1216            
1217            $host = new DataServiceHost2($hostInfo);
1218            $dataService = new NorthWindDataService2();
1219            $dataService->setHost($host);
1220            $uriProcessor = $dataService->handleRequest();
1221            $requestDescription = $uriProcessor->getRequestDescription();
1222            $this->assertTrue(!is_null($requestDescription));
1223            $this->assertEquals($requestDescription->isSingleResult(), true);
1224            $this->assertEquals($requestDescription->getTopCount(), null); 
1225            $this->assertEquals($requestDescription->getSkipCount(), null); 
1226            //paging not applicable enabled
1227            $internalOrderByInfo = $requestDescription->getInternalOrderByInfo();
1228            $this->assertTrue(is_null($internalOrderByInfo));
1229            //$filter applied
1230            $internalFilterInfo = $requestDescription->getInternalFilterInfo();
1231            $this->assertTrue(!is_null($internalFilterInfo));
1232            $this->assertTrue($internalFilterInfo instanceof InternalFilterInfo);
1233            $filterFunction = $internalFilterInfo->getFilterFunction();
1234            $this->assertTrue(!is_null($filterFunction));
1235            $this->assertTrue($filterFunction instanceof AnonymousFunction);
1236            $code = $filterFunction->getCode();                        
1237            $this->assertEquals($code, 'if(true) { return true; } else { return false;}');
1238            $host->getWebOperationContext()->resetWebContextInternal();
1239
1240        } catch (\Exception $exception) {
1241            if ($host != null) {
1242                $host->getWebOperationContext()->resetWebContextInternal();
1243            }
1244            $this->fail('An unexpected Exception has been raised' . $exception->getMessage());
1245        }
1246    }
1247
1248    /**
1249     * $orderby option cannot be applied to $links resource set reference
1250     */
1251    public function testUriProcessorForLinksResourceSetReference2()
1252    {
1253        try {
1254            $baseUri = 'http://localhost:8083/NorthWindDataService.svc/';
1255            $resourcePath = 'Customers(CustomerID=\'ALFKI\', CustomerGuid=guid\'05b242e752eb46bd8f0e6568b72cd9a5\')/$links/Orders(123)';
1256            $hostInfo = array('AbsoluteRequestUri' => new Url($baseUri . $resourcePath),                                
1257			    	  			'AbsoluteServiceUri' => new Url($baseUri),
1258				      			'QueryString' => '$orderby=OrderID',
1259                  	  			'DataServiceVersion' => new Version(2, 0),
1260                  	  			'MaxDataServiceVersion' => new Version(2, 0));            
1261            $host = new DataServiceHost2($hostInfo);
1262            $dataService = new NorthWindDataService2();
1263            $dataService->setHost($host);
1264            $exceptionThrown = false;
1265            try {
1266                $dataService->handleRequest();
1267            } catch (ODataException $odataException) {
1268                $exceptionThrown = true;                
1269                $this->assertStringStartsWith('Query options $orderby, $inlinecount, $skip and $top cannot be applied to the requested resource', $odataException->getMessage());
1270            }
1271
1272            if (!$exceptionThrown) {                
1273                $this->fail('An expected ODataException for $orderby query option on non-set has not been thrown');
1274            }
1275            $host->getWebOperationContext()->resetWebContextInternal();
1276            $baseUri = 'http://localhost:8083/NorthWindDataService.svc/';
1277            $resourcePath = 'Orders(1234)/$links/Customer';
1278            $hostInfo = array('AbsoluteRequestUri' => new Url($baseUri . $resourcePath),                                
1279			        	  			'AbsoluteServiceUri' => new Url($baseUri),
1280				          			'QueryString' => '$orderby=CustomerID',
1281                  	      			'DataServiceVersion' => new Version(2, 0),
1282                  	  	    		'MaxDataServiceVersion' => new Version(2, 0));           
1283            $host = new DataServiceHost2($hostInfo);
1284            $dataService = new NorthWindDataService2();
1285            $dataService->setHost($host);
1286            $exceptionThrown = false;
1287            try {
1288                $dataService->handleRequest();
1289            } catch (ODataException $odataException) {
1290                $exceptionThrown = true;                
1291                $this->assertStringStartsWith('Query options $orderby, $inlinecount, $skip and $top cannot be applied to the requested resource', $odataException->getMessage());
1292            }
1293
1294            if (!$exceptionThrown) {                
1295                $this->fail('An expected ODataException for $orderby query option on non-set has not been thrown');
1296            }
1297            $host->getWebOperationContext()->resetWebContextInternal();
1298        } catch (\Exception $exception) {
1299            if ($host != null) {
1300                $host->getWebOperationContext()->resetWebContextInternal();
1301            }
1302            $this->fail('An unexpected Exception has been raised' . $exception->getMessage());
1303        }
1304    }
1305
1306    /**
1307     * $skiptoken option cannot be applied to $links resource set reference
1308     */
1309   public function testUriProcessorForLinksResourceSetReference3()
1310    {
1311        try {
1312            $baseUri = 'http://localhost:8083/NorthWindDataService.svc/';
1313            $resourcePath = 'Customers(CustomerID=\'ALFKI\', CustomerGuid=guid\'05b242e752eb46bd8f0e6568b72cd9a5\')/$links/Orders(123)';
1314            $hostInfo = array('AbsoluteRequestUri' => new Url($baseUri . $resourcePath),                                
1315			    	  			'AbsoluteServiceUri' => new Url($baseUri),
1316				      			'QueryString' => '$skiptoken=345',
1317                  	  			'DataServiceVersion' => new Version(2, 0),
1318                  	  			'MaxDataServiceVersion' => new Version(2, 0));
1319            $host = new DataServiceHost2($hostInfo);
1320            $dataService = new NorthWindDataService2();
1321            $dataService->setHost($host);
1322            $exceptionThrown = false;
1323            try {
1324                $dataService->handleRequest();
1325            } catch (ODataException $odataException) {
1326                $exceptionThrown = true;                
1327                $this->assertStringStartsWith('Query option $skiptoken cannot be applied to the requested resource', $odataException->getMessage());
1328            }
1329
1330            if (!$exceptionThrown) {                
1331                $this->fail('An expected ODataException for $skiptoken query option on non-set has not been thrown');
1332            }
1333            $host->getWebOperationContext()->resetWebContextInternal();
1334        } catch (\Exception $exception) {
1335            if ($host != null) {
1336                $host->getWebOperationContext()->resetWebContextInternal();
1337            }
1338            $this->fail('An unexpected Exception has been raised' . $exception->getMessage());
1339        }
1340    }
1341
1342    /**
1343     * $top and $skip option cannot be applied to $links resource set reference
1344     */
1345    public function testUriProcessorForLinksResourceSetReference4()
1346    {
1347         try {
1348            $baseUri = 'http://localhost:8083/NorthWindDataService.svc/';
1349            $resourcePath = 'Customers(CustomerID=\'ALFKI\', CustomerGuid=guid\'05b242e752eb46bd8f0e6568b72cd9a5\')/$links/Orders(123)';
1350            $hostInfo = array('AbsoluteRequestUri' => new Url($baseUri . $resourcePath),                                
1351			    	  			'AbsoluteServiceUri' => new Url($baseUri),
1352				      			'QueryString' => '$skip=1',
1353                  	  			'DataServiceVersion' => new Version(2, 0),
1354                  	  			'MaxDataServiceVersion' => new Version(2, 0));
1355            
1356            $host = new DataServiceHost2($hostInfo);
1357            $dataService = new NorthWindDataService2();
1358            $dataService->setHost($host);
1359            $exceptionThrown = false;
1360            try {
1361                $dataService->handleRequest();
1362            } catch (ODataException $odataException) {
1363                $exceptionThrown = true;                
1364                $this->assertStringStartsWith('Query options $orderby, $inlinecount, $skip and $top cannot be applied to the requested resource', $odataException->getMessage());
1365            }
1366
1367            if (!$exceptionThrown) {                
1368                $this->fail('An expected ODataException for $skip query option on non-set has not been thrown');
1369            }
1370            $host->getWebOperationContext()->resetWebContextInternal();
1371            $baseUri = 'http://localhost:8083/NorthWindDataService.svc/';
1372            $resourcePath = 'Customers(CustomerID=\'ALFKI\', CustomerGuid=guid\'05b242e752eb46bd8f0e6568b72cd9a5\')/$links/Orders(234)';
1373            $hostInfo = array('AbsoluteRequestUri' => new Url($baseUri . $resourcePath),                                
1374			    	  			'AbsoluteServiceUri' => new Url($baseUri),
1375				      			'QueryString' => '$top=4',
1376                  	  			'DataServiceVersion' => new Version(2, 0),
1377                  	  			'MaxDataServiceVersion' => new Version(2, 0));
1378            
1379            $host = new DataServiceHost2($hostInfo);
1380            $dataService = new NorthWindDataService2();
1381            $dataService->setHost($host);
1382            $exceptionThrown = false;
1383            try {
1384                $dataService->handleRequest();
1385            } catch (ODataException $odataException) {
1386                $exceptionThrown = true;                
1387                $this->assertStringStartsWith('Query options $orderby, $inlinecount, $skip and $top cannot be applied to the requested resource', $odataException->getMessage());
1388            }
1389
1390            if (!$exceptionThrown) {                
1391                $this->fail('An expected ODataException for $top query option on non-set has not been thrown');
1392            }
1393            $host->getWebOperationContext()->resetWebContextInternal();    
1394        } catch (\Exception $exception) {
1395            if ($host != null) {
1396                $host->getWebOperationContext()->resetWebContextInternal();
1397            }
1398            $this->fail('An unexpected Exception has been raised' . $exception->getMessage());
1399        }
1400    }
1401
1402    /**
1403     * $inlinecount option cannot be applied to $links resource set reference
1404     */
1405    public function testUriProcessorForLinksResourceSetReference5()
1406    {
1407         try {
1408            $baseUri = 'http://localhost:8083/NorthWindDataService.svc/';
1409            $resourcePath = 'Customers(CustomerID=\'ALFKI\', CustomerGuid=guid\'05b242e752eb46bd8f0e6568b72cd9a5\')/$links/Orders(123)';
1410            $hostInfo = array('AbsoluteRequestUri' => new Url($baseUri . $resourcePath),                                
1411	    	  			'AbsoluteServiceUri' => new Url($baseUri),
1412		      			'QueryString' => '$inlinecount=allpages',
1413          	  			'DataServiceVersion' => new Version(2, 0),
1414          	  			'MaxDataServiceVersion' => new Version(2, 0));
1415            
1416            $host = new DataServiceHost2($hostInfo);
1417            $dataService = new NorthWindDataService2();
1418            $dataService->setHost($host);
1419            $exceptionThrown = false;
1420            try {
1421                $dataService->handleRequest();
1422            } catch (ODataException $odataException) {
1423                $exceptionThrown = true;                
1424                $this->assertStringStartsWith('Query options $orderby, $inlinecount, $skip and $top cannot be applied to the requested resource', $odataException->getMessage());
1425            }
1426
1427            if (!$exceptionThrown) {                
1428                $this->fail('An expected ODataException for $inlinecount query option on non-set has not been thrown');
1429            }
1430            $host->getWebOperationContext()->resetWebContextInternal();
1431
1432        } catch (\Exception $exception) {
1433            if ($host != null) {
1434                $host->getWebOperationContext()->resetWebContextInternal();
1435            }
1436            $this->fail('An unexpected Exception has been raised' . $exception->getMessage());
1437        }
1438    }
1439
1440    /**
1441     * $expand, $select option cannot be applied to $links resource set reference or $link resource set
1442     */
1443    public function testUriProcessorForLinksResource()
1444    {
1445        try {
1446            $baseUri = 'http://localhost:8083/NorthWindDataService.svc/';
1447            $resourcePath = 'Customers(CustomerID=\'ALFKI\', CustomerGuid=guid\'05b242e752eb46bd8f0e6568b72cd9a5\')/$links/Orders(123)';
1448            $hostInfo = array('AbsoluteRequestUri' => new Url($baseUri . $resourcePath),                                
1449			    	  			'AbsoluteServiceUri' => new Url($baseUri),
1450				      			'QueryString' => '$expand=Order_Details',
1451                  	  			'DataServiceVersion' => new Version(2, 0),
1452                  	  			'MaxDataServiceVersion' => new Version(2, 0));
1453            $host = new DataServiceHost2($hostInfo);
1454            $dataService = new NorthWindDataService2();
1455            $dataService->setHost($host);
1456            $exceptionThrown = false;
1457            try {
1458                $dataService->handleRequest();
1459            } catch (ODataException $odataException) {
1460                $exceptionThrown = true;                               
1461                $this->assertStringStartsWith('Query option $expand cannot be applied to the requested resource', $odataException->getMessage());
1462            }
1463
1464            if (!$exceptionThrown) {                
1465                $this->fail('An expected ODataException for $expand query option on $link resource has not been thrown');
1466            }
1467            $host->getWebOperationContext()->resetWebContextInternal();
1468            $baseUri = 'http://localhost:8083/NorthWindDataService.svc/';
1469            $resourcePath = 'Customers(CustomerID=\'ALFKI\', CustomerGuid=guid\'05b242e752eb46bd8f0e6568b72cd9a5\')/$links/Orders(123)';
1470            $hostInfo = array('AbsoluteRequestUri' => new Url($baseUri . $resourcePath),                                
1471			    	  			'AbsoluteServiceUri' => new Url($baseUri),
1472				      			'QueryString' => '$select=OrderID',
1473                  	  			'DataServiceVersion' => new Version(2, 0),
1474                  	  			'MaxDataServiceVersion' => new Version(2, 0));
1475            $host = new DataServiceHost2($hostInfo);
1476            $dataService = new NorthWindDataService2();
1477            $dataService->setHost($host);
1478            $exceptionThrown = false;
1479            try {
1480                $dataService->handleRequest();
1481            } catch (ODataException $odataException) {
1482                $exceptionThrown = true;                               
1483                $this->assertStringStartsWith('Query option $select cannot be applied to the requested resource', $odataException->getMessage());
1484            }
1485
1486            if (!$exceptionThrown) {                
1487                $this->fail('An expected ODataException for $select query option on $link resource has not been thrown');
1488            }
1489            $host->getWebOperationContext()->resetWebContextInternal();
1490        } catch (\Exception $exception) {
1491            if ($host != null) {
1492                $host->getWebOperationContext()->resetWebContextInternal();
1493            }
1494            $this->fail('An unexpected Exception has been raised' . $exception->getMessage());
1495        }
1496    }
1497
1498    /**
1499     * $inline count is not supported for protocol version V1
1500     */
1501    public function testUriProcessorForInlineCount1()
1502    {
1503        try {
1504            $baseUri = 'http://localhost:8083/NorthWindDataService.svc/';
1505            $resourcePath = 'Products(11)/Order_Details';
1506            $hostInfo = array('AbsoluteRequestUri' => new Url($baseUri . $resourcePath),                                
1507	    		    		'AbsoluteServiceUri' => new Url($baseUri), 
1508                            //Paging is enabled this cause skiptoken to be included 
1509                            //in the response, thus reponse version become 2.0
1510                            //But if $top is specified and its value is less than page size
1511                            //then we don't need to include $skiptoken in response 
1512                            //so response version is 1.0.
1513                            //If the paging is enabled and protocol to be used is V1
1514                            //then a request (without a $top or $top value > pagesize)
1515                            //cause the repsonse version of 2.0 to be used, but server
1516                            //will throw error as protocol version is set to V1. 
1517                            //This error will be thrown from ProcessSkipAndTopCount function.
1518                            
1519                            //$inlinecount is a V2 feature, so with configured version of V1
1520                            //ProcessCount will thorow error. 
1521
1522                            //We are adding a $top value (< pagesize) with $inlinecount so that
1523                            //version error will be thrown from ProcessCount instead of from
1524                            //ProcessSkipAndTopCount
1525		      		    	'QueryString' => '$inlinecount=allpages&$top=3',
1526          	  				'DataServiceVersion' => new Version(2, 0),
1527          	  				'MaxDataServiceVersion' => new Version(2, 0));
1528            $host = new DataServiceHost2($hostInfo);
1529            $dataService = new NorthWindDataServiceV1();
1530            $dataService->setHost($host);
1531            $exceptionThrown = false;
1532            try {
1533                $dataService->handleRequest();
1534            } catch (ODataException $odataException) {
1535                $exceptionThrown = true;                               
1536                $this->assertStringStartsWith('The response requires that version 2.0 of the protocol be used, but the MaxProtocolVersion of the data service is set to 1.0', $odataException->getMessage());
1537            }
1538
1539            if (!$exceptionThrown) {                
1540                $this->fail('An expected ODataException for $inlinecount query option with V1 configured service has not been thrown');
1541            }
1542            $host->getWebOperationContext()->resetWebContextInternal();
1543        } catch (\Exception $exception) {
1544            if ($host != null) {
1545                $host->getWebOperationContext()->resetWebContextInternal();
1546            }
1547            $this->fail('An unexpected Exception has been raised' . $exception->getMessage());
1548        }
1549    }
1550
1551    /**
1552     * For $inline request, client's DataServiceVersion header must be >= 2.0
1553     */
1554    public function testUriProcessorForInlineCount2()
1555    {
1556            try {
1557            $baseUri = 'http://localhost:8083/NorthWindDataService.svc/';
1558            $resourcePath = 'Products(11)/Order_Details';
1559            $hostInfo = array('AbsoluteRequestUri' => new Url($baseUri . $resourcePath),
1560            				'AbsoluteServiceUri' => new Url($baseUri), 
1561		      		    	'QueryString' => '$inlinecount=allpages',
1562          	  				'DataServiceVersion' => new Version(1, 0),
1563          	  				'MaxDataServiceVersion' => new Version(2, 0));
1564            $host = new DataServiceHost2($hostInfo);
1565            $dataService = new NorthWindDataService2();
1566            $dataService->setHost($host);
1567            $exceptionThrown = false;
1568            try {
1569                $dataService->handleRequest();
1570            } catch (ODataException $odataException) {
1571                $exceptionThrown = true;                               
1572                $this->assertStringStartsWith("Request version '1.0' is not supported for the request payload. The only supported version is '2.0'", $odataException->getMessage());
1573            }
1574
1575            if (!$exceptionThrown) {                
1576                $this->fail('An expected ODataException for $inlinecount query option request DataServiceVersion 1.0 has not been thrown');
1577            }
1578            $host->getWebOperationContext()->resetWebContextInternal();
1579        } catch (\Exception $exception) {
1580            if ($host != null) {
1581                $host->getWebOperationContext()->resetWebContextInternal();
1582            }
1583            $this->fail('An unexpected Exception has been raised' . $exception->getMessage());
1584        }
1585    }
1586
1587    /**
1588     * For $inline request, client's MaxDataServiceVersion header must be >= 2.0
1589     */
1590    public function testUriProcessorForInlineCount3()
1591    {
1592        try {
1593            $baseUri = 'http://localhost:8083/NorthWindDataService.svc/';
1594            $resourcePath = 'Products(11)/Order_Details';
1595            $hostInfo = array('AbsoluteRequestUri' => new Url($baseUri . $resourcePath),
1596            				'AbsoluteServiceUri' => new Url($baseUri), 
1597		      		    	'QueryString' => '$inlinecount=allpages',
1598          	  				'DataServiceVersion' => new Version(2, 0),
1599          	  				'MaxDataServiceVersion' => new Version(1, 0));
1600            $host = new DataServiceHost2($hostInfo);
1601            $dataService = new NorthWindDataService2();
1602            $dataService->setHost($host);
1603            $exceptionThrown = false;
1604            try {
1605                $dataService->handleRequest();
1606            } catch (ODataException $odataException) {
1607                $exceptionThrown = true;                               
1608                $this->assertStringStartsWith("Request version '1.0' is not supported for the request payload. The only supported version is '2.0'", $odataException->getMessage());
1609            }
1610
1611            if (!$exceptionThrown) {                
1612                $this->fail('An expected ODataException for $inlinecount query option with request DataServiceVersion 1.0 has not been thrown');
1613            }
1614            $host->getWebOperationContext()->resetWebContextInternal();
1615        } catch (\Exception $exception) {
1616            if ($host != null) {
1617                $host->getWebOperationContext()->resetWebContextInternal();
1618            }
1619            $this->fail('An unexpected Exception has been raised' . $exception->getMessage());
1620        }
1621    }
1622
1623    /**
1624     * only supported $inlinecount valus are 'allpages' and 'none'
1625     */
1626    public function testUriProcessorForInlineCount4()
1627    {
1628         try {
1629            $baseUri = 'http://localhost:8083/NorthWindDataService.svc/';
1630            $resourcePath = 'Products(11)/Order_Details';
1631            $hostInfo = array('AbsoluteRequestUri' => new Url($baseUri . $resourcePath),
1632            				'AbsoluteServiceUri' => new Url($baseUri), 
1633		      		    	'QueryString' => '$inlinecount=partialpages',
1634          	  				'DataServiceVersion' => new Version(2, 0),
1635          	  				'MaxDataServiceVersion' => new Version(2, 0));
1636            $host = new DataServiceHost2($hostInfo);
1637            $dataService = new NorthWindDataService2();
1638            $dataService->setHost($host);
1639            $exceptionThrown = false;
1640            try {
1641                $dataService->handleRequest();
1642            } catch (ODataException $odataException) {
1643                $exceptionThrown = true;                               
1644                $this->assertStringStartsWith('Unknown $inlinecount option, only "allpages" and "none" are supported', $odataException->getMessage());
1645            }
1646
1647            if (!$exceptionThrown) {                
1648                $this->fail('An expected ODataException for invalid $inlinecount query option has not been thrown');
1649            }
1650            $host->getWebOperationContext()->resetWebContextInternal();
1651        } catch (\Exception $exception) {
1652            if ($host != null) {
1653                $host->getWebOperationContext()->resetWebContextInternal();
1654            }
1655            $this->fail('An unexpected Exception has been raised' . $exception->getMessage());
1656        }
1657    }
1658
1659    /**
1660     * $filter can be applied on complex resource
1661     */
1662    public function testUriProcessorForFilterOnComplex()
1663    {
1664        try {
1665            $baseUri = 'http://localhost:8083/NorthWindDataService.svc/';
1666            $resourcePath = 'Orders(123)/Customer/Address';
1667            $hostInfo = array('AbsoluteRequestUri' => new Url($baseUri . $resourcePath),
1668            				'AbsoluteServiceUri' => new Url($baseUri), 
1669		      		    	'QueryString' => '$filter=HouseNumber eq null',
1670          	  				'DataServiceVersion' => new Version(1, 0),
1671          	  				'MaxDataServiceVersion' => new Version(1, 0));
1672            $host = new DataServiceHost2($hostInfo);
1673            $dataService = new NorthWindDataService2();
1674            $dataService->setHost($host);
1675            $exceptionThrown = false;            
1676            $dataService->handleRequest();
1677            $uriProcessor = $dataService->handleRequest();
1678            $requestDescription = $uriProcessor->getRequestDescription();
1679            $this->assertTrue(!is_null($requestDescription));
1680            $this->assertEquals($requestDescription->isSingleResult(), true);             
1681            //$filter applied
1682            $internalFilterInfo = $requestDescription->getInternalFilterInfo();
1683            $this->assertTrue(!is_null($internalFilterInfo));
1684            $this->assertTrue($internalFilterInfo instanceof InternalFilterInfo);
1685            $filterFunction = $internalFilterInfo->getFilterFunction();
1686            $this->assertTrue(!is_null($filterFunction));
1687            $this->assertTrue($filterFunction instanceof AnonymousFunction);
1688            $code = $filterFunction->getCode();    
1689            $this->assertTrue(is_null($requestDescription->getRootProjectionNode()));
1690            $host->getWebOperationContext()->resetWebContextInternal();
1691        } catch (\Exception $exception) {
1692            if ($host != null) {
1693                $host->getWebOperationContext()->resetWebContextInternal();
1694            }
1695            $this->fail('An unexpected Exception has been raised' . $exception->getMessage());
1696        }
1697    }
1698
1699    /**
1700     * $filter cannot be applied on primitve resource
1701     */
1702   public function testUriProcessorForFilterOnPrimitiveType()
1703    {
1704             try {
1705            $baseUri = 'http://localhost:8083/NorthWindDataService.svc/';
1706            $resourcePath = 'Products(11)/ProductID';
1707            $hostInfo = array('AbsoluteRequestUri' => new Url($baseUri . $resourcePath),
1708            				'AbsoluteServiceUri' => new Url($baseUri), 
1709		      		    	'QueryString' => '$filter=true',
1710          	  				'DataServiceVersion' => new Version(1, 0),
1711          	  				'MaxDataServiceVersion' => new Version(1, 0));
1712            $host = new DataServiceHost2($hostInfo);
1713            $dataService = new NorthWindDataService2();
1714            $dataService->setHost($host);
1715            $exceptionThrown = false;
1716            try {
1717                   $dataService->handleRequest();
1718            } catch (ODataException $odataException) {
1719                $exceptionThrown = true;                               
1720                $this->assertStringStartsWith('Query option $filter cannot be applied to the requested resource', $odataException->getMessage());
1721            }
1722
1723            if (!$exceptionThrown) {
1724                $this->fail('An expected ODataException for $filter query on primitve  has not been thrown');
1725            }
1726            $host->getWebOperationContext()->resetWebContextInternal();
1727        } catch (\Exception $exception) {
1728            if ($host != null) {
1729                $host->getWebOperationContext()->resetWebContextInternal();
1730            }
1731            $this->fail('An unexpected Exception has been raised' . $exception->getMessage());
1732        }
1733    }
1734
1735    /**
1736     * $filter cannot be applied on bag resource
1737     */
1738    public function testUriProcessorForFilterOnBag()
1739    {
1740        try {
1741            $baseUri = 'http://localhost:8083/NorthWindDataService.svc/';
1742            $resourcePath = 'Employees(\'EMP1\')/Emails';
1743            $hostInfo = array('AbsoluteRequestUri' => new Url($baseUri . $resourcePath),
1744            				'AbsoluteServiceUri' => new Url($baseUri), 
1745		      		    	'QueryString' => '$filter=true',
1746          	  				'DataServiceVersion' => new Version(3, 0),
1747          	  				'MaxDataServiceVersion' => new Version(3, 0));
1748            $host = new DataServiceHost2($hostInfo);
1749            //Note we are using V3 data service
1750            $dataService = new NorthWindDataServiceV3();
1751            $dataService->setHost($host);
1752            $exceptionThrown = false;
1753            try {
1754                $dataService->handleRequest();
1755            } catch (ODataException $odataException) {
1756                $exceptionThrown = true;                                                               
1757                $this->assertStringStartsWith('Query option $filter cannot be applied to the requested resource', $odataException->getMessage());
1758            }
1759
1760            if (!$exceptionThrown) {
1761                $this->fail('An expected ODataException for $filter query option on bag has not been thrown');
1762            }
1763            $host->getWebOperationContext()->resetWebContextInternal();
1764        } catch (\Exception $exception) {
1765            if ($host != null) {
1766                $host->getWebOperationContext()->resetWebContextInternal();
1767            }
1768            $this->fail('An unexpected Exception has been raised' . $exception->getMessage());
1769        }
1770    }
1771
1772    /**
1773     * $filter cannot be applied on primitve value
1774     */
1775   public function testUriProcessorForFilterOnValue()
1776    {
1777        try {
1778            $baseUri = 'http://localhost:8083/NorthWindDataService.svc/';
1779            $resourcePath = 'Orders(11)/Customer/CustomerID/$value';
1780            $hostInfo = array('AbsoluteRequestUri' => new Url($baseUri . $resourcePath),
1781            				'AbsoluteServiceUri' => new Url($baseUri), 
1782		      		    	'QueryString' => '$filter=true',
1783          	  				'DataServiceVersion' => new Version(1, 0),
1784          	  				'MaxDataServiceVersion' => new Version(1, 0));
1785            $host = new DataServiceHost2($hostInfo);
1786            $dataService = new NorthWindDataService2();
1787            $dataService->setHost($host);
1788            $exceptionThrown = false;
1789            try {
1790                $dataService->handleRequest();
1791            } catch (ODataException $odataException) {
1792                $exceptionThrown = true;           
1793                $this->assertStringStartsWith('Query option $filter cannot be applied to the requested resource', $odataException->getMessage());
1794            }
1795
1796            if (!$exceptionThrown) {
1797                $this->fail('An expected ODataException for $filter query option on primitve value has not been thrown');
1798            }
1799            $host->getWebOperationContext()->resetWebContextInternal();
1800        } catch (\Exception $exception) {
1801            if ($host != null) {
1802                $host->getWebOperationContext()->resetWebContextInternal();
1803            }
1804            $this->fail('An unexpected Exception has been raised' . $exception->getMessage());
1805        }
1806    }
1807
1808    /**
1809     * When requesting for a bag DataServiceVersion should be >= 3.0     
1810     */
1811    public function testUriProcessorWithTargetAsBag1()
1812    {
1813        try {
1814            $baseUri = 'http://localhost:8083/NorthWindDataService.svc/';
1815            $resourcePath = 'Employees(\'EMP1\')/Emails';
1816            $hostInfo = array('AbsoluteRequestUri' => new Url($baseUri . $resourcePath),
1817            				'AbsoluteServiceUri' => new Url($baseUri), 
1818		      		    	'QueryString' => null,
1819          	  				'DataServiceVersion' => new Version(2, 0),
1820          	  				'MaxDataServiceVersion' => new Version(2, 0));
1821            $host = new DataServiceHost2($hostInfo);
1822            $dataService = new NorthWindDataService2();
1823            $dataService->setHost($host);
1824            $exceptionThrown = false;
1825            try {
1826                  $dataService->handleRequest();
1827            } catch (ODataException $odataException) {
1828                $exceptionThrown = true;       
1829                $this->assertStringStartsWith("Request version '2.0' is not supported for the request payload. The only supported version is '3.0'", $odataException->getMessage());
1830            }
1831
1832            if (!$exceptionThrown) {
1833                $this->fail('An expected ODataException for a bag request with  MaxDataServiceVersion < 3.0 has not been thrown');
1834            }
1835            $host->getWebOperationContext()->resetWebContextInternal();
1836        } catch (\Exception $exception) {
1837            if ($host != null) {
1838                $host->getWebOperationContext()->resetWebContextInternal();
1839            }
1840            $this->fail('An unexpected Exception has been raised' . $exception->getMessage());
1841        }
1842    }
1843
1844    /**
1845     * The MaxProtocolVersion configured for the service should be >=3.0 to respond to request for Bag 
1846     */
1847   public function testUriProcessorWithTargetAsBag2()
1848    {
1849        try {
1850            $baseUri = 'http://localhost:8083/NorthWindDataService.svc/';
1851            $resourcePath = 'Employees(\'EMP1\')/Emails';
1852            $hostInfo = array('AbsoluteRequestUri' => new Url($baseUri . $resourcePath),
1853            				'AbsoluteServiceUri' => new Url($baseUri), 
1854		      		    	'QueryString' => null,
1855          	  				'DataServiceVersion' => new Version(3, 0),
1856          	  				'MaxDataServiceVersion' => new Version(3, 0));
1857            $host = new DataServiceHost2($hostInfo);
1858            $dataService = new NorthWindDataService2();
1859            $dataService->setHost($host);
1860            $exceptionThrown = false;
1861            try {
1862                  $dataService->handleRequest();
1863            } catch (ODataException $odataException) {
1864                $exceptionThrown = true;       
1865                $this->assertStringStartsWith("The response requires that version 3.0 of the protocol be used, but the MaxProtocolVersion of the data service is set to 2.0", $odataException->getMessage());
1866            }
1867
1868            if (!$exceptionThrown) {
1869                $this->fail('An expected ODataException for a bag request to a service configured with V2 has not been thrown');
1870            }
1871            $host->getWebOperationContext()->resetWebContextInternal();
1872        } catch (\Exception $exception) {
1873            if ($host != null) {
1874                $host->getWebOperationContext()->resetWebContextInternal();
1875            }
1876            $this->fail('An unexpected Exception has been raised' . $exception->getMessage());
1877        }
1878    }
1879
1880    /**
1881     * $select cannot be applied if its disabled on configuration
1882     */
1883    public function testUriProcessorForSelectWhereProjectionDisabled()
1884    {
1885         try {
1886            $baseUri = 'http://localhost:8083/NorthWindDataService.svc/';
1887            $resourcePath = 'Orders(11)/Customer';
1888            $hostInfo = array('AbsoluteRequestUri' => new Url($baseUri . $resourcePath),
1889            				'AbsoluteServiceUri' => new Url($baseUri), 
1890		      		    	'QueryString' => '$expand=Orders&$select=CustomerID,Orders',
1891          	  				'DataServiceVersion' => new Version(1, 0),
1892          	  				'MaxDataServiceVersion' => new Version(1, 0));
1893            $host = new DataServiceHost2($hostInfo);
1894            $dataService = new NorthWindDataServiceV3();
1895            $dataService->setHost($host);
1896            $exceptionThrown = false;
1897            try {
1898                  $dataService->handleRequest();
1899            } catch (ODataException $odataException) {
1900                $exceptionThrown = true;       
1901                $this->assertStringStartsWith('The ability to use the $select query option to define a projection in a data service query is disabled', $odataException->getMessage());
1902            }
1903
1904            if (!$exceptionThrown) {
1905                $this->fail('An expected ODataException for $select option on projection disabled service  has not been thrown');
1906            }
1907            $host->getWebOperationContext()->resetWebContextInternal();
1908        } catch (\Exception $exception) {
1909            if ($host != null) {
1910                $host->getWebOperationContext()->resetWebContextInternal();
1911            }
1912            $this->fail('An unexpected Exception has been raised' . $exception->getMessage());
1913        }
1914    }
1915
1916    /**
1917     * select and expand can be applied to request url identifying resource set
1918     */
1919 /**   public function testUriProcessorForSelelctExpandOnResourceSet()
1920    {
1921        
1922    }
1923
1924    /**
1925     * $select is a V2 feature so client should request with  'DataServiceVersion' 2.0
1926     * but the response of select can be handled by V1 client so a value of 1.0 for MaxDataServiceVersion
1927     * will work
1928     */
1929    public function testUriProcessorForSelectExpandOnResourceWithDataServiceVersion1_0()
1930    {
1931             try {
1932            $baseUri = 'http://localhost:8083/NorthWindDataService.svc/';
1933            $resourcePath = 'Orders(11)/Customer';
1934            $hostInfo = array('AbsoluteRequestUri' => new Url($baseUri . $resourcePath),
1935            				'AbsoluteServiceUri' => new Url($baseUri), 
1936		      		    	'QueryString' => '$expand=Orders&$select=CustomerID,Orders',
1937                            //use of $select requires this header to 2.0 
1938          	  				'DataServiceVersion' => new Version(1, 0),
1939          	  				'MaxDataServiceVersion' => new Version(1, 0));
1940            $host = new DataServiceHost2($hostInfo);
1941            $dataService = new NorthWindDataService2();
1942            $dataService->setHost($host);
1943            $exceptionThrown = false;
1944            try {
1945                $dataService->handleRequest();
1946            } catch (ODataException $odataException) {
1947                $exceptionThrown = true;                                                                      
1948                $this->assertStringStartsWith("Request version '1.0' is not supported for the request payload. The only supported version is '2.0'", $odataException->getMessage());
1949            }
1950
1951            if (!$exceptionThrown) {
1952                $this->fail('An expected ODataException for $select query option with  DataServiceVersion 1.0 has not been thrown');
1953            }
1954            $host->getWebOperationContext()->resetWebContextInternal();
1955        } catch (\Exception $exception) {
1956            if ($host != null) {
1957                $host->getWebOperationContext()->resetWebContextInternal();
1958            }
1959            $this->fail('An unexpected Exception has been raised' . $exception->getMessage());
1960        }
1961    }
1962
1963    /**
1964     * if paging is applicable for top level resource
1965     *  (1) Paging enabled and $top > pageSize => require next link
1966     *  (2) Paging enabled and no $top => require next link
1967     * Then 'MaxDataServiceVersion' in request header must be >= 2.0
1968     */
1969    public function testUriProcessorForPagedTopLevelResourceWithMaxDataServiceVersion1_0()
1970    {
1971         try {
1972             
1973            //Paging enabled for top level resource set and $top > pageSize => require next link
1974            //so MaxDataServiceVersion 1.0 will not work
1975            $baseUri = 'http://localhost:8083/NorthWindDataService.svc/';
1976            $resourcePath = 'Orders';
1977            $hostInfo = array('AbsoluteRequestUri' => new Url($baseUri . $resourcePath),
1978            				'AbsoluteServiceUri' => new Url($baseUri), 
1979		      		    	'QueryString' => '$top=10&$expand=Customer',
1980          	  				'DataServiceVersion' => new Version(1, 0),
1981          	  				'MaxDataServiceVersion' => new Version(1, 0));
1982            $host = new DataServiceHost2($hostInfo);
1983            $dataService = new NorthWindDataService2();
1984            $dataService->setHost($host);          
1985            $exceptionThrown = false;
1986            try {
1987                $dataService->handleRequest();
1988            } catch (ODataException $odataException) {
1989                $exceptionThrown = true;                                                                      
1990                $this->assertStringStartsWith("Request version '1.0' is not supported for the request payload. The only supported version is '2.0'", $odataException->getMessage());
1991            }
1992
1993            if (!$exceptionThrown) {
1994                $this->fail('An expected ODataException for a paged top level result (having $top) with  MaxDataServiceVersion 1.0 has not been thrown');
1995            }
1996            $host->getWebOperationContext()->resetWebContextInternal();
1997            //Paging enabled for top level resource set and no $top => require next link
1998            //so MaxDataServiceVersion 1.0 will not work
1999            $baseUri = 'http://localhost:8083/NorthWindDataService.svc/';
2000            $resourcePath = 'Orders';
2001            $hostInfo = array('AbsoluteRequestUri' => new Url($baseUri . $resourcePath),
2002            				'AbsoluteServiceUri' => new Url($baseUri), 
2003                            //error will be thrown from processskipAndTopOption before processor process expand
2004		      		    	'QueryString' => '$expand=Customer',
2005                            //DataServiceVersion can be 1.0 no issue                            
2006          	  				'DataServiceVersion' => new Version(1, 0),
2007                            //But MaxDataServiceVersion must be 2.0 as respose will include
2008                            //a nextlink for expanded 'Orders' property
2009          	  				'MaxDataServiceVersion' => new Version(1, 0));
2010            $host = new DataServiceHost2($hostInfo);
2011            $dataService = new NorthWindDataService2();
2012            $dataService->setHost($host);
2013            $exceptionThrown = false;
2014            try {
2015                $dataService->handleRequest();
2016            } catch (ODataException $odataException) {
2017                $exceptionThrown = true;                                                                      
2018                $this->assertStringStartsWith("Request version '1.0' is not supported for the request payload. The only supported version is '2.0'", $odataException->getMessage());
2019            }
2020
2021            if (!$exceptionThrown) {
2022                $this->fail('An expected ODataException for a paged top level result with  MaxDataServiceVersion 1.0 has not been thrown');
2023            }
2024            $host->getWebOperationContext()->resetWebContextInternal();
2025            //Paging enabled for top level resource set and $top < pageSize => not require next link
2026            //so MaxDataServiceVersion 1.0 will work
2027            $baseUri = 'http://localhost:8083/NorthWindDataService.svc/';
2028            $resourcePath = 'Orders';
2029            $hostInfo = array('AbsoluteRequestUri' => new Url($baseUri . $resourcePath),
2030            				'AbsoluteServiceUri' => new Url($baseUri), 
2031		      		    	'QueryString' => '$top=2&$expand=Customer',
2032          	  				'DataServiceVersion' => new Version(1, 0),
2033          	  				'MaxDataServiceVersion' => new Version(1, 0));
2034            $host = new DataServiceHost2($hostInfo);
2035            $dataService = new NorthWindDataService2();
2036            $dataService->setHost($host);
2037            $uriProcessor = $dataService->handleRequest();    
2038            $requestDescription = $uriProcessor->getRequestDescription();
2039            $this->assertTrue(!is_null($requestDescription));
2040            $this->assertEquals($requestDescription->isSingleResult(), false);
2041            $this->assertEquals($requestDescription->getTopCount(), 2); 
2042            //has orderby infor            
2043            $internalOrderByInfo = $requestDescription->getInternalOrderByInfo();
2044            $this->assertTrue(!is_null($internalOrderByInfo));
2045            $projectionTreeRoot = $requestDescription->getRootProjectionNode();
2046            $this->assertTrue(!is_null($projectionTreeRoot));
2047            $this->assertTrue($projectionTreeRoot instanceof RootProjectionNode);
2048            //There will be one child nodes 
2049            //Expand Projection Node => 'Customer'
2050            $childNodes = $projectionTreeRoot->getChildNodes();
2051            $this->assertTrue(!is_null($childNodes));
2052            $this->assertTrue(is_array($childNodes));
2053            //$this->assertEquals(count($childNodes), 1);
2054            $this->assertTrue(array_key_exists('Customer', $childNodes));
2055            $this->assertTrue($childNodes['Customer'] instanceof ExpandedProjectionNode);
2056            $customerExpandedNode = $childNodes['Customer'];
2057            //Sort info will not be there for expanded 'Customer' as its resource set reference
2058            $internalOrderByInfo = $customerExpandedNode->getInternalOrderByInfo();
2059            $this->assertTrue(is_null($internalOrderByInfo));
2060            $host->getWebOperationContext()->resetWebContextInternal();
2061        } catch (\Exception $exception) {
2062            if ($host != null) {
2063                $host->getWebOperationContext()->resetWebContextInternal();
2064            }
2065            $this->fail('An unexpected Exception has been raised' . $exception->getMessage());
2066        }
2067    }
2068
2069    /**
2070     * If paging is enabled expanded result is resource set (top level is resource set reference 
2071     * so no paging for top level resoure) then client should request with 
2072     * MaxDataServiceVersion >= 2.0     
2073     */
2074    public function testUriProcessorForPagedExpandedResourceSetWithMaxDataServiceVersion1_0()
2075    {
2076         try {
2077            $baseUri = 'http://localhost:8083/NorthWindDataService.svc/';
2078            $resourcePath = 'Orders(11)/Customer';
2079            $hostInfo = array('AbsoluteRequestUri' => new Url($baseUri . $resourcePath),
2080            				'AbsoluteServiceUri' => new Url($baseUri), 
2081		      		    	'QueryString' => '$expand=Orders',
2082                            //DataServiceVersion can be 1.0 no issue                            
2083          	  				'DataServiceVersion' => new Version(1, 0),
2084                            //But MaxDataServiceVersion must be 2.0 as respose will include
2085                            //a nextlink for expanded 'Orders' property
2086          	  				'MaxDataServiceVersion' => new Version(1, 0));
2087            $host = new DataServiceHost2($hostInfo);
2088            $dataService = new NorthWindDataService2();
2089            $dataService->setHost($host);
2090            $exceptionThrown = false;
2091            try {
2092                $dataService->handleRequest();
2093            } catch (ODataException $odataException) {
2094                $exceptionThrown = true;                                                                      
2095                $this->assertStringStartsWith("Request version '1.0' is not supported for the request payload. The only supported version is '2.0'", $odataException->getMessage());
2096            }
2097
2098            if (!$exceptionThrown) {
2099                $this->fail('An expected ODataException for an paged expanded result with  MaxDataServiceVersion 1.0 has not been thrown');
2100            }
2101            $host->getWebOperationContext()->resetWebContextInternal();
2102        } catch (\Exception $exception) {
2103            if ($host != null) {
2104                $host->getWebOperationContext()->resetWebContextInternal();
2105            }
2106            $this->fail('An unexpected Exception has been raised' . $exception->getMessage());
2107        }
2108    }
2109
2110    /**
2111     * select and expand can be applied to request url identifying resource set reference
2112     * Here the top level resource will not be paged as its a resource set reference
2113     * But if there is an expansion that leads to resource set then paging will be required for
2114     * the expanded result means hould request with MaxDataServiceVersion 2_0     
2115     */
2116    public function testUriProcessorForSelectExpandOnResourceSetReference()
2117    {
2118         try {
2119            $baseUri = 'http://localhost:8083/NorthWindDataService.svc/';
2120            $resourcePath = 'Orders(11)/Customer';
2121            $hostInfo = array('AbsoluteRequestUri' => new Url($baseUri . $resourcePath),
2122            				'AbsoluteServiceUri' => new Url($baseUri), 
2123		      		    	'QueryString' => '$expand=Orders&$select=CustomerID,Orders',
2124                            //use of $select requires this header to 1.0 
2125          	  				'DataServiceVersion' => new Version(2, 0),
2126                            //The expanded property will be paged, so skiptoken will be there
2127                            //client says i can handle it
2128          	  				'MaxDataServiceVersion' => new Version(2, 0));
2129            $host = new DataServiceHost2($hostInfo);
2130            $dataService = new NorthWindDataService2();
2131            $dataService->setHost($host);          
2132            $uriProcessor = $dataService->handleRequest();    
2133            $requestDescription = $uriProcessor->getRequestDescription();
2134            $this->assertTrue(!is_null($requestDescription));
2135            $this->assertEquals($requestDescription->isSingleResult(), true);
2136            //paging is not applicable for resource set reference 'Customer'
2137            $this->assertEquals($requestDescription->getTopCount(), null); 
2138            //no orderby infor
2139            $internalOrderByInfo = $requestDescription->getInternalOrderByInfo();
2140            $this->assertTrue(is_null($internalOrderByInfo));
2141            $projectionTreeRoot = $requestDescription->getRootProjectionNode();
2142            $this->assertTrue(!is_null($projectionTreeRoot));
2143            $this->assertTrue($projectionTreeRoot instanceof RootProjectionNode);
2144            //There will be two child nodes 
2145            //Expand Projection Node => 'Orders'
2146            //Projection Node => 'CustomerID'
2147            $childNodes = $projectionTreeRoot->getChildNodes();
2148            $this->assertTrue(!is_null($childNodes));
2149            $this->assertTrue(is_array($childNodes));
2150            $this->assertEquals(count($childNodes), 2);
2151            $this->assertTrue(array_key_exists('Orders', $childNodes));
2152            $this->assertTrue($childNodes['Orders'] instanceof ExpandedProjectionNode);
2153            $this->assertTrue(array_key_exists('Orders', $childNodes));
2154            $this->assertTrue($childNodes['Orders'] instanceof ProjectionNode);
2155            $ordersExpandedNode = $childNodes['Orders'];
2156            //Sort info will be there for expanded 'Orders' as paging is
2157            //enabled for this resource set
2158            $internalOrderByInfo = $ordersExpandedNode->getInternalOrderByInfo();
2159            $this->assertTrue(!is_null($internalOrderByInfo));
2160            $this->assertTrue($internalOrderByInfo instanceof InternalOrderByInfo);
2161            $host->getWebOperationContext()->resetWebContextInternal();
2162        } catch (\Exception $exception) {
2163            if ($host != null) {
2164                $host->getWebOperationContext()->resetWebContextInternal();
2165            }
2166            $this->fail('An unexpected Exception has been raised' . $exception->getMessage());
2167        }
2168    }
2169
2170    /**
2171     * select and expand can be applied to only request uri identifying a resource set
2172     * or resource set refernce.     
2173     */
2174    public function testUriProcessorForSelectExpandOnNonResourceSetOrReference()
2175    {
2176        try {             
2177            $baseUri = 'http://localhost:8083/NorthWindDataService.svc/';
2178            $resourcePath = 'Orders(123)/Customer/Address';
2179            $hostInfo = array('AbsoluteRequestUri' => new Url($baseUri . $resourcePath),
2180            				'AbsoluteServiceUri' => new Url($baseUri), 
2181		      		    	'QueryString' => '$expand=Address2',
2182          	  				'DataServiceVersion' => new Version(2, 0),
2183          	  				'MaxDataServiceVersion' => new Version(2, 0));
2184            $host = new DataServiceHost2($hostInfo);
2185            $dataService = new NorthWindDataService2();
2186            $dataService->setHost($host);          
2187            $exceptionThrown = false;
2188            try {
2189                $dataService->handleRequest();
2190            } catch (ODataException $odataException) {
2191                $exceptionThrown = true;                                                                      
2192                $this->assertStringStartsWith('Query option $expand cannot be applied to the requested resource', $odataException->getMessage());
2193            }
2194
2195            if (!$exceptionThrown) {
2196                $this->fail('An expected ODataException for $expand on  non resource set or resource set refernce has not been thrown');
2197            }
2198            $host->getWebOperationContext()->resetWebContextInternal();
2199            $baseUri = 'http://localhost:8083/NorthWindDataService.svc/';
2200            $resourcePath = 'Orders(123)/Customer/Address';
2201            $hostInfo = array('AbsoluteRequestUri' => new Url($baseUri . $resourcePath),
2202            				'AbsoluteServiceUri' => new Url($baseUri),                             
2203		      		    	'QueryString' => '$select=LineNumber',
2204          	  				'DataServiceVersion' => new Version(2, 0),                            
2205          	  				'MaxDataServiceVersion' => new Version(2, 0));
2206            $host = new DataServiceHost2($hostInfo);
2207            $dataService = new NorthWindDataService2();
2208            $dataService->setHost($host);
2209            $exceptionThrown = false;
2210            try {
2211                $dataService->handleRequest();
2212            } catch (ODataException $odataException) {
2213                $exceptionThrown = true;                                                                      
2214                $this->assertStringStartsWith('Query option $select cannot be applied to the requested resource', $odataException->getMessage());
2215            }
2216
2217            if (!$exceptionThrown) {
2218              $this->fail('An expected ODataException for $select on  non resource set or resource set refernce has not been thrown');
2219            }                        
2220            $host->getWebOperationContext()->resetWebContextInternal();
2221        } catch (\Exception $exception) {
2222            if ($host != null) {
2223                $host->getWebOperationContext()->resetWebContextInternal();
2224            }
2225            $this->fail('An unexpected Exception has been raised' . $exception->getMessage());
2226        }
2227    }
2228
2229    /**
2230     * Test uri prcoessor for $skip and $top options
2231     */
2232   public function testUriPrcoessorForSkipAndTop()
2233    {
2234            try {
2235            $baseUri = 'http://localhost:8083/NorthWindDataService.svc/';
2236            $resourcePath = 'Orders';
2237            $hostInfo = array('AbsoluteRequestUri' => new Url($baseUri . $resourcePath),                                
2238			    	  			'AbsoluteServiceUri' => new Url($baseUri),
2239				      			'QueryString' => '$top=\'ABC\'',
2240                  	  			'DataServiceVersion' => new Version(2, 0),
2241                  	  			'MaxDataServiceVersion' => new Version(2, 0));            
2242            $host = new DataServiceHost2($hostInfo);
2243            $dataService = new NorthWindDataService2();
2244            $dataService->setHost($host);
2245            $exceptionThrown = false;
2246            try {
2247                $dataService->handleRequest();
2248            } catch (ODataException $odataException) {
2249                $exceptionThrown = true;                
2250                $this->assertStringStartsWith("Incorrect format for \$top", $odataException->getMessage());
2251            }
2252
2253            if (!$exceptionThrown) {                
2254                $this->fail('An expected ODataException for incorrect $top value has not been thrown');
2255            }
2256            $host->getWebOperationContext()->resetWebContextInternal();
2257            $baseUri = 'http://localhost:8083/NorthWindDataService.svc/';
2258            $resourcePath = 'Orders';
2259            $hostInfo = array('AbsoluteRequestUri' => new Url($baseUri . $resourcePath),                                
2260			        	  			'AbsoluteServiceUri' => new Url($baseUri),
2261				          			'QueryString' => '$top=-123',
2262                  	      			'DataServiceVersion' => new Version(2, 0),
2263                  	  	    		'MaxDataServiceVersion' => new Version(2, 0));           
2264            $host = new DataServiceHost2($hostInfo);
2265            $dataService = new NorthWindDataService2();
2266            $dataService->setHost($host);
2267            $exceptionThrown = false;
2268            try {
2269                $dataService->handleRequest();
2270            } catch (ODataException $odataException) {
2271                $exceptionThrown = true;                
2272                $this->assertStringStartsWith('Incorrect format for $top', $odataException->getMessage());
2273            }
2274
2275            if (!$exceptionThrown) {                
2276                $this->fail('An expected ODataException for incorrect $top value has not been thrown');
2277            }
2278            $host->getWebOperationContext()->resetWebContextInternal();
2279        } catch (\Exception $exception) {
2280            if ($host != null) {
2281                $host->getWebOperationContext()->resetWebContextInternal();
2282            }
2283            $this->fail('An unexpected Exception has been raised' . $exception->getMessage());
2284        }
2285
2286        try {
2287            $host->getWebOperationContext()->resetWebContextInternal();
2288            $baseUri = 'http://localhost:8083/NorthWindDataService.svc/';
2289            $resourcePath = 'Orders';
2290            $hostInfo = array('AbsoluteRequestUri' => new Url($baseUri . $resourcePath),                                
2291			    	  			'AbsoluteServiceUri' => new Url($baseUri),
2292				      			'QueryString' => '$skip=\'ABC\'',
2293                  	  			'DataServiceVersion' => new Version(2, 0),
2294                  	  			'MaxDataServiceVersion' => new Version(2, 0));            
2295            $host = new DataServiceHost2($hostInfo);
2296            $dataService = new NorthWindDataService2();
2297            $dataService->setHost($host);
2298            $exceptionThrown = false;
2299            try {
2300                $dataService->handleRequest();
2301            } catch (ODataException $odataException) {
2302                $exceptionThrown = true;                
2303                $this->assertStringStartsWith("Incorrect format for \$skip", $odataException->getMessage());
2304            }
2305
2306            if (!$exceptionThrown) {                
2307                $this->fail('An expected ODataException for incorrect $skip value has not been thrown');
2308            }
2309            
2310            $baseUri = 'http://localhost:8083/NorthWindDataService.svc/';
2311            $resourcePath = 'Orders';
2312            $hostInfo = array('AbsoluteRequestUri' => new Url($baseUri . $resourcePath),                                
2313			        	  			'AbsoluteServiceUri' => new Url($baseUri),
2314				          			'QueryString' => '$skip=-123',
2315                  	      			'DataServiceVersion' => new Version(2, 0),
2316                  	  	    		'MaxDataServiceVersion' => new Version(2, 0));           
2317            $host = new DataServiceHost2($hostInfo);
2318            $dataService = new NorthWindDataService2();
2319            $dataService->setHost($host);
2320            $exceptionThrown = false;
2321            try {
2322                $dataService->handleRequest();
2323            } catch (ODataException $odataException) {
2324                $exceptionThrown = true;                
2325                $this->assertStringStartsWith('Incorrect format for $skip', $odataException->getMessage());
2326            }
2327
2328            if (!$exceptionThrown) {                
2329                $this->fail('An expected ODataException for incorrect $skip value has not been thrown');
2330            }
2331            $host->getWebOperationContext()->resetWebContextInternal();
2332        } catch (\Exception $exception) {
2333            if ($host != null) {
2334                $host->getWebOperationContext()->resetWebContextInternal();
2335            }
2336            $this->fail('An unexpected Exception has been raised' . $exception->getMessage());
2337        }
2338    }
2339
2340    /**
2341     * Test uri processor with all options
2342     */
2343    public function testUriProcessorWithBigQuery()
2344    {
2345            try {             
2346            $baseUri = 'http://localhost:8083/NorthWindDataService.svc/';
2347            $resourcePath = 'Orders(123)/Customer/Orders';
2348            $hostInfo = array('AbsoluteRequestUri' => new Url($baseUri . $resourcePath),
2349            				'AbsoluteServiceUri' => new Url($baseUri), 
2350		      		    	'QueryString' => '$expand=Customer&$select=Customer,OrderDate&$filter=OrderID eq 123&$orderby=OrderDate&top=6&$skip=10&$skiptoken=datetime\'2000-11-11\',567',
2351          	  				'DataServiceVersion' => new Version(2, 0),
2352          	  				'MaxDataServiceVersion' => new Version(2, 0));
2353            $host = new DataServiceHost2($hostInfo);
2354            $dataService = new NorthWindDataService2();
2355            $dataService->setHost($host);
2356            $uriProcessor = $dataService->handleRequest();
2357            $requestDescription = $uriProcessor->getRequestDescription();
2358            $this->assertEquals($requestDescription->getTopCount(), 5);
2359            $this->assertEquals($requestDescription->getSkipCount(), 10);
2360            $this->assertTrue(!is_null($requestDescription->getInternalOrderByInfo()));
2361            $this->assertTrue(!is_null($requestDescription->getInternalFilterInfo()));
2362            $this->assertTrue(!is_null($requestDescription->getInternalSkipTokenInfo()));
2363            $this->assertTrue(!is_null($requestDescription->getRootProjectionNode()));
2364            $host->getWebOperationContext()->resetWebContextInternal();
2365        } catch (\Exception $exception) {
2366            if ($host != null) {
2367                $host->getWebOperationContext()->resetWebContextInternal();
2368            }
2369            $this->fail('An unexpected Exception has been raised' . $exception->getMessage());
2370        }
2371    }
2372
2373    /**
2374     * test Request Description with all geter method.
2375     */
2376    public function testRequestDescription()
2377    {
2378        try {
2379            $hostInfo = array('AbsoluteRequestUri' => new Url('http://localhost:8083/NorthWindDataService.svc/Orders'), 
2380			    	  'AbsoluteServiceUri' => new Url('http://localhost:8083/NorthWindDataService.svc'),
2381				      'QueryString' => null,
2382                  	  'DataServiceVersion' => new Version(1, 0),
2383                  	  'MaxDataServiceVersion' => new Version(2, 0));
2384
2385            $host = new DataServiceHost2($hostInfo);
2386            $dataService = new NorthWindDataService2();
2387            $dataService->setHost($host);
2388            $uriProcessor = $dataService->handleRequest();
2389            
2390            $requestDescription = $uriProcessor->getRequestDescription();
2391            $this->assertTrue(!is_null($requestDescription));
2392            
2393            $countValue = $requestDescription->getCountValue();
2394            $this->assertTrue(is_null($countValue));
2395            
2396            $identifier = $requestDescription->getIdentifier();
2397            $this->assertTrue(!is_null($identifier));
2398            
2399            $internalFilterInfo = $requestDescription->getInternalFilterInfo();
2400            $this->assertTrue(is_null($internalFilterInfo));
2401            
2402            $internalOrderByInfo = $requestDescription->getInternalOrderByInfo();
2403            $this->assertTrue(!is_null($internalOrderByInfo));
2404            
2405            $internalSkipTokenInfo = $requestDescription->getInternalSkipTokenInfo();
2406            $this->assertTrue(is_null($internalSkipTokenInfo));
2407            
2408            $knownDataServiceVersions = $requestDescription->getKnownDataServiceVersions();
2409            $this->assertTrue(!is_null($knownDataServiceVersions));
2410            
2411            $lastSegmentDescriptor = $requestDescription->getLastSegmentDescriptor();
2412            $this->assertTrue(!is_null($lastSegmentDescriptor));
2413            
2414            $projectedProperty = $requestDescription->getProjectedProperty();
2415            $this->assertTrue(is_null($projectedProperty));
2416            
2417            $requestCountOption = $requestDescription->getRequestCountOption();
2418            $this->assertTrue(!is_null($requestCountOption));
2419            
2420            $requestUri = $requestDescription->getRequestUri();
2421            $this->assertTrue(!is_null($requestUri));
2422            
2423            $resourceStreamInfo = $requestDescription->getResourceStreamInfo();
2424            $this->assertTrue(is_null($resourceStreamInfo));
2425            
2426            $rootProjectionNode = $requestDescription->getRootProjectionNode();
2427            $this->assertTrue(!is_null($rootProjectionNode));
2428            
2429            $segmentDescriptors = $requestDescription->getSegmentDescriptors();
2430            $this->assertTrue(!is_null($segmentDescriptors));
2431            
2432            $skipCount = $requestDescription->getSkipCount();
2433            $this->assertTrue(is_null($skipCount));
2434            
2435            $targetKind = $requestDescription->getTargetKind();
2436            $this->assertTrue(!is_null($targetKind));
2437            
2438            $targetResourceSetWrapper = $requestDescription->getTargetResourceSetWrapper();
2439            $this->assertTrue(!is_null($targetResourceSetWrapper));
2440            
2441            $targetResourceType = $requestDescription->getTargetResourceType();
2442            $this->assertTrue(!is_null($targetResourceType));
2443            
2444            $targetSource = $requestDescription->getTargetSource();
2445            $this->assertTrue(!is_null($targetSource));
2446            
2447            $topCount = $requestDescription->getTopCount();
2448            $this->assertTrue(!is_null($topCount));
2449            $host->getWebOperationContext()->resetWebContextInternal();
2450            
2451            
2452        } catch (\Exception $exception) {
2453            $this->fail('An unexpected Exception has been raised' . $exception->getMessage());
2454        }
2455    }
2456    
2457    protected function tearDown()
2458    {
2459    }
2460}
2461?>