11
11
using System . Web . Http . Controllers ;
12
12
using System . Web . Http . Filters ;
13
13
using System . Web . Http . Hosting ;
14
+ using System . Web . Http . OData . Builder ;
14
15
using System . Web . Http . OData . Query ;
15
16
using System . Web . Http . OData . Query . Controllers ;
16
17
using System . Web . Http . OData . TestCommon . Models ;
@@ -357,9 +358,21 @@ public void ValidateQuery_Throws_With_Null_Request()
357
358
{
358
359
// Arrange
359
360
QueryableAttribute attribute = new QueryableAttribute ( ) ;
361
+ var model = new ODataModelBuilder ( ) . Add_Customer_EntityType ( ) . Add_Customers_EntitySet ( ) . GetEdmModel ( ) ;
362
+ var options = new ODataQueryOptions ( new ODataQueryContext ( model , typeof ( System . Web . Http . OData . Builder . TestModels . Customer ) , "Customers" ) , new HttpRequestMessage ( ) ) ;
360
363
361
364
// Act & Assert
362
- Assert . ThrowsArgumentNull ( ( ) => attribute . ValidateQuery ( null ) , "request" ) ;
365
+ Assert . ThrowsArgumentNull ( ( ) => attribute . ValidateQuery ( null , options ) , "request" ) ;
366
+ }
367
+
368
+ [ Fact ]
369
+ public void ValidateQuery_Throws_WithNullQueryOptions ( )
370
+ {
371
+ // Arrange
372
+ QueryableAttribute attribute = new QueryableAttribute ( ) ;
373
+
374
+ // Act & Assert
375
+ Assert . ThrowsArgumentNull ( ( ) => attribute . ValidateQuery ( new HttpRequestMessage ( ) , null ) , "queryOptions" ) ;
363
376
}
364
377
365
378
[ Theory ]
@@ -368,10 +381,12 @@ public void ValidateQuery_Accepts_All_Supported_QueryNames(string queryName)
368
381
{
369
382
// Arrange
370
383
QueryableAttribute attribute = new QueryableAttribute ( ) ;
371
- HttpRequestMessage request = new HttpRequestMessage ( HttpMethod . Get , "http://localhost/?" + queryName ) ;
384
+ HttpRequestMessage request = new HttpRequestMessage ( HttpMethod . Get , "http://localhost/?" + queryName + "=x" ) ;
385
+ var model = new ODataModelBuilder ( ) . Add_Customer_EntityType ( ) . Add_Customers_EntitySet ( ) . GetEdmModel ( ) ;
386
+ var options = new ODataQueryOptions ( new ODataQueryContext ( model , typeof ( System . Web . Http . OData . Builder . TestModels . Customer ) , "Customers" ) , request ) ;
372
387
373
388
// Act & Assert
374
- attribute . ValidateQuery ( request ) ;
389
+ attribute . ValidateQuery ( request , options ) ;
375
390
}
376
391
377
392
[ Theory ]
@@ -381,10 +396,12 @@ public void ValidateQuery_Sends_BadRequest_For_Unsupported_QueryNames(string que
381
396
// Arrange
382
397
QueryableAttribute attribute = new QueryableAttribute ( ) ;
383
398
HttpRequestMessage request = new HttpRequestMessage ( HttpMethod . Get , "http://localhost/?" + queryName ) ;
399
+ var model = new ODataModelBuilder ( ) . Add_Customer_EntityType ( ) . Add_Customers_EntitySet ( ) . GetEdmModel ( ) ;
400
+ var options = new ODataQueryOptions ( new ODataQueryContext ( model , typeof ( System . Web . Http . OData . Builder . TestModels . Customer ) , "Customers" ) , request ) ;
384
401
385
402
// Act & Assert
386
403
HttpResponseException responseException = Assert . Throws < HttpResponseException > (
387
- ( ) => attribute . ValidateQuery ( request ) ) ;
404
+ ( ) => attribute . ValidateQuery ( request , options ) ) ;
388
405
389
406
Assert . Equal ( HttpStatusCode . BadRequest , responseException . Response . StatusCode ) ;
390
407
}
@@ -395,10 +412,12 @@ public void ValidateQuery_Sends_BadRequest_For_Unrecognized_QueryNames()
395
412
// Arrange
396
413
QueryableAttribute attribute = new QueryableAttribute ( ) ;
397
414
HttpRequestMessage request = new HttpRequestMessage ( HttpMethod . Get , "http://localhost/?$xxx" ) ;
415
+ var model = new ODataModelBuilder ( ) . Add_Customer_EntityType ( ) . Add_Customers_EntitySet ( ) . GetEdmModel ( ) ;
416
+ var options = new ODataQueryOptions ( new ODataQueryContext ( model , typeof ( System . Web . Http . OData . Builder . TestModels . Customer ) , "Customers" ) , request ) ;
398
417
399
418
// Act & Assert
400
419
HttpResponseException responseException = Assert . Throws < HttpResponseException > (
401
- ( ) => attribute . ValidateQuery ( request ) ) ;
420
+ ( ) => attribute . ValidateQuery ( request , options ) ) ;
402
421
403
422
Assert . Equal ( HttpStatusCode . BadRequest , responseException . Response . StatusCode ) ;
404
423
}
@@ -408,13 +427,10 @@ public void ValidateQuery_Can_Override_Base()
408
427
{
409
428
// Arrange
410
429
Mock < QueryableAttribute > mockAttribute = new Mock < QueryableAttribute > ( ) ;
411
- mockAttribute . Setup ( m => m . ValidateQuery ( It . IsAny < HttpRequestMessage > ( ) ) ) . Callback ( ( ) => { } ) . Verifiable ( ) ;
412
-
413
- QueryableAttribute attribute = new QueryableAttribute ( ) ;
414
- HttpRequestMessage request = new HttpRequestMessage ( HttpMethod . Get , "http://localhost/?$xxx" ) ;
430
+ mockAttribute . Setup ( m => m . ValidateQuery ( It . IsAny < HttpRequestMessage > ( ) , It . IsAny < ODataQueryOptions > ( ) ) ) . Callback ( ( ) => { } ) . Verifiable ( ) ;
415
431
416
432
// Act & Assert
417
- mockAttribute . Object . ValidateQuery ( null ) ;
433
+ mockAttribute . Object . ValidateQuery ( null , null ) ;
418
434
mockAttribute . Verify ( ) ;
419
435
}
420
436
0 commit comments