15
15
using Xunit ;
16
16
using JsonApiDotNetCore . Services ;
17
17
using JsonApiDotNetCore . Serialization ;
18
+ using System . Linq ;
18
19
19
20
namespace JsonApiDotNetCoreExampleTests . Acceptance
20
21
{
@@ -366,5 +367,35 @@ public async Task Can_Patch_TodoItem()
366
367
Assert . Equal ( newTodoItem . Description , deserializedBody . Description ) ;
367
368
Assert . Equal ( newTodoItem . Ordinal , deserializedBody . Ordinal ) ;
368
369
}
370
+
371
+ [ Fact ]
372
+ public async Task Can_Delete_TodoItem ( )
373
+ {
374
+ // Arrange
375
+ var person = new Person ( ) ;
376
+ _context . People . Add ( person ) ;
377
+ _context . SaveChanges ( ) ;
378
+
379
+ var todoItem = _todoItemFaker . Generate ( ) ;
380
+ todoItem . Owner = person ;
381
+ _context . TodoItems . Add ( todoItem ) ;
382
+ _context . SaveChanges ( ) ;
383
+
384
+ var httpMethod = new HttpMethod ( "DELETE" ) ;
385
+ var route = $ "/api/v1/todo-items/{ todoItem . Id } ";
386
+
387
+ var request = new HttpRequestMessage ( httpMethod , route ) ;
388
+ request . Content = new StringContent ( string . Empty ) ;
389
+ request . Content . Headers . ContentType = new MediaTypeHeaderValue ( "application/vnd.api+json" ) ;
390
+
391
+ var description = new RequestProperties ( "Delete TodoItem" ) ;
392
+
393
+ // Act
394
+ var response = await _fixture . MakeRequest < TodoItem > ( description , request ) ;
395
+
396
+ // Assert
397
+ Assert . Equal ( HttpStatusCode . OK , response . StatusCode ) ;
398
+ Assert . Null ( _context . TodoItems . FirstOrDefault ( t => t . Id == todoItem . Id ) ) ;
399
+ }
369
400
}
370
401
}
0 commit comments