Skip to content

Commit 2b4ef36

Browse files
committed
Fix incorrect resource inheritance tests
1 parent 37c03ec commit 2b4ef36

File tree

3 files changed

+20
-73
lines changed

3 files changed

+20
-73
lines changed

test/JsonApiDotNetCoreTests/IntegrationTests/ResourceInheritance/Models/Tandem.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ public sealed class Tandem : Bike
1010
[Attr]
1111
public int PassengerCount { get; set; }
1212

13+
[HasOne]
14+
public Box? FoldingDimensions { get; set; }
15+
1316
[HasMany]
1417
public ISet<GenericFeature> Features { get; set; } = new HashSet<GenericFeature>();
1518
}

test/JsonApiDotNetCoreTests/IntegrationTests/ResourceInheritance/ResourceInheritanceReadTests.cs

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
112112
resource.Attributes.ShouldContainKey("gearCount").With(value => value.Should().Be(tandem.GearCount));
113113
resource.Attributes.ShouldContainKey("passengerCount").With(value => value.Should().Be(tandem.PassengerCount));
114114

115-
resource.Relationships.ShouldOnlyContainKeys("manufacturer", "wheels", "cargoBox", "lights", "features");
115+
resource.Relationships.ShouldOnlyContainKeys("manufacturer", "wheels", "cargoBox", "lights", "foldingDimensions", "features");
116116

117117
foreach ((string name, RelationshipObject? value) in resource.Relationships)
118118
{
@@ -235,7 +235,7 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
235235
resource.Attributes.ShouldContainKey("gearCount").With(value => value.Should().Be(tandem.GearCount));
236236
resource.Attributes.ShouldContainKey("passengerCount").With(value => value.Should().Be(tandem.PassengerCount));
237237

238-
resource.Relationships.ShouldOnlyContainKeys("manufacturer", "wheels", "cargoBox", "lights", "features");
238+
resource.Relationships.ShouldOnlyContainKeys("manufacturer", "wheels", "cargoBox", "lights", "foldingDimensions", "features");
239239

240240
foreach ((string name, RelationshipObject? value) in resource.Relationships)
241241
{
@@ -287,7 +287,7 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
287287
resource.Attributes.ShouldContainKey("gearCount").With(value => value.Should().Be(tandem.GearCount));
288288
resource.Attributes.ShouldContainKey("passengerCount").With(value => value.Should().Be(tandem.PassengerCount));
289289

290-
resource.Relationships.ShouldOnlyContainKeys("manufacturer", "wheels", "cargoBox", "lights", "features");
290+
resource.Relationships.ShouldOnlyContainKeys("manufacturer", "wheels", "cargoBox", "lights", "foldingDimensions", "features");
291291

292292
foreach ((string name, RelationshipObject? value) in resource.Relationships)
293293
{
@@ -323,7 +323,7 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
323323
responseDocument.Data.SingleValue.Type.Should().Be("tandems");
324324
responseDocument.Data.SingleValue.Id.Should().Be(tandem.StringId);
325325
responseDocument.Data.SingleValue.Attributes.ShouldOnlyContainKeys("weight", "requiresDriverLicense", "gearCount", "passengerCount");
326-
responseDocument.Data.SingleValue.Relationships.ShouldOnlyContainKeys("manufacturer", "wheels", "cargoBox", "lights", "features");
326+
responseDocument.Data.SingleValue.Relationships.ShouldOnlyContainKeys("manufacturer", "wheels", "cargoBox", "lights", "foldingDimensions", "features");
327327
}
328328

329329
[Fact]
@@ -350,7 +350,7 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
350350
responseDocument.Data.SingleValue.Type.Should().Be("tandems");
351351
responseDocument.Data.SingleValue.Id.Should().Be(tandem.StringId);
352352
responseDocument.Data.SingleValue.Attributes.ShouldOnlyContainKeys("weight", "requiresDriverLicense", "gearCount", "passengerCount");
353-
responseDocument.Data.SingleValue.Relationships.ShouldOnlyContainKeys("manufacturer", "wheels", "cargoBox", "lights", "features");
353+
responseDocument.Data.SingleValue.Relationships.ShouldOnlyContainKeys("manufacturer", "wheels", "cargoBox", "lights", "foldingDimensions", "features");
354354
}
355355

356356
[Fact]
@@ -377,7 +377,7 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
377377
responseDocument.Data.SingleValue.Type.Should().Be("tandems");
378378
responseDocument.Data.SingleValue.Id.Should().Be(tandem.StringId);
379379
responseDocument.Data.SingleValue.Attributes.ShouldOnlyContainKeys("weight", "requiresDriverLicense", "gearCount", "passengerCount");
380-
responseDocument.Data.SingleValue.Relationships.ShouldOnlyContainKeys("manufacturer", "wheels", "cargoBox", "lights", "features");
380+
responseDocument.Data.SingleValue.Relationships.ShouldOnlyContainKeys("manufacturer", "wheels", "cargoBox", "lights", "foldingDimensions", "features");
381381
}
382382

