|
1 |
| -using System; |
| 1 | +using System; |
2 | 2 | using System.Collections.Generic;
|
3 | 3 | using JsonApiDotNetCore.Builders;
|
4 | 4 | using JsonApiDotNetCore.Configuration;
|
@@ -271,6 +271,54 @@ public void Can_Deserialize_Independent_Side_Of_One_To_One_Relationship_With_Rel
|
271 | 271 | Assert.Equal(property, result.Property);
|
272 | 272 | }
|
273 | 273 |
|
| 274 | + [Fact] |
| 275 | + public void Sets_The_DocumentMeta_Property_In_JsonApiContext() |
| 276 | + { |
| 277 | + // arrange |
| 278 | + var contextGraphBuilder = new ContextGraphBuilder(); |
| 279 | + contextGraphBuilder.AddResource<Independent>("independents"); |
| 280 | + contextGraphBuilder.AddResource<Dependent>("dependents"); |
| 281 | + var contextGraph = contextGraphBuilder.Build(); |
| 282 | + |
| 283 | + var jsonApiContextMock = new Mock<IJsonApiContext>(); |
| 284 | + jsonApiContextMock.SetupAllProperties(); |
| 285 | + jsonApiContextMock.Setup(m => m.ContextGraph).Returns(contextGraph); |
| 286 | + jsonApiContextMock.Setup(m => m.AttributesToUpdate).Returns(new Dictionary<AttrAttribute, object>()); |
| 287 | + |
| 288 | + var jsonApiOptions = new JsonApiOptions(); |
| 289 | + jsonApiContextMock.Setup(m => m.Options).Returns(jsonApiOptions); |
| 290 | + |
| 291 | + var genericProcessorFactoryMock = new Mock<IGenericProcessorFactory>(); |
| 292 | + |
| 293 | + var deserializer = new JsonApiDeSerializer(jsonApiContextMock.Object, genericProcessorFactoryMock.Object); |
| 294 | + |
| 295 | + var property = Guid.NewGuid().ToString(); |
| 296 | + |
| 297 | + var content = new Document |
| 298 | + { |
| 299 | + Meta = new Dictionary<string, object>() { {"foo", "bar"}}, |
| 300 | + Data = new DocumentData |
| 301 | + { |
| 302 | + Type = "independents", |
| 303 | + Id = "1", |
| 304 | + Attributes = new Dictionary<string, object> { { "property", property } |
| 305 | + }, |
| 306 | + // a common case for this is deserialization in unit tests |
| 307 | + Relationships = new Dictionary<string, RelationshipData> { { "dependent", new RelationshipData { } } |
| 308 | + } |
| 309 | + } |
| 310 | + }; |
| 311 | + |
| 312 | + var contentString = JsonConvert.SerializeObject(content); |
| 313 | + |
| 314 | + // act |
| 315 | + var result = deserializer.Deserialize<Independent>(contentString); |
| 316 | + |
| 317 | + // assert |
| 318 | + jsonApiContextMock.VerifySet(mock => mock.DocumentMeta = content.Meta); |
| 319 | + } |
| 320 | + |
| 321 | + |
274 | 322 | private class TestResource : Identifiable {
|
275 | 323 | [Attr("complex-member")]
|
276 | 324 | public ComplexType ComplexMember { get; set; }
|
|
0 commit comments