Skip to content

Commit 9f272e8

Browse files
committed
Add assertion method to clarify intent
1 parent f4980c3 commit 9f272e8

File tree

6 files changed

+25
-14
lines changed

6 files changed

+25
-14
lines changed

test/DapperTests/IntegrationTests/ReadWrite/Relationships/FetchRelationshipTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
5050
responseDocument.Data.SingleValue.Type.Should().Be("people");
5151
responseDocument.Data.SingleValue.Id.Should().Be(todoItem.Owner.StringId);
5252

53-
responseDocument.Meta.Should().BeNull();
53+
responseDocument.Meta.Should().NotContainTotal();
5454

5555
store.SqlCommands.Should().HaveCount(1);
5656

@@ -95,7 +95,7 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
9595

9696
responseDocument.Data.Value.Should().BeNull();
9797

98-
responseDocument.Meta.Should().BeNull();
98+
responseDocument.Meta.Should().NotContainTotal();
9999

100100
store.SqlCommands.Should().HaveCount(1);
101101

test/DapperTests/IntegrationTests/ReadWrite/Resources/FetchResourceTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
128128
responseDocument.Data.SingleValue.Attributes.Should().ContainKey("modifiedAt").WhoseValue.Should().Be(todoItem.LastModifiedAt);
129129
responseDocument.Data.SingleValue.Relationships.Should().OnlyContainKeys("owner", "assignee", "tags");
130130

131-
responseDocument.Meta.Should().BeNull();
131+
responseDocument.Meta.Should().NotContainTotal();
132132

133133
store.SqlCommands.Should().HaveCount(1);
134134

@@ -285,7 +285,7 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
285285
responseDocument.Data.SingleValue.Attributes.Should().ContainKey("displayName").WhoseValue.Should().Be(todoItem.Owner.DisplayName);
286286
responseDocument.Data.SingleValue.Relationships.Should().OnlyContainKeys("account", "ownedTodoItems", "assignedTodoItems");
287287

288-
responseDocument.Meta.Should().BeNull();
288+
responseDocument.Meta.Should().NotContainTotal();
289289

290290
store.SqlCommands.Should().HaveCount(1);
291291

@@ -329,7 +329,7 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
329329

330330
responseDocument.Data.SingleValue.Should().BeNull();
331331

332-
responseDocument.Meta.Should().BeNull();
332+
responseDocument.Meta.Should().NotContainTotal();
333333

334334
store.SqlCommands.Should().HaveCount(1);
335335

test/JsonApiDotNetCoreTests/IntegrationTests/Meta/TopLevelCountTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ public async Task Hides_resource_count_in_create_resource_response()
122122
// Assert
123123
httpResponse.ShouldHaveStatusCode(HttpStatusCode.Created);
124124

125-
responseDocument.Meta.Should().BeNull();
125+
responseDocument.Meta.Should().NotContainTotal();
126126
}
127127

128128
[Fact]
@@ -160,6 +160,6 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
160160
// Assert
161161
httpResponse.ShouldHaveStatusCode(HttpStatusCode.OK);
162162

163-
responseDocument.Meta.Should().BeNull();
163+
responseDocument.Meta.Should().NotContainTotal();
164164
}
165165
}

test/JsonApiDotNetCoreTests/IntegrationTests/ResourceDefinitions/Reading/ResourceDefinitionReadTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,7 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
438438
responseDocument.Data.ManyValue.Should().HaveCount(1);
439439
responseDocument.Data.ManyValue[0].Id.Should().Be(star.Planets.ElementAt(0).StringId);
440440

441-
responseDocument.Meta.Should().BeNull();
441+
responseDocument.Meta.Should().NotContainTotal();
442442

