public async Task Get_secondary_resources_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}/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); responseDocument.ManyData[0].Attributes["archivedAt"].Should().BeNull(); }
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); }
public async Task Get_primary_resource_by_ID_with_include_and_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}?include=broadcasts&filter[broadcasts]=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.SingleData.Should().NotBeNull(); responseDocument.SingleData.Id.Should().Be(station.StringId); responseDocument.Included.Should().HaveCount(2); responseDocument.Included[0].Id.Should().Be(station.Broadcasts.ElementAt(0).StringId); responseDocument.Included[0].Attributes["archivedAt"].Should().BeCloseTo(station.Broadcasts.ElementAt(0).ArchivedAt); responseDocument.Included[1].Id.Should().Be(station.Broadcasts.ElementAt(1).StringId); responseDocument.Included[1].Attributes["archivedAt"].Should().BeNull(); }