|
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;
|
@@ -113,12 +114,12 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
|
113 | 114 | string route = $"/customers/{existingOrder.Customer.Id}";
|
114 | 115 |
|
115 | 116 | // Act
|
116 |
| - (HttpResponseMessage httpResponse, Document responseDocument) = await _testContext.ExecuteDeleteAsync<Document>(route); |
| 117 | + (HttpResponseMessage httpResponse, string responseDocument) = await _testContext.ExecuteDeleteAsync<string>(route); |
117 | 118 |
|
118 | 119 | // Assert
|
119 | 120 | httpResponse.Should().HaveStatusCode(HttpStatusCode.NoContent);
|
120 | 121 |
|
121 |
| - responseDocument.Should().BeNull(); |
| 122 | + responseDocument.Should().BeEmpty(); |
122 | 123 |
|
123 | 124 | await _testContext.RunOnDatabaseAsync(async dbContext =>
|
124 | 125 | {
|
@@ -147,12 +148,12 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
|
147 | 148 | string route = $"/orders/{existingOrder.Id}";
|
148 | 149 |
|
149 | 150 | // Act
|
150 |
| - (HttpResponseMessage httpResponse, Document responseDocument) = await _testContext.ExecuteDeleteAsync<Document>(route); |
| 151 | + (HttpResponseMessage httpResponse, string responseDocument) = await _testContext.ExecuteDeleteAsync<string>(route); |
151 | 152 |
|
152 | 153 | // Assert
|
153 | 154 | httpResponse.Should().HaveStatusCode(HttpStatusCode.NoContent);
|
154 | 155 |
|
155 |
| - responseDocument.Should().BeNull(); |
| 156 | + responseDocument.Should().BeEmpty(); |
156 | 157 |
|
157 | 158 | await _testContext.RunOnDatabaseAsync(async dbContext =>
|
158 | 159 | {
|
@@ -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();
|
@@ -421,21 +422,24 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
|
421 | 422 | string route = $"/orders/{orderWithoutShipment.Id}";
|
422 | 423 |
|
423 | 424 | // Act
|
424 |
| - (HttpResponseMessage httpResponse, ErrorDocument responseDocument) = await _testContext.ExecutePatchAsync<ErrorDocument>(route, requestBody); |
| 425 | + (HttpResponseMessage httpResponse, string responseDocument) = await _testContext.ExecutePatchAsync<string>(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 | + responseDocument.Should().BeEmpty(); |
430 | 431 |
|
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."); |
| 432 | + await _testContext.RunOnDatabaseAsync(async dbContext => |
| 433 | + { |
| 434 | + Shipment existingShipmentInDatabase = |
| 435 | + await dbContext.Shipments.Include(shipment => shipment.Order).FirstWithIdOrDefaultAsync(orderWithShipment.Shipment.Id); |
| 436 | + |
| 437 | + existingShipmentInDatabase.Order.Id.Should().Be(orderWithoutShipment.Id); |
| 438 | + }); |
435 | 439 | }
|
436 | 440 |
|
437 | 441 | [Fact]
|
438 |
| - public async Task Cannot_reassign_dependent_side_of_OneToOne_relationship_with_identifying_foreign_key_through_relationship_endpoint() |
| 442 | + public async Task Can_reassign_dependent_side_of_ZeroOrOneToOne_relationship_through_relationship_endpoint() |
439 | 443 | {
|
440 | 444 | // Arrange
|
441 | 445 | Order orderWithShipment = _fakers.Orders.Generate();
|
@@ -463,17 +467,20 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
|
463 | 467 | string route = $"/orders/{orderWithoutShipment.Id}/relationships/shipment";
|
464 | 468 |
|
465 | 469 | // Act
|
466 |
| - (HttpResponseMessage httpResponse, ErrorDocument responseDocument) = await _testContext.ExecutePatchAsync<ErrorDocument>(route, requestBody); |
| 470 | + (HttpResponseMessage httpResponse, string responseDocument) = await _testContext.ExecutePatchAsync<string>(route, requestBody); |
467 | 471 |
|
468 | 472 | // Assert
|
469 |
| - httpResponse.Should().HaveStatusCode(HttpStatusCode.InternalServerError); |
| 473 | + httpResponse.Should().HaveStatusCode(HttpStatusCode.NoContent); |
470 | 474 |
|
471 |
| - responseDocument.Errors.Should().HaveCount(1); |
| 475 | + responseDocument.Should().BeEmpty(); |
472 | 476 |
|
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."); |
| 477 | + await _testContext.RunOnDatabaseAsync(async dbContext => |
| 478 | + { |
| 479 | + Shipment existingShipmentInDatabase = |
| 480 | + await dbContext.Shipments.Include(shipment => shipment.Order).FirstWithIdOrDefaultAsync(orderWithShipment.Shipment.Id); |
| 481 | + |
| 482 | + existingShipmentInDatabase.Order.Id.Should().Be(orderWithoutShipment.Id); |
| 483 | + }); |
477 | 484 | }
|
478 | 485 | }
|
479 | 486 | }
|
0 commit comments