443443
hitCounter.HitExtensibilityPoints.Should().BeEquivalentTo(new[]
444444
{
@@ -534,7 +534,7 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
534534
responseDocument.Data.ManyValue.Should().HaveCount(1);
535535
responseDocument.Data.ManyValue[0].Id.Should().Be(star.Planets.ElementAt(0).StringId);
536536

537-
responseDocument.Meta.Should().BeNull();
537+
responseDocument.Meta.Should().NotContainTotal();
538538

539539
hitCounter.HitExtensibilityPoints.Should().BeEquivalentTo(new[]
540540
{

test/OpenApiNSwagClientTests/LegacyOpenApi/ResponseTests.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ public async Task Getting_resource_collection_translates_response()
102102
// Assert
103103
response.Jsonapi.Should().BeNull();
104104
response.Meta.Should().HaveCount(1);
105-
response.Meta["total-resources"].Should().Be(documentMetaValue);
105+
response.Meta.Should().ContainKey("total-resources").WhoseValue.Should().Be(documentMetaValue);
106106
response.Links.Self.Should().Be(topLevelLink);
107107
response.Links.First.Should().Be(topLevelLink);
108108
response.Links.Last.Should().Be(topLevelLink);
@@ -112,7 +112,7 @@ public async Task Getting_resource_collection_translates_response()
112112
flight.Id.Should().Be(flightId);
113113
flight.Links.Self.Should().Be(flightResourceLink);
114114
flight.Meta.Should().HaveCount(1);
115-
flight.Meta["docs"].Should().Be(flightMetaValue);
115+
flight.Meta.Should().ContainKey("docs").WhoseValue.Should().Be(flightMetaValue);
116116

117117
flight.Attributes.FinalDestination.Should().Be(flightDestination);
118118
flight.Attributes.StopOverDestination.Should().BeNull();
@@ -128,19 +128,19 @@ public async Task Getting_resource_collection_translates_response()
128128
flight.Relationships.Purser.Links.Self.Should().Be($"{flightResourceLink}/relationships/purser");
129129
flight.Relationships.Purser.Links.Related.Should().Be($"{flightResourceLink}/purser");
130130
flight.Relationships.Purser.Meta.Should().HaveCount(1);
131-
flight.Relationships.Purser.Meta["docs"].Should().Be(purserMetaValue);
131+
flight.Relationships.Purser.Meta.Should().ContainKey("docs").WhoseValue.Should().Be(purserMetaValue);
132132

133133
flight.Relationships.CabinCrewMembers.Data.Should().BeNull();
134134
flight.Relationships.CabinCrewMembers.Links.Self.Should().Be($"{flightResourceLink}/relationships/cabin-crew-members");
135135
flight.Relationships.CabinCrewMembers.Links.Related.Should().Be($"{flightResourceLink}/cabin-crew-members");
136136
flight.Relationships.CabinCrewMembers.Meta.Should().HaveCount(1);
137-
flight.Relationships.CabinCrewMembers.Meta["docs"].Should().Be(cabinCrewMembersMetaValue);
137+
flight.Relationships.CabinCrewMembers.Meta.Should().ContainKey("docs").WhoseValue.Should().Be(cabinCrewMembersMetaValue);
138138

139139
flight.Relationships.Passengers.Data.Should().BeNull();
140140
flight.Relationships.Passengers.Links.Self.Should().Be($"{flightResourceLink}/relationships/passengers");
141141
flight.Relationships.Passengers.Links.Related.Should().Be($"{flightResourceLink}/passengers");
142142
flight.Relationships.Passengers.Meta.Should().HaveCount(1);
143-
flight.Relationships.Passengers.Meta["docs"].Should().Be(passengersMetaValue);
143+
flight.Relationships.Passengers.Meta.Should().ContainKey("docs").WhoseValue.Should().Be(passengersMetaValue);
144144
}
145145

146146
[Fact]

test/TestBuildingBlocks/FluentMetaExtensions.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,17 @@ public static void ContainTotal(this GenericDictionaryAssertions<IDictionary<str
1919
element.GetInt32().Should().Be(expected);
2020
}
2121

22+
/// <summary>
23+
/// Asserts that a "meta" dictionary does not contain a single element named "total" when not null.
24+
/// </summary>
25+
[CustomAssertion]
26+
#pragma warning disable AV1553 // Do not use optional parameters with default value null for strings, collections or tasks
27+
public static void NotContainTotal(this GenericDictionaryAssertions<IDictionary<string, object?>, string, object?> source, string? keyName = null)
28+
#pragma warning restore AV1553 // Do not use optional parameters with default value null for strings, collections or tasks
29+
{
30+
source.Subject?.Should().NotContainKey(keyName ?? "total");
31+
}
32+
2233
/// <summary>
2334
/// Asserts that a "meta" dictionary contains a single element named "requestBody" that isn't empty.
2435
/// </summary>

0 commit comments

Comments
 (0)