8
8
using JsonApiDotNetCore . Serialization ;
9
9
using JsonApiDotNetCore . Services ;
10
10
using JsonApiDotNetCoreExample ;
11
+ using JsonApiDotNetCoreExample . Data ;
11
12
using JsonApiDotNetCoreExample . Models ;
12
13
using Microsoft . AspNetCore . Hosting ;
13
14
using Microsoft . AspNetCore . TestHost ;
@@ -27,11 +28,57 @@ public CreatingDataTests(DocsFixture<Startup, JsonDocWriter> fixture)
27
28
{
28
29
_fixture = fixture ;
29
30
_jsonApiContext = fixture . GetService < IJsonApiContext > ( ) ;
30
- _todoItemFaker = new Faker < TodoItem > ( )
31
+ _todoItemFaker = new Faker < TodoItem > ( )
31
32
. RuleFor ( t => t . Description , f => f . Lorem . Sentence ( ) )
32
33
. RuleFor ( t => t . Ordinal , f => f . Random . Number ( ) ) ;
33
34
}
34
35
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
+
35
82
[ Fact ]
36
83
public async Task Request_With_ClientGeneratedId_Returns_403 ( )
37
84
{
0 commit comments