public async Task Can_filter_secondary_resources_with_sparse_fieldset() { // Arrange SwimmingPool pool = _fakers.SwimmingPool.Generate(); pool.WaterSlides = _fakers.WaterSlide.Generate(2); pool.WaterSlides[0].LengthInMeters = 1; pool.WaterSlides[1].LengthInMeters = 5; await _testContext.RunOnDatabaseAsync(async dbContext => { dbContext.SwimmingPools.Add(pool); await dbContext.SaveChangesAsync(); }); string route = $"/public-api/swimming-pools/{pool.StringId}/water-slides" + "?filter=greaterThan(length-in-meters,'1')&fields[water-slides]=length-in-meters"; // Act (HttpResponseMessage httpResponse, Document responseDocument) = await _testContext.ExecuteGetAsync <Document>(route); // Assert httpResponse.Should().HaveStatusCode(HttpStatusCode.OK); responseDocument.ManyData.Should().HaveCount(1); responseDocument.ManyData[0].Type.Should().Be("water-slides"); responseDocument.ManyData[0].Id.Should().Be(pool.WaterSlides[1].StringId); responseDocument.ManyData[0].Attributes.Should().HaveCount(1); }
public async Task Can_create_resource() { // Arrange SwimmingPool newPool = _fakers.SwimmingPool.Generate(); var requestBody = new { data = new { type = "swimming-pools", attributes = new Dictionary <string, object> { ["is-indoor"] = newPool.IsIndoor } } }; const string route = "/public-api/swimming-pools"; // Act (HttpResponseMessage httpResponse, Document responseDocument) = await _testContext.ExecutePostAsync <Document>(route, requestBody); // Assert httpResponse.Should().HaveStatusCode(HttpStatusCode.Created); responseDocument.SingleData.Should().NotBeNull(); responseDocument.SingleData.Type.Should().Be("swimming-pools"); responseDocument.SingleData.Attributes["is-indoor"].Should().Be(newPool.IsIndoor); int newPoolId = int.Parse(responseDocument.SingleData.Id); string poolLink = route + $"/{newPoolId}"; responseDocument.SingleData.Relationships.Should().NotBeEmpty(); responseDocument.SingleData.Relationships["water-slides"].Links.Self.Should().Be(poolLink + "/relationships/water-slides"); responseDocument.SingleData.Relationships["water-slides"].Links.Related.Should().Be(poolLink + "/water-slides"); responseDocument.SingleData.Relationships["diving-boards"].Links.Self.Should().Be(poolLink + "/relationships/diving-boards"); responseDocument.SingleData.Relationships["diving-boards"].Links.Related.Should().Be(poolLink + "/diving-boards"); await _testContext.RunOnDatabaseAsync(async dbContext => { SwimmingPool poolInDatabase = await dbContext.SwimmingPools.FirstWithIdAsync(newPoolId); poolInDatabase.IsIndoor.Should().Be(newPool.IsIndoor); }); }