383383
[Fact]
@@ -549,15 +549,15 @@ public async Task Cannot_get_secondary_resource_defined_in_derived_type_at_concr
549549
{
550550
// Arrange
551551
Tandem tandem = _fakers.Tandem.GenerateOne();
552-
tandem.Features = _fakers.GenericFeature.GenerateSet(1);
552+
tandem.FoldingDimensions = _fakers.Box.GenerateOne();
553553

554554
await _testContext.RunOnDatabaseAsync(async dbContext =>
555555
{
556556
dbContext.Vehicles.Add(tandem);
557557
await dbContext.SaveChangesAsync();
558558
});
559559

560-
string route = $"/bikes/{tandem.StringId}/features";
560+
string route = $"/bikes/{tandem.StringId}/foldingDimensions";
561561

562562
// Act
563563
(HttpResponseMessage httpResponse, Document responseDocument) = await _testContext.ExecuteGetAsync<Document>(route);
@@ -570,7 +570,7 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
570570
ErrorObject error = responseDocument.Errors[0];
571571
error.StatusCode.Should().Be(HttpStatusCode.NotFound);
572572
error.Title.Should().Be("The requested relationship does not exist.");
573-
error.Detail.Should().Be("Resource of type 'bikes' does not contain a relationship named 'features'.");
573+
error.Detail.Should().Be("Resource of type 'bikes' does not contain a relationship named 'foldingDimensions'.");
574574
error.Source.Should().BeNull();
575575
}
576576

@@ -1244,7 +1244,7 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
12441244
{
12451245
resource.Id.Should().Be(tandem.StringId);
12461246
resource.Attributes.ShouldOnlyContainKeys("weight", "requiresDriverLicense", "gearCount", "passengerCount");
1247-
resource.Relationships.ShouldOnlyContainKeys("manufacturer", "wheels", "lights", "cargoBox", "features");
1247+
resource.Relationships.ShouldOnlyContainKeys("manufacturer", "wheels", "lights", "cargoBox", "foldingDimensions", "features");
12481248
});
12491249

