@@ -41,7 +41,7 @@ public UpdatingRelationshipsTests(DocsFixture<Startup, JsonDocWriter> fixture)
41
41
}
42
42
43
43
[ Fact ]
44
- public async Task Can_Update_ToManyRelationship_ThroughLink ( )
44
+ public async Task Can_Update_ToMany_Relationship_ThroughLink ( )
45
45
{
46
46
// arrange
47
47
var person = _personFaker . Generate ( ) ;
@@ -57,7 +57,7 @@ public async Task Can_Update_ToManyRelationship_ThroughLink()
57
57
58
58
var server = new TestServer ( builder ) ;
59
59
var client = server . CreateClient ( ) ;
60
-
60
+
61
61
var content = new
62
62
{
63
63
data = new List < object >
@@ -84,5 +84,48 @@ public async Task Can_Update_ToManyRelationship_ThroughLink()
84
84
Assert . Equal ( HttpStatusCode . OK , response . StatusCode ) ;
85
85
Assert . NotEmpty ( personsTodoItems ) ;
86
86
}
87
+
88
+ [ Fact ]
89
+ public async Task Can_Update_ToOne_Relationship_ThroughLink ( )
90
+ {
91
+ // arrange
92
+ var person = _personFaker . Generate ( ) ;
93
+ _context . People . Add ( person ) ;
94
+
95
+ var todoItem = _todoItemFaker . Generate ( ) ;
96
+ _context . TodoItems . Add ( todoItem ) ;
97
+
98
+ _context . SaveChanges ( ) ;
99
+
100
+ var builder = new WebHostBuilder ( )
101
+ . UseStartup < Startup > ( ) ;
102
+
103
+ var server = new TestServer ( builder ) ;
104
+ var client = server . CreateClient ( ) ;
105
+
106
+ var content = new
107
+ {
108
+ data = new
109
+ {
110
+ type = "person" ,
111
+ id = $ "{ person . Id } "
112
+ }
113
+ } ;
114
+
115
+ var httpMethod = new HttpMethod ( "PATCH" ) ;
116
+ var route = $ "/api/v1/todo-items/{ todoItem . Id } /relationships/owner";
117
+ var request = new HttpRequestMessage ( httpMethod , route ) ;
118
+
119
+ request . Content = new StringContent ( JsonConvert . SerializeObject ( content ) ) ;
120
+ request . Content . Headers . ContentType = new MediaTypeHeaderValue ( "application/vnd.api+json" ) ;
121
+
122
+ // Act
123
+ var response = await client . SendAsync ( request ) ;
124
+ var todoItemsOwner = _context . TodoItems . Include ( t => t . Owner ) . Single ( t => t . Id == todoItem . Id ) ;
125
+
126
+ // Assert
127
+ Assert . Equal ( HttpStatusCode . OK , response . StatusCode ) ;
128
+ Assert . NotNull ( todoItemsOwner ) ;
129
+ }
87
130
}
88
131
}
0 commit comments