Skip to content

Commit 4a8bfdd

Browse files
author
Bart Koelman
committed
Added test for broken resource linkage
1 parent 7c6684f commit 4a8bfdd

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

test/JsonApiDotNetCoreTests/IntegrationTests/QueryStrings/SparseFieldSets/SparseFieldSetTests.cs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -727,5 +727,34 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
727727
postCaptured.Caption.Should().Be(post.Caption);
728728
postCaptured.Url.Should().Be(postCaptured.Url);
729729
}
730+
731+
[Fact]
732+
public async Task Returns_related_resources_on_broken_resource_linkage()
733+
{
734+
// Arrange
735+
WebAccount account = _fakers.WebAccount.Generate();
736+
account.Posts = _fakers.BlogPost.Generate(2);
737+
738+
await _testContext.RunOnDatabaseAsync(async dbContext =>
739+
{
740+
dbContext.Accounts.Add(account);
741+
await dbContext.SaveChangesAsync();
742+
});
743+
744+
string route = $"/webAccounts/{account.StringId}?include=posts&fields[webAccounts]=displayName";
745+
746+
// Act
747+
(HttpResponseMessage httpResponse, Document responseDocument) = await _testContext.ExecuteGetAsync<Document>(route);
748+
749+
// Assert
750+
httpResponse.Should().HaveStatusCode(HttpStatusCode.OK);
751+
752+
responseDocument.Data.SingleValue.Should().NotBeNull();
753+
responseDocument.Data.SingleValue.Id.Should().Be(account.StringId);
754+
responseDocument.Data.SingleValue.Relationships.Should().BeNull();
755+
756+
responseDocument.Included.Should().HaveCount(2);
757+
responseDocument.Included.Should().OnlyContain(resourceObject => resourceObject.Type == "blogPosts");
758+
}
730759
}
731760
}

0 commit comments

Comments
 (0)