6
6
using System . Net . Http ;
7
7
using System . Net . Http . Headers ;
8
8
using System . Threading ;
9
+ using System . Web . Http . OData ;
9
10
using System . Web . Http . OData . Batch ;
11
+ using System . Web . Http . OData . Builder ;
12
+ using System . Web . Http . OData . Extensions ;
10
13
using System . Web . Http . Routing ;
14
+ using Microsoft . Data . Edm ;
11
15
using Microsoft . TestCommon ;
12
16
13
17
namespace System . Web . Http
@@ -324,5 +328,68 @@ public void ValidateRequest_Throws_IfRequestContentTypeDoesNotHaveBoundary()
324
328
Assert . Equal ( "The batch request must have a boundary specification in the \" Content-Type\" header." ,
325
329
errorResponse . Response . Content . ReadAsAsync < HttpError > ( ) . Result . Message ) ;
326
330
}
331
+
332
+ [ Fact ]
333
+ public void BatchRequest_Works_AbsoluteAndRelativeUri ( )
334
+ {
335
+ // Arrange
336
+ ODataConventionModelBuilder builder = new ODataConventionModelBuilder ( ) ;
337
+ builder . EntitySet < BatchCustomer > ( "BatchCustomers" ) ;
338
+ IEdmModel model = builder . GetEdmModel ( ) ;
339
+
340
+ HttpConfiguration configuration = new HttpConfiguration ( ) ;
341
+ HttpServer server = new HttpServer ( configuration ) ;
342
+ HttpClient client = new HttpClient ( server ) ;
343
+ configuration . Routes . MapODataServiceRoute ( "odata" , "odata" , model , new DefaultODataBatchHandler ( server ) ) ;
344
+
345
+ HttpRequestMessage request = new HttpRequestMessage ( HttpMethod . Post , "http://localhost/odata/$batch" ) ;
346
+ request . Content = new StringContent (
347
+ @"--batch_36522ad7-fc75-4b56-8c71-56071383e77b
348
+ Content-Type: application/http
349
+ Content-Transfer-Encoding:binary
350
+
351
+ GET http://localhost/odata/BatchCustomers(5) HTTP/1.1
352
+
353
+ --batch_36522ad7-fc75-4b56-8c71-56071383e77b
354
+ Content-Type: application/http
355
+ Content-Transfer-Encoding:binary
356
+
357
+ GET /odata/BatchCustomers(6) HTTP/1.1
358
+ Host: localhost
359
+
360
+ --batch_36522ad7-fc75-4b56-8c71-56071383e77b
361
+ Content-Type: application/http
362
+ Content-Transfer-Encoding:binary
363
+
364
+ GET BatchCustomers(7) HTTP/1.1
365
+
366
+ --batch_36522ad7-fc75-4b56-8c71-56071383e77b--
367
+ " ) ;
368
+ request . Content . Headers . ContentType =
369
+ MediaTypeHeaderValue . Parse ( "multipart/mixed;boundary=batch_36522ad7-fc75-4b56-8c71-56071383e77b" ) ;
370
+
371
+ // Act
372
+ HttpResponseMessage response = client . SendAsync ( request ) . Result ;
373
+ string responseString = response . Content . ReadAsStringAsync ( ) . Result ;
374
+
375
+ // Assert
376
+ Assert . Equal ( HttpStatusCode . Accepted , response . StatusCode ) ;
377
+ Assert . Contains ( "\" odata.metadata\" :\" http://localhost/odata/$metadata#BatchCustomers/@Element\" ,\" ID\" :5" , responseString ) ;
378
+ Assert . Contains ( "\" odata.metadata\" :\" http://localhost/odata/$metadata#BatchCustomers/@Element\" ,\" ID\" :6" , responseString ) ;
379
+ Assert . Contains ( "\" odata.metadata\" :\" http://localhost/odata/$metadata#BatchCustomers/@Element\" ,\" ID\" :7" , responseString ) ;
380
+ }
381
+
382
+ public class BatchCustomersController : ODataController
383
+ {
384
+ public IHttpActionResult Get ( int key )
385
+ {
386
+ return Ok ( new BatchCustomer { ID = key } ) ;
387
+ }
388
+ }
389
+
390
+ public class BatchCustomer
391
+ {
392
+ public int ID { get ; set ; }
393
+ }
327
394
}
328
395
}
0 commit comments