@@ -41,7 +41,7 @@ public UpdatingRelationshipsTests(DocsFixture<Startup, JsonDocWriter> fixture)
4141 }
4242
4343 [ Fact ]
44- public async Task Can_Update_ToManyRelationship_ThroughLink ( )
44+ public async Task Can_Update_ToMany_Relationship_ThroughLink ( )
4545 {
4646 // arrange
4747 var person = _personFaker . Generate ( ) ;
@@ -57,7 +57,7 @@ public async Task Can_Update_ToManyRelationship_ThroughLink()
5757
5858 var server = new TestServer ( builder ) ;
5959 var client = server . CreateClient ( ) ;
60-
60+
6161 var content = new
6262 {
6363 data = new List < object >
@@ -84,5 +84,48 @@ public async Task Can_Update_ToManyRelationship_ThroughLink()
8484 Assert . Equal ( HttpStatusCode . OK , response . StatusCode ) ;
8585 Assert . NotEmpty ( personsTodoItems ) ;
8686 }
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+ }
87130 }
88131}
0 commit comments