@@ -268,9 +268,67 @@ public async Task Can_Update_Many_To_Many_With_Complete_Replacement()
268268 Tag = firstTag
269269 } ;
270270 context . ArticleTags . Add ( articleTag ) ;
271+ var secondTag = _tagFaker . Generate ( ) ;
272+ context . Tags . Add ( secondTag ) ;
271273 await context . SaveChangesAsync ( ) ;
272274
275+ var route = $ "/api/v1/articles/{ article . Id } ";
276+ var request = new HttpRequestMessage ( new HttpMethod ( "PATCH" ) , route ) ;
277+ var content = new
278+ {
279+ data = new
280+ {
281+ type = "articles" ,
282+ id = article . StringId ,
283+ relationships = new Dictionary < string , dynamic >
284+ {
285+ { "tags" , new {
286+ data = new [ ] { new
287+ {
288+ type = "tags" ,
289+ id = secondTag . StringId
290+ } }
291+ } }
292+ }
293+ }
294+ } ;
295+
296+ request . Content = new StringContent ( JsonConvert . SerializeObject ( content ) ) ;
297+ request . Content . Headers . ContentType = new MediaTypeHeaderValue ( "application/vnd.api+json" ) ;
298+
299+ // act
300+ var response = await _fixture . Client . SendAsync ( request ) ;
301+
302+ // assert
303+ var body = await response . Content . ReadAsStringAsync ( ) ;
304+ Assert . True ( HttpStatusCode . OK == response . StatusCode , $ "{ route } returned { response . StatusCode } status code with payload: { body } ") ;
305+
306+ var articleResponse = _fixture . GetService < IJsonApiDeSerializer > ( ) . Deserialize < Article > ( body ) ;
307+ Assert . NotNull ( articleResponse ) ;
308+
309+ _fixture . ReloadDbContext ( ) ;
310+ var persistedArticle = await _fixture . Context . Articles
311+ . Include ( "ArticleTags.Tag" )
312+ . SingleOrDefaultAsync ( a => a . Id == article . Id ) ;
313+ var tag = persistedArticle . ArticleTags . Select ( at => at . Tag ) . Single ( ) ;
314+ Assert . Equal ( secondTag . Id , tag . Id ) ;
315+ }
316+ [ Fact ]
317+ public async Task Can_Update_Many_To_Many_With_Complete_Replacement_With_Overlap ( )
318+ {
319+ // arrange
320+ var context = _fixture . GetService < AppDbContext > ( ) ;
321+ var firstTag = _tagFaker . Generate ( ) ;
322+ var article = _articleFaker . Generate ( ) ;
323+ var articleTag = new ArticleTag
324+ {
325+ Article = article ,
326+ Tag = firstTag
327+ } ;
328+ context . ArticleTags . Add ( articleTag ) ;
273329 var secondTag = _tagFaker . Generate ( ) ;
330+ context . Tags . Add ( secondTag ) ;
331+ await context . SaveChangesAsync ( ) ;
274332
275333 var route = $ "/api/v1/articles/{ article . Id } ";
276334 var request = new HttpRequestMessage ( new HttpMethod ( "PATCH" ) , route ) ;
0 commit comments