|
5 | 5 | using JsonApiDotNetCore.Configuration;
|
6 | 6 | using JsonApiDotNetCore.Serialization.Objects;
|
7 | 7 | using JsonApiDotNetCoreExampleTests.Startups;
|
| 8 | +using Microsoft.EntityFrameworkCore; |
8 | 9 | using Microsoft.Extensions.DependencyInjection;
|
9 | 10 | using TestBuildingBlocks;
|
10 | 11 | using Xunit;
|
@@ -382,7 +383,7 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
|
382 | 383 | }
|
383 | 384 |
|
384 | 385 | [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() |
386 | 387 | {
|
387 | 388 | // Arrange
|
388 | 389 | Order orderWithShipment = _fakers.Orders.Generate();
|
@@ -424,18 +425,19 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
|
424 | 425 | (HttpResponseMessage httpResponse, ErrorDocument responseDocument) = await _testContext.ExecutePatchAsync<ErrorDocument>(route, requestBody);
|
425 | 426 |
|
426 | 427 | // Assert
|
427 |
| - httpResponse.Should().HaveStatusCode(HttpStatusCode.InternalServerError); |
| 428 | + httpResponse.Should().HaveStatusCode(HttpStatusCode.NoContent); |
428 | 429 |
|
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); |
430 | 434 |
|
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 | + }); |
435 | 437 | }
|
436 | 438 |
|
437 | 439 | [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() |
439 | 441 | {
|
440 | 442 | // Arrange
|
441 | 443 | Order orderWithShipment = _fakers.Orders.Generate();
|
@@ -466,14 +468,15 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
|
466 | 468 | (HttpResponseMessage httpResponse, ErrorDocument responseDocument) = await _testContext.ExecutePatchAsync<ErrorDocument>(route, requestBody);
|
467 | 469 |
|
468 | 470 | // Assert
|
469 |
| - httpResponse.Should().HaveStatusCode(HttpStatusCode.InternalServerError); |
| 471 | + httpResponse.Should().HaveStatusCode(HttpStatusCode.NoContent); |
470 | 472 |
|
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); |
472 | 477 |
|
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 | + }); |
477 | 480 | }
|
478 | 481 | }
|
479 | 482 | }
|
0 commit comments