12501250
responseDocument.Data.ManyValue.Should().ContainSingle(resource => resource.Type == "cars").Subject.With(resource =>
@@ -1547,6 +1547,12 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
15471547
"weight": {{tandem.Weight.ToString(CultureInfo.InvariantCulture)}}
15481548
},
15491549
"relationships": {
1550+
"foldingDimensions": {
1551+
"links": {
1552+
"self": "/tandems/{{tandem.StringId}}/relationships/foldingDimensions",
1553+
"related": "/tandems/{{tandem.StringId}}/foldingDimensions"
1554+
}
1555+
},
15501556
"features": {
15511557
"links": {
15521558
"self": "/tandems/{{tandem.StringId}}/relationships/features",

test/JsonApiDotNetCoreTests/IntegrationTests/ResourceInheritance/ResourceInheritanceWriteTests.cs

Lines changed: 1 addition & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,7 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
486486
responseDocument.Data.SingleValue.ShouldNotBeNull();
487487
responseDocument.Data.SingleValue.Type.Should().Be("tandems");
488488
responseDocument.Data.SingleValue.Attributes.ShouldOnlyContainKeys("weight", "requiresDriverLicense", "gearCount", "passengerCount");
489-
responseDocument.Data.SingleValue.Relationships.ShouldOnlyContainKeys("manufacturer", "wheels", "cargoBox", "lights", "features");
489+
responseDocument.Data.SingleValue.Relationships.ShouldOnlyContainKeys("manufacturer", "wheels", "cargoBox", "lights", "foldingDimensions", "features");
490490

491491
long newTandemId = long.Parse(responseDocument.Data.SingleValue.Id.ShouldNotBeNull());
492492

@@ -620,68 +620,6 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
620620
error.Source.Pointer.Should().Be("/data/relationships/engine/data/type");
621621
}
622622

623-
[Fact]
624-
public async Task Can_create_resource_with_concrete_base_relationship_type_stored_as_derived_type()
625-
{
626-
// Arrange
627-
var carbonWheelStore = _testContext.Factory.Services.GetRequiredService<ResourceTypeCaptureStore<CarbonWheel, long>>();
628-
629-
Tandem existingTandem = _fakers.Tandem.GenerateOne();
630-
631-
await _testContext.RunOnDatabaseAsync(async dbContext =>
632-
{
633-
dbContext.Vehicles.Add(existingTandem);
634-
await dbContext.SaveChangesAsync();
635-
});
636-
637-
var requestBody = new
638-
{
639-
data = new
640-
{
641-
type = "carbonWheels",
642-
relationships = new
643-
{
644-
vehicle = new
645-
{
646-
data = new
647-
{
648-
type = "bikes",
649-
id = existingTandem.StringId
650-
}
651-
}
652-
}
653-
}
654-
};
655-
656-
const string route = "/carbonWheels";
657-
658-
// Act
659-
(HttpResponseMessage httpResponse, Document responseDocument) = await _testContext.ExecutePostAsync<Document>(route, requestBody);
660-
661-
// Assert
662-
httpResponse.ShouldHaveStatusCode(HttpStatusCode.Created);
663-
664-
responseDocument.Data.SingleValue.ShouldNotBeNull();
665-
responseDocument.Data.SingleValue.Type.Should().Be("carbonWheels");
666-
responseDocument.Data.SingleValue.Attributes.ShouldNotBeEmpty();
667-
responseDocument.Data.SingleValue.Relationships.ShouldNotBeEmpty();
668-
669-
long newCarbonWheelId = long.Parse(responseDocument.Data.SingleValue.Id.ShouldNotBeNull());
670-
671-
await _testContext.RunOnDatabaseAsync(async dbContext =>
672-
{
673-
CarbonWheel carbonWheelInDatabase = await dbContext.CarbonWheels.Include(wheel => wheel.Vehicle).FirstWithIdAsync(newCarbonWheelId);
674-
675-
carbonWheelInDatabase.Should().BeOfType<CarbonWheel>();
676-
carbonWheelInDatabase.Vehicle.ShouldNotBeNull();
677-
carbonWheelInDatabase.Vehicle.Should().BeOfType<Tandem>();
678-
carbonWheelInDatabase.Vehicle.Id.Should().Be(existingTandem.Id);
679-
});
680-
681-
carbonWheelStore.AssertLeftType<CarbonWheel>();
682-
carbonWheelStore.AssertRightTypes(typeof(Tandem));
683-
}
684-
685623
[Fact]
686624
public async Task Can_create_resource_with_concrete_base_ToOne_relationship_type_stored_as_derived_type_at_resource_endpoint()
687625
{

0 commit comments

Comments
 (0)