Skip to content

Commit c8a6012

Browse files
author
Bart Koelman
committed
Adjusted test names for pagination
1 parent d94235d commit c8a6012

File tree

4 files changed

+25
-33
lines changed

4 files changed

+25
-33
lines changed

test/JsonApiDotNetCoreExampleTests/IntegrationTests/Pagination/PaginationWithoutTotalCountTests.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public PaginationWithoutTotalCountTests(ExampleIntegrationTestContext<Startup, A
3333
}
3434

3535
[Fact]
36-
public async Task When_page_size_is_unconstrained_it_should_not_render_pagination_links()
36+
public async Task Hides_pagination_links_when_unconstrained_page_size()
3737
{
3838
// Arrange
3939
var options = (JsonApiOptions) _testContext.Factory.Services.GetRequiredService<IJsonApiOptions>();
@@ -56,7 +56,7 @@ public async Task When_page_size_is_unconstrained_it_should_not_render_paginatio
5656
}
5757

5858
[Fact]
59-
public async Task When_page_size_is_specified_in_query_string_with_no_data_it_should_render_pagination_links()
59+
public async Task Renders_pagination_links_when_page_size_is_specified_in_query_string_with_no_data()
6060
{
6161
// Arrange
6262
var options = (JsonApiOptions) _testContext.Factory.Services.GetRequiredService<IJsonApiOptions>();
@@ -85,7 +85,7 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
8585
}
8686

