88using JsonApiDotNetCore . Serialization ;
99using JsonApiDotNetCore . Services ;
1010using JsonApiDotNetCoreExample ;
11+ using JsonApiDotNetCoreExample . Data ;
1112using JsonApiDotNetCoreExample . Models ;
1213using Microsoft . AspNetCore . Hosting ;
1314using Microsoft . AspNetCore . TestHost ;
@@ -27,11 +28,57 @@ public CreatingDataTests(DocsFixture<Startup, JsonDocWriter> fixture)
2728 {
2829 _fixture = fixture ;
2930 _jsonApiContext = fixture . GetService < IJsonApiContext > ( ) ;
30- _todoItemFaker = new Faker < TodoItem > ( )
31+ _todoItemFaker = new Faker < TodoItem > ( )
3132 . RuleFor ( t => t . Description , f => f . Lorem . Sentence ( ) )
3233 . RuleFor ( t => t . Ordinal , f => f . Random . Number ( ) ) ;
3334 }
3435
36+ [ Fact ]
37+ public async Task Can_Create_Guid_Identifiable_Entities ( )
38+ {
39+ // arrange
40+ var builder = new WebHostBuilder ( )
41+ . UseStartup < Startup > ( ) ;
42+ var httpMethod = new HttpMethod ( "POST" ) ;
43+ var server = new TestServer ( builder ) ;
44+ var client = server . CreateClient ( ) ;
45+
46+ var context = _fixture . GetService < AppDbContext > ( ) ;
47+
48+ var owner = new JsonApiDotNetCoreExample . Models . Person ( ) ;
49+ context . People . Add ( owner ) ;
50+ await context . SaveChangesAsync ( ) ;
51+
52+ var route = "/api/v1/todo-item-collections" ;
53+ var request = new HttpRequestMessage ( httpMethod , route ) ;
54+ var content = new
55+ {
56+ data = new
57+ {
58+ type = "todo-item-collections"
59+ } ,
60+ relationships = new
61+ {
62+ owner = new
63+ {
64+ data = new
65+ {
66+ type = "people" ,
67+ id = owner . Id . ToString ( )
68+ }
69+ }
70+ }
71+ } ;
72+ request . Content = new StringContent ( JsonConvert . SerializeObject ( content ) ) ;
73+ request . Content . Headers . ContentType = new MediaTypeHeaderValue ( "application/vnd.api+json" ) ;
74+
75+ // act
76+ var response = await client . SendAsync ( request ) ;
77+
78+ // assert
79+ Assert . Equal ( HttpStatusCode . Created , response . StatusCode ) ;
80+ }
81+
3582 [ Fact ]
3683 public async Task Request_With_ClientGeneratedId_Returns_403 ( )
3784 {
0 commit comments