@@ -222,6 +222,51 @@ public void Can_Deserialize_Independent_Side_Of_One_To_One_Relationship()
222
222
Assert . Equal ( property , result . Property ) ;
223
223
}
224
224
225
+ [ Fact ]
226
+ public void Can_Deserialize_Independent_Side_Of_One_To_One_Relationship_With_String_Keys ( )
227
+ {
228
+ // arrange
229
+ var resourceGraphBuilder = new ResourceGraphBuilder ( ) ;
230
+ resourceGraphBuilder . AddResource < IndependentWithStringKey , string > ( "independents" ) ;
231
+ resourceGraphBuilder . AddResource < DependentWithStringKey , string > ( "dependents" ) ;
232
+ var resourceGraph = resourceGraphBuilder . Build ( ) ;
233
+
234
+ var jsonApiContextMock = new Mock < IJsonApiContext > ( ) ;
235
+ jsonApiContextMock . SetupAllProperties ( ) ;
236
+ jsonApiContextMock . Setup ( m => m . ResourceGraph ) . Returns ( resourceGraph ) ;
237
+ jsonApiContextMock . Setup ( m => m . AttributesToUpdate ) . Returns ( new Dictionary < AttrAttribute , object > ( ) ) ;
238
+ jsonApiContextMock . Setup ( m => m . HasOneRelationshipPointers ) . Returns ( new HasOneRelationshipPointers ( ) ) ;
239
+
240
+ var jsonApiOptions = new JsonApiOptions ( ) ;
241
+ jsonApiContextMock . Setup ( m => m . Options ) . Returns ( jsonApiOptions ) ;
242
+
243
+ var deserializer = new JsonApiDeSerializer ( jsonApiContextMock . Object ) ;
244
+
245
+ var property = Guid . NewGuid ( ) . ToString ( ) ;
246
+ var content = new Document
247
+ {
248
+ Data = new ResourceObject
249
+ {
250
+ Type = "independents" ,
251
+ Id = "natural-key" ,
252
+ Attributes = new Dictionary < string , object > { { "property" , property } } ,
253
+ Relationships = new Dictionary < string , RelationshipData >
254
+ {
255
+ { "dependent" , new RelationshipData { } }
256
+ }
257
+ }
258
+ } ;
259
+
260
+ var contentString = JsonConvert . SerializeObject ( content ) ;
261
+
262
+ // act
263
+ var result = deserializer . Deserialize < IndependentWithStringKey > ( contentString ) ;
264
+
265
+ // assert
266
+ Assert . NotNull ( result ) ;
267
+ Assert . Equal ( property , result . Property ) ;
268
+ }
269
+
225
270
[ Fact ]
226
271
public void Can_Deserialize_Independent_Side_Of_One_To_One_Relationship_With_Relationship_Body ( )
227
272
{
@@ -348,6 +393,19 @@ private class Dependent : Identifiable
348
393
public int IndependentId { get ; set ; }
349
394
}
350
395
396
+ private class IndependentWithStringKey : Identifiable < string >
397
+ {
398
+ [ Attr ( "property" ) ] public string Property { get ; set ; }
399
+ [ HasOne ( "dependent" ) ] public Dependent Dependent { get ; set ; }
400
+ public string DependentId { get ; set ; }
401
+ }
402
+
403
+ private class DependentWithStringKey : Identifiable < string >
404
+ {
405
+ [ HasOne ( "independent" ) ] public Independent Independent { get ; set ; }
406
+ public string IndependentId { get ; set ; }
407
+ }
408
+
351
409
[ Fact ]
352
410
public void Can_Deserialize_Object_With_HasManyRelationship ( )
353
411
{
@@ -538,7 +596,7 @@ public void Can_Deserialize_Nested_Included_HasMany_Relationships()
538
596
resourceGraphBuilder . AddResource < ManyToManyNested > ( "many-to-manys" ) ;
539
597
540
598
var deserializer = GetDeserializer ( resourceGraphBuilder ) ;
541
-
599
+
542
600
var contentString =
543
601
@"{
544
602
""data"": {
0 commit comments