Skip to content

Commit 8cad017

Browse files
committed
Simplify assertions (ShouldContainKey already checks for null)
1 parent ac7d3ae commit 8cad017

File tree

3 files changed

+6
-23
lines changed

3 files changed

+6
-23
lines changed

Diff for: test/JsonApiDotNetCoreTests/IntegrationTests/Meta/TopLevelCountTests.cs

-4
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,6 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
5252
// Assert
5353
httpResponse.ShouldHaveStatusCode(HttpStatusCode.OK);
5454

55-
responseDocument.Meta.ShouldNotBeNull();
56-
5755
responseDocument.Meta.ShouldContainKey("total").With(value =>
5856
{
5957
JsonElement element = value.Should().BeOfType<JsonElement>().Subject;
@@ -78,8 +76,6 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
7876
// Assert
7977
httpResponse.ShouldHaveStatusCode(HttpStatusCode.OK);
8078

81-
responseDocument.Meta.ShouldNotBeNull();
82-
8379
responseDocument.Meta.ShouldContainKey("total").With(value =>
8480
{
8581
JsonElement element = value.Should().BeOfType<JsonElement>().Subject;

Diff for: test/JsonApiDotNetCoreTests/IntegrationTests/ResourceInheritance/ResourceInheritanceReadTests.cs

+6-18
Original file line numberDiff line numberDiff line change
@@ -614,19 +614,15 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
614614
resource.Links.ShouldNotBeNull();
615615
resource.Links.Self.Should().Be($"/chromeWheels/{resource.Id}");
616616

617-
resource.Attributes.ShouldHaveCount(2);
618-
resource.Attributes.ShouldContainKey("radius");
619-
resource.Attributes.ShouldContainKey("paintColor");
617+
resource.Attributes.ShouldOnlyContainKeys("radius", "paintColor");
620618
}
621619

622620
foreach (ResourceObject resource in responseDocument.Data.ManyValue.Where(value => value.Type == "carbonWheels"))
623621
{
624622
resource.Links.ShouldNotBeNull();
625623
resource.Links.Self.Should().Be($"/carbonWheels/{resource.Id}");
626624

627-
resource.Attributes.ShouldHaveCount(2);
628-
resource.Attributes.ShouldContainKey("radius");
629-
resource.Attributes.ShouldContainKey("hasTube");
625+
resource.Attributes.ShouldOnlyContainKeys("radius", "hasTube");
630626
}
631627

632628
foreach (ResourceObject resource in responseDocument.Data.ManyValue)
@@ -686,19 +682,15 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
686682
resource.Links.ShouldNotBeNull();
687683
resource.Links.Self.Should().Be($"/chromeWheels/{resource.Id}");
688684

689-
resource.Attributes.ShouldHaveCount(2);
690-
resource.Attributes.ShouldContainKey("radius");
691-
resource.Attributes.ShouldContainKey("paintColor");
685+
resource.Attributes.ShouldOnlyContainKeys("radius", "paintColor");
692686
}
693687

694688
foreach (ResourceObject resource in responseDocument.Data.ManyValue.Where(value => value.Type == "carbonWheels"))
695689
{
696690
resource.Links.ShouldNotBeNull();
697691
resource.Links.Self.Should().Be($"/carbonWheels/{resource.Id}");
698692

699-
resource.Attributes.ShouldHaveCount(2);
700-
resource.Attributes.ShouldContainKey("radius");
701-
resource.Attributes.ShouldContainKey("hasTube");
693+
resource.Attributes.ShouldOnlyContainKeys("radius", "hasTube");
702694
}
703695

704696
foreach (ResourceObject resource in responseDocument.Data.ManyValue)
@@ -752,19 +744,15 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
752744
resource.Links.ShouldNotBeNull();
753745
resource.Links.Self.Should().Be($"/chromeWheels/{resource.Id}");
754746

755-
resource.Attributes.ShouldHaveCount(2);
756-
resource.Attributes.ShouldContainKey("radius");
757-
resource.Attributes.ShouldContainKey("paintColor");
747+
resource.Attributes.ShouldOnlyContainKeys("radius", "paintColor");
758748
}
759749

760750
foreach (ResourceObject resource in responseDocument.Data.ManyValue.Where(value => value.Type == "carbonWheels"))
761751
{
762752
resource.Links.ShouldNotBeNull();
763753
resource.Links.Self.Should().Be($"/carbonWheels/{resource.Id}");
764754

765-
resource.Attributes.ShouldHaveCount(2);
766-
resource.Attributes.ShouldContainKey("radius");
767-
resource.Attributes.ShouldContainKey("hasTube");
755+
resource.Attributes.ShouldOnlyContainKeys("radius", "hasTube");
768756
}
769757

770758
foreach (ResourceObject resource in responseDocument.Data.ManyValue)

Diff for: test/NoEntityFrameworkTests/WorkItemTests.cs

-1
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,6 @@ public async Task Can_create_WorkItem()
119119
httpResponse.ShouldHaveStatusCode(HttpStatusCode.Created);
120120

121121
responseDocument.Data.SingleValue.ShouldNotBeNull();
122-
responseDocument.Data.SingleValue.Attributes.ShouldNotBeEmpty();
123122
responseDocument.Data.SingleValue.Attributes.ShouldContainKey("isBlocked").With(value => value.Should().Be(newWorkItem.IsBlocked));
124123
responseDocument.Data.SingleValue.Attributes.ShouldContainKey("title").With(value => value.Should().Be(newWorkItem.Title));
125124
responseDocument.Data.SingleValue.Attributes.ShouldContainKey("durationInHours").With(value => value.Should().Be(newWorkItem.DurationInHours));

0 commit comments

Comments
 (0)