Skip to content

Commit 04dac0e

Browse files
maureiBart Koelman
authored and
Bart Koelman
committed
Updated tests to cover for zero-or-one-to-one cases
1 parent 5eae4e2 commit 04dac0e

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed

test/JsonApiDotNetCoreExampleTests/IntegrationTests/RequiredRelationships/DefaultBehaviorTests.cs

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using JsonApiDotNetCore.Configuration;
66
using JsonApiDotNetCore.Serialization.Objects;
77
using JsonApiDotNetCoreExampleTests.Startups;
8+
using Microsoft.EntityFrameworkCore;
89
using Microsoft.Extensions.DependencyInjection;
910
using TestBuildingBlocks;
1011
using Xunit;
@@ -382,7 +383,7 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
382383
}
383384

384385
[Fact]
385-
public async Task Cannot_reassign_dependent_side_of_OneToOne_relationship_with_identifying_foreign_key_through_primary_endpoint()
386+
public async Task Can_reassign_dependent_side_of_ZeroOrOneToOne_relationship_through_primary_endpoint()
386387
{
387388
// Arrange
388389
Order orderWithShipment = _fakers.Orders.Generate();
@@ -424,18 +425,19 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
424425
(HttpResponseMessage httpResponse, ErrorDocument responseDocument) = await _testContext.ExecutePatchAsync<ErrorDocument>(route, requestBody);
425426

426427
// Assert
427-
httpResponse.Should().HaveStatusCode(HttpStatusCode.InternalServerError);
428+
httpResponse.Should().HaveStatusCode(HttpStatusCode.NoContent);
428429

429-
responseDocument.Errors.Should().HaveCount(1);
430+
await _testContext.RunOnDatabaseAsync(async dbContext =>
431+
{
432+
Shipment existingShipmentInDatabase =
433+
await dbContext.Shipments.Include(shipment => shipment.Order).FirstWithIdOrDefaultAsync(orderWithShipment.Shipment.Id);
430434

431-
Error error = responseDocument.Errors[0];
432-
error.StatusCode.Should().Be(HttpStatusCode.InternalServerError);
433-
error.Title.Should().Be("An unhandled error occurred while processing this request.");
434-
error.Detail.Should().StartWith("The property 'Id' on entity type 'Shipment' is part of a key and so cannot be modified or marked as modified.");
435+
existingShipmentInDatabase.Order.Id.Should().Be(orderWithoutShipment.Id);
436+
});
435437
}
436438

437439
[Fact]
438-
public async Task Cannot_reassign_dependent_side_of_OneToOne_relationship_with_identifying_foreign_key_through_relationship_endpoint()
440+
public async Task Can_reassign_dependent_side_of_ZeroOrOneToOne_relationship_through_relationship_endpoint()
439441
{
440442
// Arrange
441443
Order orderWithShipment = _fakers.Orders.Generate();
@@ -466,14 +468,15 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
466468
(HttpResponseMessage httpResponse, ErrorDocument responseDocument) = await _testContext.ExecutePatchAsync<ErrorDocument>(route, requestBody);
467469

468470
// Assert
469-
httpResponse.Should().HaveStatusCode(HttpStatusCode.InternalServerError);
471+
httpResponse.Should().HaveStatusCode(HttpStatusCode.NoContent);
470472

471-
responseDocument.Errors.Should().HaveCount(1);
473+
await _testContext.RunOnDatabaseAsync(async dbContext =>
474+
{
475+
Shipment existingShipmentInDatabase =
476+
await dbContext.Shipments.Include(shipment => shipment.Order).FirstWithIdOrDefaultAsync(orderWithShipment.Shipment.Id);
472477

473-
Error error = responseDocument.Errors[0];
474-
error.StatusCode.Should().Be(HttpStatusCode.InternalServerError);
475-
error.Title.Should().Be("An unhandled error occurred while processing this request.");
476-
error.Detail.Should().StartWith("The property 'Id' on entity type 'Shipment' is part of a key and so cannot be modified or marked as modified.");
478+
existingShipmentInDatabase.Order.Id.Should().Be(orderWithoutShipment.Id);
479+
});
477480
}
478481
}
479482
}

0 commit comments

Comments
 (0)