Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Added Get Relationship tests
  • Loading branch information
Bart Koelman committed May 14, 2021
commit e8e70265df2355e7e309072114ade1fbd6170219
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,59 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
responseDocument.Included[1].Attributes["archivedAt"].Should().BeNull();
}

[Fact]
public async Task Get_ToMany_relationship_excludes_archived()
{
// Arrange
TelevisionStation station = _fakers.TelevisionStation.Generate();
station.Broadcasts = _fakers.TelevisionBroadcast.Generate(2).ToHashSet();
station.Broadcasts.ElementAt(1).ArchivedAt = null;

await _testContext.RunOnDatabaseAsync(async dbContext =>
{
dbContext.Stations.Add(station);
await dbContext.SaveChangesAsync();
});

string route = $"/televisionStations/{station.StringId}/relationships/broadcasts";

// Act
(HttpResponseMessage httpResponse, Document responseDocument) = await _testContext.ExecuteGetAsync<Document>(route);

// Assert
httpResponse.Should().HaveStatusCode(HttpStatusCode.OK);

responseDocument.ManyData.Should().HaveCount(1);
responseDocument.ManyData[0].Id.Should().Be(station.Broadcasts.ElementAt(1).StringId);
}

[Fact]
public async Task Get_ToMany_relationship_with_filter_includes_archived()
{
// Arrange
TelevisionStation station = _fakers.TelevisionStation.Generate();
station.Broadcasts = _fakers.TelevisionBroadcast.Generate(2).ToHashSet();
station.Broadcasts.ElementAt(1).ArchivedAt = null;

await _testContext.RunOnDatabaseAsync(async dbContext =>
{
dbContext.Stations.Add(station);
await dbContext.SaveChangesAsync();
});

string route = $"/televisionStations/{station.StringId}/relationships/broadcasts?filter=or(equals(archivedAt,null),not(equals(archivedAt,null)))";

// Act
(HttpResponseMessage httpResponse, Document responseDocument) = await _testContext.ExecuteGetAsync<Document>(route);

// Assert
httpResponse.Should().HaveStatusCode(HttpStatusCode.OK);

responseDocument.ManyData.Should().HaveCount(2);
responseDocument.ManyData[0].Id.Should().Be(station.Broadcasts.ElementAt(0).StringId);
responseDocument.ManyData[1].Id.Should().Be(station.Broadcasts.ElementAt(1).StringId);
}

[Fact]
public async Task Can_create_unarchived_resource()
{
Expand Down