Closed
Description
Repro:
[Fact]
public async Task Can_include_chain_of_recursive_relationships()
{
// Arrange
var options = (JsonApiOptions) _testContext.Factory.Services.GetRequiredService<IJsonApiOptions>();
options.TopLevelLinks = LinkTypes.None;
options.ResourceLinks = LinkTypes.None;
options.RelationshipLinks = LinkTypes.None;
var todoItem = new TodoItem
{
Collection = new TodoItemCollection
{
Owner = new Person(),
TodoItems = new HashSet<TodoItem>
{
new TodoItem
{
Owner = new Person()
},
new TodoItem()
}
}
};
await _testContext.RunOnDatabaseAsync(async dbContext =>
{
dbContext.TodoItems.Add(todoItem);
await dbContext.SaveChangesAsync();
});
string route = $"/api/v1/todoItems/{todoItem.StringId}?include=collection.todoItems.owner";
// Act
var (httpResponse, responseDocument) = await _testContext.ExecuteGetAsync<string>(route);
// Assert
httpResponse.Should().HaveStatusCode(HttpStatusCode.OK);
}
responseDocument:
{
"data": {
"type": "todoItems",
"id": "1",
"attributes": {
"description": null,
"ordinal": 0,
"alwaysChangingValue": "8243d009-419f-49e6-b81a-aeb49e7bd0cd",
"createdDate": "2021-02-06T00:50:25.580035",
"achievedDate": null,
"calculatedValue": "calculated",
"offsetDate": null
},
"relationships": {
"collection": {
"data": {
"type": "todoCollections",
"id": "b435a82b-921f-4a7c-9b02-5bf2a0974e56"
}
}
}
},
"included": [
{
"type": "todoCollections",
"id": "b435a82b-921f-4a7c-9b02-5bf2a0974e56",
"attributes": {
"name": null
},
"relationships": {
"todoItems": {
"data": [
{
"type": "todoItems",
"id": "1"
},
{
"type": "todoItems",
"id": "2"
},
{
"type": "todoItems",
"id": "3"
}
]
}
}
},
{
"type": "todoItems",
"id": "1",
"attributes": {
"description": null,
"ordinal": 0,
"alwaysChangingValue": "69b7b623-e122-4925-a796-52e671030de9",
"createdDate": "2021-02-06T00:50:25.580035",
"achievedDate": null,
"calculatedValue": "calculated",
"offsetDate": null
},
"relationships": {
"owner": {
"data": null
}
}
},
{
"type": "todoItems",
"id": "2",
"attributes": {
"description": null,
"ordinal": 0,
"alwaysChangingValue": "9d2aa44e-c151-4860-bb49-ce9b4652fd2a",
"createdDate": "2021-02-06T00:50:25.580035",
"achievedDate": null,
"calculatedValue": "calculated",
"offsetDate": null
},
"relationships": {
"owner": {
"data": {
"type": "people",
"id": "2"
}
}
}
},
{
"type": "people",
"id": "2",
"attributes": {
"firstName": null,
"initials": null,
"lastName": null,
"the-Age": 0,
"gender": "Unknown",
"category": null
},
"relationships": {
"unIncludeableItem": {
"links": {
"self": "http://localhost/api/v1/people/2/relationships/unIncludeableItem",
"related": "http://localhost/api/v1/people/2/unIncludeableItem"
}
}
}
},
{
"type": "todoItems",
"id": "3",
"attributes": {
"description": null,
"ordinal": 0,
"alwaysChangingValue": "18cab3ea-44e7-4b4e-be1a-b4af8dad5fc9",
"createdDate": "2021-02-06T00:50:25.580035",
"achievedDate": null,
"calculatedValue": "calculated",
"offsetDate": null
},
"relationships": {
"owner": {
"data": null
}
}
}
]
}
The response body should not contain relationship links, but it does. There are no tests for this.