8787
[Fact]
88-
public async Task When_page_number_is_specified_in_query_string_with_no_data_it_should_render_pagination_links()
88+
public async Task Renders_pagination_links_when_page_number_is_specified_in_query_string_with_no_data()
8989
{
9090
// Arrange
9191
await _testContext.RunOnDatabaseAsync(async dbContext =>
@@ -111,7 +111,7 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
111111
}
112112

113113
[Fact]
114-
public async Task When_page_number_is_specified_in_query_string_with_partially_filled_page_it_should_render_pagination_links()
114+
public async Task Renders_pagination_links_when_page_number_is_specified_in_query_string_with_partially_filled_page()
115115
{
116116
// Arrange
117117
var articles = _fakers.Article.Generate(12);
@@ -143,7 +143,7 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
143143
}
144144

145145
[Fact]
146-
public async Task When_page_number_is_specified_in_query_string_with_full_page_it_should_render_pagination_links()
146+
public async Task Renders_pagination_links_when_page_number_is_specified_in_query_string_with_full_page()
147147
{
148148
// Arrange
149149
var articles = _fakers.Article.Generate(_defaultPageSize * 3);
@@ -175,7 +175,7 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
175175
}
176176

177177
[Fact]
178-
public async Task When_page_number_is_specified_in_query_string_with_full_page_on_secondary_endpoint_it_should_render_pagination_links()
178+
public async Task Renders_pagination_links_when_page_number_is_specified_in_query_string_with_full_page_on_secondary_endpoint()
179179
{
180180
// Arrange
181181
var author = new Author

test/JsonApiDotNetCoreExampleTests/IntegrationTests/Pagination/RangeValidationTests.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public RangeValidationTests(ExampleIntegrationTestContext<Startup, AppDbContext>
3232
}
3333

3434
[Fact]
35-
public async Task When_page_number_is_negative_it_must_fail()
35+
public async Task Cannot_use_negative_page_number()
3636
{
3737
// Arrange
3838
var route = "/api/v1/todoItems?page[number]=-1";
@@ -51,7 +51,7 @@ public async Task When_page_number_is_negative_it_must_fail()
5151
}
5252

5353
[Fact]
54-
public async Task When_page_number_is_zero_it_must_fail()
54+
public async Task Cannot_use_zero_page_number()
5555
{
5656
// Arrange
5757
var route = "/api/v1/todoItems?page[number]=0";
@@ -70,7 +70,7 @@ public async Task When_page_number_is_zero_it_must_fail()
7070
}
7171

7272
[Fact]
73-
public async Task When_page_number_is_positive_it_must_succeed()
73+
public async Task Can_use_positive_page_number()
7474
{
7575
// Arrange
7676
var route = "/api/v1/todoItems?page[number]=20";
@@ -83,7 +83,7 @@ public async Task When_page_number_is_positive_it_must_succeed()
8383
}
8484

8585
[Fact]
86-
public async Task When_page_number_is_too_high_it_must_return_empty_set_of_resources()
86+
public async Task Returns_empty_set_of_resources_when_page_number_is_too_high()
8787
{
8888
// Arrange
8989
var todoItems = _fakers.TodoItem.Generate(3);
@@ -108,7 +108,7 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
108108
}
109109

110110
[Fact]
111-
public async Task When_page_size_is_negative_it_must_fail()
111+
public async Task Cannot_use_negative_page_size()
112112
{
113113
// Arrange
114114
var route = "/api/v1/todoItems?page[size]=-1";
@@ -127,7 +127,7 @@ public async Task When_page_size_is_negative_it_must_fail()
127127
}
128128

129129
[Fact]
130-
public async Task When_page_size_is_zero_it_must_succeed()
130+
public async Task Can_use_zero_page_size()
131131
{
132132
// Arrange
133133
var route = "/api/v1/todoItems?page[size]=0";
@@ -140,7 +140,7 @@ public async Task When_page_size_is_zero_it_must_succeed()
140140
}
141141

142142
[Fact]
143-
public async Task When_page_size_is_positive_it_must_succeed()
143+
public async Task Can_use_positive_page_size()
144144
{
145145
// Arrange
146146
var route = "/api/v1/todoItems?page[size]=50";

test/JsonApiDotNetCoreExampleTests/IntegrationTests/Pagination/RangeValidationWithMaximumTests.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public RangeValidationWithMaximumTests(ExampleIntegrationTestContext<Startup, Ap
2929
}
3030

3131
[Fact]
32-
public async Task When_page_number_is_below_maximum_it_must_succeed()
32+
public async Task Can_use_page_number_below_maximum()
3333
{
3434
// Arrange
3535
const int pageNumber = _maximumPageNumber - 1;
@@ -43,7 +43,7 @@ public async Task When_page_number_is_below_maximum_it_must_succeed()
4343
}
4444

4545
[Fact]
46-
public async Task When_page_number_equals_maximum_it_must_succeed()
46+
public async Task Can_use_page_number_equal_to_maximum()
4747
{
4848
// Arrange
4949
const int pageNumber = _maximumPageNumber;
@@ -57,7 +57,7 @@ public async Task When_page_number_equals_maximum_it_must_succeed()
5757
}
5858

5959
[Fact]
60-
public async Task When_page_number_is_over_maximum_it_must_fail()
60+
public async Task Cannot_use_page_number_over_maximum()
6161
{
6262
// Arrange
6363
const int pageNumber = _maximumPageNumber + 1;
@@ -77,7 +77,7 @@ public async Task When_page_number_is_over_maximum_it_must_fail()
7777
}
7878

7979
[Fact]
80-
public async Task When_page_size_equals_zero_it_must_fail()
80+
public async Task Cannot_use_zero_page_size()
8181
{
8282
// Arrange
8383
var route = "/api/v1/todoItems?page[size]=0";
@@ -96,7 +96,7 @@ public async Task When_page_size_equals_zero_it_must_fail()
9696
}
9797

9898
[Fact]
99-
public async Task When_page_size_is_below_maximum_it_must_succeed()
99+
public async Task Can_use_page_size_below_maximum()
100100
{
101101
// Arrange
102102
const int pageSize = _maximumPageSize - 1;
@@ -110,7 +110,7 @@ public async Task When_page_size_is_below_maximum_it_must_succeed()
110110
}
111111

112112
[Fact]
113-
public async Task When_page_size_equals_maximum_it_must_succeed()
113+
public async Task Can_use_page_size_equal_to_maximum()
114114
{
115115
// Arrange
116116
const int pageSize = _maximumPageSize;
@@ -124,7 +124,7 @@ public async Task When_page_size_equals_maximum_it_must_succeed()
124124
}
125125

126126
[Fact]
127-
public async Task When_page_size_is_over_maximum_it_must_fail()
127+
public async Task Cannot_use_page_size_over_maximum()
128128
{
129129
// Arrange
130130
const int pageSize = _maximumPageSize + 1;

test/MultiDbContextTests/ResourceTests.cs

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using Microsoft.AspNetCore.Mvc.Testing;
77
using MultiDbContextExample;
88
using Newtonsoft.Json;
9+
using TestBuildingBlocks;
910
using Xunit;
1011

1112
namespace MultiDbContextTests
@@ -20,7 +21,7 @@ public ResourceTests(WebApplicationFactory<Startup> factory)
2021
}
2122

2223
[Fact]
23-
public async Task Can_Get_ResourceAs()
24+
public async Task Can_get_ResourceAs()
2425
{
2526
// Arrange
2627
var client = _factory.CreateClient();
@@ -31,7 +32,7 @@ public async Task Can_Get_ResourceAs()
3132
var response = await client.SendAsync(request);
3233

3334
// Assert
34-
AssertStatusCode(HttpStatusCode.OK, response);
35+
response.Should().HaveStatusCode(HttpStatusCode.OK);
3536

3637
string responseBody = await response.Content.ReadAsStringAsync();
3738
var document = JsonConvert.DeserializeObject<Document>(responseBody);
@@ -41,7 +42,7 @@ public async Task Can_Get_ResourceAs()
4142
}
4243

4344
[Fact]
44-
public async Task Can_Get_ResourceBs()
45+
public async Task Can_get_ResourceBs()
4546
{
4647
// Arrange
4748
var client = _factory.CreateClient();
@@ -52,22 +53,13 @@ public async Task Can_Get_ResourceBs()
5253
var response = await client.SendAsync(request);
5354

5455
// Assert
55-
AssertStatusCode(HttpStatusCode.OK, response);
56+
response.Should().HaveStatusCode(HttpStatusCode.OK);
5657

5758
string responseBody = await response.Content.ReadAsStringAsync();
5859
var document = JsonConvert.DeserializeObject<Document>(responseBody);
5960

6061
document.ManyData.Should().HaveCount(1);
6162
document.ManyData[0].Attributes["nameB"].Should().Be("SampleB");
6263
}
63-
64-
private static void AssertStatusCode(HttpStatusCode expected, HttpResponseMessage response)
65-
{
66-
if (expected != response.StatusCode)
67-
{
68-
var responseBody = response.Content.ReadAsStringAsync().Result;
69-
Assert.True(expected == response.StatusCode, $"Got {response.StatusCode} status code instead of {expected}. Response body: {responseBody}");
70-
}
71-
}
7264
}
7365
}

0 commit comments

Comments
 (0)