Skip to content

Commit 8d6ef80

Browse files
committed
test(Deserializer): add test for independent id setting
1 parent 2f5d684 commit 8d6ef80

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

src/JsonApiDotNetCore/Models/ResourceIdentifierObject.cs

+8-1
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,16 @@ namespace JsonApiDotNetCore.Models
44
{
55
public class ResourceIdentifierObject
66
{
7+
public ResourceIdentifierObject() { }
8+
public ResourceIdentifierObject(string type, string id)
9+
{
10+
Type = type;
11+
Id = id;
12+
}
13+
714
[JsonProperty("type")]
815
public string Type { get; set; }
9-
16+
1017
[JsonProperty("id")]
1118
public string Id { get; set; }
1219

test/UnitTests/Serialization/JsonApiDeSerializerTests.cs

+11-1
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,7 @@ public void Can_Deserialize_Independent_Side_Of_One_To_One_Relationship_With_Rel
240240
jsonApiContextMock.SetupAllProperties();
241241
jsonApiContextMock.Setup(m => m.ContextGraph).Returns(contextGraph);
242242
jsonApiContextMock.Setup(m => m.AttributesToUpdate).Returns(new Dictionary<AttrAttribute, object>());
243+
jsonApiContextMock.Setup(m => m.HasOneRelationshipPointers).Returns(new HasOneRelationshipPointers());
243244

244245
var jsonApiOptions = new JsonApiOptions();
245246
jsonApiContextMock.Setup(m => m.Options).Returns(jsonApiOptions);
@@ -255,7 +256,14 @@ public void Can_Deserialize_Independent_Side_Of_One_To_One_Relationship_With_Rel
255256
Id = "1",
256257
Attributes = new Dictionary<string, object> { { "property", property } },
257258
// a common case for this is deserialization in unit tests
258-
Relationships = new Dictionary<string, RelationshipData> { { "dependent", new RelationshipData { } } }
259+
Relationships = new Dictionary<string, RelationshipData> {
260+
{
261+
"dependent", new RelationshipData
262+
{
263+
SingleData = new ResourceIdentifierObject("dependents", "1")
264+
}
265+
}
266+
}
259267
}
260268
};
261269

@@ -267,6 +275,8 @@ public void Can_Deserialize_Independent_Side_Of_One_To_One_Relationship_With_Rel
267275
// assert
268276
Assert.NotNull(result);
269277
Assert.Equal(property, result.Property);
278+
Assert.NotNull(result.Dependent);
279+
Assert.Equal(1, result.Dependent.Id);
270280
}
271281

272282
[Fact]

0 commit comments

Comments
 (0)