@@ -634,6 +634,60 @@ public async Task Updating_ToOne_Relationship_With_Implicit_Remove()
634634 context . People . AddRange ( new List < Person > ( ) { person1 , person2 } ) ;
635635 await context . SaveChangesAsync ( ) ;
636636
637+ var passportId = person1 . PassportId ;
638+
639+ var content = new
640+ {
641+ data = new
642+ {
643+ type = "people" ,
644+ id = person2 . Id ,
645+ relationships = new Dictionary < string , object >
646+ {
647+ { "passport" , new
648+ {
649+ data = new { type = "passports" , id = $ "{ passportId } " }
650+ }
651+ }
652+ }
653+ }
654+ } ;
655+
656+ var httpMethod = new HttpMethod ( "PATCH" ) ;
657+ var route = $ "/api/v1/people/{ person2 . Id } ";
658+ var request = new HttpRequestMessage ( httpMethod , route ) ;
659+
660+ string serializedContent = JsonConvert . SerializeObject ( content ) ;
661+ request . Content = new StringContent ( serializedContent ) ;
662+ request . Content . Headers . ContentType = new MediaTypeHeaderValue ( "application/vnd.api+json" ) ;
663+
664+ // Act
665+ var response = await _fixture . Client . SendAsync ( request ) ;
666+
667+ // Assert
668+ var body = await response . Content . ReadAsStringAsync ( ) ;
669+ Assert . True ( HttpStatusCode . OK == response . StatusCode , $ "{ route } returned { response . StatusCode } status code with payload: { body } ") ;
670+
671+ var _person1 = context . People . AsNoTracking ( ) . Include ( ppl => ppl . Passport ) . Single ( ppl => ppl . Id == person1 . Id ) ;
672+ var _person2 = context . People . AsNoTracking ( ) . Include ( ppl => ppl . Passport ) . Single ( ppl => ppl . Id == person2 . Id ) ;
673+ Assert . Null ( _person1 . Passport ) ;
674+ Assert . Equal ( passportId , _person2 . PassportId ) ;
675+ }
676+
677+ [ Fact ]
678+ public async Task Updating_ToMany_Relationship_With_Implicit_Remove ( )
679+ {
680+ // Arrange
681+ var context = _fixture . GetService < AppDbContext > ( ) ;
682+ var passport = new Passport ( ) ;
683+ var person1 = _personFaker . Generate ( ) ;
684+ person1 . Passport = passport ;
685+ var person2 = _personFaker . Generate ( ) ;
686+ context . People . AddRange ( new List < Person > ( ) { person1 , person2 } ) ;
687+ await context . SaveChangesAsync ( ) ;
688+
689+ var passportId = person1 . PassportId ;
690+
637691 var content = new
638692 {
639693 data = new
@@ -644,7 +698,7 @@ public async Task Updating_ToOne_Relationship_With_Implicit_Remove()
644698 {
645699 { "passport" , new
646700 {
647- data = new { type = "passports" , id = $ "{ person1 . PassportId } " }
701+ data = new { type = "passports" , id = $ "{ passportId } " }
648702 }
649703 }
650704 }
@@ -666,6 +720,10 @@ public async Task Updating_ToOne_Relationship_With_Implicit_Remove()
666720 var body = await response . Content . ReadAsStringAsync ( ) ;
667721 Assert . True ( HttpStatusCode . OK == response . StatusCode , $ "{ route } returned { response . StatusCode } status code with payload: { body } ") ;
668722
723+ var _person1 = context . People . AsNoTracking ( ) . Include ( ppl => ppl . Passport ) . Single ( ppl => ppl . Id == person1 . Id ) ;
724+ var _person2 = context . People . AsNoTracking ( ) . Include ( ppl => ppl . Passport ) . Single ( ppl => ppl . Id == person2 . Id ) ;
725+ Assert . Null ( _person1 . Passport ) ;
726+ Assert . Equal ( passportId , _person2 . PassportId ) ;
669727 }
670728 }
671729}
0 commit comments