@@ -176,5 +176,50 @@ public async Task Can_Update_Many_To_Many()
176
176
var persistedArticleTag = Assert . Single ( persistedArticle . ArticleTags ) ;
177
177
Assert . Equal ( tag . Id , persistedArticleTag . TagId ) ;
178
178
}
179
+
180
+ [ Fact ]
181
+ public async Task Can_Update_Many_To_Many_Through_Relationship_Link ( )
182
+ {
183
+ // arrange
184
+ var context = _fixture . GetService < AppDbContext > ( ) ;
185
+ var tag = _tagFaker . Generate ( ) ;
186
+ var article = _articleFaker . Generate ( ) ;
187
+ context . Tags . Add ( tag ) ;
188
+ context . Articles . Add ( article ) ;
189
+ await context . SaveChangesAsync ( ) ;
190
+
191
+ var route = $ "/api/v1/articles/{ article . Id } /relationships/tags";
192
+ var request = new HttpRequestMessage ( new HttpMethod ( "PATCH" ) , route ) ;
193
+ var content = new
194
+ {
195
+ data = new [ ] {
196
+ new {
197
+ type = "tags" ,
198
+ id = tag . StringId
199
+ }
200
+ }
201
+ } ;
202
+
203
+ request . Content = new StringContent ( JsonConvert . SerializeObject ( content ) ) ;
204
+ request . Content . Headers . ContentType = new MediaTypeHeaderValue ( "application/vnd.api+json" ) ;
205
+
206
+ // act
207
+ var response = await _fixture . Client . SendAsync ( request ) ;
208
+
209
+ // assert
210
+ var body = await response . Content . ReadAsStringAsync ( ) ;
211
+ Assert . True ( HttpStatusCode . OK == response . StatusCode , $ "{ route } returned { response . StatusCode } status code with payload: { body } ") ;
212
+
213
+ var articleResponse = _fixture . GetService < IJsonApiDeSerializer > ( ) . Deserialize < Article > ( body ) ;
214
+ Assert . NotNull ( articleResponse ) ;
215
+
216
+ _fixture . ReloadDbContext ( ) ;
217
+ var persistedArticle = await _fixture . Context . Articles
218
+ . Include ( a => a . ArticleTags )
219
+ . SingleAsync ( a => a . Id == articleResponse . Id ) ;
220
+
221
+ var persistedArticleTag = Assert . Single ( persistedArticle . ArticleTags ) ;
222
+ Assert . Equal ( tag . Id , persistedArticleTag . TagId ) ;
223
+ }
179
224
}
180
225
}
0 commit comments